natnat-mc / MoonPlus

Moonscript compiler written in C++.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MoonPlus

macOS Linux Windows
CI CI Build status

MoonPlus is a compiler with features from Moonscript language 0.5.0 and adopting new features to make Moonscript more up to date.

Since original Moonscript has been used to write web framework lapis and run a few business web sites like itch.io and streak.club with some large code bases. The original language is getting too hard to adopt new features for those may break the stablility for existing applications.

So MoonPlus is a new code base for pushing the language to go forward and being a playground to try introducing new language syntax or programing paradigms to make Moonscript language more expressive and productive.

Features

  • No other dependencies needed except modified parserlib library from Achilleas Margaritis with some performance enhancement. lpeg library is no longer needed.
  • Written in C++17.
  • Support full Moonscript language features, generate the same Lua codes with original compiler.
  • Reserve line numbers from Moonscript sources in compiled Lua codes to help with debugging.
  • See other details in the changelog.

Installation & Usage

  • Lua Module

  Build moonp.so file with

> make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua

  Then get the binary file from path bin/shared/moonp.so.

  Or you can install luarocks, a package manager for Lua modules. Then install it as a Lua module with

> luarocks install moonplus

  Then require the MoonPlus module in Lua:

require("moonp")("main") -- require `main.mp`

local moonp = require("moonp")
local codes, err, globals = moonp.to_lua([[
f = ->
  print "hello world"
f!
]],{
  implicit_return_root = true,
  reserve_line_number = true,
  lint_global = true
})
  • Binary Tool

  Clone this repo, then build and install executable with:

> make install

  Build MoonPlus tool without macro feature:

> make install NO_MACRO=true

  Build MoonPlus tool without built-in Lua binary:

> make install NO_LUA=true

  Use MoonPlus tool with:

> moonp -h
Usage: moonp [options|files|directories] ...

   -h       Print this message
   -e str   Execute a file or raw codes
   -t path  Specify where to place compiled files
   -o file  Write output to file
   -s       Use spaces in generated codes instead of tabs
   -m       Generate minified codes
   -p       Write output to standard out
   -b       Dump compile time (doesn't write output)
   -l       Write line numbers from source codes
   -v       Print version
   --       Read from standard in, print to standard out
            (Must be first and only argument)

   Execute without options to enter REPL, type symbol '$'
   in a single line to start/stop multi-line mode

  Use cases:
  Recursively compile every moon+ file with extension .mp under current path: moonp .
  Compile and save results to a target path: moonp -t /target/path/ .
  Compile and reserve debug info: moonp -l .
  Compile and generate minified codes: moonp -m .
  Execute raw codes: moonp -e 'print 123'
  Execute a moon+ file: moonp -e main.mp

Editor Support

License

MIT

About

Moonscript compiler written in C++.

License:MIT License


Languages

Language:C 50.8%Language:C++ 35.7%Language:Lua 12.3%Language:Makefile 0.9%Language:Objective-C 0.1%Language:CMake 0.1%Language:Dockerfile 0.0%