[svn:parrot] r35773 - in trunk/compilers/pirc: src t

[email protected]
Newsgroups perl.cvs.parrot
Message-ID <[email protected]>
Author: kjs
Date: Mon Jan 19 14:06:08 2009
New Revision: 35773

Modified:
   trunk/compilers/pirc/src/bcgen.c
   trunk/compilers/pirc/src/piremit.c
   trunk/compilers/pirc/t/basic.t
   trunk/compilers/pirc/t/stmts.t

Log:
[pirc] add some #if for comments. + add tests

Modified: trunk/compilers/pirc/src/bcgen.c
==============================================================================
--- trunk/compilers/pirc/src/bcgen.c	(original)
+++ trunk/compilers/pirc/src/bcgen.c	Mon Jan 19 14:06:08 2009
@@ -235,6 +235,9 @@
     PackFile_Constant *constant = bc->interp->code->const_table->constants[index];
     constant->type              = PFC_NUMBER;
     constant->u.number          = f;
+#if DEBUGBC
+    fprintf(stderr, "add_num_const (%f) at index: %d\n", f, index);
+#endif
     return index;
 }
 
@@ -579,7 +582,10 @@
 
     index = add_key_const(bc, pfc->u.key);
 
+#if DEBUGBC
     fprintf(stderr, "store key at index %d\n", index);
+#endif
+
     mem_sys_free(pfc);
 
     return index;

Modified: trunk/compilers/pirc/src/piremit.c
==============================================================================
--- trunk/compilers/pirc/src/piremit.c	(original)
+++ trunk/compilers/pirc/src/piremit.c	Mon Jan 19 14:06:08 2009
@@ -631,11 +631,12 @@
      * flags/types and the register/constant index.
      */
     keysize = pc - key;
-
+/*
     fprintf(stderr, "key: ");
     for (index = 0; index < keysize; ++index) {
         fprintf(stderr, "%d|", key[index]);
     }
+*/
     /* store the key, and emit the index at which it's stored into the code segment */
     index = store_key_bytecode(lexer->bc, key);
     emit_int_arg(lexer->bc, index);

Modified: trunk/compilers/pirc/t/basic.t
==============================================================================
--- trunk/compilers/pirc/t/basic.t	(original)
+++ trunk/compilers/pirc/t/basic.t	Mon Jan 19 14:06:08 2009
@@ -3,7 +3,7 @@
 # $Id$
 
 use lib "../../lib";
-use Parrot::Test tests => 5;
+use Parrot::Test tests => 6;
 
 pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "a local, a reg and an if-stat");
 .sub main
@@ -84,7 +84,7 @@
 OUTPUT
 
 
-pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "indexing a hash");
+pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "indexing a hash with a string constant");
 .sub main
     .local pmc p
     p = new "Hash"
@@ -100,6 +100,24 @@
 3.3
 OUTPUT
 
+pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "indexing a hash with a string register");
+.sub main
+    .local pmc p
+    p = new "Hash"
+    $S0 = "hello"
+    p[$S0] = 42
+    $I0 = p[$S0]
+    say $I0
+    # and combine indexing with string constant and register
+    $S1 = "bye"
+    p["bye"] = 3.3
+    $N1 = p["bye"]
+    say $N1
+.end
+CODE
+42
+3.3
+OUTPUT
 
 
 

Modified: trunk/compilers/pirc/t/stmts.t
==============================================================================
--- trunk/compilers/pirc/t/stmts.t	(original)
+++ trunk/compilers/pirc/t/stmts.t	Mon Jan 19 14:06:08 2009
@@ -3,16 +3,76 @@
 # $Id$
 
 use lib "../../lib";
-use Parrot::Test tests => 1;
+use Parrot::Test tests => 4;
 
-pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "a single const declaration");
+pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "a simple sub call - no params");
 .sub main
+    foo()
+.end
+
+.sub foo
     say "ok"
 .end
 CODE
 ok
 OUTPUT
 
+
+pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "a simple sub call - single param");
+.sub main
+    foo(42)
+.end
+
+.sub foo
+    .param int i
+    say i
+.end
+CODE
+42
+OUTPUT
+
+
+
+pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "a simple sub call - boxing");
+.sub main
+    foo(42, 3.14, "hi there")
+.end
+
+.sub foo
+    .param pmc i
+    .param pmc f
+    .param pmc t
+    .local string s
+    s = typeof i
+    say s
+    s = typeof f
+    say s
+    s = typeof t
+    say s
+.end
+CODE
+Integer
+Float
+String
+OUTPUT
+
+
+
+pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "a simple sub call - slurpy param");
+.sub main
+    foo(1, 2, 3)
+.end
+
+.sub foo
+    .param pmc args :slurpy
+    $I0 = args
+    say 3
+.end
+CODE
+3
+OUTPUT
+
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.