Skip to content

Commit

Permalink
[js] Fixup some convertions to primitive types in async/await mode
Browse files Browse the repository at this point in the history
Some grammars now work
  • Loading branch information
pmurias committed Jul 19, 2017
1 parent 282e72f commit 2f72761
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/vm/js/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
%convert{$T_STR} := 'toStr';
%convert{$T_NUM} := 'toNum';
%convert{$T_INT} := 'toInt';
return Chunk.new($desired, 'nqp.' ~ %convert{$desired} ~ '(' ~ $chunk.expr ~ ", {$*CTX})", $chunk);
return Chunk.new($desired, '(' ~ self.await ~ 'nqp.' ~ %convert{$desired} ~ '(' ~ $chunk.expr ~ ", {$*CTX}))", $chunk);
}

if $desired == $T_STR {
Expand Down
2 changes: 1 addition & 1 deletion src/vm/js/RegexCompiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RegexCompiler {
"{$!cursor} = $start[0];\n",
self.set_cursor_var(),
"{$!target} = $start[1];\n",
"{$!pos} = nqp.toInt($start[2], $*CTX);\n",
"{$!pos} = await nqp.toInt($start[2], $*CTX);\n",
($!has_cursor_type ?? '' !! "{$!cursor_type_runtime} = $start[3];\n"),
"{$!bstack} = $start[4].array;\n",
"{$!restart} = $start[5];\n",
Expand Down
12 changes: 6 additions & 6 deletions src/vm/js/nqp-runtime/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ op.setdispatcherfor = function(dispatcher, dispatcherFor) {
}
};

exports.toStr = function(arg_, ctx) {
exports.toStr = async function(arg_, ctx) {
var arg = arg_.$$decont(ctx);
if (typeof arg == 'number') {
return numToStr(arg);
Expand All @@ -192,7 +192,7 @@ exports.toStr = function(arg_, ctx) {
} else if (arg.$$getStr) {
return arg.$$getStr();
} else if (arg.Str) {
let ret = arg.Str(ctx, null, arg).$$decont(ctx); // eslint-disable-line new-cap
let ret = (await arg.Str(ctx, null, arg)).$$decont(ctx); // eslint-disable-line new-cap
if (typeof ret == 'string') return ret;
return ret.$$getStr();
} else if (arg.$$getNum) {
Expand Down Expand Up @@ -227,7 +227,7 @@ function numToStr(num) {

exports.numToStr = numToStr;

exports.toNum = function(arg_, ctx) {
exports.toNum = async function(arg_, ctx) {
let arg = arg_.$$decont(ctx);
if (typeof arg == 'number') {
return arg;
Expand All @@ -236,7 +236,7 @@ exports.toNum = function(arg_, ctx) {
} else if (typeof arg == 'string') {
return strToNum(arg);
} else if (arg._STable && arg._STable.methodCache && arg._STable.methodCache.get('Num')) {
var result = arg.Num(ctx, null, arg); // eslint-disable-line new-cap
var result = await arg.Num(ctx, null, arg); // eslint-disable-line new-cap
if (result.$$getNum) {
return result.$$getNum();
} else if (result.$$numify) {
Expand All @@ -259,8 +259,8 @@ exports.toNum = function(arg_, ctx) {
}
};

exports.toInt = function(arg, ctx) {
return (exports.toNum(arg, ctx) | 0);
exports.toInt = async function(arg, ctx) {
return ((await exports.toNum(arg, ctx)) | 0);
};

exports.intToObj = function(hllName, i) {
Expand Down

0 comments on commit 2f72761

Please sign in to comment.