Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:jnthn/6model
  • Loading branch information
diakopter committed Dec 4, 2010
2 parents 8fbb45c + d08fd86 commit 512cfdb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion common/NQP/P6Objects.pm
Expand Up @@ -23,7 +23,7 @@ class Mu {
}

method isa($type) {
return self.HOW.isa(self, $type);
self.HOW.isa(self, $type)
}

method Bool() {
Expand Down
14 changes: 14 additions & 0 deletions dotnet/LHF.txt
Expand Up @@ -47,3 +47,17 @@ foundation for getting that in place. To do this:
RakudoObject).
3) Edit Actions.pm and make .WHO use the get_who op (see .WHAT and
.HOW for examples).

Constant Table Dupe Elimination
-------------------------------
DIFFICULTY: Intermediate
SKILLS: NQP
DETAILS:
We have a constant table. This is good. However, in the program:
say("foo");
say("foo");
The "foo" ends up in the constants table twice. This is not good.
Take a look in multi sub dnst_for(PAST::Val $val) { ... } and see
about eliminating the duplication. It happens for integer and
numeric constants too. If you use some weird unique string you can
easily look at x.cs to see it only appears once, not once per usage.
9 changes: 8 additions & 1 deletion dotnet/compiler/DNST.pm
Expand Up @@ -375,6 +375,7 @@ class DNST::Bind is DNST::Node {
class DNST::Literal is DNST::Node {
has $!value;
has $!escape;
has $!type;

method value($set?) {
if pir::defined($set) { $!value := $set }
Expand All @@ -386,10 +387,16 @@ class DNST::Literal is DNST::Node {
$!escape
}

method new(:$value!, :$escape) {
method type($set?) {
if pir::defined($set) { $!type := $set }
$!type
}

method new(:$value!, :$escape, :$type) {
my $obj := self.CREATE;
$obj.value($value);
$obj.escape($escape);
$obj.type($type);
$obj;
}
}
Expand Down
27 changes: 14 additions & 13 deletions dotnet/compiler/PAST2DNSTCompiler.pm
Expand Up @@ -894,32 +894,33 @@ our multi sub dnst_for(PAST::Val $val) {
return DNST::Literal.new( :value($val.value<SBI>) );
}

# Look up the type to box to.
my $type;
# Work out type to box to.
my $primitive;
if pir::isa($val.value, 'Integer') {
$primitive := 'int';
$type := 'NQPInt';
}
elsif pir::isa($val.value, 'String') {
$primitive := 'str';
$type := 'NQPStr';
}
elsif pir::isa($val.value, 'Float') {
$primitive := 'num';
$type := 'NQPNum';
}
else {
pir::die("Can not detect type of value")
}
my $*BIND_CONTEXT := 0;
my $type_dnst := emit_lexical_lookup($type);

# If we have a non-object type context, can hand back a literal value.
if $*TYPE_CONTEXT ne 'obj' {
return DNST::Literal.new(
:value($val.value),
:type(vm_type_for($primitive)),
:escape($primitive eq 'str')
);
}

# Add to constants table.
my $make_const := emit_op('box_' ~ $primitive,
DNST::Literal.new( :value($val.value), :escape($primitive eq 'str') ),
$type_dnst
);
# Otherwise, need to box it. Add to constants table if possible.
my $make_const := box($primitive, DNST::Literal.new(
:value($val.value), :escape($primitive eq 'str') ));
if $*IN_LOADINIT || $*COMPILING_NQP_SETTING {
return $make_const;
}
Expand Down Expand Up @@ -1888,7 +1889,7 @@ sub emit_op($name, *@args) {
# We may need to auto-unbox it if we don't have the desired type
# of thing.
if $*TYPE_CONTEXT ne 'obj' {
unless ($arg_dnst ~~ DNST::MethodCall || $arg_dnst ~~ DNST::Call)
unless ($arg_dnst ~~ DNST::MethodCall || $arg_dnst ~~ DNST::Call || $arg_dnst ~~ DNST::Literal)
&& $arg_dnst.type eq vm_type_for($*TYPE_CONTEXT) {
$arg_dnst := unbox($*TYPE_CONTEXT, $arg_dnst);
}
Expand Down

0 comments on commit 512cfdb

Please sign in to comment.