diff options
author | Eduardo Julian | 2017-05-09 17:48:27 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-05-09 17:48:27 -0400 |
commit | dd5220e13b03c8f85972feac535a34ef64525222 (patch) | |
tree | 2ac08a118eaa63f11c2397a08eaca74d199f2d1e /new-luxc/source/luxc/module | |
parent | 7b74c1258f345d576b0c798303b0ed28f1734368 (diff) |
- Added tests for some kinds of analysis.
- WIP: Porting more code.
Diffstat (limited to '')
-rw-r--r-- | new-luxc/source/luxc/module.lux | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/new-luxc/source/luxc/module.lux b/new-luxc/source/luxc/module.lux index e5848fccb..1e6174143 100644 --- a/new-luxc/source/luxc/module.lux +++ b/new-luxc/source/luxc/module.lux @@ -17,12 +17,35 @@ #;module-anns (list) #;module-state #;Active}) +(def: #export (define (^@ full-name [module-name def-name]) + definition) + (-> Ident Def (Lux Unit)) + (function [compiler] + (case (&;pl-get module-name (get@ #;modules compiler)) + (#;Some module) + (case (&;pl-get def-name (get@ #;defs module)) + #;None + (#E;Success [(update@ #;modules + (&;pl-put module-name + (update@ #;defs + (: (-> (List [Text Def]) (List [Text Def])) + (|>. (#;Cons [def-name definition]))) + module)) + compiler) + []]) + + (#;Some already-existing) + (#E;Error (format "Cannot re-define definiton: " (%ident full-name)))) + + #;None + (#E;Error (format "Cannot define in unknown module: " module-name))))) + (def: #export (create hash name) (-> Nat Text (Lux Module)) (function [compiler] (let [module (new-module hash)] (#E;Success [(update@ #;modules - (&;pl::put name module) + (&;pl-put name module) compiler) module])))) @@ -30,19 +53,24 @@ [(def: #export (<flagger> module-name) (-> Text (Lux Unit)) (function [compiler] - (case (|> compiler (get@ #;modules) (&;pl::get module-name)) + (case (|> compiler (get@ #;modules) (&;pl-get module-name)) (#;Some module) - (#E;Success [(update@ #;modules - (&;pl::put module-name (set@ #;module-state <tag> module)) - compiler) - []]) + (let [active? (case (get@ #;module-state module) + #;Active true + _ false)] + (if active? + (#E;Success [(update@ #;modules + (&;pl-put module-name (set@ #;module-state <tag> module)) + compiler) + []]) + (#E;Error "Can only change the state of a currently-active module."))) #;None (#E;Error (format "Module does not exist: " module-name))))) (def: #export (<asker> module-name) (-> Text (Lux Bool)) (function [compiler] - (case (|> compiler (get@ #;modules) (&;pl::get module-name)) + (case (|> compiler (get@ #;modules) (&;pl-get module-name)) (#;Some module) (#E;Success [compiler (case (get@ #;module-state module) |