diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-02-05 15:34:57 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-02-05 15:35:06 -0800 |
| commit | e8d5d2a24061347a96ae9feda45ceb0d6dca09be (patch) | |
| tree | 51f97cfeb21af11a598c000a4758262e2082e8c1 /nomsu.moon | |
| parent | d02b4b8718fd06116a52b2be57c81f3f44a4ba33 (diff) | |
Added check for circular imports.
Diffstat (limited to 'nomsu.moon')
| -rwxr-xr-x | nomsu.moon | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -155,6 +155,7 @@ class NomsuCompiler @[key] = id return id }) + @use_stack = {} @compilestack = {} @debug = false @@ -323,9 +324,15 @@ class NomsuCompiler else error("Invalid filetype for #{filename}", 0) - require_file: (filename)=> + use_file: (filename)=> loaded = @environment.LOADED if not loaded[filename] + for i,f in ipairs @use_stack + if f == filename + loop = [@use_stack[j] for j=i,#@use_stack] + insert loop, filename + error("Circular import, this loops forever: #{concat loop, " -> "}") + insert @use_stack, filename loaded[filename] = @run_file(filename) or true return loaded[filename] @@ -933,8 +940,8 @@ class NomsuCompiler @define_compile_action "use %filename", get_line_no!, (_filename)-> filename = nomsu\tree_to_value(_filename) - nomsu\require_file(filename) - return expr:"nomsu:require_file(#{repr filename});" + nomsu\use_file(filename) + return expr:"nomsu:use_file(#{repr filename});" -- Only run this code if this file was run directly with command line arguments, and not require()'d: if arg and debug.getinfo(2).func != require |
