aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/common-lisp
diff options
context:
space:
mode:
authorEduardo Julian2019-05-01 20:33:42 -0400
committerEduardo Julian2019-05-01 20:33:42 -0400
commitc923517c864dad362ef00ae78b449bb40cc27e84 (patch)
treea758099e76424db4fc8ec8d8cc18a8a699d68d66 /new-luxc/source/luxc/lang/translation/common-lisp
parent0c20f4a8362d42572edecb6ef9844b75c4c859f8 (diff)
The Common Lisp compiler is alive.
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/common-lisp')
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/case.jvm.lux183
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/expression.jvm.lux87
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/function.jvm.lux82
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/loop.jvm.lux37
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/primitive.jvm.lux22
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/procedure/common.jvm.lux314
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/procedure/host.jvm.lux89
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/reference.jvm.lux42
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/runtime.jvm.lux316
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/statement.jvm.lux45
-rw-r--r--new-luxc/source/luxc/lang/translation/common-lisp/structure.jvm.lux31
11 files changed, 0 insertions, 1248 deletions
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/case.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/case.jvm.lux
deleted file mode 100644
index 78149471d..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/case.jvm.lux
+++ /dev/null
@@ -1,183 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do]
- ["ex" exception #+ exception:])
- (data [number]
- [text]
- text/format
- (coll [list "list/" Functor<List> Fold<List>]
- (set ["set" unordered #+ Set])))
- [macro #+ "meta/" Monad<Meta>]
- (macro [code]))
- (luxc [lang]
- (lang [".L" variable #+ Register Variable]
- ["ls" synthesis #+ Synthesis Path]
- (host ["_" common-lisp #+ Expression Handler SVar @@])))
- [//]
- (// [".T" runtime]
- [".T" primitive]
- [".T" reference]))
-
-(def: #export (translate-let translate register valueS bodyS)
- (-> (-> Synthesis (Meta Expression)) Register Synthesis Synthesis
- (Meta Expression))
- (do macro.Monad<Meta>
- [valueO (translate valueS)
- bodyO (translate bodyS)
- #let [$register (referenceT.variable register)]]
- (wrap (_.let (list [$register valueO])
- bodyO))))
-
-(def: #export (translate-record-get translate valueS pathP)
- (-> (-> Synthesis (Meta Expression)) Synthesis (List [Nat Bit])
- (Meta Expression))
- (do macro.Monad<Meta>
- [valueO (translate valueS)]
- (wrap (list/fold (function (_ [idx tail?] source)
- (let [method (if tail?
- runtimeT.product//right
- runtimeT.product//left)]
- (method source (_.int (:coerce Int idx)))))
- valueO
- pathP))))
-
-(def: #export (translate-if testO thenO elseO)
- (-> Expression Expression Expression Expression)
- (_.if testO thenO elseO))
-
-(def: $savepoint (_.var "lux_pm_cursor_savepoint"))
-(def: $cursor (_.var "lux_pm_cursor"))
-
-(def: top _.length)
-(def: (push! value var)
- (-> Expression SVar Expression)
- (_.setq! var (_.cons value (@@ var))))
-(def: (pop! var)
- (-> SVar Expression)
- (_.setq! var (@@ var)))
-
-(def: (push-cursor! value)
- (-> Expression Expression)
- (push! value $cursor))
-
-(def: save-cursor!
- Expression
- (push! (@@ $cursor) $savepoint))
-
-(def: restore-cursor!
- Expression
- (_.setq! $cursor (_.car (@@ $savepoint))))
-
-(def: cursor-top
- Expression
- (_.car (@@ $cursor)))
-
-(def: pop-cursor!
- Expression
- (pop! $cursor))
-
-(def: pm-error (_.string "PM-ERROR"))
-
-(def: fail-pm! (_.error pm-error))
-
-(def: $temp (_.var "lux_pm_temp"))
-
-(exception: #export (Unrecognized-Path {message Text})
- message)
-
-(def: $alt_error (_.var "alt_error"))
-
-(def: (pm-catch handler)
- (-> Expression Handler)
- [(_.bool #1) $alt_error
- (_.progn
- (list
- (_.setq! $alt_error (_.format/3 _.nil (_.string "~A") (@@ $alt_error)))
- (_.if (|> (@@ $alt_error) (_.equal pm-error))
- handler
- (_.error (@@ $alt_error)))))])
-
-(def: (translate-pattern-matching' translate pathP)
- (-> (-> Synthesis (Meta Expression)) Path (Meta Expression))
- (case pathP
- (^code ("lux case exec" (~ bodyS)))
- (do macro.Monad<Meta>
- [bodyO (translate bodyS)]
- (wrap bodyO))
-
- (^code ("lux case pop"))
- (meta/wrap pop-cursor!)
-
- (^code ("lux case bind" (~ [_ (#.Nat register)])))
- (meta/wrap (_.setq! (referenceT.variable register) cursor-top))
-
- (^template [<tag> <format> <=>]
- [_ (<tag> value)]
- (meta/wrap (_.when (|> value <format> (<=> cursor-top) _.not)
- fail-pm!)))
- ([#.Bit _.bool _.equal]
- [#.Nat (<| _.int (:coerce Int)) _.=]
- [#.Int _.int _.=]
- [#.Rev (<| _.int (:coerce Int)) _.=]
- [#.Frac _.float _.=]
- [#.Text _.string _.equal])
-
- (^template [<pm> <getter>]
- (^code (<pm> (~ [_ (#.Nat idx)])))
- (meta/wrap (push-cursor! (<getter> cursor-top (_.int (:coerce Int idx))))))
- (["lux case tuple left" runtimeT.product//left]
- ["lux case tuple right" runtimeT.product//right])
-
- (^template [<pm> <flag>]
- (^code (<pm> (~ [_ (#.Nat idx)])))
- (meta/wrap (_.progn (list (_.setq! $temp (runtimeT.sum//get cursor-top (_.int (:coerce Int idx)) <flag>))
- (_.if (_.null (@@ $temp))
- fail-pm!
- (push-cursor! (@@ $temp)))))))
- (["lux case variant left" _.nil]
- ["lux case variant right" (_.string "")])
-
- (^code ("lux case seq" (~ leftP) (~ rightP)))
- (do macro.Monad<Meta>
- [leftO (translate-pattern-matching' translate leftP)
- rightO (translate-pattern-matching' translate rightP)]
- (wrap (_.progn (list leftO
- rightO))))
-
- (^code ("lux case alt" (~ leftP) (~ rightP)))
- (do macro.Monad<Meta>
- [leftO (translate-pattern-matching' translate leftP)
- rightO (translate-pattern-matching' translate rightP)]
- (wrap (runtimeT.with-vars [error]
- (_.handler-case
- (list (pm-catch (_.progn (list restore-cursor!
- rightO))))
- (_.progn (list save-cursor!
- leftO))))))
-
- _
- (lang.throw Unrecognized-Path (%code pathP))
- ))
-
-(def: (translate-pattern-matching translate pathP)
- (-> (-> Synthesis (Meta Expression)) Path (Meta Expression))
- (do macro.Monad<Meta>
- [pattern-matching! (translate-pattern-matching' translate pathP)]
- (wrap (_.handler-case
- (list (pm-catch (_.error (_.string "Invalid expression for pattern-matching."))))
- pattern-matching!))))
-
-(def: (initialize-pattern-matching! stack-init body)
- (-> Expression Expression Expression)
- (_.let (list [$cursor (_.list (list stack-init))]
- [$savepoint (_.list (list))]
- [$temp _.nil])
- body))
-
-(def: #export (translate-case translate valueS pathP)
- (-> (-> Synthesis (Meta Expression)) Synthesis Path (Meta Expression))
- (do macro.Monad<Meta>
- [valueO (translate valueS)
- pattern-matching! (translate-pattern-matching translate pathP)]
- (wrap (<| (initialize-pattern-matching! valueO)
- pattern-matching!))))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/expression.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/expression.jvm.lux
deleted file mode 100644
index 437648fbb..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/expression.jvm.lux
+++ /dev/null
@@ -1,87 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do]
- ["ex" exception #+ exception:]
- ["p" parser])
- (data ["e" error]
- text/format)
- [macro]
- (macro ["s" syntax]))
- (luxc ["&" lang]
- (lang [".L" variable #+ Variable Register]
- [".L" extension]
- ["ls" synthesis]
- (host ["_" common-lisp #+ Expression])))
- [//]
- (// [".T" runtime]
- [".T" primitive]
- [".T" structure]
- [".T" function]
- [".T" reference]
- [".T" case]
- [".T" procedure]))
-
-(template [<name>]
- [(exception: #export (<name> {message Text})
- message)]
-
- [Invalid-Function-Syntax]
- [Unrecognized-Synthesis]
- )
-
-(def: #export (translate synthesis)
- (-> ls.Synthesis (Meta Expression))
- (case synthesis
- (^code [])
- (:: macro.Monad<Meta> wrap runtimeT.unit)
-
- (^template [<tag> <generator>]
- [_ (<tag> value)]
- (<generator> value))
- ([#.Bit primitiveT.translate-bit]
- [#.Nat primitiveT.translate-nat]
- [#.Int primitiveT.translate-int]
- [#.Rev primitiveT.translate-rev]
- [#.Frac primitiveT.translate-frac]
- [#.Text primitiveT.translate-text])
-
- (^code ((~ [_ (#.Nat tag)]) (~ [_ (#.Bit last?)]) (~ valueS)))
- (structureT.translate-variant translate tag last? valueS)
-
- (^code [(~ singleton)])
- (translate singleton)
-
- (^code [(~+ members)])
- (structureT.translate-tuple translate members)
-
- (^ [_ (#.Form (list [_ (#.Int var)]))])
- (referenceT.translate-variable var)
-
- [_ (#.Identifier definition)]
- (referenceT.translate-definition definition)
-
- (^code ("lux call" (~ functionS) (~+ argsS)))
- (functionT.translate-apply translate functionS argsS)
-
- (^code ("lux function" (~ [_ (#.Nat arity)]) [(~+ environment)] (~ bodyS)))
- (case (s.run environment (p.some s.int))
- (#e.Success environment)
- (functionT.translate-function translate environment arity bodyS)
-
- _
- (&.throw Invalid-Function-Syntax (%code synthesis)))
-
- (^code ("lux let" (~ [_ (#.Nat register)]) (~ inputS) (~ exprS)))
- (caseT.translate-let translate register inputS exprS)
-
- (^code ("lux case" (~ inputS) (~ pathPS)))
- (caseT.translate-case translate inputS pathPS)
-
- (^code ((~ [_ (#.Text procedure)]) (~+ argsS)))
- (procedureT.translate-procedure translate procedure argsS)
- ## (do macro.Monad<Meta>
- ## [translation (extensionL.find-translation procedure)]
- ## (translation argsS))
-
- _
- (&.throw Unrecognized-Synthesis (%code synthesis))))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/function.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/function.jvm.lux
deleted file mode 100644
index 54834b65c..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/function.jvm.lux
+++ /dev/null
@@ -1,82 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do]
- pipe)
- (data [product]
- [text]
- text/format
- (coll [list "list/" Functor<List> Fold<List>]))
- [macro])
- (luxc ["&" lang]
- (lang ["ls" synthesis]
- [".L" variable #+ Variable]
- (host ["_" common-lisp #+ Expression @@])))
- [//]
- (// [".T" reference]
- [".T" runtime]))
-
-(def: #export (translate-apply translate functionS argsS+)
- (-> (-> ls.Synthesis (Meta Expression)) ls.Synthesis (List ls.Synthesis) (Meta Expression))
- (do macro.Monad<Meta>
- [functionO (translate functionS)
- argsO+ (monad.map @ translate argsS+)]
- (wrap (_.funcall argsO+ functionO))))
-
-(def: $curried (_.var "curried"))
-(def: $missing (_.var "missing"))
-
-(def: input-declaration
- (|>> inc referenceT.variable))
-
-(def: (with-closure function-name inits function-definition)
- (-> Text (List Expression) Expression (Meta Expression))
- (let [$closure (_.var (format function-name "___CLOSURE"))]
- (do macro.Monad<Meta>
- []
- (case inits
- #.Nil
- (wrap function-definition)
-
- _
- (wrap (_.labels (list [$closure [(|> (list.enumerate inits)
- (list/map (|>> product.left referenceT.closure))
- _.poly)
- function-definition]])
- (_.funcall inits (_.function (@@ $closure)))))))))
-
-(def: #export (translate-function translate env arity bodyS)
- (-> (-> ls.Synthesis (Meta Expression))
- (List Variable) ls.Arity ls.Synthesis
- (Meta Expression))
- (do macro.Monad<Meta>
- [[function-name bodyO] (//.with-sub-context
- (do @
- [function-name //.context]
- (//.with-anchor [function-name +1]
- (translate bodyS))))
- closureO+ (monad.map @ referenceT.translate-variable env)
- #let [arityO (|> arity .int _.int)
- $num_args (_.var "num_args")
- $function (_.var function-name)]]
- (with-closure function-name closureO+
- (_.labels (list [$function [(_.poly+ (list) $curried)
- (_.let (list [$num_args (_.length (@@ $curried))])
- (<| (_.if (|> (@@ $num_args) (_.= arityO))
- (_.let (list [(referenceT.variable +0) (_.function (@@ $function))])
- (_.destructuring-bind [(|> (list.n/range +0 (dec arity))
- (list/map input-declaration)
- _.poly)
- (@@ $curried)]
- bodyO)))
- (_.if (|> (@@ $num_args) (_.> arityO))
- (let [arity-args (_.subseq/3 (@@ $curried) (_.int 0) arityO)
- output-func-args (_.subseq/3 (@@ $curried) arityO (@@ $num_args))]
- (|> (_.function (@@ $function))
- (_.apply arity-args)
- (_.apply output-func-args))))
- ## (|> (@@ $num_args) (_.< arityO))
- (_.lambda (_.poly+ (list) $missing)
- (|> (_.function (@@ $function))
- (_.apply (_.append (@@ $curried) (@@ $missing)))))))]])
- (_.function (@@ $function))))
- ))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/loop.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/loop.jvm.lux
deleted file mode 100644
index c64973d8f..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/loop.jvm.lux
+++ /dev/null
@@ -1,37 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do])
- (data [text]
- text/format
- (coll [list "list/" Functor<List>]))
- [macro])
- (luxc [lang]
- (lang ["ls" synthesis]
- (host [r #+ Expression @@])))
- [//]
- (// [".T" reference]))
-
-(def: #export (translate-loop translate offset initsS+ bodyS)
- (-> (-> ls.Synthesis (Meta Expression)) Nat (List ls.Synthesis) ls.Synthesis
- (Meta Expression))
- (do macro.Monad<Meta>
- [loop-name (|> (macro.gensym "loop")
- (:: @ map (|>> %code lang.normalize-name)))
- initsO+ (monad.map @ translate initsS+)
- bodyO (//.with-anchor [loop-name offset]
- (translate bodyS))
- #let [$loop-name (r.var loop-name)
- @loop-name (@@ $loop-name)]
- _ (//.save (r.set! $loop-name
- (r.function (|> (list.n/range +0 (dec (list.size initsS+)))
- (list/map (|>> (n/+ offset) referenceT.variable)))
- bodyO)))]
- (wrap (r.apply initsO+ @loop-name))))
-
-(def: #export (translate-recur translate argsS+)
- (-> (-> ls.Synthesis (Meta Expression)) (List ls.Synthesis)
- (Meta Expression))
- (do macro.Monad<Meta>
- [[loop-name offset] //.anchor
- argsO+ (monad.map @ translate argsS+)]
- (wrap (r.apply argsO+ (r.global loop-name)))))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/primitive.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/primitive.jvm.lux
deleted file mode 100644
index 7556e6ebb..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/primitive.jvm.lux
+++ /dev/null
@@ -1,22 +0,0 @@
-(.module:
- lux
- (lux [macro "meta/" Monad<Meta>])
- (luxc (lang (host ["_" common-lisp #+ Expression])))
- [//]
- (// [".T" runtime]))
-
-(def: #export translate-bit
- (-> Bit (Meta Expression))
- (|>> _.bool meta/wrap))
-
-(def: #export translate-int
- (-> Int (Meta Expression))
- (|>> _.int meta/wrap))
-
-(def: #export translate-frac
- (-> Frac (Meta Expression))
- (|>> _.double meta/wrap))
-
-(def: #export translate-text
- (-> Text (Meta Expression))
- (|>> _.string meta/wrap))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/procedure/common.jvm.lux
deleted file mode 100644
index 3eaa60821..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/procedure/common.jvm.lux
+++ /dev/null
@@ -1,314 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do]
- ["ex" exception #+ exception:]
- ["p" parser])
- (data ["e" error]
- [text]
- text/format
- [number #+ hex]
- (coll [list "list/" Functor<List>]
- (dictionary ["dict" unordered #+ Dict])))
- [macro #+ with-gensyms]
- (macro [code]
- ["s" syntax #+ syntax:])
- [host])
- (luxc ["&" lang]
- (lang ["la" analysis]
- ["ls" synthesis]
- (host ["_" common-lisp #+ Expression])))
- [///]
- (/// [".T" runtime]
- [".T" case]
- [".T" function]
- [".T" loop]))
-
-## [Types]
-(type: #export Translator
- (-> ls.Synthesis (Meta Expression)))
-
-(type: #export Proc
- (-> Translator (List ls.Synthesis) (Meta Expression)))
-
-(type: #export Bundle
- (Dict Text Proc))
-
-(syntax: (Vector {size s.nat} elemT)
- (wrap (list (` [(~+ (list.repeat size elemT))]))))
-
-(type: #export Nullary (-> (Vector +0 Expression) Expression))
-(type: #export Unary (-> (Vector +1 Expression) Expression))
-(type: #export Binary (-> (Vector +2 Expression) Expression))
-(type: #export Trinary (-> (Vector +3 Expression) Expression))
-(type: #export Variadic (-> (List Expression) Expression))
-
-## [Utils]
-(def: #export (install name unnamed)
- (-> Text (-> Text Proc)
- (-> Bundle Bundle))
- (dict.put name (unnamed name)))
-
-(def: #export (prefix prefix bundle)
- (-> Text Bundle Bundle)
- (|> bundle
- dict.entries
- (list/map (function (_ [key val]) [(format prefix " " key) val]))
- (dict.from-list text.Hash<Text>)))
-
-(def: (wrong-arity proc expected actual)
- (-> Text Nat Nat Text)
- (format "Wrong number of arguments for " (%t proc) "\n"
- "Expected: " (|> expected .int %i) "\n"
- " Actual: " (|> actual .int %i)))
-
-(syntax: (arity: {name s.local-identifier} {arity s.nat})
- (with-gensyms [g!_ g!proc g!name g!translate g!inputs]
- (do @
- [g!input+ (monad.seq @ (list.repeat arity (macro.gensym "input")))]
- (wrap (list (` (def: #export ((~ (code.local-identifier name)) (~ g!proc))
- (-> (-> (..Vector (~ (code.nat arity)) Expression) Expression)
- (-> Text ..Proc))
- (function ((~ g!_) (~ g!name))
- (function ((~ g!_) (~ g!translate) (~ g!inputs))
- (case (~ g!inputs)
- (^ (list (~+ g!input+)))
- (do macro.Monad<Meta>
- [(~+ (|> g!input+
- (list/map (function (_ g!input)
- (list g!input (` ((~ g!translate) (~ g!input))))))
- list.concat))]
- ((~' wrap) ((~ g!proc) [(~+ g!input+)])))
-
- (~' _)
- (macro.fail (wrong-arity (~ g!name) +1 (list.size (~ g!inputs))))))))))))))
-
-(arity: nullary +0)
-(arity: unary +1)
-(arity: binary +2)
-(arity: trinary +3)
-
-(def: #export (variadic proc)
- (-> Variadic (-> Text Proc))
- (function (_ proc-name)
- (function (_ translate inputsS)
- (do macro.Monad<Meta>
- [inputsI (monad.map @ translate inputsS)]
- (wrap (proc inputsI))))))
-
-## [Procedures]
-## [[Lux]]
-(def: (lux//is [leftO rightO])
- Binary
- (_.eq leftO rightO))
-
-(def: (lux//if [testO thenO elseO])
- Trinary
- (caseT.translate-if testO thenO elseO))
-
-(exception: #export (Wrong-Syntax {message Text})
- message)
-
-(def: #export (wrong-syntax procedure args)
- (-> Text (List ls.Synthesis) Text)
- (format "Procedure: " procedure "\n"
- "Arguments: " (%code (code.tuple args))))
-
-(def: lux//loop
- (-> Text Proc)
- (function (_ proc-name)
- (function (_ translate inputsS)
- (case (s.run inputsS ($_ p.seq s.nat (s.tuple (p.many s.any)) s.any))
- (#e.Success [offset initsS+ bodyS])
- (loopT.translate-loop translate offset initsS+ bodyS)
-
- (#e.Error error)
- (&.throw Wrong-Syntax (wrong-syntax proc-name inputsS)))
- )))
-
-(def: lux//recur
- (-> Text Proc)
- (function (_ proc-name)
- (function (_ translate inputsS)
- (loopT.translate-recur translate inputsS))))
-
-(def: lux-procs
- Bundle
- (|> (dict.new text.Hash<Text>)
- (install "is" (binary lux//is))
- (install "try" (unary runtimeT.lux//try))
- (install "if" (trinary lux//if))
- (install "loop" lux//loop)
- (install "recur" lux//recur)
- ))
-
-## [[Bits]]
-(template [<name> <op>]
- [(def: (<name> [subjectO paramO])
- Binary
- (<op> paramO subjectO))]
-
- [bit//and _.logand]
- [bit//or _.logior]
- [bit//xor _.logxor]
- )
-
-(def: (bit//left-shift [subjectO paramO])
- Binary
- (_.ash (_.rem (_.int 64) paramO) subjectO))
-
-(def: (bit//arithmetic-right-shift [subjectO paramO])
- Binary
- (_.ash (|> paramO (_.rem (_.int 64)) (_.* (_.int -1)))
- subjectO))
-
-(def: (bit//logical-right-shift [subjectO paramO])
- Binary
- (runtimeT.bit//logical-right-shift (_.rem (_.int 64) paramO) subjectO))
-
-(def: bit-procs
- Bundle
- (<| (prefix "bit")
- (|> (dict.new text.Hash<Text>)
- (install "and" (binary bit//and))
- (install "or" (binary bit//or))
- (install "xor" (binary bit//xor))
- (install "left-shift" (binary bit//left-shift))
- (install "logical-right-shift" (binary bit//logical-right-shift))
- (install "arithmetic-right-shift" (binary bit//arithmetic-right-shift))
- )))
-
-## [[Numbers]]
-(host.import: java/lang/Double
- (#static MIN_VALUE Double)
- (#static MAX_VALUE Double))
-
-(template [<name> <const> <encode>]
- [(def: (<name> _)
- Nullary
- (<encode> <const>))]
-
- [frac//smallest Double::MIN_VALUE _.double]
- [frac//min (f/* -1.0 Double::MAX_VALUE) _.double]
- [frac//max Double::MAX_VALUE _.double]
- )
-
-(template [<name> <op>]
- [(def: (<name> [subjectO paramO])
- Binary
- (|> subjectO (<op> paramO)))]
-
- [int//+ _.+]
- [int//- _.-]
- [int//* _.*]
- [int/// _.floor]
- [int//% _.rem]
- [int//= _.=]
- [int//< _.<]
- )
-
-(template [<name> <op>]
- [(def: (<name> [subjectO paramO])
- Binary
- (<op> paramO subjectO))]
-
- [frac//+ _.+]
- [frac//- _.-]
- [frac//* _.*]
- [frac/// _./]
- [frac//% _.mod]
- [frac//= _.=]
- [frac//< _.<]
-
- [text//= _.string=]
- )
-
-(def: (text//< [subjectO paramO])
- Binary
- (|> (_.string< paramO subjectO)
- _.null
- _.not))
-
-(def: int-procs
- Bundle
- (<| (prefix "int")
- (|> (dict.new text.Hash<Text>)
- (install "+" (binary int//+))
- (install "-" (binary int//-))
- (install "*" (binary int//*))
- (install "/" (binary int///))
- (install "%" (binary int//%))
- (install "=" (binary int//=))
- (install "<" (binary int//<))
- (install "to-frac" (unary (|>> (_./ (_.double 1.0))))))))
-
-(def: frac-procs
- Bundle
- (<| (prefix "frac")
- (|> (dict.new text.Hash<Text>)
- (install "+" (binary frac//+))
- (install "-" (binary frac//-))
- (install "*" (binary frac//*))
- (install "/" (binary frac///))
- (install "%" (binary frac//%))
- (install "=" (binary frac//=))
- (install "<" (binary frac//<))
- (install "smallest" (nullary frac//smallest))
- (install "min" (nullary frac//min))
- (install "max" (nullary frac//max))
- (install "to-int" (unary _.floor/1)))))
-
-## ## [[Text]]
-(def: (text//concat [subjectO paramO])
- Binary
- (_.concatenate/string subjectO paramO))
-
-(def: (text//char [text idx])
- Binary
- (runtimeT.text//char idx text))
-
-(def: (text//clip [text from to])
- Trinary
- (runtimeT.text//clip from to text))
-
-(def: (text//index [space reference start])
- Trinary
- (runtimeT.text//index reference start space))
-
-(def: text-procs
- Bundle
- (<| (prefix "text")
- (|> (dict.new text.Hash<Text>)
- (install "=" (binary text//=))
- (install "<" (binary text//<))
- (install "concat" (binary text//concat))
- (install "index" (trinary text//index))
- (install "size" (unary _.length))
- (install "char" (binary text//char))
- (install "clip" (trinary text//clip))
- )))
-
-## [[IO]]
-(def: (void code)
- (-> Expression Expression)
- (_.progn (list code runtimeT.unit)))
-
-(def: io-procs
- Bundle
- (<| (prefix "io")
- (|> (dict.new text.Hash<Text>)
- (install "log" (unary (|>> _.print ..void)))
- (install "error" (unary _.error))
- (install "exit" (unary runtimeT.io//exit))
- (install "current-time" (nullary (function (_ _) (runtimeT.io//current-time runtimeT.unit)))))))
-
-## [Bundles]
-(def: #export procedures
- Bundle
- (<| (prefix "lux")
- (|> lux-procs
- (dict.merge bit-procs)
- (dict.merge int-procs)
- (dict.merge frac-procs)
- (dict.merge text-procs)
- (dict.merge io-procs)
- )))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/procedure/host.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/procedure/host.jvm.lux
deleted file mode 100644
index 2793b40e8..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/procedure/host.jvm.lux
+++ /dev/null
@@ -1,89 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do])
- (data [text]
- text/format
- (coll [list "list/" Functor<List>]
- (dictionary ["dict" unordered #+ Dict])))
- [macro "macro/" Monad<Meta>])
- (luxc ["&" lang]
- (lang ["la" analysis]
- ["ls" synthesis]
- (host [ruby #+ Ruby Expression Statement])))
- [///]
- (/// [".T" runtime])
- (// ["@" common]))
-
-## (template [<name> <lua>]
-## [(def: (<name> _) @.Nullary <lua>)]
-
-## [lua//nil "nil"]
-## [lua//table "{}"]
-## )
-
-## (def: (lua//global proc translate inputs)
-## (-> Text @.Proc)
-## (case inputs
-## (^ (list [_ (#.Text name)]))
-## (do macro.Monad<Meta>
-## []
-## (wrap name))
-
-## _
-## (&.throw @.Wrong-Syntax (@.wrong-syntax proc inputs))))
-
-## (def: (lua//call proc translate inputs)
-## (-> Text @.Proc)
-## (case inputs
-## (^ (list& functionS argsS+))
-## (do macro.Monad<Meta>
-## [functionO (translate functionS)
-## argsO+ (monad.map @ translate argsS+)]
-## (wrap (lua.apply functionO argsO+)))
-
-## _
-## (&.throw @.Wrong-Syntax (@.wrong-syntax proc inputs))))
-
-## (def: lua-procs
-## @.Bundle
-## (|> (dict.new text.Hash<Text>)
-## (@.install "nil" (@.nullary lua//nil))
-## (@.install "table" (@.nullary lua//table))
-## (@.install "global" lua//global)
-## (@.install "call" lua//call)))
-
-## (def: (table//call proc translate inputs)
-## (-> Text @.Proc)
-## (case inputs
-## (^ (list& tableS [_ (#.Text field)] argsS+))
-## (do macro.Monad<Meta>
-## [tableO (translate tableS)
-## argsO+ (monad.map @ translate argsS+)]
-## (wrap (lua.method field tableO argsO+)))
-
-## _
-## (&.throw @.Wrong-Syntax (@.wrong-syntax proc inputs))))
-
-## (def: (table//get [fieldO tableO])
-## @.Binary
-## (runtimeT.lua//get tableO fieldO))
-
-## (def: (table//set [fieldO valueO tableO])
-## @.Trinary
-## (runtimeT.lua//set tableO fieldO valueO))
-
-## (def: table-procs
-## @.Bundle
-## (<| (@.prefix "table")
-## (|> (dict.new text.Hash<Text>)
-## (@.install "call" table//call)
-## (@.install "get" (@.binary table//get))
-## (@.install "set" (@.trinary table//set)))))
-
-(def: #export procedures
- @.Bundle
- (<| (@.prefix "lua")
- (dict.new text.Hash<Text>)
- ## (|> lua-procs
- ## (dict.merge table-procs))
- ))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/reference.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/reference.jvm.lux
deleted file mode 100644
index def77fc35..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/reference.jvm.lux
+++ /dev/null
@@ -1,42 +0,0 @@
-(.module:
- lux
- (lux [macro]
- (data [text]
- text/format))
- (luxc ["&" lang]
- (lang [".L" variable #+ Variable Register]
- (host ["_" common-lisp #+ Expression SVar @@])))
- [//]
- (// [".T" runtime]))
-
-(template [<register> <translation> <prefix>]
- [(def: #export (<register> register)
- (-> Register SVar)
- (_.var (format <prefix> (%i (.int register)))))
-
- (def: #export (<translation> register)
- (-> Register (Meta Expression))
- (:: macro.Monad<Meta> wrap (@@ (<register> register))))]
-
- [closure translate-captured "c"]
- [variable translate-local "v"])
-
-(def: #export (local var)
- (-> Variable SVar)
- (if (variableL.captured? var)
- (closure (variableL.captured-register var))
- (variable (.nat var))))
-
-(def: #export (translate-variable var)
- (-> Variable (Meta Expression))
- (if (variableL.captured? var)
- (translate-captured (variableL.captured-register var))
- (translate-local (.nat var))))
-
-(def: #export global
- (-> Name SVar)
- (|>> //.definition-name _.var))
-
-(def: #export (translate-definition name)
- (-> Name (Meta Expression))
- (:: macro.Monad<Meta> wrap (@@ (global name))))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/runtime.jvm.lux
deleted file mode 100644
index 5fa6179c7..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/runtime.jvm.lux
+++ /dev/null
@@ -1,316 +0,0 @@
-(.module:
- lux
- (lux (control ["p" parser "p/" Monad<Parser>]
- [monad #+ do])
- (data [bit]
- [number #+ hex]
- text/format
- (coll [list "list/" Monad<List>]))
- [macro]
- (macro [code]
- ["s" syntax #+ syntax:])
- [io #+ Process])
- [//]
- (luxc [lang]
- (lang (host ["_" common-lisp #+ SVar Expression @@]))))
-
-(def: prefix Text "LuxRuntime")
-
-(def: #export unit Expression (_.string //.unit))
-
-(def: (flag value)
- (-> Bit Expression)
- (if value
- (_.string "")
- _.nil))
-
-(def: (variant' tag last? value)
- (-> Expression Expression Expression Expression)
- (<| (_.cons (_.symbol //.variant-tag))
- (_.cons tag)
- (_.cons last?)
- value))
-
-(def: #export (variant tag last? value)
- (-> Nat Bit Expression Expression)
- (variant' (_.int (:coerce Int tag)) (flag last?) value))
-
-(def: #export none
- Expression
- (variant +0 #0 unit))
-
-(def: #export some
- (-> Expression Expression)
- (variant +1 #1))
-
-(def: #export left
- (-> Expression Expression)
- (variant +0 #0))
-
-(def: #export right
- (-> Expression Expression)
- (variant +1 #1))
-
-(type: Runtime Expression)
-
-(def: declaration
- (s.Syntax [Text (List Text)])
- (p.either (p.seq s.local-identifier (p/wrap (list)))
- (s.form (p.seq s.local-identifier (p.some s.local-identifier)))))
-
-(syntax: (runtime: {[name args] declaration}
- definition)
- (let [implementation (code.local-identifier (format "@@" name))
- runtime (format prefix "__" (lang.normalize-name name))
- $runtime (` (_.var (~ (code.text runtime))))
- @runtime (` (@@ (~ $runtime)))
- argsC+ (list/map code.local-identifier args)
- argsLC+ (list/map (|>> lang.normalize-name (format "LRV__") code.text (~) (_.var) (`))
- args)
- declaration (` ((~ (code.local-identifier name))
- (~+ argsC+)))
- type (` (-> (~+ (list.repeat (list.size argsC+) (` _.Expression)))
- _.Expression))]
- (wrap (list (` (def: (~' #export) (~ declaration)
- (~ type)
- (~ (case argsC+
- #.Nil
- @runtime
-
- _
- (` (_.$apply (~ @runtime) (list (~+ argsC+))))))))
- (` (def: (~ implementation)
- _.Expression
- (~ (case argsC+
- #.Nil
- (` (_.defparameter (~ $runtime) (~ definition)))
-
- _
- (` (let [(~+ (|> (list.zip2 argsC+ argsLC+)
- (list/map (function (_ [left right])
- (list left right)))
- list/join))]
- (_.defun (~ $runtime) (list (~+ argsLC+))
- (~ definition))))))))))))
-
-(syntax: #export (with-vars {vars (s.tuple (p.many s.local-identifier))}
- body)
- (wrap (list (` (let [(~+ (|> vars
- (list/map (function (_ var)
- (list (code.local-identifier var)
- (` (_.var (~ (code.text (format "LRV__" (lang.normalize-name var)))))))))
- list/join))]
- (~ body))))))
-
-(runtime: (lux//try op)
- (with-vars [error]
- (_.handler-case
- (list [(_.bool #1) error
- (..left (_.format/3 _.nil (_.string "~A") (@@ error)))])
- (..right (_.funcall (list ..unit) (@@ op))))))
-
-(runtime: (lux//program-args program-args)
- (with-vars [loop input output]
- (_.labels (list [loop [(_.poly (list input output))
- (_.if (_.null (@@ input))
- (@@ output)
- (_.funcall (list (_.cdr (@@ input))
- (..some (_.vector (list (_.car (@@ input)) (@@ output)))))
- (_.function (@@ loop))))]])
- (_.funcall (list (_.reverse (@@ program-args))
- ..none)
- (_.function (@@ loop))))))
-
-(def: runtime//lux
- Runtime
- (_.progn (list @@lux//try
- @@lux//program-args)))
-
-(def: minimum-index-length
- (-> Expression Expression)
- (|>> (_.+ (_.int 1))))
-
-(def: product-element
- (-> Expression Expression Expression)
- _.svref)
-
-(def: (product-tail product)
- (-> Expression Expression)
- (_.svref product (|> (_.length product) (_.- (_.int 1)))))
-
-(def: (updated-index min-length product)
- (-> Expression Expression Expression)
- (|> min-length (_.- (_.length product))))
-
-(runtime: (product//left product index)
- (with-vars [$index_min_length]
- (_.let (list [$index_min_length (minimum-index-length (@@ index))])
- (_.if (|> (_.length (@@ product)) (_.> (@@ $index_min_length)))
- ## No need for recursion
- (product-element (@@ product) (@@ index))
- ## Needs recursion
- (product//left (product-tail (@@ product))
- (updated-index (@@ $index_min_length) (@@ product)))))))
-
-(runtime: (product//right product index)
- (with-vars [$index_min_length $product_length]
- (_.let (list [$index_min_length (minimum-index-length (@@ index))]
- [$product_length (_.length (@@ product))])
- (<| (_.if (|> (@@ $product_length) (_.= (@@ $index_min_length)))
- ## Last element.
- (product-element (@@ product) (@@ index)))
- (_.if (|> (@@ $product_length) (_.< (@@ $index_min_length)))
- ## Needs recursion
- (product//right (product-tail (@@ product))
- (updated-index (@@ $index_min_length) (@@ product))))
- ## Must slice
- (_.subseq/3 (@@ product) (@@ index) (@@ $product_length))))))
-
-(runtime: (sum//get sum wanted_tag wants_last)
- (with-vars [variant-tag sum-tag sum-flag sum-value]
- (let [no-match _.nil
- is-last? (|> (@@ sum-flag) (_.equal (_.string "")))
- test-recursion (_.if is-last?
- ## Must recurse.
- (sum//get (@@ sum-value)
- (|> (@@ wanted_tag) (_.- (@@ sum-tag)))
- (@@ wants_last))
- no-match)]
- (<| (_.destructuring-bind [(_.poly (list variant-tag sum-tag sum-flag sum-value))
- (@@ sum)])
- (_.if (|> (@@ wanted_tag) (_.= (@@ sum-tag)))
- (_.if (|> (@@ sum-flag) (_.equal (@@ wants_last)))
- (@@ sum-value)
- test-recursion))
- (_.if (|> (@@ wanted_tag) (_.> (@@ sum-tag)))
- test-recursion)
- (_.if (_.and (list (|> (@@ wants_last) (_.equal (_.string "")))
- (|> (@@ wanted_tag) (_.< (@@ sum-tag)))))
- (variant' (|> (@@ sum-tag) (_.- (@@ wanted_tag))) (@@ sum-flag) (@@ sum-value)))
- no-match))))
-
-(def: runtime//adt
- Runtime
- (_.progn (list @@product//left
- @@product//right
- @@sum//get)))
-
-(runtime: (bit//logical-right-shift shift input)
- (_.if (_.= (_.int 0) (@@ shift))
- (@@ input)
- (|> (@@ input)
- (_.ash (_.* (_.int -1) (@@ shift)))
- (_.logand (_.int (hex "7FFFFFFFFFFFFFFF"))))))
-
-(def: runtime//bit
- Runtime
- (_.progn (list @@bit//logical-right-shift)))
-
-(template [<name> <top-cmp>]
- [(def: (<name> top value)
- (-> Expression Expression Expression)
- (_.and (list (|> value (_.>= (_.int 0)))
- (|> value (<top-cmp> top)))))]
-
- [within? _.<]
- [up-to? _.<=]
- )
-
-(runtime: (text//char idx text)
- (_.if (|> (@@ idx) (within? (_.length (@@ text))))
- (..some (_.char-int/1 (_.char/2 (@@ text) (@@ idx))))
- ..none))
-
-(runtime: (text//clip from to text)
- (_.if (_.and (list (|> (@@ to) (within? (_.length (@@ text))))
- (|> (@@ from) (up-to? (@@ to)))))
- (..some (_.subseq/3 (@@ text) (@@ from) (@@ to)))
- ..none))
-
-(runtime: (text//index reference start space)
- (with-vars [index]
- (_.let (list [index (_.search/start2 (@@ reference) (@@ space) (@@ start))])
- (_.if (@@ index)
- (..some (@@ index))
- ..none))))
-
-(def: runtime//text
- Runtime
- (_.progn (list @@text//index
- @@text//clip
- @@text//char)))
-
-(def: (check-index-out-of-bounds array idx body)
- (-> Expression Expression Expression Expression)
- (_.if (|> idx (_.<= (_.length array)))
- body
- (_.error (_.string "Array index out of bounds!"))))
-
-(runtime: (array//get array idx)
- (with-vars [temp]
- (<| (check-index-out-of-bounds (@@ array) (@@ idx))
- (_.let (list [temp (_.svref (@@ array) (@@ idx))])
- (_.if (_.null (@@ temp))
- ..none
- (..some (@@ temp)))))))
-
-(runtime: (array//put array idx value)
- (<| (check-index-out-of-bounds (@@ array) (@@ idx))
- (_.progn
- (list (_.setf! (_.svref (@@ array) (@@ idx)) (@@ value))
- (@@ array)))))
-
-(def: runtime//array
- Runtime
- (_.progn
- (list @@array//get
- @@array//put)))
-
-(runtime: (box//write value box)
- (_.progn
- (list
- (_.setf! (_.svref (@@ box) (_.int 0)) (@@ value))
- ..unit)))
-
-(def: runtime//box
- Runtime
- (_.progn (list @@box//write)))
-
-(runtime: (io//exit code)
- (_.progn
- (list (_.conditional+ (list "sbcl")
- (_.$apply (_.global "sb-ext:quit") (list (@@ code))))
- (_.conditional+ (list "clisp")
- (_.$apply (_.global "ext:exit") (list (@@ code))))
- (_.conditional+ (list "ccl")
- (_.$apply (_.global "ccl:quit") (list (@@ code))))
- (_.conditional+ (list "allegro")
- (_.$apply (_.global "excl:exit") (list (@@ code))))
- (_.$apply (_.global "cl-user::quit") (list (@@ code))))))
-
-(runtime: (io//current-time _)
- (|> _.get-universal-time
- (_.* (_.int 1,000))))
-
-(def: runtime//io
- (_.progn (list @@io//exit
- @@io//current-time)))
-
-(def: runtime
- Runtime
- (_.progn (list runtime//lux
- runtime//bit
- runtime//adt
- runtime//text
- runtime//array
- runtime//box
- runtime//io)))
-
-(def: #export artifact Text (format prefix //.file-extension))
-
-(def: #export translate
- (Meta (Process Any))
- (do macro.Monad<Meta>
- [_ //.init-module-buffer
- _ (//.save runtime)]
- (//.save-module! artifact)))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/statement.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/statement.jvm.lux
deleted file mode 100644
index 48ec2a2fa..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/statement.jvm.lux
+++ /dev/null
@@ -1,45 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do])
- [macro]
- (data text/format))
- (luxc (lang [".L" module]
- (host ["_" common-lisp #+ Expression @@])))
- [//]
- (// [".T" runtime]
- [".T" reference]
- [".T" eval]))
-
-(def: #export (translate-def name expressionT expressionO metaV)
- (-> Text Type Expression Code (Meta Any))
- (do macro.Monad<Meta>
- [current-module macro.current-module-name
- #let [def-name [current-module name]]]
- (case (macro.get-identifier-ann (name-of #.alias) metaV)
- (#.Some real-def)
- (do @
- [[realT realA realV] (macro.find-def real-def)
- _ (moduleL.define def-name [realT metaV realV])]
- (wrap []))
-
- _
- (do @
- [#let [def-name (referenceT.global def-name)]
- _ (//.save (_.defparameter def-name expressionO))
- expressionV (evalT.eval (@@ def-name))
- _ (moduleL.define def-name [expressionT metaV expressionV])
- _ (if (macro.type? metaV)
- (case (macro.declared-tags metaV)
- #.Nil
- (wrap [])
-
- tags
- (moduleL.declare-tags tags (macro.export? metaV) (:coerce Type expressionV)))
- (wrap []))
- #let [_ (log! (format "DEF " (%name def-name)))]]
- (wrap []))
- )))
-
-(def: #export (translate-program programO)
- (-> Expression (Meta Expression))
- (macro.fail "translate-program NOT IMPLEMENTED YET"))
diff --git a/new-luxc/source/luxc/lang/translation/common-lisp/structure.jvm.lux b/new-luxc/source/luxc/lang/translation/common-lisp/structure.jvm.lux
deleted file mode 100644
index dcf7e5693..000000000
--- a/new-luxc/source/luxc/lang/translation/common-lisp/structure.jvm.lux
+++ /dev/null
@@ -1,31 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do])
- (data [text]
- text/format)
- [macro])
- (luxc ["&" lang]
- (lang [synthesis #+ Synthesis]
- (host ["_" common-lisp #+ Expression])))
- [//]
- (// [".T" runtime]))
-
-(def: #export (translate-tuple translate elemsS+)
- (-> (-> Synthesis (Meta Expression)) (List Synthesis) (Meta Expression))
- (case elemsS+
- #.Nil
- (:: macro.Monad<Meta> wrap runtimeT.unit)
-
- (#.Cons singletonS #.Nil)
- (translate singletonS)
-
- _
- (do macro.Monad<Meta>
- [elemsT+ (monad.map @ translate elemsS+)]
- (wrap (_.vector elemsT+)))))
-
-(def: #export (translate-variant translate tag tail? valueS)
- (-> (-> Synthesis (Meta Expression)) Nat Bit Synthesis (Meta Expression))
- (do macro.Monad<Meta>
- [valueT (translate valueS)]
- (wrap (runtimeT.variant tag tail? valueT))))