aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/js/procedure
diff options
context:
space:
mode:
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/js/procedure')
-rw-r--r--new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux375
-rw-r--r--new-luxc/source/luxc/lang/translation/js/procedure/host.jvm.lux149
2 files changed, 0 insertions, 524 deletions
diff --git a/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux
deleted file mode 100644
index 641eb9e02..000000000
--- a/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux
+++ /dev/null
@@ -1,375 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do]
- ["ex" exception #+ exception:]
- ["p" parser])
- (data ["e" error]
- [text]
- text/format
- (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 [js #+ JS Expression Statement])))
- [///]
- (/// [".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))))))
-
-(def: (self-contained content)
- (-> Expression Expression)
- (format "(" content ")"))
-
-(def: (void action)
- (-> Expression Expression)
- (format "(" action "," runtimeT.unit ")"))
-
-## [Procedures]
-## [[Lux]]
-(def: (lux//is [leftJS rightJS])
- Binary
- (self-contained (format leftJS " === " rightJS)))
-
-(def: (lux//if [testJS thenJS elseJS])
- Trinary
- (caseT.translate-if testJS thenJS elseJS))
-
-(def: (lux//try riskyJS)
- Unary
- (format runtimeT.lux//try "(" riskyJS ")"))
-
-(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))))
-
-## [[Bits]]
-(do-template [<name> <op>]
- [(def: (<name> [subjectJS paramJS])
- Binary
- (format <op> "(" subjectJS "," paramJS ")"))]
-
- [bit//and runtimeT.bit//and]
- [bit//or runtimeT.bit//or]
- [bit//xor runtimeT.bit//xor]
- )
-
-(do-template [<name> <op>]
- [(def: (<name> [subjectJS paramJS])
- Binary
- (let [simple-param (format runtimeT.int//to-number "(" paramJS ")")]
- (format <op> "(" subjectJS "," simple-param ")")))]
-
- [bit//left-shift runtimeT.bit//left-shift]
- [bit//arithmetic-right-shift runtimeT.bit//arithmetic-right-shift]
- [bit//logical-right-shift runtimeT.bit//logical-right-shift]
- )
-
-## [[Numbers]]
-(host.import: java/lang/Double
- (#static MIN_VALUE Double)
- (#static MAX_VALUE Double))
-
-(do-template [<name> <const> <encode>]
- [(def: (<name> _)
- Nullary
- (<encode> <const>))]
-
- [frac//smallest Double::MIN_VALUE runtimeT.frac]
- [frac//min (f/* -1.0 Double::MAX_VALUE) runtimeT.frac]
- [frac//max Double::MAX_VALUE runtimeT.frac]
- )
-
-(do-template [<name> <op>]
- [(def: (<name> [subjectJS paramJS])
- Binary
- (format <op> "(" subjectJS "," paramJS ")"))]
-
- [int//add runtimeT.int//+]
- [int//sub runtimeT.int//-]
- [int//mul runtimeT.int//*]
- [int//div runtimeT.int///]
- [int//rem runtimeT.int//%]
- )
-
-(do-template [<name> <op>]
- [(def: (<name> [subjectJS paramJS])
- Binary
- (self-contained (format subjectJS " " <op> " " paramJS)))]
-
- [frac//add "+"]
- [frac//sub "-"]
- [frac//mul "*"]
- [frac//div "/"]
- [frac//rem "%"]
- [frac//= "==="]
- [frac//< "<"]
-
- [text//= "==="]
- [text//< "<"]
- )
-
-(do-template [<name> <cmp>]
- [(def: (<name> [subjectJS paramJS])
- Binary
- (format <cmp> "(" subjectJS "," paramJS ")"))]
-
- [int//= runtimeT.int//=]
- [int//< runtimeT.int//<]
- )
-
-(def: (frac//encode inputJS)
- Unary
- (format (self-contained inputJS) ".toString()"))
-
-(def: (frac//decode inputJS)
- Unary
- (let [decoding (format "parseFloat(" inputJS ")")
- thunk (self-contained (format "function () { return " decoding "; }"))]
- (lux//try thunk)))
-
-(do-template [<name> <transform>]
- [(def: (<name> inputJS)
- Unary
- (format <transform> "(" inputJS ")"))]
-
- [int//to-frac runtimeT.int//to-number]
- [frac//to-int runtimeT.int//from-number]
- )
-
-(def: (int//char inputJS)
- Unary
- (format "String.fromCharCode" "(" (int//to-frac inputJS) ")"))
-
-## [[Text]]
-(def: (text//size inputJS)
- Unary
- (format inputJS ".length"))
-
-(def: (text//concat [subjectJS paramJS])
- Binary
- (format subjectJS "." "concat" "(" paramJS ")"))
-
-(def: (text//char [subjectJS paramJS])
- Binary
- (format runtimeT.text//char "(" subjectJS "," paramJS ")"))
-
-(do-template [<name> <runtime>]
- [(def: (<name> [subjectJS paramJS extraJS])
- Trinary
- (format <runtime> "(" subjectJS "," paramJS "," extraJS ")"))]
-
- [text//clip runtimeT.text//clip]
- [text//index runtimeT.text//index]
-
- )
-
-## [[IO]]
-(def: (io//log messageJS)
- Unary
- (void (format runtimeT.io//log "(" messageJS ")")))
-
-(def: (io//error messageJS)
- Unary
- (format runtimeT.io//error "(" messageJS ")"))
-
-(def: (io//exit codeJS)
- Unary
- (format "("
- (format "(!((typeof process) === \"undefined\") && process.exit && process.exit(" (int//to-frac codeJS) "))")
- " || "
- "window.close()"
- " || "
- "location.reload()"
- ")"))
-
-(def: (io//current-time [])
- Nullary
- (frac//to-int "(new Date()).getTime()"))
-
-## [Bundles]
-(def: lux-procs
- Bundle
- (|> (dict.new text.Hash<Text>)
- (install "is" (binary lux//is))
- (install "try" (unary lux//try))
- (install "if" (trinary lux//if))
- (install "loop" lux//loop)
- (install "recur" lux//recur)
- ))
-
-(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))
- )))
-
-(def: int-procs
- Bundle
- (<| (prefix "int")
- (|> (dict.new text.Hash<Text>)
- (install "+" (binary int//add))
- (install "-" (binary int//sub))
- (install "*" (binary int//mul))
- (install "/" (binary int//div))
- (install "%" (binary int//rem))
- (install "=" (binary int//=))
- (install "<" (binary int//<))
- (install "to-frac" (unary int//to-frac))
- (install "char" (unary int//char)))))
-
-(def: frac-procs
- Bundle
- (<| (prefix "frac")
- (|> (dict.new text.Hash<Text>)
- (install "+" (binary frac//add))
- (install "-" (binary frac//sub))
- (install "*" (binary frac//mul))
- (install "/" (binary frac//div))
- (install "%" (binary frac//rem))
- (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 frac//to-int))
- (install "encode" (unary frac//encode))
- (install "decode" (unary frac//decode)))))
-
-(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 text//size))
- (install "char" (binary text//char))
- (install "clip" (trinary text//clip))
- )))
-
-(def: io-procs
- Bundle
- (<| (prefix "io")
- (|> (dict.new text.Hash<Text>)
- (install "log" (unary io//log))
- (install "error" (unary io//error))
- (install "exit" (unary io//exit))
- (install "current-time" (nullary io//current-time)))))
-
-(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/js/procedure/host.jvm.lux b/new-luxc/source/luxc/lang/translation/js/procedure/host.jvm.lux
deleted file mode 100644
index 00c2429a4..000000000
--- a/new-luxc/source/luxc/lang/translation/js/procedure/host.jvm.lux
+++ /dev/null
@@ -1,149 +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]))
- [///]
- (/// [".T" runtime])
- (// ["@" common]))
-
-(do-template [<name> <js>]
- [(def: (<name> _) @.Nullary <js>)]
-
- [js//null "null"]
- [js//undefined "undefined"]
- [js//object "{}"]
- )
-
-(def: (js//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: (js//call proc translate inputs)
- (-> Text @.Proc)
- (case inputs
- (^ (list& functionS argsS+))
- (do macro.Monad<Meta>
- [functionJS (translate functionS)
- argsJS+ (monad.map @ translate argsS+)]
- (wrap (format "(" functionJS ")("
- (text.join-with "," argsJS+)
- ")")))
-
- _
- (&.throw @.Wrong-Syntax (@.wrong-syntax proc inputs))))
-
-(def: js-procs
- @.Bundle
- (|> (dict.new text.Hash<Text>)
- (@.install "null" (@.nullary js//null))
- (@.install "undefined" (@.nullary js//undefined))
- (@.install "object" (@.nullary js//object))
- (@.install "global" js//global)
- (@.install "call" js//call)))
-
-(def: (object//new proc translate inputs)
- (-> Text @.Proc)
- (case inputs
- (^ (list& constructorS argsS+))
- (do macro.Monad<Meta>
- [constructorJS (translate constructorS)
- argsJS+ (monad.map @ translate argsS+)]
- (wrap (format "new (" constructorJS ")("
- (text.join-with "," argsJS+)
- ")")))
-
- _
- (&.throw @.Wrong-Syntax (@.wrong-syntax proc inputs))))
-
-(def: (object//call proc translate inputs)
- (-> Text @.Proc)
- (case inputs
- (^ (list& objectS fieldS argsS+))
- (do macro.Monad<Meta>
- [objectJS (translate objectS)
- fieldJS (translate fieldS)
- argsJS+ (monad.map @ translate argsS+)]
- (wrap (format runtimeT.js//call
- "(" objectJS
- "," fieldJS
- "," "[" (text.join-with "," argsJS+) "]"
- ")")))
-
- _
- (&.throw @.Wrong-Syntax (@.wrong-syntax proc inputs))))
-
-(def: (object//get [fieldJS objectJS])
- @.Binary
- (format runtimeT.js//get "(" objectJS "," fieldJS ")"))
-
-(def: (object//set [fieldJS valueJS objectJS])
- @.Trinary
- (format runtimeT.js//set "(" objectJS "," fieldJS "," valueJS ")"))
-
-(def: (object//delete [fieldJS objectJS])
- @.Binary
- (format runtimeT.js//delete "(" objectJS "," fieldJS ")"))
-
-(def: object-procs
- @.Bundle
- (<| (@.prefix "object")
- (|> (dict.new text.Hash<Text>)
- (@.install "new" object//new)
- (@.install "call" object//call)
- (@.install "get" (@.binary object//get))
- (@.install "set" (@.trinary object//set))
- (@.install "delete" (@.binary object//delete))
- )))
-
-(def: (array//literal elementsJS+)
- @.Variadic
- (format "[" (text.join-with "," elementsJS+) "]"))
-
-(def: (array//read [indexJS arrayJS])
- @.Binary
- (format runtimeT.array//get "(" arrayJS "," indexJS ")"))
-
-(def: (array//write [indexJS valueJS arrayJS])
- @.Trinary
- (format runtimeT.array//put "(" arrayJS "," indexJS "," valueJS ")"))
-
-(def: (array//delete [indexJS arrayJS])
- @.Binary
- (format runtimeT.array//remove "(" arrayJS "," indexJS ")"))
-
-(def: (array//length arrayJS)
- @.Unary
- (format arrayJS ".length"))
-
-(def: array-procs
- @.Bundle
- (<| (@.prefix "array")
- (|> (dict.new text.Hash<Text>)
- (@.install "literal" (@.variadic array//literal))
- (@.install "read" (@.binary array//read))
- (@.install "write" (@.trinary array//write))
- (@.install "delete" (@.binary array//delete))
- (@.install "length" (@.unary array//length))
- )))
-
-(def: #export procedures
- @.Bundle
- (<| (@.prefix "js")
- (|> js-procs
- (dict.merge object-procs)
- (dict.merge array-procs)
- )))