Author: fperrad
Date: Tue May  1 23:03:19 2007
New Revision: 18393

Modified:
   trunk/languages/lua/src/dumplex.tg
   trunk/languages/lua/t/test_lex.t
   trunk/languages/lua/test_lex.pir

Log:
[Lua]
- test_lex uses PAST/POST

Modified: trunk/languages/lua/src/dumplex.tg
==============================================================================
--- trunk/languages/lua/src/dumplex.tg  (original)
+++ trunk/languages/lua/src/dumplex.tg  Tue May  1 23:03:19 2007
@@ -16,91 +16,120 @@
 grammar Lua::DumpLex is TGE::Grammar;
 
 transform past (ROOT) :language('PIR') {
+    .local pmc past
+    new past, 'PAST::Block'
+    past.'init'('node'=>node, 'name'=>'anon')
+    .local pmc past_stmts
+    new past_stmts, 'PAST::Stmts'
+    past_stmts.'init'('node'=>node)
     $P0 = node['token']
-
+    if null $P0 goto L1
     .local pmc iter
-    iter = new .Iterator, $P0
-    iter = 0
-
+    new iter, .Iterator, $P0
+L2:
+    unless iter goto L1
+    $P0 = shift iter
+    $P1 = tree.'get'('past', $P0, 'Lua::TestLex::token')
+    past_stmts.'push'($P1)
+    goto L2
 L1:
-    unless iter, L2
-    shift $P0, iter
+    past.'push'(past_stmts)
+    .return (past)
+}
 
-    $I0 = defined $P0['Name']
+transform past (Lua::TestLex::token) :language('PIR') {
+    .local pmc past, arg
+    new past, 'PAST::Op'
+    past.'init'('node'=>node, 'name'=>'println')
+    $I0 = defined node['Name']
+    unless $I0 goto L1
+    $P1 = node['Name']
+    arg = tree.get('past', $P1, 'Lua::TestLex::Name')
+    goto L9
+L1:
+    $I0 = defined node['keyword']
+    unless $I0 goto L2
+    $P1 = node['keyword']
+    arg = tree.get('past', $P1, 'Lua::TestLex::keyword')
+    goto L9
+L2:
+    $I0 = defined node['String']
     unless $I0 goto L3
-    $P1 = $P0['Name']
-    tree.get('past', $P1, 'Lua::TestLex::Name')
-
+    $P1 = node['String']
+    arg = tree.get('past', $P1, 'Lua::TestLex::String')
+    goto L9
 L3:
-    $I0 = defined $P0['String']
+    $I0 = defined node['Number']
     unless $I0 goto L4
-    $P1 = $P0['String']
-    tree.get('past', $P1, 'Lua::TestLex::String')
-
+    $P1 = node['Number']
+    arg = tree.get('past', $P1, 'Lua::TestLex::Number')
+    goto L9
 L4:
-    $I0 = defined $P0['Number']
+    $I0 = defined node['punctuator']
     unless $I0 goto L5
-    $P1 = $P0['Number']
-    tree.get('past', $P1, 'Lua::TestLex::Number')
-
+    $P1 = node['punctuator']
+    arg = tree.get('past', $P1, 'Lua::TestLex::punctuator')
+    goto L9
 L5:
-    $I0 = defined $P0['punctuator']
-    unless $I0 goto L6
-    $P1 = $P0['punctuator']
-    tree.get('past', $P1, 'Lua::TestLex::punctuator')
-
-L6:
-    $I0 = defined $P0['keyword']
-    unless $I0 goto L7
-    $P1 = $P0['keyword']
-    tree.get('past', $P1, 'Lua::TestLex::keyword')
-
-L7:
-    goto L1
-L2:
-    .return (node)
+L9:
+    past.'push'(arg)
+    .return (past)
 }
 
 transform past (Lua::TestLex::keyword) :language('PIR') {
-    print "keyword:\t"
-    print node
-    print "\n"
+    .local pmc past
+    new past, 'PAST::Val'
+    $S0 = node
+    $S0 = concat "keyword:\t", $S0
+    past.'init'('node'=>node, 'vtype'=>'.String', 'name'=>$S0, 'ctype'=>'s~')
+    .return (past)
 }
 
 transform past (Lua::TestLex::punctuator) :language('PIR') {
-    print "punct:\t"
-    print node
-    print "\n"
+    .local pmc past
+    new past, 'PAST::Val'
+    $S0 = node
+    $S0 = concat "punct:\t", $S0
+    past.'init'('node'=>node, 'vtype'=>'.String', 'name'=>$S0, 'ctype'=>'s~')
+    .return (past)
 }
 
 transform past (Lua::TestLex::Name) :language('PIR') {
-    print "Name:\t"
-    print node
-    print "\n"
+    .local pmc past
+    new past, 'PAST::Val'
+    $S0 = node
+    $S0 = concat "Name:\t", $S0
+    past.'init'('node'=>node, 'vtype'=>'.String', 'name'=>$S0, 'ctype'=>'s~')
+    .return (past)
 }
 
 transform past (Lua::TestLex::String) :language('PIR') {
+    .local pmc past
+    new past, 'PAST::Val'
     $I0 = defined node['quoted_literal']
     unless $I0 goto L1
     $P0 = node['quoted_literal']
-    print "String:\t"
-    print $P0
-    print "\n"
+    $S0 = $P0
+    $S0 = concat "String:\t", $S0
     goto L2
 L1:
     $I0 = defined node['long_string']
     unless $I0 goto L2
     $P0 = node['long_string']
-    print "LongString:\t"
-    print $P0
-    print "\n"
+    $S0 = $P0
+    $S0 = concat "LongString:\t", $S0
 L2:
+    past.'init'('node'=>node, 'vtype'=>'.String', 'name'=>$S0, 'ctype'=>'s~')
+    .return (past)
 }
 
 transform past (Lua::TestLex::Number) :language('PIR') {
-    print "Number:\t"
-    print node
-    print "\n"
+    .local pmc past
+    new past, 'PAST::Val'
+    $S0 = node
+    $S0 = concat "Number:\t", $S0
+    past.'init'('node'=>node, 'vtype'=>'.String', 'name'=>$S0, 'ctype'=>'s~')
+    .return (past)
 }
 
 =head1 AUTHOR

