Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Nicer syntax for boxing in NIL
  • Loading branch information
sorear committed Jul 7, 2010
1 parent 7292187 commit 8c57de0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CodeGen.pm
Expand Up @@ -250,6 +250,12 @@ use 5.010;
$self->unreach(1);
}

sub clr_wrap {
my ($self) = @_;
my $v = $self->_pop;
$self->_push('Variable', "Kernel.NewROVar(new CLRImportObject($v))");
}

sub clr_unwrap {
my ($self, $ty) = @_;
my $v = $self->_pop;
Expand Down
8 changes: 8 additions & 0 deletions Niecza/Actions.pm
Expand Up @@ -352,6 +352,14 @@ sub insn__S_dup_fetch { my ($cl, $M) = @_;
$M->{_ast} = [[ 'dup_fetch' ]];
}

sub insn__S_wrap { my ($cl, $M) = @_;
$M->{_ast} = [[ 'clr_wrap' ]];
}

sub insn__S_wrapobj { my ($cl, $M) = @_;
$M->{_ast} = [[ 'clr_call_direct', 'Kernel.NewROVar', 1 ]];
}

sub insn__S_pos { my ($cl, $M) = @_;
$M->{_ast} = [[ pos => $M->{decint}{_ast} ]];
}
Expand Down
2 changes: 2 additions & 0 deletions Niecza/Grammar.pm6
Expand Up @@ -56,6 +56,8 @@ grammar NIL is STD {
token insn:lexput { 'L!' {} <up> <varid> }
token insn:how { <sym> }
token insn:callframe { <sym> }
token insn:wrap { <sym> }
token insn:wrapobj { <sym> }
token insn:fetch { '@' }
token insn:dup_fetch { 'dup@' }
token insn:pos { '=[' <?> ~ ']' <decint> }
Expand Down
14 changes: 5 additions & 9 deletions setting
Expand Up @@ -53,7 +53,7 @@ PRE-INIT {
L@$self @.slots L@$pmo ![meta-object]
L@$self =[0] @ cast:DynObject @.klass !.klass

L@$self .plaincall/1:Kernel.NewROVar
L@$self wrapobj
} }

# $how.push-scope($outer)
Expand Down Expand Up @@ -94,7 +94,7 @@ PRE-INIT {
L@$p null:Dictionary<string,object> !.slots
L@$p L@$mo !.klass

L@$p .plaincall/1:Kernel.NewROVar
L@$p wrapobj
} }

sub compose { Q:NIL { null:Variable } }
Expand All @@ -108,9 +108,7 @@ PRE-INIT {
L@$chpmo "ClassHOW" !.name
L@$ch @.slots L@$chpmo ![meta-object]

L@&create-protoobject @
L@$ch .plaincall/1:Kernel.NewROVar
callframe new/1:CLRImportObject .plaincall/1:Kernel.NewROVar
L@&create-protoobject @ L@$ch wrapobj callframe wrap
.call/2 L!^ClassHOW

L@$ch L@^ClassHOW @ cast:DynObject @.klass !.klass
Expand All @@ -124,15 +122,13 @@ PRE-INIT {
my class Mu { ... }
PRE-INIT { Q:NIL {
L@^ClassHOW dup@ ="Mu" .method/1:new L!^'Mu!HOW'
L@^'Mu!HOW' dup@ callframe new/1:CLRImportObject
.plaincall/1:Kernel.NewROVar
.method/1:create-protoobject L!^Mu
L@^'Mu!HOW' dup@ callframe wrap .method/1:create-protoobject L!^Mu
null:Variable
} }

sub infix:<~> { Q:NIL {
=[0] @ unwrap:String =[1] @ unwrap:String .plaincall/2:String.Concat
new/1:CLRImportObject .plaincall/1:Kernel.NewROVar
wrap
} }

sub say { Q:NIL {
Expand Down

0 comments on commit 8c57de0

Please sign in to comment.