Skip to content

Commit

Permalink
[js] Implement a bunch of p6* ops.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed May 13, 2016
1 parent f16c03d commit 130a92b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/vm/js/Perl6/Ops.nqp
Expand Up @@ -7,12 +7,24 @@ sub register_op_desugar($op, $desugar) is export {
}

# Stub
register_op_desugar('p6setbinder', -> $qast {
register_op_desugar('', -> $qast {
QAST::Op.new(:op('null'));
});

register_op_desugar('p6init', -> $qast {
QAST::Op.new(:op('null'));
# Signature binding related bits.

$ops.add_simple_op('p6setbinder', $ops.VOID, [$ops.OBJ], :sideffects, sub ($binder) {"nqp.p6binder = $binder"});
$ops.add_op('p6bindsig', :!inlinable, sub ($comp, $node, :$want, :$cps) {
my $ops := nqp::getcomp('QAST').operations;
my $tmp := $*BLOCK.add_tmp;
$ops.new_chunk($ops.VOID, "", [
"$tmp = nqp.p6binder.bind_sig($*CTX, null, nqp.op.savecapture(Array.prototype.slice.call(arguments)));\n",

This comment has been minimized.

Copy link
@vendethiel

vendethiel May 13, 2016

Contributor

Calling slice on arguments like that kills optimizations in most JS engines.
The usual workaround is

var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; ++i)
  args[i] = arguments[i];
"if ($tmp !== null) return $tmp;\n"
]);
});

$ops.add_simple_op('p6isbindable', $ops.INT, [$ops.OBJ, $ops.OBJ], :!inlinable, sub ($sig, $cap) {
"nqp.p6binder.is_bindable($*CTX, null, $sig, $cap)"
});

$ops.add_simple_op('p6bindattrinvres', $ops.OBJ, [$ops.OBJ, $ops.OBJ, $ops.STR, $ops.OBJ], :sideffects,
Expand All @@ -21,3 +33,11 @@ $ops.add_simple_op('p6bindattrinvres', $ops.OBJ, [$ops.OBJ, $ops.OBJ, $ops.STR,
"($obj[$attr] = $value, $obj)";
}
);

$ops.add_simple_op('p6invokeunder', $ops.OBJ, [$ops.OBJ, $ops.OBJ], :sideffects, sub ($fake, $code) {
"$code.\$call($*CTX, null)"
});

$ops.add_simple_op('p6settypes', $ops.OBJ, [$ops.OBJ], :sideffects);
$ops.add_simple_op('p6init', $ops.OBJ, [], :sideffects, -> {'require("perl6-runtime")'});
$ops.add_simple_op('p6bool', $ops.OBJ, [$ops.BOOL], :sideffects);
18 changes: 18 additions & 0 deletions src/vm/js/perl6-runtime/package.json
@@ -0,0 +1,18 @@
{
"name": "perl6-runtime",
"version": "0.1.0",
"description": "the runtime for the js backend for rakudo",
"bugs": {
"email": "pawelmurias@gmail.com"
},
"licenses": [
{
"type": "Artistic 2",
"url": "http://opensource.org/licenses/Artistic-2.0"
}
],
"repository": "http://github.com/rakudo/rakudo/",
"main": "runtime.js",
"dependencies": {
}
}
2 changes: 2 additions & 0 deletions src/vm/js/perl6-runtime/runtime.js
@@ -0,0 +1,2 @@
console.log("loading up the rakudo runtime");
module.exports = null;

0 comments on commit 130a92b

Please sign in to comment.