Skip to content

Commit

Permalink
Tie the knot and grandfather Scalar and Sub under ClassHOW
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jul 8, 2010
1 parent bd25cc5 commit a3a064e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
16 changes: 16 additions & 0 deletions CodeGen.pm
Expand Up @@ -37,6 +37,10 @@ use 5.010;
'Kernel.NewRWLValue' => 'LValue',
'Console.WriteLine' => 'Void',
'String.Concat' => 'String',
'Kernel.SubPMO' => 'DynProtoMetaObject',
'Kernel.SubMO' => 'DynMetaObject',
'Kernel.ScalarContainerPMO' => 'DynProtoMetaObject',
'Kernel.ScalarContainerMO' => 'DynMetaObject',
);

has name => (isa => 'Str', is => 'ro');
Expand Down Expand Up @@ -298,6 +302,18 @@ use 5.010;
$self->_emit("$obj.$f = $val");
}

sub clr_sfield_get {
my ($self, $f) = @_;
my $ty = $typedata{$f};
$self->_push($ty, "$f");
}

sub clr_sfield_set {
my ($self, $f) = @_;
my $val = $self->_pop;
$self->_emit("$f = $val");
}

sub clr_index_get {
my ($self, $f) = @_;
if ($f) {
Expand Down
11 changes: 8 additions & 3 deletions Kernel.cs
Expand Up @@ -145,14 +145,17 @@ public List<DynProtoMetaObject> superclasses
public class DynMetaObject {
public DynProtoMetaObject proto;
public List<Frame> outers = new List<Frame>();
public List<DynMetaObject> mro = new List<DynMetaObject>();
public List<DynMetaObject> mro;

public DynMetaObject(DynProtoMetaObject proto) {
this.proto = proto;
this.mro = new List<DynMetaObject>();
mro.Add(this);
}

public void BuildC3MRO(List<DynMetaObject> supers) {
List<List<DynMetaObject>> toMerge = new List<List<DynMetaObject>>();
mro = new List<DynMetaObject>();
toMerge.Add(new List<DynMetaObject>());
toMerge[0].Add(this);

Expand Down Expand Up @@ -429,6 +432,8 @@ public class Kernel {

public static readonly DynMetaObject SubMO;
public static readonly DynMetaObject ScalarContainerMO;
public static readonly DynProtoMetaObject SubPMO;
public static readonly DynProtoMetaObject ScalarContainerPMO;
public static readonly IP6 DieSub;

public static IP6 MakeSub(DynBlockDelegate code, Frame proto,
Expand Down Expand Up @@ -465,7 +470,7 @@ public class Kernel {
}

static Kernel() {
DynProtoMetaObject SubPMO = new DynProtoMetaObject();
SubPMO = new DynProtoMetaObject();
SubPMO.name = "Sub";
SubPMO.OnInvoke = new DynProtoMetaObject.InvokeHandler(SubInvoke);
SubPMO.local["clone"] = new DynProtoMetaObject.Method(
Expand All @@ -475,7 +480,7 @@ public class Kernel {

SubMO = new DynMetaObject(SubPMO);

DynProtoMetaObject ScalarContainerPMO = new DynProtoMetaObject();
ScalarContainerPMO = new DynProtoMetaObject();
ScalarContainerPMO.name = "ScalarContainer";
ScalarContainerPMO.OnFetch = new DynProtoMetaObject.FetchHandler(SCFetch);
ScalarContainerPMO.OnStore = new DynProtoMetaObject.StoreHandler(SCStore);
Expand Down
8 changes: 8 additions & 0 deletions Niecza/Actions.pm
Expand Up @@ -394,6 +394,14 @@ sub insn__S_unwrap { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_unwrap => $M->{clrid}->Str ]];
}

sub insn__S_clr_sfield_get { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_sfield_get => $M->{clrid}->Str ]];
}

sub insn__S_clr_sfield_set { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_sfield_set => $M->{clrid}->Str ]];
}

sub insn__S_new { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_new => $M->{clrid}->Str, $M->{decint}{_ast} ]];
}
Expand Down
2 changes: 2 additions & 0 deletions Niecza/Grammar.pm6
Expand Up @@ -76,6 +76,8 @@ grammar NIL is STD {
token insn:cast { <sym> ':' {} <clrid> }
token insn:clr_call_direct { '.plaincall/' {} <decint> ':' <clrid> }
token insn:clr_call_virt { '.virtcall/' {} <decint> ':' <clrid> }
token insn:clr_sfield_get { 'F@' {} <clrid> }
token insn:clr_sfield_set { 'F!' {} <clrid> }
token insn:return { <sym> '/' (<[ 0 1 ]>) }
token insn:push_null { 'null:' {} <clrid> }
}
Expand Down
45 changes: 44 additions & 1 deletion setting
Expand Up @@ -145,7 +145,40 @@ PRE-INIT {
my class Mu { ... }
my class Any { ... }
my class Cool { ... }
PRE-INIT { Q:NIL {
# these are really defined in the kernel
my class Scalar { ... }
my class Sub { ... }
PRE-INIT {
# (DynProtoMetaObject $dpmo, ClassHOW $super --> ClassHOW)
sub wrap-dpmo { Q:NIL {
LEXICALS: $ch : Variable, $dp : DynProtoMetaObject
L@^^ClassHOW dup@ ="" .method/1:new L!$ch
=[0] @ unwrap:DynProtoMetaObject L!$dp
L@$ch @ cast:DynObject @.slots L@$dp ![meta-object]
L@$ch dup@ =[1] .method/1:add-super:v
L@$ch
} }
# (ClassHOW $me, DynMetaObject $use, DynMetaObject $p --> Variable)
sub wrapped-protoobj { Q:NIL {
LEXICALS: $p : DynObject, $pmo : DynProtoMetaObject, $mo : DynMetaObject
LEXICALS: $s : List<DynMetaObject>
new/0:DynObject L!$p
=[0] @ cast:DynObject @.slots @[meta-object] cast:DynProtoMetaObject L!$pmo
=[1] @ unwrap:DynMetaObject L!$mo

new/0:List<DynMetaObject> L!$s
L@$s =[2] @ unwrap:DynMetaObject .virtcall/1:Add
L@$mo L@$s .virtcall/1:BuildC3MRO

L@$pmo =[0] @ !.how

L@$p null:Dictionary<string,object> !.slots
L@$p L@$mo !.klass

L@$p wrapobj
} }

Q:NIL {
LEXICALS: $plist : List<DynMetaObject>
L@^ClassHOW dup@ ="Mu" .method/1:new L!^'Mu!HOW'
new/0:List<DynMetaObject> L!$plist
Expand All @@ -166,6 +199,16 @@ PRE-INIT { Q:NIL {
L@^'Cool!HOW' dup@ callframe wrap L@$plist wrap
.method/2:create-protoobject L!^Cool

L@&wrap-dpmo @ F@Kernel.SubPMO wrap L@^'Any!HOW'
.call/2 L!^'Sub!HOW'
L@&wrapped-protoobj @ L@^'Sub!HOW' F@Kernel.SubMO wrap
L@^Any @ cast:DynObject @.klass wrap .call/3 L!^Sub

L@&wrap-dpmo @ F@Kernel.ScalarContainerPMO wrap L@^'Any!HOW'
.call/2 L!^'Scalar!HOW'
L@&wrapped-protoobj @ L@^'Scalar!HOW' F@Kernel.ScalarContainerMO wrap
L@^Any @ cast:DynObject @.klass wrap .call/3 L!^Scalar

null:Variable
} }

Expand Down

0 comments on commit a3a064e

Please sign in to comment.