Author: chromatic
Date: Wed Apr 19 19:11:06 2006
New Revision: 12385

Added:
   trunk/languages/pheme/t/write.t   (contents, props changed)
Modified:
   trunk/config/gen/makefiles/pheme.in
   trunk/languages/pheme/lib/PAST/Node.pir
   trunk/languages/pheme/lib/PAST/Val.pir
   trunk/languages/pheme/lib/POST/Node.pir
   trunk/languages/pheme/lib/POST/Val.pir
   trunk/languages/pheme/lib/PhemeSymbols.pir
   trunk/languages/pheme/lib/past2post.tg
   trunk/languages/pheme/lib/pge2past.tg
   trunk/languages/pheme/lib/pheme.g
   trunk/languages/pheme/lib/post2pir.tg

Log:
Added support for 'write'.
Rebuild compiler when grammar changes.
Minor bugfixes in PAST/POST nodes.

Modified: trunk/config/gen/makefiles/pheme.in
==============================================================================
--- trunk/config/gen/makefiles/pheme.in (original)
+++ trunk/config/gen/makefiles/pheme.in Wed Apr 19 19:11:06 2006
@@ -14,7 +14,7 @@
 lib/PhemeGrammar.pbc: lib/PhemeGrammar.pir lib/pheme_grammar_gen.pir
        $(PARROT) -o lib/PhemeGrammar.pbc --output-pbc lib/PhemeGrammar.pir 
 
-lib/pheme_grammar_gen.pir:
+lib/pheme_grammar_gen.pir: lib/pheme.g
        $(PARROT) $(PGE_DIR)pgc.pir --output=lib/pheme_grammar_gen.pir 
lib/pheme.g
 
 lib/PhemeSymbols.pbc: lib/PhemeSymbols.pir

Modified: trunk/languages/pheme/lib/PAST/Node.pir
==============================================================================
--- trunk/languages/pheme/lib/PAST/Node.pir     (original)
+++ trunk/languages/pheme/lib/PAST/Node.pir     Wed Apr 19 19:11:06 2006
@@ -30,6 +30,10 @@
     setattribute self, "children", $P3
 .end
 
+.sub __get_bool :method
+       .return( 1 )
+.end
+
 .sub "set_node" :method
     .param string source
     .param int pos

Modified: trunk/languages/pheme/lib/PAST/Val.pir
==============================================================================
--- trunk/languages/pheme/lib/PAST/Val.pir      (original)
+++ trunk/languages/pheme/lib/PAST/Val.pir      Wed Apr 19 19:11:06 2006
@@ -81,7 +81,7 @@
        .local pmc valtype
   set:
     valtype = new .String
-    valtype = valtype
+    valtype = new_valtype
     setattribute self, 'valtype', valtype
     .return( valtype )
   get:

Modified: trunk/languages/pheme/lib/POST/Node.pir
==============================================================================
--- trunk/languages/pheme/lib/POST/Node.pir     (original)
+++ trunk/languages/pheme/lib/POST/Node.pir     Wed Apr 19 19:11:06 2006
@@ -33,6 +33,10 @@
     setattribute self, 'symbols', $P4
 .end
 
+.sub __get_bool :method
+       .return( 1 )
+.end
+
 .sub "set_node" :method
     .param string source
     .param int pos

Modified: trunk/languages/pheme/lib/POST/Val.pir
==============================================================================
--- trunk/languages/pheme/lib/POST/Val.pir      (original)
+++ trunk/languages/pheme/lib/POST/Val.pir      Wed Apr 19 19:11:06 2006
@@ -76,7 +76,7 @@
     .param int got_valtype :opt_flag
     unless got_valtype goto get
   set:
-    $P1 = new PerlString
+    $P1 = new String
     $P1 = valtype
     setattribute self, "valtype", $P1
     .return ($P1)

Modified: trunk/languages/pheme/lib/PhemeSymbols.pir
==============================================================================
--- trunk/languages/pheme/lib/PhemeSymbols.pir  (original)
+++ trunk/languages/pheme/lib/PhemeSymbols.pir  Wed Apr 19 19:11:06 2006
@@ -8,6 +8,7 @@
        symbols['cdr']  = 1
        symbols['cons'] = 1
        symbols['include_file'] = 1
+       symbols['write'] = 1
 
        store_global 'PhemeCompiler', 'symbols', symbols
        .return()
@@ -91,3 +92,28 @@
 
        .return( r )
 .end
+
+.sub 'write' :multi()
+       .param pmc messages :slurpy
+
+       .local string message
+       .local pmc iter
+       iter = new .Iterator, messages
+       iter = 0
+
+  iter_loop:
+       unless iter goto iter_end
+       message = shift iter
+       print message
+       goto iter_loop
+
+  iter_end:
+       .return()
+.end
+
+.sub 'write' :multi( string )
+       .param string message_string
+
+       print message_string
+       .return()
+.end

