Skip to content

Commit

Permalink
[mm] First runnable prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Sep 18, 2010
1 parent 8743f45 commit eb45fca
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 22 deletions.
17 changes: 1 addition & 16 deletions 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
74 changes: 68 additions & 6 deletions src/Metamodel.pm
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;

0 comments on commit eb45fca

Please sign in to comment.