diff options
author | Eduardo Julian | 2017-11-14 23:57:15 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-11-14 23:57:15 -0400 |
commit | 772ff99830d133b2e36ad1b09c66223ef1085c71 (patch) | |
tree | 66588cb41e82c1334e4a75f44ad6014a14fbc776 | |
parent | a3b9b19231047ec6da8decfc7d45db0598622651 (diff) |
- Modified the syntax for module definitions.
- Fixed some bugs.
-rw-r--r-- | luxc/src/lux/analyser.clj | 17 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/syntax.lux | 11 | ||||
-rw-r--r-- | new-luxc/source/luxc/lang/translation.lux | 42 | ||||
-rw-r--r-- | stdlib/source/lux.lux | 2 |
4 files changed, 46 insertions, 26 deletions
diff --git a/luxc/src/lux/analyser.clj b/luxc/src/lux/analyser.clj index 6fc5986ac..13bf3bc61 100644 --- a/luxc/src/lux/analyser.clj +++ b/luxc/src/lux/analyser.clj @@ -157,6 +157,11 @@ (&/with-analysis-meta cursor exo-type (&&lux/analyse-function analyse exo-type ?self ?arg ?body))) + "lux module" + (|let [(&/$Cons ?meta (&/$Nil)) parameters] + (&/with-cursor cursor + (&&lux/analyse-module analyse optimize eval! compile-module ?meta))) + ;; else (&/with-analysis-meta cursor exo-type (cond (.startsWith ^String ?procedure "jvm") @@ -170,18 +175,6 @@ :else (&&common/analyse-proc analyse exo-type ?procedure parameters)))) - (&/$Symbol _ command-name) - (case command-name - "_lux_module" - (|let [(&/$Cons ?meta (&/$Nil)) parameters] - (&/with-cursor cursor - (&&lux/analyse-module analyse optimize eval! compile-module ?meta))) - - ;; else - (&/with-cursor cursor - (|do [=fn (just-analyse analyse (&/T [command-meta command]))] - (&&lux/analyse-apply analyse cursor exo-type macro-caller =fn parameters)))) - (&/$Nat idx) (&/with-analysis-meta cursor exo-type (&&lux/analyse-variant analyse (&/$Right exo-type) idx nil parameters)) diff --git a/new-luxc/source/luxc/lang/syntax.lux b/new-luxc/source/luxc/lang/syntax.lux index 2d8cb364a..9fe4939a2 100644 --- a/new-luxc/source/luxc/lang/syntax.lux +++ b/new-luxc/source/luxc/lang/syntax.lux @@ -27,7 +27,8 @@ (;module: lux (lux (control monad - ["p" parser "p/" Monad<Parser>]) + ["p" parser "p/" Monad<Parser>] + ["ex" exception #+ exception:]) (data [bool] [text] ["e" error] @@ -584,6 +585,9 @@ [tag #;Tag (p;after (l;this "#") (ident^ current-module)) +1] ) +(exception: #export End-Of-File) +(exception: #export Unrecognized-Input) + (def: (ast current-module) (-> Text Cursor (l;Lexer [Cursor Code])) (: (-> Cursor (l;Lexer [Cursor Code])) @@ -602,6 +606,11 @@ (symbol current-module where) (tag current-module where) (text where) + (do @ + [end? l;end?] + (if end? + (p;fail (End-Of-File current-module)) + (p;fail (Unrecognized-Input current-module)))) ))))) (def: #export (parse current-module [where offset source]) diff --git a/new-luxc/source/luxc/lang/translation.lux b/new-luxc/source/luxc/lang/translation.lux index 62b56783c..5b11a8e39 100644 --- a/new-luxc/source/luxc/lang/translation.lux +++ b/new-luxc/source/luxc/lang/translation.lux @@ -14,7 +14,8 @@ (world [file #+ File])) (luxc ["&" base] [";L" host] - (host [";H" macro]) + (host [";H" macro] + ["$" jvm]) ["&;" io] ["&;" module] ["&;" eval] @@ -73,20 +74,26 @@ ([#;UnivQ] [#;ExQ]) )) +(def: (process-annotations annsC) + (-> Code (Meta [$;Inst Code])) + (do meta;Monad<Meta> + [[_ annsA] (&;with-scope + (&;with-expected-type Code + (analyse annsC))) + annsI (expressionT;translate (expressionS;synthesize annsA)) + annsV (evalT;eval annsI)] + (wrap [annsI (:! Code annsV)]))) + (def: (translate code) (-> Code (Meta Unit)) (case code - (^code ("lux def" (~ [_ (#;Symbol ["" def-name])]) (~ valueC) (~ metaC))) + (^code ("lux def" (~ [_ (#;Symbol ["" def-name])]) (~ valueC) (~ annsC))) (hostL;with-context def-name (&;with-fresh-type-env (do meta;Monad<Meta> - [[_ metaA] (&;with-scope - (&;with-expected-type Code - (analyse metaC))) - metaI (expressionT;translate (expressionS;synthesize metaA)) - metaV (evalT;eval metaI) + [[annsI annsV] (process-annotations annsC) [_ valueT valueA] (&;with-scope - (if (meta;type? (:! Code metaV)) + (if (meta;type? (:! Code annsV)) (do @ [valueA (&;with-expected-type Type (analyse valueC))] @@ -97,7 +104,7 @@ (clean valueT)) valueI (expressionT;translate (expressionS;synthesize valueA)) _ (&;with-scope - (statementT;translate-def def-name valueT valueI metaI (:! Code metaV)))] + (statementT;translate-def def-name valueT valueI annsI annsV))] (wrap [])))) (^code ("lux program" (~ [_ (#;Symbol ["" program-args])]) (~ programC))) @@ -108,6 +115,11 @@ programI (expressionT;translate (expressionS;synthesize programA))] (statementT;translate-program program-args programI)) + (^code ("lux module" (~ annsC))) + (do meta;Monad<Meta> + [[annsI annsV] (process-annotations annsC)] + (&;fail (%code annsV))) + (^code ((~ [_ (#;Symbol macro-name)]) (~@ args))) (do meta;Monad<Meta> [macro-name (meta;normalize macro-name) @@ -130,9 +142,15 @@ (def: (exhaust action) (All [a] (-> (Meta a) (Meta Unit))) - (do meta;Monad<Meta> - [result action] - (exhaust action))) + (function [compiler] + (case (action compiler) + (#e;Success [compiler' _]) + ((exhaust action) compiler') + + (#e;Error error) + (if (ex;match? &syntax;End-Of-File error) + (#e;Success [compiler []]) + (#e;Error error))))) (def: prelude Text "lux") diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index d70318f83..407e895a3 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -4788,7 +4788,7 @@ imports) =meta (process-def-meta (list& [(` #;imports) (` [(~@ =imports)])] _meta)) - =module (` (;_lux_module [(~ cursor-code) + =module (` ("lux module" [(~ cursor-code) (#;Record (~ =meta))]))]] (wrap (#;Cons =module =refers)))) |