From 772ff99830d133b2e36ad1b09c66223ef1085c71 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 14 Nov 2017 23:57:15 -0400 Subject: - Modified the syntax for module definitions. - Fixed some bugs. --- new-luxc/source/luxc/lang/syntax.lux | 11 +++++++- new-luxc/source/luxc/lang/translation.lux | 42 ++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 13 deletions(-) (limited to 'new-luxc') 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]) + ["p" parser "p/" Monad] + ["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 + [[_ 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 - [[_ 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 + [[annsI annsV] (process-annotations annsC)] + (&;fail (%code annsV))) + (^code ((~ [_ (#;Symbol macro-name)]) (~@ args))) (do meta;Monad [macro-name (meta;normalize macro-name) @@ -130,9 +142,15 @@ (def: (exhaust action) (All [a] (-> (Meta a) (Meta Unit))) - (do meta;Monad - [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") -- cgit v1.2.3