Skip to content

Commit

Permalink
Retire NIL
Browse files Browse the repository at this point in the history
Now the CodeGen stack machine interface is only used by CgOp.pm
  • Loading branch information
Stefan O'Rear committed Jul 16, 2010
1 parent 2375faa commit acb3c4e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 345 deletions.
253 changes: 0 additions & 253 deletions Niecza/Actions.pm
Expand Up @@ -151,8 +151,6 @@ sub nibbler { my ($cl, $M) = @_;
$M->{_ast} = $M->{EXPR}{_ast};
} elsif ($M->isa('Niecza::Grammar::CgOp')) {
$M->{_ast} = Op::CgOp->new(op => $M->{cgexp}{_ast});
} elsif ($M->isa('Niecza::Grammar::NIL')) {
$M->{_ast} = Op::NIL->new(ops => [map { @{$_->{_ast}} } @{$M->{insn}}]);
} else {
# garden variety nibbler
my $str = "";
Expand Down Expand Up @@ -570,257 +568,6 @@ sub cgexp__S_op { my ($cl, $M) = @_;
$M->{_ast} = &{"CgOp::$op"}(@p, map { $_->{_ast} } @{ $M->{cgexp} });
}

sub voidmark { my ($cl, $M) = @_;
$M->{_ast} = 1;
}

sub up { my ($cl, $M) = @_;
$M->{_ast} = length ($M->Str);
}

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

# :: [row of NIL op]
sub insn {}
sub insn__S_lextypes { my ($cl, $M) = @_;
$M->{_ast} = [[ lextypes => map { @{ $_->{_ast} } } @{ $M->{lexdecl} } ]];
}

sub insn__S_clone_lex { my ($cl, $M) = @_;
$M->{_ast} = [ map { [ clone_lex => $_->{_ast} ] } @{ $M->{varid} } ];
}

sub insn__S_copy_lex { my ($cl, $M) = @_;
$M->{_ast} = [ map { [ copy_lex => $_->{_ast} ] } @{ $M->{varid} } ];
}

sub insn__S_string_var { my ($cl, $M) = @_;
if (!$M->{quote}{_ast}->isa('Op::StringLiteral')) {
$M->sorry("Strings used in NIL code must be compile time constants");
}
$M->{_ast} = [[ string_var => $M->{quote}{_ast}->text ]];
}

sub insn__S_clr_string { my ($cl, $M) = @_;
if (!$M->{quote}{_ast}->isa('Op::StringLiteral')) {
$M->sorry("Strings used in NIL code must be compile time constants");
}
$M->{_ast} = [[ clr_string => $M->{quote}{_ast}->text ]];
}

sub insn__S_clr_int { my ($cl, $M) = @_;
my $s = ($M->{sign}->Str eq '-') ? -1 : +1;
$M->{_ast} = [[ clr_int => $s * $M->{decint}{_ast} ]];
}

# the negatives here are somewhat of a cheat.
sub insn__S_label { my ($cl, $M) = @_;
$M->{_ast} = [[ labelhere => -$M->{decint}{_ast} ]];
}

sub insn__S_goto { my ($cl, $M) = @_;
$M->{_ast} = [[ goto => -$M->{decint}{_ast} ]];
}

sub insn__S_cgoto { my ($cl, $M) = @_;
$M->{_ast} = [[ cgoto => -$M->{decint}{_ast} ]];
}

sub insn__S_ncgoto { my ($cl, $M) = @_;
$M->{_ast} = [[ ncgoto => -$M->{decint}{_ast} ]];
}

my $labelid = 1000;
sub insn__S_if { my ($cl, $M) = @_;
my @r;
my $end1 = $labelid++;
my $end2 = $labelid++;
push @r, [ 'ncgoto', -$end1 ];
push @r, @{ $M->{nibbler}[0]{_ast}->code };
if ($M->{nibbler}[1]) {
push @r, [ 'goto', -$end2 ], [ 'labelhere', -$end1 ];
push @r, @{ $M->{nibbler}[1]{_ast}->code };
push @r, [ 'labelhere', -$end2 ];
} else {
push @r, [ 'labelhere', -$end1 ];
}
$M->{_ast} = \@r;
}

sub insn__S_begin { my ($cl, $M) = @_;
my @r;
my $b1 = $labelid++;
push @r, [ 'labelhere', -$b1 ];
push @r, @{ $M->{nibbler}[0]{_ast}->code };
if ($M->{while}) {
my $b2 = $labelid++;
push @r, [ 'ncgoto', -$b2 ];
push @r, @{ $M->{nibbler}[1]{_ast}->code };
push @r, [ 'goto', -$b1 ], [ 'labelhere', -$b2 ];
} elsif ($M->{until}) {
push @r, [ 'ncgoto', -$b1 ];
} elsif ($M->{again}) {
push @r, [ 'goto', -$b1 ];
}
$M->{_ast} = \@r;
}

sub insn__S_lex { my ($cl, $M) = @_;
$M->{_ast} = [[ lex => $M->{up}{_ast}, $M->{varid}{_ast} ]];
}

sub insn__S_lexget { my ($cl, $M) = @_;
$M->{_ast} = [[ lexget => $M->{up}{_ast}, $M->{varid}{_ast} ]];
}

sub insn__S_lexput { my ($cl, $M) = @_;
$M->{_ast} = [[ lexput => $M->{up}{_ast}, $M->{varid}{_ast} ]];
}

sub insn__S_how { my ($cl, $M) = @_;
$M->{_ast} = [[ 'how' ]];
}

sub insn__S_callframe { my ($cl, $M) = @_;
$M->{_ast} = [[ 'callframe' ]];
}

sub insn__S_fetch { my ($cl, $M) = @_;
$M->{_ast} = [[ 'fetch' ]];
}

sub insn__S_assign { my ($cl, $M) = @_;
$M->{_ast} = [[ 'assign' ]];
}

sub insn__S_dup_fetch { my ($cl, $M) = @_;
$M->{_ast} = [[ 'dup_fetch' ]];
}

sub insn__S_wrap { my ($cl, $M) = @_;
$M->{_ast} = [[ 'clr_wrap' ]];
}

sub insn__S_wrapobj { my ($cl, $M) = @_;
$M->{_ast} = [[ 'newscalar' ]];
}

sub insn__S_pos { my ($cl, $M) = @_;
$M->{_ast} = [[ pos => $M->{decint}{_ast} ]];
}

sub insn__S_call_method { my ($cl, $M) = @_;
$M->{_ast} = [[ call_method => !$M->{voidmark}[0], $M->{identifier}->Str,
$M->{decint}{_ast} ]];
}

sub insn__S_call_sub { my ($cl, $M) = @_;
$M->{_ast} = [[ call_sub => !$M->{voidmark}[0], $M->{decint}{_ast} ]];
}

sub insn__S_tail_call_sub { my ($cl, $M) = @_;
$M->{_ast} = [[ tail_call_sub => $M->{decint}{_ast} ]];
}

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

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

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

sub insn__S_box { my ($cl, $M) = @_;
$M->{_ast} = [[ box => $M->{varid}->Str ]];
}

sub insn__S_unbox { my ($cl, $M) = @_;
$M->{_ast} = [[ unbox => $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} ]];
}

