aboutsummaryrefslogtreecommitdiff
path: root/nomsu_environment.moon
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-09 16:40:36 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-11-09 16:41:19 -0800
commit69aaea030e08e083151aa25b8080eddd0d4c1683 (patch)
tree6cd90a65e6828f60cc052c4a1b33a4a4c0d65570 /nomsu_environment.moon
parenta2f07415c5284bf94c146cea6eed4a15f171b9ab (diff)
No longer passing `tree` to every compile action. Now, you can just
return a LuaCode object, and it will automatically get a source from `tree` if it didn't already have a source. Plus some fixes/cleanup.
Diffstat (limited to 'nomsu_environment.moon')
-rw-r--r--nomsu_environment.moon17
1 files changed, 13 insertions, 4 deletions
diff --git a/nomsu_environment.moon b/nomsu_environment.moon
index b216242..bfc5edc 100644
--- a/nomsu_environment.moon
+++ b/nomsu_environment.moon
@@ -32,6 +32,7 @@ for version=1,999
{:tree_to_nomsu, :tree_to_inline_nomsu} = require "nomsu_decompiler"
compile = require('nomsu_compiler')
+_currently_running_files = List{} -- Used to check for circular imports in run_file_1_in
nomsu_environment = Importer{
NOMSU_COMPILER_VERSION: 12, NOMSU_SYNTAX_VERSION: max_parser_version
-- Lua stuff:
@@ -57,7 +58,7 @@ nomsu_environment = Importer{
_1_parsed: (nomsu_code)->
if type(nomsu_code) == 'string'
filename = Files.spoof(nomsu_code)
- nomsu_code = NomsuCode(Source(filename, 1, #nomsu_code), nomsu_code)
+ nomsu_code = NomsuCode\from(Source(filename, 1, #nomsu_code), nomsu_code)
source = nomsu_code.source
nomsu_code = tostring(nomsu_code)
version = nomsu_code\match("^#![^\n]*nomsu[ ]+-V[ ]*([0-9.]+)")
@@ -88,7 +89,7 @@ nomsu_environment = Importer{
run_1_in: (to_run, environment)->
if type(to_run) == 'string'
filename = Files.spoof(to_run)
- to_run = NomsuCode(Source(filename, 1, #to_run), to_run)
+ to_run = NomsuCode\from(Source(filename, 1, #to_run), to_run)
ret = environment.run_1_in(to_run, environment)
return ret
elseif NomsuCode\is_instance(to_run)
@@ -151,6 +152,13 @@ nomsu_environment = Importer{
if environment.FILE_CACHE[path]
import_to_1_from(environment, environment.FILE_CACHE[path])
return
+ if _currently_running_files\has(path)
+ i = _currently_running_files\index_of(path)
+ _currently_running_files\add path
+ circle = _currently_running_files\from_1_to(i, -1)
+ print(_currently_running_files, path)
+ error("Circular import detected:\n "..circle\joined_with("\n..imports "))
+ _currently_running_files\add path
mod = _1_forked(environment)
assert mod._1_parsed
mod._ENV = mod
@@ -160,13 +168,14 @@ nomsu_environment = Importer{
-- TODO: don't automatically use precompiled version?
code = if optimization != 0 and Files.read(lua_filename)
file = Files.read(lua_filename)
- LuaCode(Source(filename, 1, #file), file)
+ LuaCode\from(Source(filename, 1, #file), file)
else
file = Files.read(filename)
- NomsuCode(Source(filename, 1, #file), file)
+ NomsuCode\from(Source(filename, 1, #file), file)
environment.run_1_in(code, mod)
import_to_1_from(environment, mod)
environment.FILE_CACHE[path] = mod
+ _currently_running_files\remove!
compile_error_at: (tree, err_msg, hint=nil)->
err_str = pretty_error{