diff options
Diffstat (limited to 'new-luxc/source/luxc/lang')
7 files changed, 60 insertions, 35 deletions
diff --git a/new-luxc/source/luxc/lang/analysis/procedure.lux b/new-luxc/source/luxc/lang/analysis/procedure.lux index 225fb7b23..9f5f61d59 100644 --- a/new-luxc/source/luxc/lang/analysis/procedure.lux +++ b/new-luxc/source/luxc/lang/analysis/procedure.lux @@ -1,6 +1,7 @@ (;module: lux - (lux (control [monad #+ do]) + (lux (control [monad #+ do] + ["ex" exception #+ exception:]) (data [maybe] [text] text/format @@ -10,6 +11,8 @@ (. ["./;" common] ["./;" host])) +(exception: #export Unknown-Procedure) + (def: procedures ./common;Bundle (|> ./common;procedures @@ -17,7 +20,7 @@ (def: #export (analyse-procedure analyse eval proc-name proc-args) (-> &;Analyser &;Eval Text (List Code) (Meta la;Analysis)) - (<| (maybe;default (&;fail (format "Unknown procedure: " (%t proc-name)))) + (<| (maybe;default (&;throw Unknown-Procedure proc-name)) (do maybe;Monad<Maybe> [proc (dict;get proc-name procedures)] - (wrap (proc analyse eval proc-args))))) + (wrap ((proc proc-name) analyse eval proc-args))))) diff --git a/new-luxc/source/luxc/lang/analysis/procedure/common.lux b/new-luxc/source/luxc/lang/analysis/procedure/common.lux index e06a3d2b4..f3c296b2b 100644 --- a/new-luxc/source/luxc/lang/analysis/procedure/common.lux +++ b/new-luxc/source/luxc/lang/analysis/procedure/common.lux @@ -1,7 +1,7 @@ (;module: lux (lux (control [monad #+ do]) - (concurrency ["A" atom]) + (concurrency [atom #+ Atom]) (data [text] text/format (coll [list "list/" Functor<List>] @@ -23,12 +23,12 @@ (-> &;Analyser &;Eval (List Code) (Meta la;Analysis))) (type: #export Bundle - (Dict Text Proc)) + (Dict Text (-> Text Proc))) (def: #export (install name unnamed) (-> Text (-> Text Proc) (-> Bundle Bundle)) - (dict;put name (unnamed name))) + (dict;put name unnamed)) (def: #export (prefix prefix bundle) (-> Text Bundle Bundle) @@ -357,7 +357,7 @@ [initA (&;with-expected-type varT (analyse initC)) outputT (&;with-type-env - (tc;clean var-id (type (A;Atom varT)))) + (tc;clean var-id (type (Atom varT)))) expected meta;expected-type _ (&;with-type-env (tc;check expected outputT))] @@ -371,7 +371,7 @@ (function [analyse eval args] (&common;with-var (function [[var-id varT]] - ((unary (type (A;Atom varT)) varT proc) + ((unary (type (Atom varT)) varT proc) analyse eval args))))) (def: (atom-compare-and-swap proc) @@ -379,7 +379,7 @@ (function [analyse eval args] (&common;with-var (function [[var-id varT]] - ((trinary varT varT (type (A;Atom varT)) Bool proc) + ((trinary varT varT (type (Atom varT)) Bool proc) analyse eval args))))) (def: atom-procs diff --git a/new-luxc/source/luxc/lang/translation/case.jvm.lux b/new-luxc/source/luxc/lang/translation/case.jvm.lux index 09ffae328..3e05ba334 100644 --- a/new-luxc/source/luxc/lang/translation/case.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/case.jvm.lux @@ -199,6 +199,18 @@ $i;NULL ($i;GOTO @end))))) +(def: #export (translate-if testI thenI elseI) + (-> $;Inst $;Inst $;Inst $;Inst) + (<| $i;with-label (function [@else]) + $i;with-label (function [@end]) + (|>. testI + ($i;IFEQ @else) + thenI + ($i;GOTO @end) + ($i;label @else) + elseI + ($i;label @end)))) + (def: #export (translate-case translate valueS path) (-> (-> ls;Synthesis (Meta $;Inst)) ls;Synthesis ls;Path (Meta $;Inst)) diff --git a/new-luxc/source/luxc/lang/translation/function.jvm.lux b/new-luxc/source/luxc/lang/translation/function.jvm.lux index 1b7f6267b..eceaecd9d 100644 --- a/new-luxc/source/luxc/lang/translation/function.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/function.jvm.lux @@ -301,7 +301,7 @@ (do meta;Monad<Meta> [[context bodyI] (hostL;with-sub-context (translate body)) - #let [function-class (text;replace-all "/+" "$" context)] + #let [function-class (&;normalize-name context)] [functionD instanceI] (with-function function-class env arity bodyI) _ (commonT;store-class function-class ($d;class #$;V1.6 #$;Public $;finalC diff --git a/new-luxc/source/luxc/lang/translation/procedure.jvm.lux b/new-luxc/source/luxc/lang/translation/procedure.jvm.lux index d74b559cf..82b7c5d44 100644 --- a/new-luxc/source/luxc/lang/translation/procedure.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/procedure.jvm.lux @@ -1,6 +1,7 @@ (;module: lux - (lux (control [monad #+ do]) + (lux (control [monad #+ do] + ["ex" exception #+ exception:]) (data [maybe] text/format (coll [dict]))) @@ -10,6 +11,8 @@ (. ["./;" common] ["./;" host])) +(exception: #export Unknown-Procedure) + (def: procedures ./common;Bundle (|> ./common;procedures @@ -18,7 +21,7 @@ (def: #export (translate-procedure translate name args) (-> (-> ls;Synthesis (Meta $;Inst)) Text (List ls;Synthesis) (Meta $;Inst)) - (<| (maybe;default (&;fail (format "Unknown procedure: " (%t name)))) + (<| (maybe;default (&;throw Unknown-Procedure name)) (do maybe;Monad<Maybe> [proc (dict;get name procedures)] (wrap (proc translate args))))) diff --git a/new-luxc/source/luxc/lang/translation/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/procedure/common.jvm.lux index 8c7668383..7c049a99f 100644 --- a/new-luxc/source/luxc/lang/translation/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/procedure/common.jvm.lux @@ -17,7 +17,8 @@ ["$i" inst])) (lang ["la" analysis] ["ls" synthesis] - (translation [";T" runtime])))) + (translation [";T" runtime] + [";T" case])))) (host;import java.lang.Long (#static MIN_VALUE Long) @@ -133,14 +134,17 @@ rightI (predicateI $i;IF_ACMPEQ))) -(def: try-method - $;Method - ($t;method (list $Function) (#;Some $Object-Array) (list))) +(def: (lux//if [testI thenI elseI]) + Trinary + (caseT;translate-if testI thenI elseI)) + (def: (lux//try riskyI) Unary (|>. riskyI ($i;CHECKCAST hostL;function-class) - ($i;INVOKESTATIC hostL;runtime-class "try" try-method false))) + ($i;INVOKESTATIC hostL;runtime-class "try" + ($t;method (list $Function) (#;Some $Object-Array) (list)) + false))) (def: (lux//noop valueI) Unary @@ -536,9 +540,11 @@ (def: lux-procs Bundle (|> (dict;new text;Hash<Text>) - (install "lux noop" (unary lux//noop)) - (install "lux is" (binary lux//is)) - (install "lux try" (unary lux//try)))) + (install "noop" (unary lux//noop)) + (install "is" (binary lux//is)) + (install "try" (unary lux//try)) + (install "if" (trinary lux//if)) + )) (def: bit-procs Bundle @@ -691,17 +697,18 @@ (def: #export procedures Bundle - (|> (dict;new text;Hash<Text>) - (dict;merge lux-procs) - (dict;merge bit-procs) - (dict;merge nat-procs) - (dict;merge int-procs) - (dict;merge deg-procs) - (dict;merge frac-procs) - (dict;merge text-procs) - (dict;merge array-procs) - (dict;merge math-procs) - (dict;merge io-procs) - (dict;merge atom-procs) - (dict;merge process-procs) - )) + (<| (prefix "lux") + (|> (dict;new text;Hash<Text>) + (dict;merge lux-procs) + (dict;merge bit-procs) + (dict;merge nat-procs) + (dict;merge int-procs) + (dict;merge deg-procs) + (dict;merge frac-procs) + (dict;merge text-procs) + (dict;merge array-procs) + (dict;merge math-procs) + (dict;merge io-procs) + (dict;merge atom-procs) + (dict;merge process-procs) + ))) diff --git a/new-luxc/source/luxc/lang/translation/reference.jvm.lux b/new-luxc/source/luxc/lang/translation/reference.jvm.lux index 57336f27c..c9243cae3 100644 --- a/new-luxc/source/luxc/lang/translation/reference.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/reference.jvm.lux @@ -19,7 +19,7 @@ (do meta;Monad<Meta> [function-class hostL;context] (wrap (|>. ($i;ALOAD +0) - ($i;GETFIELD (text;replace-all "/+" "$" function-class) + ($i;GETFIELD (&;normalize-name function-class) (|> variable i.inc (i.* -1) int-to-nat functionT;captured) commonT;$Object))))) |