sub insn__S_clr_field_get { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_field_get => $M->{varid}{_ast} ]];
}

sub insn__S_clr_field_set { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_field_set => $M->{varid}{_ast} ]];
}

sub insn__S_clr_index_get { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_index_get => ($M->{varid}[0] ? ($M->{varid}[0]{_ast}) : ()) ]];
}

sub insn__S_clr_index_set { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_index_set => ($M->{varid}[0] ? ($M->{varid}[0]{_ast}) : ()) ]];
}

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

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

sub insn__S_attr_get { my ($cl, $M) = @_;
$M->{_ast} = [[ attr_get => $M->{varid}{_ast} ]];
}

sub insn__S_attr_set { my ($cl, $M) = @_;
$M->{_ast} = [[ attr_set => $M->{varid}{_ast} ]];
}

sub insn__S_attr_var { my ($cl, $M) = @_;
$M->{_ast} = [[ attr_var => $M->{varid}{_ast} ]];
}

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

sub insn__S_return { my ($cl, $M) = @_;
$M->{_ast} = [[ return => $M->{0} ]];
}

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

sub insn__S_hll { my ($cl, $M) = @_;
$M->{_ast} = [ $M->{EXPR}{_ast} ];
}

sub clrid {}
sub clrqual {}
sub clrgeneric {}
sub varid { my ($cl, $M) = @_;
if ($M->{quote}) {
if (!$M->{quote}{_ast}->isa('Op::StringLiteral')) {
$M->sorry("Strings used in NIL code must be compile time constants");
}
$M->{_ast} = $M->{quote}{_ast}->text;
} else {
$M->{_ast} = $M->Str;
}
}
sub apostrophe {}
sub quibble {}
sub tribble {}
Expand Down
92 changes: 0 additions & 92 deletions Niecza/Grammar.pm6
Expand Up @@ -14,14 +14,11 @@ grammar P6 is STD::P6 {

token statement_prefix:sym<PRE-INIT>
{ :my %*MYSTERY; <sym> <.spacey> <blast> <.explain_mystery> }
token statement_control:sym<PRELUDE>
{ <sym> <.spacey> <quibble($¢.cursor_fresh( %*LANG<Q> ).tweak(:NIL))> }
}

