aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc
diff options
context:
space:
mode:
Diffstat (limited to 'new-luxc/source/luxc')
-rw-r--r--new-luxc/source/luxc/lang/syntax.lux11
-rw-r--r--new-luxc/source/luxc/lang/translation.lux42
2 files changed, 40 insertions, 13 deletions
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")