Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
passes and Niecza::Compiler that will tie stuff together
- Loading branch information
Showing
5 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,28 @@ | ||
| #!/usr/bin/perl | ||
| #my $compiler = Niecza::Compiler->new( | ||
| # frontend=>Niecza::Frontend::STD->new() | ||
| #); | ||
|
|
||
| use lib 'src'; | ||
| use Niecza::Frontend::STD; | ||
| use Niecza::Backend::NAM; | ||
| use Niecza::Pass::Beta; | ||
| use Niecza::Pass::Simplifier; | ||
| use Niecza::Pass::Begin; | ||
| use Niecza::Compiler; | ||
| use Metamodel; | ||
|
|
||
| my $parser = Niecza::Frontend::STD->new(lang=>'CORE'); | ||
|
|
||
| my $begin = Niecza::Pass::Begin->new(); | ||
| my $beta = Niecza::Pass::Beta->new(); | ||
| my $simplifier = Niecza::Pass::Simplifier->new(); | ||
|
|
||
| my $backend = Niecza::Backend::NAM->new(); | ||
| my $ast = $parser->parse('123'); | ||
| $ast = $ast->begin; | ||
| $backend->compile($ast,'file.nam'); | ||
|
|
||
| my $compiler = Niecza::Compiler->new( | ||
| frontend =>$parser, | ||
| passes => [$begin,$beta,$simplifier], | ||
| backend => $backend | ||
| ); | ||
|
|
||
| $compiler->compile('1','foo.p6','file.nam'); | ||
|
|
||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package Niecza::Compiler; | ||
| use Moose; | ||
| has frontend => (is=>'ro'); | ||
| has passes => (is=>'ro'); | ||
| has backend => (is=>'ro'); | ||
| sub compile { | ||
| my ($self,$input,$filename,$output) = @_; | ||
| my $ast = $self->frontend->parse($input,$filename); | ||
| for my $pass (@{$self->passes}) { | ||
| $ast = $pass->run($ast); | ||
| } | ||
| $self->backend->compile($ast,$output); | ||
| } | ||
| 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package Niecza::Pass::Begin; | ||
| use Moose; | ||
| sub run { | ||
| my ($self,$ast) = @_; | ||
| $ast->begin; | ||
| } | ||
| 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package Niecza::Pass::Beta; | ||
| use Optimizer::Beta; | ||
| use Moose; | ||
| sub run { | ||
| my ($self,$ast) = @_; | ||
| Optimizer::Beta::run($ast); | ||
| $ast; | ||
| } | ||
| 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package Niecza::Pass::Simplifier; | ||
| use Optimizer::Simplifier; | ||
| use Moose; | ||
| sub run { | ||
| my ($self,$ast) = @_; | ||
| Optimizer::Simplifier::run($ast); | ||
| $ast; | ||
| } | ||
| 1; |