From eb45fca341db04cff7c796ef761935b824d5d1f0 Mon Sep 17 00:00:00 2001 From: Stefan O'Rear Date: Fri, 17 Sep 2010 23:55:50 -0700 Subject: [PATCH] [mm] First runnable prototype --- TODO | 17 +---------- src/Metamodel.pm | 74 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 22 deletions(-) diff --git a/TODO b/TODO index 9ec65160..1e7ceb38 100644 --- a/TODO +++ b/TODO @@ -1,16 +1 @@ -* Variable overhaul - -class GeneralContainer { - IP6 objref; - bool islist; - bool isrw; - IP6 whence; -} - -Fields other than objref and whence constant - -my $x; # allocates 1 GeneralContainer -$x = 2; # change objref -$x := 3; # set [$x] in stackframe to new container - -Blockers: our $x needs bvalue aliasing and I haven't decided the best way yet +checkblock, loop, try, given, when, labelled loops, tilde quantifier, negation metaops diff --git a/src/Metamodel.pm b/src/Metamodel.pm index 6fe3a660..f3cebf40 100644 --- a/src/Metamodel.pm +++ b/src/Metamodel.pm @@ -3,6 +3,13 @@ use strict; use warnings; use utf8; +package Metamodel; +use Unit; +use Body; +use Op; +use RxOp; +use YAML::XS; + ### NIECZA COMPILER METAMODEL # The metamodel exists to create a timeline inside the compiler. Previously, # the compiler operated as a pure tree transformer with no conception of how @@ -96,9 +103,7 @@ use utf8; use Moose; extends 'Metamodel::Lexical'; - has name => (isa => 'Str', is => 'ro'); - - sub sigil { substr($_[0]->name, 0, 1) } + has sigil => (isa => 'Str', is => 'ro'); no Moose; __PACKAGE__->meta->make_immutable; @@ -146,12 +151,23 @@ use utf8; package Metamodel::StaticSub; use Moose; - has lexicals => (isa => 'ArrayRef[Metamodel::Lexical]', is => 'ro', - default => sub { [] }); + has outer => (isa => 'Maybe[Metamodel::StaticSub]', is => 'ro', + weak_ref => 1); + has run_once => (isa => 'Bool', is => 'ro', default => 0); + + has lexicals => (isa => 'HashRef[Metamodel::Lexical]', is => 'ro', + default => sub { +{} }); has code => (isa => 'Op', is => 'rw'); has initq => (isa => 'ArrayRef[Metamodel::StaticSub]', is => 'ro', default => sub { [] }); + sub add_my_name { my ($self, $slot, $list, $hash) = @_; + $self->lexicals->{$slot} = Metamodel::Lexical::Simple->new( + slot => $slot, list => $list, hash => $hash); + } + + sub close { } + no Moose; __PACKAGE__->meta->make_immutable; } @@ -160,7 +176,53 @@ use utf8; # We should eventually wire this to the parser, so that metamodel stuff can # exist during the parse itself; will be needed for macros +our @opensubs; +our $mainline; + +sub Unit::begin { + my $self = shift; + + $mainline = $self->mainline->begin; +} + +sub Body::begin { + my $self = shift; + + my $top = @opensubs ? $opensubs[-1] : undef; + + push @opensubs, Metamodel::StaticSub->new( + outer => $top, + run_once => !defined($top)); + $self->do->begin; + + $opensubs[-1]->close; + pop @opensubs; +} + +sub Op::begin { + my $self = shift; + + $_->begin for $self->zyg; +} + +sub Op::Lexical::begin { + my $self = shift; + + if ($self->state_backing) { + $opensubs[-1]->add_state_name($self->name, $self->state_backing, + $self->list, $self->hash); + } elsif ($self->declaring) { + $opensubs[-1]->add_my_name($self->name, $self->list, + $self->hash); + } +} + ### Code goes here to generate C# from the metamodel -# +# + +my $y = YAML::XS::LoadFile(\*STDIN); +$y->begin; + +print(YAML::XS::Dump($mainline)); 1;