Author: bernhard
Date: Mon Mar 31 11:15:57 2008
New Revision: 26669
Modified:
trunk/languages/hq9plus/hq9plus.pir
trunk/languages/hq9plus/src/builtins/plus.pir
trunk/languages/hq9plus/src/parser/actions.pm
Log:
[HQ9+]
Implement '+' with 'postfix:++'
Modified: trunk/languages/hq9plus/hq9plus.pir
==============================================================================
--- trunk/languages/hq9plus/hq9plus.pir (original)
+++ trunk/languages/hq9plus/hq9plus.pir Mon Mar 31 11:15:57 2008
@@ -45,12 +45,6 @@
.sub 'main' :main
.param pmc args
- # needed for 'plus'
- .local pmc accumulator
- accumulator = new 'Integer'
- accumulator = 0
- .lex "$accumulator", accumulator
-
$P0 = compreg 'HQ9plus'
$P1 = $P0.'command_line'(args)
.end
Modified: trunk/languages/hq9plus/src/builtins/plus.pir
==============================================================================
--- trunk/languages/hq9plus/src/builtins/plus.pir (original)
+++ trunk/languages/hq9plus/src/builtins/plus.pir Mon Mar 31 11:15:57 2008
@@ -9,17 +9,13 @@
.namespace
-.sub 'plus' :outer(main)
-
- .local pmc accumulator
- accumulator = find_lex "$accumulator"
-
- inc accumulator
-
- .return( )
+.sub 'postfix:++' :multi(_)
+ .param pmc a
+ $P0 = clone a
+ inc a
+ .return ($P0)
.end
-
# Local Variables:
# mode: pir
# fill-column: 100
Modified: trunk/languages/hq9plus/src/parser/actions.pm
==============================================================================
--- trunk/languages/hq9plus/src/parser/actions.pm (original)
+++ trunk/languages/hq9plus/src/parser/actions.pm Mon Mar 31 11:15:57 2008
@@ -34,6 +34,19 @@
PAST::Val.new(
:value(~$/)
)
+ ),
+ PAST::Op.new(
+ :name('infix:='),
+ :pasttype('copy'),
+ PAST::Var.new(
+ :name('hq9plus_accumulator'),
+ :viviself('Integer'),
+ :isdecl(1),
+ :scope('lexical')
+ ),
+ PAST::Val.new(
+ :value(0)
+ )
)
);
for $<statement> {
@@ -53,8 +66,18 @@
:scope('lexical')
) );
}
+ elsif ( $key eq 'plus' ) {
+ $past := PAST::Op.new( :name('postfix:++'),
+ :lvalue(1),
+ PAST::Var.new(
+ :name('hq9plus_accumulator'),
+ :scope('lexical')
+ ) );
+ }
else {
- $past := PAST::Op.new( :name($key), :pasttype('call'), :node( $/ ) );
+ $past := PAST::Op.new( :name($key),
+ :pasttype('call'),
+ :node( $/ ) );
}
make $past;
}