Modified: trunk/languages/pheme/lib/past2post.tg
==============================================================================
--- trunk/languages/pheme/lib/past2post.tg      (original)
+++ trunk/languages/pheme/lib/past2post.tg      Wed Apr 19 19:11:06 2006
@@ -155,6 +155,7 @@
        tmpvar      = new 'POST::Var'
        tmpvar.'new_temp'()
        var_op_name.'value'( var_name )
+       var_op_name.'valtype'( '' )
        var_op.'op'( 'declare' )
        var_ops.'tmpvar'( tmpvar )
        var_ops.'add_child'( var_op )
@@ -381,6 +382,7 @@
   is_val:
        result = new 'POST::Val'
        result.'value'( op_name )
+       result.'valtype'( '' )
 
   return_result:
        .return( result )
@@ -398,12 +400,17 @@
        .local string value
        value = node.'value'()
 
+       .local string valtype
+       valtype = node.'valtype'()
+
        .local int is_variable
        is_variable = exists variables[value]
 
        if is_variable goto rebind_variable
+
        result = new 'POST::Val'
        result.'value'( value )
+       result.'valtype'( valtype )
        .return( result )
 
   rebind_variable:

Modified: trunk/languages/pheme/lib/pge2past.tg
==============================================================================
--- trunk/languages/pheme/lib/pge2past.tg       (original)
+++ trunk/languages/pheme/lib/pge2past.tg       Wed Apr 19 19:11:06 2006
@@ -138,6 +138,35 @@
        value    = node
 
        result.'value'( value )
+       result.'valtype'( '' )
+       .return( result )
+}
+
+quoted_string: result(.) = {
+       .local pmc result
+       result = new 'PAST::Val'
+
+       .local string value
+       value  = node
+
+       .local int string_length
+       string_length = length value
+       sub string_length, 2
+
+       .local string val_type
+       val_type = substr value, 0, 1
+       if val_type == '"' goto double_quoted
+       result.'valtype'( 'single_quoted' )
+       goto remove_quotes
+
+  double_quoted:
+       result.'valtype'( 'double_quoted' )
+
+  remove_quotes:
+       value  = substr value, 1, string_length
+
+       result.'value'( value )
+       
        .return( result )
 }
 

Modified: trunk/languages/pheme/lib/pheme.g
==============================================================================
--- trunk/languages/pheme/lib/pheme.g   (original)
+++ trunk/languages/pheme/lib/pheme.g   Wed Apr 19 19:11:06 2006
@@ -4,10 +4,13 @@
 
 rule list { \( <list_items>+ \s* \) }
 
-rule list_items { [ <atom> | <list> | <empty_list> ] \s* }
+# quoted_string has to come first
+rule list_items { [ <quoted_string> | <atom> | <list> | <empty_list> ] \s* }
 
 rule empty_list { '\(\) }
 
 rule atom { <symbol_tag>? [ <-[ \n\r\(\)]> ]+ }
 
+rule quoted_string { <PGE::Text::bracketed: '"> }
+
 rule symbol_tag { \# }

Modified: trunk/languages/pheme/lib/post2pir.tg
==============================================================================
--- trunk/languages/pheme/lib/post2pir.tg       (original)
+++ trunk/languages/pheme/lib/post2pir.tg       Wed Apr 19 19:11:06 2006
@@ -148,9 +148,9 @@
        outvar     = join ', ', outvars
        result    .= "\t"
        result    .= varname
-       result    .= " = "
+       result    .= " = '"
        result    .= op_name
-       result    .= '( '
+       result    .= "'( "
        result    .= outvar
        result    .= " )\n"
        goto return_result
@@ -191,24 +191,22 @@
        .return( result )
 }
 
-PAST::Val: emit(.) = {
+POST::Val: emit(.) = {
        .local string result
-
        result = node.'value'()
 
-       result  = "'" . result
-       result .= "'"
-
-       .return( result )
-}
+       .local string quote_type
+       quote_type = node.'valtype'()
 
-POST::Val: emit(.) = {
-       .local string result
+       .local string quote
+       quote = "'"
 
-       result = node.'value'()
+       unless quote_type == 'double_quoted' goto build_result
+       quote = '"'
 
-       result  = "'" . result
-       result .= "'"
+  build_result:
+       result  = concat quote, result
+       result .= quote
 
        .return( result )
 }

Added: trunk/languages/pheme/t/write.t
==============================================================================
--- (empty file)
+++ trunk/languages/pheme/t/write.t     Wed Apr 19 19:11:06 2006
@@ -0,0 +1,19 @@
+(write "1..4\n")
+
+(write "ok 1 - all in one line\n")
+
+(write "ok " 2 ' - a list of quoted and unquoted atoms' "\n")
+
+(write 'ok' ' ' '3' " - a list of mixed, quoted atoms\n")
+
+(write ok)
+
+(write ' ')
+
+(write '4')
+
+(write ' - ' )
+
+(write 'separate write statements')
+
+(write "\n")

Reply via email to