Skip to content

Commit

Permalink
[mm] Connect to the compiler driver
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Sep 19, 2010
1 parent 31b2aaa commit 51c12fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/CompilerDriver.pm
Expand Up @@ -19,6 +19,7 @@ use Unit ();
use Op ();
use Optimizer::Beta ();
use ResolveLex ();
use Metamodel ();
use Storable;

use Niecza::Grammar ();
Expand Down Expand Up @@ -223,6 +224,7 @@ sub compile {
[ 'parse', sub {
$ast = Niecza::Grammar->$m($a, setting => $lang,
actions => 'Niecza::Actions')->{_ast}; } ],
[ 'begin', sub { $ast = $ast->begin } ],
[ 'lift_decls', sub {
$::SETTING_RESUME = undef;
$ast->lift_decls; } ],
Expand Down
28 changes: 17 additions & 11 deletions src/Metamodel.pm
Expand Up @@ -31,7 +31,6 @@ use YAML::XS;
# This graph is a lot more random than the old trees were...

our @opensubs;
our $mainline;
our $global;

# package, class, etc. Things with stashes, protoobjects, etc.
Expand Down Expand Up @@ -275,17 +274,32 @@ our $global;
__PACKAGE__->meta->make_immutable;
}

{
package Metamodel::Unit;
use Moose;

has mainline => (isa => 'Metamodel::StaticSub', is => 'rw');
has global => (isa => 'Metamodel::Stash', is => 'ro');
has name => (isa => 'Str', is => 'ro');

no Moose;
__PACKAGE__->meta->make_immutable;
}


### Code goes here to build up the metamodel from an Op tree
# We should eventually wire this to the parser, so that metamodel stuff can
# exist during the parse itself; will be needed for macros

sub Unit::begin {
my $self = shift;
local $global = Metamodel::Stash->new;
my $munit = Metamodel::Unit->new(global => $global, name => $self->name);

local @opensubs;
local $global = Metamodel::Stash->new;
$munit->mainline($self->mainline->begin(once => 1));

$self->mainline->begin(once => 1);
$munit;
}

sub Body::begin {
Expand Down Expand Up @@ -407,12 +421,4 @@ sub Op::Augment::begin {
delete $self->{$_} for (qw(name body pkg));
}

### Code goes here to generate C# from the metamodel
#

my $y = YAML::XS::LoadFile(\*STDIN);
local $mainline = $y->begin;

print(YAML::XS::Dump($mainline));

1;

0 comments on commit 51c12fe

Please sign in to comment.