Author: bernhard
Date: Mon Mar 31 10:36:03 2008
New Revision: 26668
Modified:
trunk/languages/hq9plus/hq9plus.pir
trunk/languages/hq9plus/src/builtins/quine.pir
trunk/languages/hq9plus/src/parser/actions.pm
Log:
[HQ9+]
Use the stringified Match object for implementing 'quine'.
Modified: trunk/languages/hq9plus/hq9plus.pir
==============================================================================
--- trunk/languages/hq9plus/hq9plus.pir (original)
+++ trunk/languages/hq9plus/hq9plus.pir Mon Mar 31 10:36:03 2008
@@ -45,16 +45,6 @@
.sub 'main' :main
.param pmc args
- # we need the code the 'quine'
- .local string code_fn
- code_fn = args[1]
- .local pmc pio
- pio = new 'ParrotIO'
- .local pmc code_string
- code_string = new 'String'
- code_string = pio.slurp( code_fn )
- .lex "$code_string", code_string
-
# needed for 'plus'
.local pmc accumulator
accumulator = new 'Integer'
Modified: trunk/languages/hq9plus/src/builtins/quine.pir
==============================================================================
--- trunk/languages/hq9plus/src/builtins/quine.pir (original)
+++ trunk/languages/hq9plus/src/builtins/quine.pir Mon Mar 31 10:36:03 2008
@@ -1,18 +1,17 @@
-# Copyright (C) 2006-2008, The Perl Foundation.
+# Copyright (C) 2008, The Perl Foundation.
# $Id$
=head1
-quine.pir -- simple implementation of a quine function
+quine.pir -- a simple print, the code is passed in
=cut
.namespace
-.sub 'quine' :outer(main)
+.sub 'quine'
- .local pmc code_string
- code_string = find_lex "$code_string"
+ .param pmc code_string
print code_string
@@ -25,4 +24,3 @@
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
-
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 10:36:03 2008
@@ -18,7 +18,24 @@
class HQ9plus::Grammar::Actions;
method TOP($/) {
- my $past := PAST::Block.new( :blocktype('declaration'), :node( $/ ) );
+ my $past :=
+ PAST::Block.new(
+ :blocktype('declaration'),
+ :node( $/ ),
+ PAST::Op.new(
+ :name('infix:='),
+ :pasttype('copy'),
+ PAST::Var.new(
+ :name('hq9plus_code'),
+ :viviself('String'),
+ :isdecl(1),
+ :scope('lexical')
+ ),
+ PAST::Val.new(
+ :value(~$/)
+ )
+ )
+ );
for $<statement> {
$past.push( $( $_ ) );
}
@@ -26,7 +43,19 @@
}
method statement($/,$key) {
- my $past := PAST::Op.new( :name($key), :pasttype('call'), :node( $/ ) );
+ my $past;
+ if ( $key eq 'quine' ) {
+ $past := PAST::Op.new( :name($key),
+ :pasttype('call'),
+ :node( $/ ),
+ PAST::Var.new(
+ :name('hq9plus_code'),
+ :scope('lexical')
+ ) );
+ }
+ else {
+ $past := PAST::Op.new( :name($key), :pasttype('call'), :node( $/ ) );
+ }
make $past;
}