Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use new MoarVM static block lexicals support.
  • Loading branch information
jnthn committed Aug 1, 2014
1 parent 9268ba7 commit 183e611
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
33 changes: 14 additions & 19 deletions src/vm/moar/QAST/QASTCompilerMAST.nqp
Expand Up @@ -14,11 +14,6 @@ my class MASTCompilerInstance {
# The filename we're compiling.
has $!file;

# Hash mapping blocks with static lexicals to an array of arrays. Each
# of the sub-arrays has the form [$name, $value, $flags], where flags
# are 0 = static lex, 1 = container, 2 = state container.
has %!block_lex_values;

# The serialization context of the code we're compiling, if we have one.
has $!sc;

Expand Down Expand Up @@ -150,18 +145,23 @@ my class MASTCompilerInstance {
}

method add_lexical($var, :$is_static, :$is_cont, :$is_state) {
my $type := $var.returns;
my $kind := $!compiler.type_to_register_kind($type);
my $index := $*MAST_FRAME.add_lexical($type, $var.name);
my $mf := $*MAST_FRAME;
my $type := $var.returns;
my $kind := $!compiler.type_to_register_kind($type);
my $index := $mf.add_lexical($type, $var.name);
self.register_lexical($var, $index, 0, $kind);
if $is_static || $is_cont || $is_state {
my %blv := $!compiler.block_lex_values;
unless nqp::existskey(%blv, $!qast.cuid) {
%blv{$!qast.cuid} := [];
my int $flags := $is_static ?? 0 !!
$is_cont ?? 1 !! 2;
my $val := $var.value;
my $sc := nqp::getobjsc($val);
if nqp::isnull($sc) {
nqp::die("Object of type " ~ $val.HOW.name($val) ~
" in QAST::Var value, but not in SC");
}
my $flags := $is_static ?? 0 !!
$is_cont ?? 1 !! 2;
nqp::push(%blv{$!qast.cuid}, [$var.name, $var.value, $flags]);
my int $idx := nqp::scgetobjidx($sc, $val);
my int $sc_idx := $!compiler.mast_compunit.sc_idx($sc);
$mf.add_static_lex_value($index, $flags, $sc_idx, $idx);
}
$kind;
}
Expand Down Expand Up @@ -288,7 +288,6 @@ my class MASTCompilerInstance {

method mast_compunit() { $!mast_compunit }
method mast_frames() { %!mast_frames }
method block_lex_values() { %!block_lex_values }
method sc() { $!sc }

method to_mast($qast) {
Expand All @@ -297,7 +296,6 @@ my class MASTCompilerInstance {
$!mast_compunit := MAST::CompUnit.new();
%!mast_frames := nqp::hash();
$!file := nqp::ifnull(nqp::getlexdyn('$?FILES'), "<unknown file>");
%!block_lex_values := nqp::hash();
$!sc := NQPMu;

# Compile, and evaluate to compilation unit.
Expand Down Expand Up @@ -522,9 +520,6 @@ my class MASTCompilerInstance {
my $comp_mode := $cu.compilation_mode;
my @pre_des := $cu.pre_deserialize;
my @post_des := $cu.post_deserialize;
if %!block_lex_values {
nqp::push(@post_des, QAST::Op.new( :op('setup_blv'), %!block_lex_values ));
}
if $comp_mode || @pre_des || @post_des {
# Create a block into which we'll install all of the other
# pieces.
Expand Down
23 changes: 0 additions & 23 deletions src/vm/moar/QAST/QASTOperationsMAST.nqp
Expand Up @@ -2449,29 +2449,6 @@ QAST::MASTOperations.add_core_op('takedispatcher', -> $qastcomp, $op {
MAST::InstructionList.new(@ops, $MVM_reg_void, MAST::VOID)
});
QAST::MASTOperations.add_core_moarop_mapping('cleardispatcher', 'takedispatcher');
QAST::MASTOperations.add_core_op('setup_blv', -> $qastcomp, $op {
if +@($op) != 1 || !nqp::ishash($op[0]) {
nqp::die('setup_blv requires one hash operand');
}

my $regalloc := $*REGALLOC;
my @ops;
for $op[0] {
my $frame := $qastcomp.mast_frames{$_.key};
my $block_reg := $regalloc.fresh_register($MVM_reg_obj);
push_op(@ops, 'getcode', $block_reg, $frame);
for $_.value -> @lex {
my $valres := $qastcomp.as_mast(QAST::WVal.new( :value(@lex[1]) ));
push_ilist(@ops, $valres);
push_op(@ops, 'setlexvalue', $block_reg, MAST::SVal.new( :value(@lex[0]) ),
$valres.result_reg, MAST::IVal.new( :value(@lex[2]) ));
$regalloc.release_register($valres.result_reg, $MVM_reg_obj);
}
$regalloc.release_register($block_reg, $MVM_reg_obj);
}

MAST::InstructionList.new(@ops, $regalloc.fresh_o(), $MVM_reg_obj)
});
QAST::MASTOperations.add_core_moarop_mapping('freshcoderef', 'freshcoderef');
QAST::MASTOperations.add_core_moarop_mapping('iscoderef', 'iscoderef');
QAST::MASTOperations.add_core_moarop_mapping('markcodestatic', 'markcodestatic');
Expand Down

0 comments on commit 183e611

Please sign in to comment.