All Projects → juancarlospaco → nim-new-backend

juancarlospaco / nim-new-backend

Licence: MIT license
Template to create a new Backend for Nim, based on the JavaScript Backend, as minimalistic as possible to focus on codegen

Programming Languages

nim
578 projects

Labels

Projects that are alternatives of or similar to nim-new-backend

razcal
Build cross platform desktop app with Lua, MoonScript, and Layout Language
Stars: ✭ 15 (-62.5%)
Mutual labels:  nim-lang
thermopi
A Nest-like intelligent thermostat implementation for the Raspberry Pi
Stars: ✭ 16 (-60%)
Mutual labels:  nim-lang
nimfmt
Nim code formatter / linter / style checker
Stars: ✭ 75 (+87.5%)
Mutual labels:  nim-lang
microparsec
⭐ A performant Nim parsing library built for humans.
Stars: ✭ 26 (-35%)
Mutual labels:  nim-lang
koi
Immediate mode UI for Nim
Stars: ✭ 27 (-32.5%)
Mutual labels:  nim-lang
nim-package-directory
Nim package directory - documentation builder
Stars: ✭ 47 (+17.5%)
Mutual labels:  nim-lang
nim-redisparser
RESP(REdis Serialization Protocol) Serialization for Nim
Stars: ✭ 16 (-60%)
Mutual labels:  nim-lang
geoguessrnim
GeoGuessr browser plugin, hide Ads, Filters for StreetView and Mapillary for Chromium and Firefox
Stars: ✭ 17 (-57.5%)
Mutual labels:  nim-lang
loco
Loco: Localization Package for Nim Apps
Stars: ✭ 20 (-50%)
Mutual labels:  nim-lang
ll
ll - a more informative `ls`, based on `k`
Stars: ✭ 24 (-40%)
Mutual labels:  nim-lang
Decimal
A big/arbitrary precision Decimal class in pure Nim
Stars: ✭ 26 (-35%)
Mutual labels:  nim-lang
nim-cocoa
macOS GUI Library for the Nim Programming Language
Stars: ✭ 28 (-30%)
Mutual labels:  nim-lang
nim-mathexpr
Tiny math expression evaluator library implemented in pure Nim
Stars: ✭ 58 (+45%)
Mutual labels:  nim-lang
badgemaker
The Nim badgemaker tool.
Stars: ✭ 15 (-62.5%)
Mutual labels:  nim-lang
Unchained
A fully type safe, compile time only units library.
Stars: ✭ 70 (+75%)
Mutual labels:  nim-lang
suru
A tqdm-style progress bar in Nim
Stars: ✭ 40 (+0%)
Mutual labels:  nim-lang
livecore
A hardcore livecoding system for realtime audio synth.
Stars: ✭ 25 (-37.5%)
Mutual labels:  nim-lang
genoiser
use the noise
Stars: ✭ 15 (-62.5%)
Mutual labels:  nim-lang
nimSocks
A filtering SOCKS proxy server and client library written in nim.
Stars: ✭ 51 (+27.5%)
Mutual labels:  nim-lang
nim-presentation-slides
Nim Presentation Slides and Examples.
Stars: ✭ 30 (-25%)
Mutual labels:  nim-lang

Nim New Backend Template

  • Template to create a new Backend for Nim, based on the JavaScript Backend.
  • Edit 4 files only to create your new Nim Backend, as minimal as possible.
  • As example it implements a new Python Backend (unfinished, PR Welcome).

Use

$ git clone https://github.com/juancarlospaco/nim-new-backend.git
$ cd nim-new-backend
$ git clone https://github.com/nim-lang/Nim.git

$ cp --verbose --force compiler/jsgen.nim Nim/compiler/jsgen.nim
'compiler/jsgen.nim' -> 'Nim/compiler/jsgen.nim'

$ cp --verbose --force compiler/jstypes.nim Nim/compiler/jstypes.nim
'compiler/jstypes.nim' -> 'Nim/compiler/jstypes.nim'

$ cp --verbose --force lib/system/jssys.nim Nim/lib/system/jssys.nim
'lib/system/jssys.nim' -> 'Nim/lib/system/jssys.nim'

$ cp --verbose --force lib/system/reprjs.nim Nim/lib/system/reprjs.nim
'lib/system/reprjs.nim' -> 'Nim/lib/system/reprjs.nim'

$ nim c Nim/koch.nim
$ Nim/koch temp js -d:release -d:danger -d:nodejs example.nim
  • Open example.js. A new Nim compiler binary executable will be saved to ./Nim/bin/nim.
  • Hack code until you get valid code generated, then compile the Nim compiler again.
$ Nim/koch temp js -d:release -d:danger -d:nodejs example.nim

Code to look at: See the dependency file generator, is a minimal working codegen:

Optional: Rename example.js to the proper file extension you are compiling to, example mv example.js example.py.

Example

echo 42

⬆️ Nim ⬆️          ⬇️ Python ⬇️

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Powered by Nim v1.1.1 https://nim-lang.org
import sys
from typing import *
sys.dont_write_bytecode: Bool = True  # type: Bool
print(str("42"))

Requisites

FAQ

  • Why not use Git SubRepos or Git SubTrees or Git SubModules?.

If you know Git SubRepos and Git SubTrees and Git SubModules, then you wont need this simplified repo.

But if you have an idea to make this less complex, not more complex, then send PR.

  • Why not use SymLinks?.

It may produce errors on import and include.

  • But it generates a *.js?.

Yes, but file extensions, tutorials, documentation, cosmetics, etc can be left for last details.

  • Why Python?.

It is the second on popularity behind JavaScript, but Nim already has JavaScript.

To clean up code because JavaScript is kinda weird which also makes codegen weird.

I imagine creating a Ruby or Go Backend from a Python backend is easier than from C.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].