grammar Q is STD::Q {
#}

multi method tweak(:$NIL!) { self.cursor_fresh( ::Niecza::Grammar::NIL ) }
multi method tweak(:$CgOp!) { self.cursor_fresh( ::Niecza::Grammar::CgOp)}
}

Expand All @@ -45,95 +42,6 @@ grammar CgOp is STD {
}
}

# mnemonic characters: (@, !, =) fetch, store, lvalue.
# (l) lexical (L) raw lexical
grammar NIL is STD {
rule nibbler {
[
|| <insn>
|| <?stdstopper>
|| <.panic: "Malformed NIL instruction">
]*
}

token terminator:then { <sym> }
token terminator:else { <sym> }
token terminator:again { <sym> }
token terminator:while { <sym> }
token terminator:repeat { <sym> }

token category:insn { <sym> }
proto token insn { <...> }

token varid {
[ <sigil> <twigil>? ]? <identifier> |
<?before "'"> [ :lang(%*LANG<MAIN>) <quote> ]
}

token clrid { <ident>**'.' <clrgeneric>? <clrqual>* }
token clrgeneric { '<' <clrid>**',' '>' }
token clrqual { '[]' }

token up { '^' * }
token voidmark { ':v' }

token lexdecl { [ \h* <varid> \h* ] ** ',' ':' \h* <clrid> \h* }
token insn:lextypes { 'LEXICALS:' <lexdecl> ** ',' \h* \n }

token insn:string_var { "=" <?before <[ ' " ]>> [ :lang(%*LANG<MAIN>) <quote> ] }
token insn:clr_string { <?before <[ ' " ]>> [ :lang(%*LANG<MAIN>) <quote> ] }
token insn:clr_int { $<sign>=[<[ - + ]>?] <decint> }
token insn:label { ':' {} <decint> }
token insn:goto { '->' {} <decint> }
token insn:cgoto { '?->' {} <decint> }
token insn:ncgoto { '!->' {} <decint> }
token insn:if { <sym>:s <nibbler> [ 'else' <nibbler> ]? 'then' }
token insn:begin {
<sym>:s <nibbler> [
| $<while>='while' <nibbler> 'repeat'
| $<again>='again'
| $<until>'until'
]
}

token insn:lexget { 'L@' {} <up> <varid> }
token insn:lexput { 'L!' {} <up> <varid> }
token insn:how { <sym> }
token insn:callframe { <sym> }
token insn:wrap { <sym> }
token insn:wrapobj { <sym> }
token insn:fetch { '@' }
token insn:assign { '=' }
token insn:dup_fetch { 'dup@' }
token insn:pos { '=[' <?> ~ ']' <decint> }
token insn:clone_lex { 'CLONE:' [ \h* <varid> \h* ] ** ',' \h* \n }
token insn:copy_lex { 'COPY:' [ \h* <varid> \h* ] ** ',' \h* \n }
token insn:call_method { '.method/' {} <decint> ':' <identifier> <voidmark>? }
token insn:call_sub { '.call/' {} <decint> <voidmark>? }
token insn:tail_call_sub { '.tailcall/' {} <decint> }
token insn:unwrap { <sym> ':' {} <clrid> }
token insn:new { <sym> '/' {} <decint> ':' <clrid> }
token insn:arith { <[ + \- * / ^ & | ]> }
token insn:compare { '<' | '>' | '>=' | '<=' | '!=' | '==' }
token insn:box { <sym> ':' {} <varid> }
token insn:unbox { <sym> ':' {} <clrid> }
token insn:clr_field_get { '@.' {} <varid> }
token insn:clr_field_set { '!.' {} <varid> }
token insn:clr_index_get { '@[' {} <varid>? ']' }
token insn:clr_index_set { '![' {} <varid>? ']' }
token insn:attr_get { '@!' {} <varid> }
token insn:attr_set { '!!' {} <varid> }
token insn:attr_raw { '=!' {} <varid> }
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> }
token insn:hll { '{' ~ '}' [ :lang(%*LANG<MAIN>) <EXPR> ] }
}

}

# vim: ft=

0 comments on commit acb3c4e

Please sign in to comment.