diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-30 14:26:08 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-30 14:26:28 -0700 |
| commit | dc0c940d65f9922407a101277ccab9e5bfa70c67 (patch) | |
| tree | c3270950e5855918566f9686e38831e6793e91e2 | |
| parent | 54906c0553147f29807c945eace6724d06ff570c (diff) | |
Added bit library and support for checking Lua version and whether
LuaJIT is being used.
| -rw-r--r-- | nomsu_compiler.lua | 14 | ||||
| -rw-r--r-- | nomsu_compiler.moon | 12 |
2 files changed, 22 insertions, 4 deletions
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua index 486e3e6..4974bce 100644 --- a/nomsu_compiler.lua +++ b/nomsu_compiler.lua @@ -204,7 +204,6 @@ do loadstring = loadstring, type = type, select = select, - debug = debug, math = math, io = io, load = load, @@ -213,6 +212,11 @@ do list = list, dict = dict } + if jit then + to_add.bit = require('bit') + elseif _VERSION == "Lua 5.2" then + to_add.bit = bit32 + end for k, v in pairs(to_add) do NomsuCompiler[k] = v end @@ -365,6 +369,12 @@ do return _accum_0 end)(), "\n") return LuaCode(tree.source, "TESTS[" .. tostring(repr(tostring(tree.source))) .. "] = ", repr(test_str)) + end, + ["is jit"] = function(self, tree, _code) + return LuaCode.Value(tree.source, jit and "true" or "false") + end, + ["Lua version"] = function(self, tree, _code) + return LuaCode.Value(tree.source, repr(_VERSION)) end }, { __index = function(self, stub) @@ -1159,7 +1169,7 @@ do end end nomsu:append(interp_nomsu) - if interp_nomsu:is_multiline() then + if interp_nomsu:is_multiline() and i < #tree then nomsu:append("\n..") end end diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon index abb48f7..a8eba0c 100644 --- a/nomsu_compiler.moon +++ b/nomsu_compiler.moon @@ -109,11 +109,13 @@ with NomsuCompiler :next, :unpack, :setmetatable, :coroutine, :rawequal, :getmetatable, :pcall, :error, :package, :os, :require, :tonumber, :tostring, :string, :xpcall, :module, :print, :loadfile, :rawset, :_VERSION, :collectgarbage, :rawget, :rawlen, - :table, :assert, :dofile, :loadstring, :type, :select, :debug, :math, :io, :load, + :table, :assert, :dofile, :loadstring, :type, :select, :math, :io, :load, :pairs, :ipairs, -- Nomsu types: :list, :dict, } + if jit then to_add.bit = require('bit') + elseif _VERSION == "Lua 5.2" then to_add.bit = bit32 for k,v in pairs(to_add) do NomsuCompiler[k] = v for k,v in pairs(AST) do NomsuCompiler[k] = v .LuaCode = LuaCode @@ -230,6 +232,12 @@ with NomsuCompiler ["test %"]: (tree, _body)=> test_str = table.concat [tostring(@tree_to_nomsu(line)) for line in *_body], "\n" LuaCode tree.source, "TESTS[#{repr(tostring(tree.source))}] = ", repr(test_str) + + ["is jit"]: (tree, _code)=> + return LuaCode.Value(tree.source, jit and "true" or "false") + + ["Lua version"]: (tree, _code)=> + return LuaCode.Value(tree.source, repr(_VERSION)) }, { __index: (stub)=> if math_expression\match(stub) @@ -743,7 +751,7 @@ with NomsuCompiler elseif bit.type != "List" and bit.type != "Dict" interp_nomsu\parenthesize! nomsu\append interp_nomsu - if interp_nomsu\is_multiline! + if interp_nomsu\is_multiline! and i < #tree nomsu\append "\n.." nomsu = NomsuCode(tree.source) add_text(nomsu, tree) |
