Skip to content

Commit

Permalink
Better static lexical code-gen.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed May 9, 2013
1 parent dd8ebc1 commit b6921f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
24 changes: 10 additions & 14 deletions src/vm/parrot/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -406,26 +406,22 @@ class QAST::Compiler is HLL::Compiler {

method block_lex_values_to_post_des(@post_des, %blv) {
for %blv {
my $cuid := $_.key;
my $tasks := QAST::Stmt.new();
my $cuid := $_.key;
my $names := QAST::Op.new( :op('list_s') );
my $values := QAST::Op.new( :op('list') );
my $flags := QAST::Op.new( :op('list_i') );
for $_.value -> @lex {
$tasks.push(QAST::Op.new(
:op('callmethod'), :name('set_lexpad_value'),
QAST::VM.new(
pir => ' .const "LexInfo" %r = "' ~ $cuid ~ '"'
),
QAST::SVal.new( :value(@lex[0]) ),
QAST::WVal.new( :value(@lex[1]) ),
QAST::IVal.new( :value(@lex[2]) )
));
$names.push(QAST::SVal.new( :value(@lex[0]) ));
$values.push(QAST::WVal.new( :value(@lex[1]) ));
$flags.push(QAST::IVal.new( :value(@lex[2]) ));
}
$tasks.push(QAST::Op.new(
:op('callmethod'), :name('finish_static_lexpad'),
nqp::push(@post_des, QAST::Op.new(
:op('callmethod'), :name('setup_static_lexpad'),
QAST::VM.new(
pir => ' .const "LexInfo" %r = "' ~ $cuid ~ '"'
),
$names, $values, $flags
));
nqp::push(@post_des, $tasks);
}
}

Expand Down
31 changes: 17 additions & 14 deletions src/vm/parrot/pmc/nqplexinfo.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,6 @@ compiler calls this method in response to a ".lex STRING, PREG" directive.
VTABLE_set_integer_keyed_str(interp, sfs, key, 0);
}

METHOD set_lexpad_value(STRING *key, PMC *value, INTVAL flags) {
PMC *svs, *sfs;
GET_ATTR_static_values(INTERP, SELF, svs);
GET_ATTR_static_flags(INTERP, SELF, sfs);
if (PMC_IS_NULL(svs)) {
svs = Parrot_pmc_new(interp, enum_class_Hash);
SET_ATTR_static_values(INTERP, SELF, svs);
sfs = Parrot_pmc_new(interp, enum_class_Hash);
SET_ATTR_static_flags(INTERP, SELF, sfs);
}
VTABLE_set_pmc_keyed_str(interp, svs, key, value);
VTABLE_set_integer_keyed_str(interp, sfs, key, flags);
}

METHOD finish_static_lexpad() {
/* Build caches from the static lexpad. */
PMC *svs, *sfs;
Expand Down Expand Up @@ -193,6 +179,23 @@ compiler calls this method in response to a ".lex STRING, PREG" directive.
}
}

METHOD setup_static_lexpad(PMC *names, PMC *values, PMC *flags) {
/* Need to turn name list into slot list. */
PMC *slots = Parrot_pmc_new(interp, enum_class_ResizableIntegerArray);
INTVAL elems = VTABLE_elements(interp, names);
INTVAL i;
for (i = 0; i < elems; i++) {
STRING *name = VTABLE_get_string_keyed_int(interp, names, i);
INTVAL slot = VTABLE_get_integer_keyed_str(interp, SELF, name);
VTABLE_push_integer(interp, slots, slot >> 2);
}
SET_ATTR_static_slots_cache(INTERP, SELF, slots);

/* Just store values and flags. */
SET_ATTR_static_values_cache(INTERP, SELF, values);
SET_ATTR_static_flags_cache(INTERP, SELF, flags);
}

METHOD get_static_code() {
PMC *static_code;
GET_ATTR_static_code(INTERP, SELF, static_code);
Expand Down

0 comments on commit b6921f3

Please sign in to comment.