Modified: trunk/languages/lua/t/test_lex.t
==============================================================================
--- trunk/languages/lua/t/test_lex.t    (original)
+++ trunk/languages/lua/t/test_lex.t    Tue May  1 23:03:19 2007
@@ -35,7 +35,6 @@
 punct: (

 String:        hello

 punct: )

-"past" => PMC 'Lua::TestLex' { ... }

 OUT

 

 language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'keyword' );

@@ -82,7 +81,6 @@
 keyword:       true

 keyword:       until

 keyword:       while

-"past" => PMC 'Lua::TestLex' { ... }

 OUT

 

 language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'not keyword' );

@@ -91,7 +89,6 @@
 CODE

 Name:  format

 Name:  doit

-"past" => PMC 'Lua::TestLex' { ... }

 OUT

 

 language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'string' );

@@ -105,7 +102,6 @@
 123"

 String:        alo

 123"

-"past" => PMC 'Lua::TestLex' { ... }

 OUT

 

 language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'long string' );

@@ -119,7 +115,6 @@
 123"

 LongString:    alo

 123"

-"past" => PMC 'Lua::TestLex' { ... }

 OUT

 

 language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'number' );

@@ -140,7 +135,6 @@
 Number:        .31416E+1

 Number:        0xff

 Number:        0x56

-"past" => PMC 'Lua::TestLex' { ... }

 OUT

 

 language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'comment' );

@@ -150,7 +144,6 @@
 CODE

 Number:        1

 Number:        2

-"past" => PMC 'Lua::TestLex' { ... }

 OUT

 

 language_output_is( 'Lua_lex', <<'CODE', <<'OUT', 'long comment' );

@@ -163,7 +156,6 @@
 ]===]

 CODE

 Number:        1

-"past" => PMC 'Lua::TestLex' { ... }

 OUT

 

 # Local Variables:


Modified: trunk/languages/lua/test_lex.pir
==============================================================================
--- trunk/languages/lua/test_lex.pir    (original)
+++ trunk/languages/lua/test_lex.pir    Tue May  1 23:03:19 2007
@@ -7,7 +7,11 @@
 
 =head1 SYNOPSIS
 
-  $ ./parrot languages/lua/test_lex.pir script.lua
+  $ parrot test_lex.pir script.lua
+  $ parrot test_lex.pir --target=parse script.lua
+                                 PAST
+                                 POST
+                                 PIR
 
 =head1 DESCRIPTION
 
@@ -51,15 +55,22 @@
 
 .sub 'main' :main
     .param pmc args
-#    load_bytecode 'PGE/Dumper.pbc'
-#    load_bytecode 'dumper.pbc'
     $P0 = compreg 'LuaTestLex'
-    $P0.'command_line'(args, 'target' => 'past')
+    $P0.'command_line'(args)
 .end
 
 .include 'languages/lua/src/dumplex_gen.pir'
 .include 'languages/lua/src/lua51_testlex_gen.pir'
 
+.namespace
+
+.sub 'println'
+    .param pmc arg
+    print arg
+    print "\n"
+    .return ()
+.end
+
 =head1 AUTHOR
 
 Francois Perrad

Reply via email to