Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[js] Implement a bunch of _n list ops.
  • Loading branch information
pmurias committed Jan 13, 2016
1 parent 03c396b commit 3abb3c4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/vm/js/QAST/Compiler.nqp
Expand Up @@ -760,11 +760,7 @@ class QAST::OperationsJS {
$comp.bind_pos($node[0], $node[1], $node[2], :$cps);
});

add_simple_op('bindpos_i', $T_INT, [$T_OBJ, $T_INT, $T_INT], sub ($list, $index, $value) {"($list[$index] = $value)"}, :sideffects);

add_simple_op('bindpos_s', $T_INT, [$T_OBJ, $T_INT, $T_STR], sub ($list, $index, $value) {"($list[$index] = $value)"}, :sideffects);

for ['_i', $T_INT, '', $T_OBJ, '_s', $T_STR] -> $suffix, $type {
for ['_i', $T_INT, '', $T_OBJ, '_s', $T_STR, '_n', $T_NUM] -> $suffix, $type {
add_op('list' ~ $suffix, sub ($comp, $node, :$want, :$cps) {
# TODO CPS
my @setup;
Expand All @@ -782,6 +778,13 @@ class QAST::OperationsJS {

$comp.cpsify_chunk(Chunk.new($T_OBJ, $list , @setup, :$node));
});

if $type != $T_OBJ {
add_simple_op('bindpos' ~ $suffix, $type, [$T_OBJ, $T_INT, $type], sub ($list, $index, $value) {"($list[$index] = $value)"}, :sideffects);
}

add_simple_op('pop' ~ $suffix, $type, [$T_OBJ], sub ($array) {"$array.pop()"}, :sideffects);
add_simple_op('push' ~ $suffix, $type, [$T_OBJ, $type], sub ($array, $elem) {"$array.push($elem)"}, :sideffects);
}

add_op('hash', sub ($comp, $node, :$want, :$cps) {
Expand Down Expand Up @@ -1033,13 +1036,10 @@ class QAST::OperationsJS {

add_simple_op('islist', $T_BOOL, [$T_OBJ], sub ($obj) {"($obj instanceof Array)"});

for ['_i', $T_INT, '', $T_OBJ, '_s', $T_STR] -> $suffix, $type {
add_simple_op('pop' ~ $suffix, $type, [$T_OBJ], sub ($array) {"$array.pop()"}, :sideffects);
add_simple_op('push' ~ $suffix, $type, [$T_OBJ, $type], sub ($array, $elem) {"$array.push($elem)"}, :sideffects);
}


add_simple_op('atpos_s', $T_STR, [$T_OBJ, $T_INT], sub ($array, $index) {"$array[$index]"});
add_simple_op('atpos_n', $T_STR, [$T_OBJ, $T_INT], sub ($array, $index) {"$array[$index]"});
# HACK
add_simple_op('atpos_i', $T_INT, [$T_OBJ, $T_INT], sub ($array, $index) {"($array[$index] === undefined ? 0 : $array[$index])"});
#TODO CPS
Expand Down

0 comments on commit 3abb3c4

Please sign in to comment.