diff options
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux | 272 |
1 files changed, 145 insertions, 127 deletions
diff --git a/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux index c3c00fde9..742185c2e 100644 --- a/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux @@ -2,52 +2,47 @@ lux (lux (data text/format) (macro [code] - ["s" syntax #+ syntax:]))) - -(type: #export JS Text) - -(type: Expression JS) - -(type: Statement JS) + ["s" syntax #+ syntax:])) + [//]) (def: prefix Text "LuxRuntime") -(def: #export unit Expression (%t "\u0000")) +(def: #export unit //.Expression (%t "\u0000")) (def: (flag value) - (-> Bool JS) + (-> Bool //.JS) (if value (%t "") "null")) (def: #export (variant tag last? value) - (-> Nat Bool Expression Expression) + (-> Nat Bool //.Expression //.Expression) (format "[" (%i (nat-to-int tag)) "," (flag last?) "," value "]")) (def: none - Expression + //.Expression (variant +0 false unit)) (def: some - (-> Expression Expression) + (-> //.Expression //.Expression) (variant +1 true)) (def: left - (-> Expression Expression) + (-> //.Expression //.Expression) (variant +0 false)) (def: right - (-> Expression Expression) + (-> //.Expression //.Expression) (variant +1 true)) -(type: Runtime JS) +(type: Runtime //.JS) (def: (runtime-name name) (-> Text Text) (format prefix "$" name)) (def: (feature name definition) - (-> Text (-> Text Expression) Statement) + (-> Text (-> Text //.Expression) //.Statement) (format "var " name " = " (definition name) ";\n")) (syntax: (runtime-implementation-name [runtime-name s.local-symbol]) @@ -55,7 +50,7 @@ (template: (runtime: <lux-name> <js-name> <js-definition>) (def: #export <lux-name> Text (runtime-name <js-name>)) - (`` (def: (~~ (runtime-implementation-name <lux-name>)) + (`` (def: ((~' ~~) (runtime-implementation-name <lux-name>)) Runtime (feature <lux-name> (function [(~' @)] @@ -146,101 +141,11 @@ __product//right __sum//get)) -(template: (bit-operation: <lux-name> <js-name> <op>) - (runtime: <lux-name> <js-name> - (format "(function " @ "(input,mask) {" - "return " int//new "(input.H " <op> " mask.H, input.L " <op> " mask.L);" - "})"))) - -(bit-operation: bit//and "andI64" "&") -(bit-operation: bit//or "orI64" "|") -(bit-operation: bit//xor "xorI64" "^") - -(runtime: bit//not "notI64" - (format "(function " @ "(i64) {" - "return " int//new "(~i64.H,~i64.L);" - "})")) - -(runtime: bit//count "countI64" - (format "(function " @ "(input) {" - "var hs = (input.H).toString(2);" - "var ls = (input.L).toString(2);" - "var num1s = hs.concat(ls).replace(/0/g,'').length;" - "return " int//from-number "(num1s);" - "})")) - -(runtime: bit//shift-left "shlI64" - (format "(function " @ "(input,shift) {" - "shift &= 63;" - (format "if(shift === 0) {" - "return input;" - "}" - "else {" - (format "if (shift < 32) {" - "var high = (input.H << shift) | (input.L >>> (32 - shift));" - "var low = input.L << shift;" - "return " int//new "(high, low);" - "}" - "else {" - "var high = (input.L << (shift - 32));" - "return " int//new "(high, 0);" - "}") - "}") - "})")) - -(runtime: bit//signed-shift-right "shrI64" - (format "(function " @ "(input,shift) {" - "shift &= 63;" - (format "if(shift === 0) {" - "return input;" - "}" - "else {" - (format "if (shift < 32) {" - "var high = input.H >> shift;" - "var low = (input.L >>> shift) | (input.H << (32 - shift));" - "return " int//new "(high, low);" - "}" - "else {" - "var low = (input.H >> (shift - 32));" - "var high = input.H >= 0 ? 0 : -1;" - "return " int//new "(high, low);" - "}") - "}") - "})")) - -(runtime: bit//shift-right "ushrI64" - (format "(function " @ "(input,shift) {" - "shift &= 63;" - (format "if(shift === 0) {" - "return input;" - "}" - "else {" - (format "if (shift < 32) {" - "var high = input.H >>> shift;" - "var low = (input.L >>> shift) | (input.H << (32 - shift));" - "return " int//new "(high, low);" - "}" - "else if(shift === 32) {" - "return " int//new "(0, input.H);" - "}" - "else {" - "var low = (input.H >>> (shift - 32));" - "return " int//new "(0, low);" - "}") - "}") +(runtime: int//new "makeI64" + (format "(function " @ "(high,low) {" + "return { H: (high|0), L: (low|0)};" "})")) -(def: runtime//bit - Runtime - (format __bit//and - __bit//or - __bit//xor - __bit//not - __bit//count - __bit//shift-left - __bit//signed-shift-right - __bit//shift-right)) - (runtime: int//2^16 "TWO_PWR_16" "(1 << 16)") @@ -266,11 +171,6 @@ (runtime: int//zero "ZERO" "{ H: (0|0), L: (0|0)}") -(runtime: int//new "makeI64" - (format "(function " @ "(high,low) {" - "return { H: (high|0), L: (low|0)};" - "})")) - (runtime: int//min "MIN_VALUE_I64" "{ H: (0x80000000|0), L: (0|0)}") @@ -313,6 +213,21 @@ "return " int//new "((x48 << 16) | x32, (x16 << 16) | x00);" "})")) +(template: (bit-operation: <lux-name> <js-name> <op>) + (runtime: <lux-name> <js-name> + (format "(function " (~' @) "(input,mask) {" + "return " int//new "(input.H " <op> " mask.H, input.L " <op> " mask.L);" + "})"))) + +(bit-operation: bit//and "andI64" "&") +(bit-operation: bit//or "orI64" "|") +(bit-operation: bit//xor "xorI64" "^") + +(runtime: bit//not "notI64" + (format "(function " @ "(i64) {" + "return " int//new "(~i64.H,~i64.L);" + "})")) + (runtime: int//negate "negateI64" (format "(function " @ "(i64) {" (format "if(" int//= "(" int//min ",i64)) {" @@ -342,6 +257,86 @@ "}") "})")) +(runtime: bit//count "countI64" + (format "(function " @ "(input) {" + "var hs = (input.H).toString(2);" + "var ls = (input.L).toString(2);" + "var num1s = hs.concat(ls).replace(/0/g,'').length;" + "return " int//from-number "(num1s);" + "})")) + +(runtime: bit//shift-left "shlI64" + (format "(function " @ "(input,shift) {" + "shift &= 63;" + (format "if(shift === 0) {" + "return input;" + "}" + "else {" + (format "if (shift < 32) {" + "var high = (input.H << shift) | (input.L >>> (32 - shift));" + "var low = input.L << shift;" + "return " int//new "(high, low);" + "}" + "else {" + "var high = (input.L << (shift - 32));" + "return " int//new "(high, 0);" + "}") + "}") + "})")) + +(runtime: bit//signed-shift-right "shrI64" + (format "(function " @ "(input,shift) {" + "shift &= 63;" + (format "if(shift === 0) {" + "return input;" + "}" + "else {" + (format "if (shift < 32) {" + "var high = input.H >> shift;" + "var low = (input.L >>> shift) | (input.H << (32 - shift));" + "return " int//new "(high, low);" + "}" + "else {" + "var low = (input.H >> (shift - 32));" + "var high = input.H >= 0 ? 0 : -1;" + "return " int//new "(high, low);" + "}") + "}") + "})")) + +(runtime: bit//shift-right "ushrI64" + (format "(function " @ "(input,shift) {" + "shift &= 63;" + (format "if(shift === 0) {" + "return input;" + "}" + "else {" + (format "if (shift < 32) {" + "var high = input.H >>> shift;" + "var low = (input.L >>> shift) | (input.H << (32 - shift));" + "return " int//new "(high, low);" + "}" + "else if(shift === 32) {" + "return " int//new "(0, input.H);" + "}" + "else {" + "var low = (input.H >>> (shift - 32));" + "return " int//new "(0, low);" + "}") + "}") + "})")) + +(def: runtime//bit + Runtime + (format __bit//and + __bit//or + __bit//xor + __bit//not + __bit//count + __bit//shift-left + __bit//signed-shift-right + __bit//shift-right)) + (runtime: int//- "subI64" (format "(function " @ "(l,r) {" "return " int//+ "(l, " int//negate "(r));" @@ -1037,12 +1032,6 @@ __array//put __array//remove)) -(runtime: io//log "log" - (format "(function " @ "(message) {" - "console.log(message);" - (format "return " &&/unit ";") - "})")) - (runtime: io//error "error" (format "(function " @ "(message) {" "throw new Error(message);" @@ -1050,8 +1039,35 @@ (def: runtime//io Runtime - (format __io//log - __io//error)) + (format __io//error)) + +(def: #export atom-field Text "V") + +(runtime: atom//compare-and-swap "atomCompareAndSwap" + (format "(function " @ "(atom,old,new) {" + "if(atom." atom-field " === old) {" + "atom." atom-field " = new;" + "return true;" + "}" + "else {" + "return false;" + "}" + "})")) + +(def: runtime//atom + Runtime + (format __atom//compare-and-swap)) + +(runtime: js//get "jsGetField" + (format "(function " @ "(object, field) {" + "var temp = object[field];" + (format "if(temp !== undefined) {" + (format "return " (some "temp") ";") + "}" + "else {" + (format "return " none ";") + "}") + "})")) (runtime: js//set "jsSetField" (format "(function " @ "(object, field, input) {" @@ -1072,7 +1088,8 @@ (def: runtime//js Runtime - (format __js//set + (format __js//get + __js//set __js//delete __js//call)) @@ -1087,10 +1104,11 @@ runtime//text runtime//array runtime//io + runtime//atom runtime//js)) (def: #export artifact Text (format prefix ".js")) -(def: #export generate - (Meta Unit) - (&&/save-js! artifact runtime)) +## (def: #export generate +## (Meta Unit) +## (&&/save-js! artifact runtime)) |