Permalink
Browse files

Add many insn: actions; implement labels & fix methods.

  • Loading branch information...
1 parent 53e6a3d commit 2c4d2c930187325338e2d1cb96c751da90110ad8 @sorear committed Jul 2, 2010
Showing with 77 additions and 5 deletions.
  1. +6 −4 CodeGen.pm
  2. +70 −0 Niecza/Actions.pm
  3. +1 −1 Niecza/Grammar.pm6
View
10 CodeGen.pm
@@ -100,13 +100,15 @@ use 5.010;
sub labelhere {
my ($self, $n) = @_;
$self->_saveall;
+ $n = ($self->labelname->{$n} //= $self->label) if $n < 0;
push @{ $self->buffer }, " goto case $n;\n" unless $self->unreach;
push @{ $self->buffer }, "case $n:\n";
$self->unreach(0);
}
sub goto {
my ($self, $n) = @_;
+ $n = ($self->labelname->{$n} //= $self->label) if $n < 0;
$self->_saveall;
push @{ $self->buffer }, " goto case $n;\n";
$self->unreach(1);
@@ -134,13 +136,13 @@ use 5.010;
}
sub rawlexget {
- my ($self, $name) = @_;
- $self->_push($self->lex2type->{$name}, "th.lex[" . qm($name) . "]");
+ my ($self, $order, $name) = @_;
+ $self->_push($self->lex2type->{$name}, "th." . ("outer." x $order) . "lex[" . qm($name) . "]");
}
sub rawlexput {
- my ($self, $name) = @_;
- $self->_emit("th.lex[" . qm($name) . "] = " . $self->_pop);
+ my ($self, $order, $name) = @_;
+ $self->_emit("th." . ("outer." x $order) . "lex[" . qm($name) . "] = " . $self->_pop);
}
sub string_lv {
View
70 Niecza/Actions.pm
@@ -185,6 +185,76 @@ sub up { my ($cl, $M) = @_;
$M->{_ast} = length ($M->Str);
}
+# :: [row of NIL op]
+sub insn {}
+sub insn__S_lextypes { my ($cl, $M) = @_;
+ say(YAML::XS::Dump($M));
+}
+
+sub insn__S_string_lv { 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_lv => $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 ]];
+}
+
+# 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_lex_lv { my ($cl, $M) = @_;
+ $M->{_ast} = [[ lex_lv => $M->{up}{_ast}, $M->{varid}->Str ]];
+}
+
+sub insn__S_rawlexget { my ($cl, $M) = @_;
+ $M->{_ast} = [[ rawlexget => $M->{up}{_ast}, $M->{varid}->Str ]];
+}
+
+sub insn__S_rawlexput { my ($cl, $M) = @_;
+ $M->{_ast} = [[ rawlexput => $M->{up}{_ast}, $M->{varid}->Str ]];
+}
+
+sub insn__S_how { my ($cl, $M) = @_;
+ $M->{_ast} = [[ 'how' ]];
+}
+
+sub insn__S_fetchlv { my ($cl, $M) = @_;
+ $M->{_ast} = [[ 'fetchlv' ]];
+}
+
+sub insn__S_dup_fetchlv { my ($cl, $M) = @_;
+ $M->{_ast} = [[ 'dup_fetchlv' ]];
+}
+
+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}, $M->{identifier}->Str,
+ $M->{decint}{_ast} ]];
+}
+
+sub insn__S_call_sub { my ($cl, $M) = @_;
+ $M->{_ast} = [[ call_sub => !$M->{voidmark}, $M->{decint}{_ast} ]];
+}
+
+sub insn__S_tail_call_sub { my ($cl, $M) = @_;
+ $M->{_ast} = [[ tail_call_sub => $M->{decint}{_ast} ]];
+}
+
sub sigil {}
sub sigil__S_Amp {}
sub sigil__S_Dollar {}
View
2 Niecza/Grammar.pm6
@@ -59,7 +59,7 @@ grammar NIL is STD {
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> <voidmark>? }
+ token insn:call_method { '.method:' {} <identifier> '/' <decint> <voidmark>? }
token insn:call_sub { '.call/' {} <decint> <voidmark>? }
token insn:tail_call_sub { '.tailcall/' {} <decint> }
token insn:unwrap { <sym> ':' {} <clrid> }

0 comments on commit 2c4d2c9

Please sign in to comment.