diff --git a/src/vm/js/Compiler.nqp b/src/vm/js/Compiler.nqp index 2d34f0c3a7..de15fded42 100644 --- a/src/vm/js/Compiler.nqp +++ b/src/vm/js/Compiler.nqp @@ -412,7 +412,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce { } else { $pos_slurpy := 1; - set_variable($param, "nqp.slurpyArray({quote_string($*HLL)}, Array.prototype.slice.call(arguments,{+@sig}))"); + set_variable($param, "nqp.slurpyArray(HLL, Array.prototype.slice.call(arguments,{+@sig}))"); } } else { my int $type := self.type_from_typeobj($param.returns); @@ -575,7 +575,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce { %convert{$T_INT} := 'intToObj'; %convert{$T_NUM} := 'numToObj'; %convert{$T_STR} := 'strToObj'; - return Chunk.new($T_OBJ, "nqp.{%convert{$got}}({quote_string($*HLL)}, {$chunk.expr})", $chunk); + return Chunk.new($T_OBJ, "nqp.{%convert{$got}}(HLL, {$chunk.expr})", $chunk); } } @@ -1057,7 +1057,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce { if $node.has_exit_handler { $result_for_exit_handler := $*BLOCK.add_tmp; $wrap_in_try := 1; - $exit_handler := "\} finally \{nqp.exitHandler($*CTX, {quote_string($*HLL)}, $result_for_exit_handler);\n"; + $exit_handler := "\} finally \{nqp.exitHandler($*CTX, HLL, $result_for_exit_handler);\n"; } if $*BLOCK.pass_on_exceptions { @@ -1331,7 +1331,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce { "var sh = nqp.createArray([{nqp::join(',',@sh)}]);\n" ~ "var sc = nqp.op.createsc({quote_string(nqp::scgethandle($sc))});\n" ~ self.emit_code_refs_list($ast) - , "nqp.op.deserialize({quote_string($*HLL)}, $quoted_data,sc,sh,code_refs,null,cuids,function() \{{self.setup_wvals}\});\n" + , "nqp.op.deserialize(HLL, $quoted_data,sc,sh,code_refs,null,cuids,function() \{{self.setup_wvals}\});\n" ~ "nqp.op.scsetdesc(sc,{quote_string(nqp::scgetdesc($sc))});\n"); } @@ -1487,7 +1487,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce { my int $comp_mode := $node.compilation_mode; - my str $set_hll := $*HLL ?? "nqp.setCodeRefHLL(cuids, {quote_string($*HLL)});\n" !! ''; + my str $set_hll := "nqp.setCodeRefHLL(cuids, HLL);\n"; my $set_code_objects := self.set_code_objects; my @setup := [$pre , $comp_mode ?? self.create_sc($node) !! '', $set_code_objects, self.declare_js_vars($*BLOCK.tmps), self.declare_js_vars($*BLOCK.js_lexicals), self.capture_inners($*BLOCK), self.clone_inners($*BLOCK), $set_hll, $post, $body]; @@ -1510,7 +1510,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce { multi method as_js(QAST::ParamTypeCheck $node) { my $check := self.as_js($node[0], :want($T_BOOL)); - Chunk.void($check, "if (!{$check.expr}) return nqp.paramcheckfailed({quote_string($*HLL)}, $*CTX, Array.prototype.slice.call(arguments));\n"); + Chunk.void($check, "if (!{$check.expr}) return nqp.paramcheckfailed(HLL, $*CTX, Array.prototype.slice.call(arguments));\n"); } my %default_value := nqp::hash($T_OBJ, 'nqp.Null', $T_INT, '0', $T_NUM, '0', $T_STR, 'nqp.null_s'); @@ -1807,7 +1807,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce { my $suffix := self.suffix_from_type($type); my $get := self.get_var($var); my $set := self.set_var($var, 'value'); - Chunk.new($T_OBJ, "nqp.lexRef{$suffix}({quote_string($*HLL)}, function() \{return $get\}, function(value) \{$set\})", :node($var)); + Chunk.new($T_OBJ, "nqp.lexRef{$suffix}(HLL, function() \{return $get\}, function(value) \{$set\})", :node($var)); } } } @@ -1881,7 +1881,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce { } - Chunk.new($T_OBJ, "nqp.attrRef{$suffix}({quote_string($*HLL)}, function() \{return $get\}, function(value) \{$set\})", :node($var)); + Chunk.new($T_OBJ, "nqp.attrRef{$suffix}(HLL, function() \{return $get\}, function(value) \{$set\})", :node($var)); } elsif $var.scope eq 'attribute' { my @types := [$T_OBJ, $T_INT, $T_NUM, $T_STR]; diff --git a/src/vm/js/Operations.nqp b/src/vm/js/Operations.nqp index 1eb3d1cd2b..c559fc9fe3 100644 --- a/src/vm/js/Operations.nqp +++ b/src/vm/js/Operations.nqp @@ -38,9 +38,9 @@ class QAST::OperationsJS { if $hll { if $method_call { - nqp::splice(@exprs, nqp::list(quote_string($*HLL)), 1, 0); + nqp::splice(@exprs, 'HLL', 1, 0); } else { - @exprs.unshift(quote_string($*HLL)); + @exprs.unshift('HLL'); } } @@ -577,7 +577,7 @@ class QAST::OperationsJS { @exprs.push($chunk.expr); } - my $hll := $type == $T_OBJ ?? quote_string($*HLL) ~ ',' !! ''; + my $hll := $type == $T_OBJ ?? 'HLL,' !! ''; @setup.push($list ~ " = nqp.list" ~ $suffix ~ "(" ~ $hll ~ "[" ~ nqp::join(',', @exprs) ~ "]);\n"); Chunk.new($T_OBJ, $list , @setup, :$node); diff --git a/src/vm/js/nqp-runtime/bignum.js b/src/vm/js/nqp-runtime/bignum.js index 98e300c78f..22f9f14804 100644 --- a/src/vm/js/nqp-runtime/bignum.js +++ b/src/vm/js/nqp-runtime/bignum.js @@ -244,15 +244,15 @@ op.bool_I = function(n) { return intishBool(getBI(n).toNumber()); }; -op.radix_I = function(hllName, radix, str, zpos, flags, type) { +op.radix_I = function(currentHLL, radix, str, zpos, flags, type) { var extracted = core.radixHelper(radix, str, zpos, flags); if (extracted == null) { - return hll.slurpyArray(hllName, [makeBI(type, bignum(0)), makeBI(type, bignum(1)), -1]); + return hll.slurpyArray(currentHLL, [makeBI(type, bignum(0)), makeBI(type, bignum(1)), -1]); } if (radix == 10 || radix == 16) { var pow = bignum(radix).pow(extracted.power); - return hll.slurpyArray(hllName, [makeBI(type, bignum(extracted.number, radix)), makeBI(type, pow), extracted.offset]); + return hll.slurpyArray(currentHLL, [makeBI(type, bignum(extracted.number, radix)), makeBI(type, pow), extracted.offset]); } else { var n = extracted.number; var base = bignum(1); @@ -271,6 +271,6 @@ op.radix_I = function(hllName, radix, str, zpos, flags, type) { if (n[0] == '-') result = result.neg(); - return hll.slurpyArray(hllName, [makeBI(type, result), makeBI(type, base), extracted.offset]); + return hll.slurpyArray(currentHLL, [makeBI(type, result), makeBI(type, base), extracted.offset]); } }; diff --git a/src/vm/js/nqp-runtime/core.js b/src/vm/js/nqp-runtime/core.js index 6416deb8ec..eea7e7f1bb 100644 --- a/src/vm/js/nqp-runtime/core.js +++ b/src/vm/js/nqp-runtime/core.js @@ -79,13 +79,13 @@ function radixHelper(radix, str, zpos, flags) { exports.radixHelper = radixHelper; -op.radix = function(hllName, radix, str, zpos, flags) { +op.radix = function(currentHLL, radix, str, zpos, flags) { var extracted = radixHelper(radix, str, zpos, flags); if (extracted == null) { - return hll.slurpyArray(hllName, [0, 1, -1]); + return hll.slurpyArray(currentHLL, [0, 1, -1]); } var pow = Math.pow(radix, extracted.power); - return hll.slurpyArray(hllName, [parseInt(extracted.number, radix), pow, extracted.offset]); + return hll.slurpyArray(currentHLL, [parseInt(extracted.number, radix), pow, extracted.offset]); }; op.setdebugtypename = function(type, debugName) { @@ -1058,11 +1058,11 @@ op.getstaticcode = function(codeRef) { return codeRef.staticCode; }; -op.backtracestrings = function(hllName, exception) { - return hll.list(hllName, [exception.stack.replace(/^Error: .*\n/, '')]); +op.backtracestrings = function(currentHLL, exception) { + return hll.list(currentHLL, [exception.stack.replace(/^Error: .*\n/, '')]); }; -op.backtrace = function(hllName, exception) { +op.backtrace = function(currentHLL, exception) { if (exception.$$ctx) { let ctx = exception.$$ctx.$$skipHandlers(); @@ -1114,9 +1114,9 @@ op.backtrace = function(hllName, exception) { ctx = ctx.$$caller; } - return hll.list(hllName, rows); + return hll.list(currentHLL, rows); } else { - return hll.list(hllName, []); + return hll.list(currentHLL, []); } }; @@ -1272,8 +1272,8 @@ op.islist = function(list) { return (list._STable && list._STable.REPR instanceof reprs.VMArray) ? 1 : 0; }; -op.split = function(hllName, separator, string) { - return hll.slurpyArray(hllName, string !== '' ? string.split(separator) : []); +op.split = function(currentHLL, separator, string) { + return hll.slurpyArray(currentHLL, string !== '' ? string.split(separator) : []); }; op.exception = function() { diff --git a/src/vm/js/nqp-runtime/deserialization.js b/src/vm/js/nqp-runtime/deserialization.js index bd76ee1808..dcb74af1c0 100644 --- a/src/vm/js/nqp-runtime/deserialization.js +++ b/src/vm/js/nqp-runtime/deserialization.js @@ -41,7 +41,7 @@ module.exports.wval = function(handle, idx) { return serializationContexts[handle].rootObjects[idx]; }; -op.deserialize = function(hllName, blob, sc, sh, codeRefs, conflict, cuids, setupWVals) { +op.deserialize = function(currentHLL, blob, sc, sh, codeRefs, conflict, cuids, setupWVals) { var buffer = new Buffer(blob, 'base64'); sc.codeRefs = codeRefs.array; @@ -54,7 +54,7 @@ op.deserialize = function(hllName, blob, sc, sh, codeRefs, conflict, cuids, setu sh = sh.array; var cursor = new BinaryCursor(buffer, 0, sh, sc); - cursor.deserialize(sc, cuids, setupWVals, hll.getHLL(hllName)); + cursor.deserialize(sc, cuids, setupWVals, currentHLL); }; op.createsc = function(handle) { diff --git a/src/vm/js/nqp-runtime/hll.js b/src/vm/js/nqp-runtime/hll.js index 42118ba1b1..75c8c2ba61 100644 --- a/src/vm/js/nqp-runtime/hll.js +++ b/src/vm/js/nqp-runtime/hll.js @@ -85,6 +85,8 @@ exports.hllConfigs = hllConfigs; function getHLL(language) { if (!hllConfigs[language]) { hllConfigs[language] = new Map; + hllConfigs[language].set('slurpy_array', BOOT.Array) + hllConfigs[language].set('list', BOOT.Array) // For serialization purposes hllConfigs[language].set('name', language); @@ -115,16 +117,12 @@ op.settypehllrole = function(type, role) { return type; }; -exports.slurpyArray = function(hllName, array) { - var slurpyArray; - if (hllConfigs[hllName]) slurpyArray = hllConfigs[hllName].get('slurpy_array'); - if (slurpyArray === undefined) slurpyArray = BOOT.Array; +exports.slurpyArray = function(currentHLL, array) { + const slurpyArray = currentHLL.get('slurpy_array'); return slurpyArray._STable.REPR.allocateFromArray(slurpyArray._STable, array); }; -exports.list = function(hllName, array) { - var list; - if (hllConfigs[hllName]) list = hllConfigs[hllName].get('list'); - if (list === undefined) list = BOOT.Array; +exports.list = function(currentHLL, array) { + const list = currentHLL.get('list'); return list._STable.REPR.allocateFromArray(list._STable, array); }; diff --git a/src/vm/js/nqp-runtime/refs.js b/src/vm/js/nqp-runtime/refs.js index b1c8af83d3..d71d2ff323 100644 --- a/src/vm/js/nqp-runtime/refs.js +++ b/src/vm/js/nqp-runtime/refs.js @@ -3,8 +3,8 @@ let hll = require('./hll.js'); let helpers = exports.helpers = {}; let op = exports.op = {}; -function attrRef_i(hllName, get, set) { - var refType = hll.hllConfigs[hllName].get('int_attr_ref'); +function attrRef_i(currentHLL, get, set) { + var refType = currentHLL.get('int_attr_ref'); if (refType === undefined) { throw 'No int attribute reference type registered for current HLL'; } @@ -15,8 +15,8 @@ function attrRef_i(hllName, get, set) { return ref; } -function attrRef_n(hllName, get, set) { - var refType = hll.hllConfigs[hllName].get('num_attr_ref'); +function attrRef_n(currentHLL, get, set) { + var refType = currentHLL.get('num_attr_ref'); if (refType === undefined) { throw 'No num attribute reference type registered for current HLL'; } @@ -27,8 +27,8 @@ function attrRef_n(hllName, get, set) { return ref; } -function attrRef_s(hllName, get, set) { - var refType = hll.hllConfigs[hllName].get('str_attr_ref'); +function attrRef_s(currentHLL, get, set) { + var refType = currentHLL.get('str_attr_ref'); if (refType === undefined) { throw 'No str attribute reference type registered for current HLL'; } @@ -39,26 +39,26 @@ function attrRef_s(hllName, get, set) { return ref; } -op.getattrref_i = function(hllName, obj, classHandle, attrName) { - return attrRef_i(hllName, +op.getattrref_i = function(currentHLL, obj, classHandle, attrName) { + return attrRef_i(currentHLL, () => obj.$$getattr_i(classHandle, attrName), value => obj.$$bindattr_i(classHandle, attrName, value)); }; -op.getattrref_n = function(hllName, obj, classHandle, attrName) { - return attrRef_n(hllName, +op.getattrref_n = function(currentHLL, obj, classHandle, attrName) { + return attrRef_n(currentHLL, () => obj.$$getattr_n(classHandle, attrName), value => obj.$$bindattr_n(classHandle, attrName, value)); }; -op.getattrref_s = function(hllName, obj, classHandle, attrName) { - return attrRef_s(hllName, +op.getattrref_s = function(currentHLL, obj, classHandle, attrName) { + return attrRef_s(currentHLL, () => obj.$$getattr_s(classHandle, attrName), value => obj.$$bindattr_s(classHandle, attrName, value)); }; -helpers.lexRef_i = function(hllName, get, set) { - var refType = hll.hllConfigs[hllName].get('int_lex_ref'); +helpers.lexRef_i = function(currentHLL, get, set) { + var refType = currentHLL.get('int_lex_ref'); if (refType === undefined) { throw 'No int lexical reference type registered for current HLL'; } @@ -69,8 +69,8 @@ helpers.lexRef_i = function(hllName, get, set) { return ref; }; -helpers.lexRef_s = function(hllName, get, set) { - var refType = hll.hllConfigs[hllName].get('str_lex_ref'); +helpers.lexRef_s = function(currentHLL, get, set) { + var refType = currentHLL.get('str_lex_ref'); if (refType === undefined) { throw 'No str lexical reference type registered for current HLL'; } @@ -81,8 +81,8 @@ helpers.lexRef_s = function(hllName, get, set) { return ref; }; -helpers.lexRef_n = function(hllName, get, set) { - var refType = hll.hllConfigs[hllName].get('num_lex_ref'); +helpers.lexRef_n = function(currentHLL, get, set) { + var refType = currentHLL.get('num_lex_ref'); if (refType === undefined) { throw 'No num lexical reference type registered for current HLL'; } @@ -93,8 +93,8 @@ helpers.lexRef_n = function(hllName, get, set) { return ref; }; -op.atposref_i = function(hllName, obj, index) { - var refType = hll.hllConfigs[hllName].get('int_pos_ref'); +op.atposref_i = function(currentHLL, obj, index) { + var refType = currentHLL.get('int_pos_ref'); if (refType === undefined) { throw 'No int lexical reference type registered for current HLL'; } @@ -105,8 +105,8 @@ op.atposref_i = function(hllName, obj, index) { return ref; }; -op.atposref_n = function(hllName, obj, index) { - var refType = hll.hllConfigs[hllName].get('num_pos_ref'); +op.atposref_n = function(currentHLL, obj, index) { + var refType = currentHLL.get('num_pos_ref'); if (refType === undefined) { throw 'No num lexical reference type registered for current HLL'; } @@ -117,8 +117,8 @@ op.atposref_n = function(hllName, obj, index) { return ref; }; -op.atposref_s = function(hllName, obj, index) { - var refType = hll.hllConfigs[hllName].get('str_pos_ref'); +op.atposref_s = function(currentHLL, obj, index) { + var refType = currentHLL.get('str_pos_ref'); if (refType === undefined) { throw 'No str lexical reference type registered for current HLL'; } diff --git a/src/vm/js/nqp-runtime/runtime.js b/src/vm/js/nqp-runtime/runtime.js index 725acc5389..f987d4013b 100644 --- a/src/vm/js/nqp-runtime/runtime.js +++ b/src/vm/js/nqp-runtime/runtime.js @@ -262,10 +262,8 @@ exports.toInt = function(arg, ctx) { return (exports.toNum(arg, ctx) | 0); }; -exports.intToObj = function(hllName, i) { - var currentHLL = hll.hllConfigs[hllName]; - var type; - if (currentHLL) type = currentHLL.get('int_box'); +exports.intToObj = function(currentHLL, i) { + const type = currentHLL.get('int_box'); if (!type) { return new NQPInt(i); } else { @@ -276,10 +274,8 @@ exports.intToObj = function(hllName, i) { } }; -exports.numToObj = function(hllName, n) { - var currentHLL = hll.hllConfigs[hllName]; - var type; - if (currentHLL) type = currentHLL.get('num_box'); +exports.numToObj = function(currentHLL, n) { + const type = currentHLL.get('num_box'); if (!type) { return n; } else { @@ -290,10 +286,8 @@ exports.numToObj = function(hllName, n) { } }; -exports.strToObj = function(hllName, s) { - var currentHLL = hll.hllConfigs[hllName]; - var type; - if (currentHLL) type = currentHLL.get('str_box'); +exports.strToObj = function(currentHLL, s) { + const type = currentHLL.get('str_box'); if (!type) { return s; } else { @@ -380,9 +374,9 @@ exports.wrapException = function(e) { return new NQPException('<>\n'); }; -exports.setCodeRefHLL = function(codeRefs, hllName) { +exports.setCodeRefHLL = function(codeRefs, currentHLL) { for (var i = 0; i < codeRefs.length; i++) { - codeRefs[i].hll = hll.hllConfigs[hllName]; + codeRefs[i].hll = currentHLL; } }; @@ -483,9 +477,9 @@ exports.extraRuntime = function(lang, path) { } }; -exports.paramcheckfailed = function(hllName, ctx, args) { +exports.paramcheckfailed = function(currentHLL, ctx, args) { let capture = new Capture(args[1], Array.prototype.slice.call(args, 2)); - return hll.hllConfigs[hllName].get('bind_error').$$call(ctx, null, capture); + return currentHLL.get('bind_error').$$call(ctx, null, capture); }; let execname; @@ -497,8 +491,8 @@ op.execname = function() { return execname; }; -exports.exitHandler = function(ctx, hllName, value) { - hll.hllConfigs[hllName].get('exit_handler').$$call(ctx, null, ctx.codeRef(), value === undefined ? Null : value); +exports.exitHandler = function(ctx, currentHLL, value) { + currentHLL.get('exit_handler').$$call(ctx, null, ctx.codeRef(), value === undefined ? Null : value); }; exports.NativeRef = require('./reprs.js').NativeRef;