Author: leo
Date: Fri Aug 19 02:51:08 2005
New Revision: 8999

Modified:
   branches/leo-ctx5/imcc/pbc.c
   branches/leo-ctx5/include/parrot/packfile.h
   branches/leo-ctx5/src/hash.c
   branches/leo-ctx5/src/packfile.c
   branches/leo-ctx5/t/pmc/hash.t
   branches/leo-ctx5/t/pmc/sub.t
Log:
Immediate code as PMC constants

* merge 8998 - hash delete
* the return value of .sub foo @IMMEDIATE is usable as a PMC constant
  at runtime now
* test t/pmc/sub_49.pir


Modified: branches/leo-ctx5/imcc/pbc.c
==============================================================================
--- branches/leo-ctx5/imcc/pbc.c        (original)
+++ branches/leo-ctx5/imcc/pbc.c        Fri Aug 19 02:51:08 2005
@@ -1014,9 +1014,6 @@ e_pbc_end_sub(Interp *interpreter, void 
     /* we run only PCC subs */
     if (!ins->r[0] || !ins->r[0]->pcc_sub)
         return 0;
-    /* if we are compiling, we don't run it */
-    if (IMCC_INFO(interpreter)->write_pbc)
-        return 0;
     pragma = ins->r[0]->pcc_sub->pragma;
     if (pragma & P_IMMEDIATE) {
         IMCC_debug(interpreter, DEBUG_PBC, "immediate sub '%s'",

Modified: branches/leo-ctx5/include/parrot/packfile.h
==============================================================================
--- branches/leo-ctx5/include/parrot/packfile.h (original)
+++ branches/leo-ctx5/include/parrot/packfile.h Fri Aug 19 02:51:08 2005
@@ -123,9 +123,9 @@ struct PackFile_FixupEntry {
 
 
 typedef enum {
+    enum_fixup_none,
     enum_fixup_label,
-    enum_fixup_sub,
-    enum_fixup_var
+    enum_fixup_sub
 } enum_fixup_t;
 
 struct PackFile_FixupTable {

Modified: branches/leo-ctx5/src/hash.c
==============================================================================
--- branches/leo-ctx5/src/hash.c        (original)
+++ branches/leo-ctx5/src/hash.c        Fri Aug 19 02:51:08 2005
@@ -854,6 +854,7 @@ hash_delete(Interp *interpreter, Hash *h
             }
             hash->entries--;
             bucket->next = hash->free_list;
+            bucket->key = NULL;
             hash->free_list = bucket;
             return;
         }

Modified: branches/leo-ctx5/src/packfile.c
==============================================================================
--- branches/leo-ctx5/src/packfile.c    (original)
+++ branches/leo-ctx5/src/packfile.c    Fri Aug 19 02:51:08 2005
@@ -232,18 +232,19 @@ sub_pragma(Parrot_Interp interpreter, in
 
 /*
 
-=item C<static void run_sub(Parrot_Interp interpreter, PMC* sub_pmc)>
+=item C<static PMC* run_sub(Parrot_Interp interpreter, PMC* sub_pmc)>
 
-Run the B<sub_pmc> due its B<@LOAD> pragma
+Run the B<sub_pmc> due its B<@LOAD>, B<@IMMEDIATE>, ... pragma
 
 =cut
 
 */
 
-static void
+static PMC*
 run_sub(Parrot_Interp interpreter, PMC* sub_pmc)
 {
     Parrot_Run_core_t old = interpreter->run_core;
+    PMC *retval;
 
     /*
      * turn off JIT and prederef - both would act on the whole
@@ -253,13 +254,14 @@ run_sub(Parrot_Interp interpreter, PMC* 
         interpreter->run_core != PARROT_SLOW_CORE  &&
         interpreter->run_core != PARROT_FAST_CORE)
         interpreter->run_core = PARROT_FAST_CORE;
-    Parrot_runops_fromc_args(interpreter, sub_pmc, "v");
+    retval = Parrot_runops_fromc_args(interpreter, sub_pmc, "P");
     interpreter->run_core = old;
+    return retval;
 }
 
 /*
 
-=item <static void
+=item <static PMC*
 do_sub_pragmas(Parrot_Interp interpreter, struct PackFile *self, int action)>
 
 Run autoloaded bytecode, mark MAIN subroutine entry
@@ -268,12 +270,14 @@ Run autoloaded bytecode, mark MAIN subro
 
 */
 
-static void
+static PMC*
 do_1_sub_pragma(Parrot_Interp interpreter, PMC* sub_pmc, int action)
 {
 
     size_t start_offs;
     struct Parrot_sub * sub = PMC_sub(sub_pmc);
+    PMC *result;
+
     switch (action) {
         case PBC_IMMEDIATE:
             /*
@@ -281,12 +285,12 @@ do_1_sub_pragma(Parrot_Interp interprete
              */
             if (PObj_get_FLAGS(sub_pmc) & SUB_FLAG_PF_IMMEDIATE) {
                 PObj_get_FLAGS(sub_pmc) &= ~SUB_FLAG_PF_IMMEDIATE;
-                run_sub(interpreter, sub_pmc);
+                result = run_sub(interpreter, sub_pmc);
                 /*
                  * reset initial flag so MAIN detection works
                  */
                 interpreter->resume_flag = RESUME_INITIAL;
-                return;
+                return result;
             }
         case PBC_POSTCOMP:
             /*
@@ -299,7 +303,7 @@ do_1_sub_pragma(Parrot_Interp interprete
                  * reset initial flag so MAIN detection works
                  */
                 interpreter->resume_flag = RESUME_INITIAL;
-                return;
+                return NULL;
             }
 
         case PBC_LOADED:
@@ -326,6 +330,7 @@ do_1_sub_pragma(Parrot_Interp interprete
                 }
             }
     }
+    return NULL;
 }
 
 static void
@@ -334,7 +339,7 @@ do_sub_pragmas(Interp* interpreter, stru
     opcode_t i, ci;
     struct PackFile_FixupTable *ft;
     struct PackFile_ConstTable *ct;
-    PMC *sub_pmc;
+    PMC *sub_pmc, *result;
 
     ft = self->fixups;
     ct = self->const_table;
@@ -351,7 +356,15 @@ do_sub_pragmas(Interp* interpreter, stru
                     case enum_class_Sub:
                     case enum_class_Closure:
                     case enum_class_Coroutine:
-                        do_1_sub_pragma(interpreter, sub_pmc, action);
+                        result = do_1_sub_pragma(interpreter, sub_pmc, action);
+                        /*
+                         * replace the Sub PMC with the result of the
+                         * computation
+                         */
+                        if (action == PBC_IMMEDIATE && !PMC_IS_NULL(result)) {
+                            ft->fixups[i]->type = enum_fixup_none;
+                            ct->constants[ci]->u.key = result;
+                        }
                 }
         }
     }
@@ -2281,6 +2294,8 @@ fixup_packed_size (Interp* interpreter, 
                 size += PF_size_cstring(ft->fixups[i]->name);
                 size ++; /* offset */
                 break;
+            case enum_fixup_none:
+                break;
             default:
                 internal_exception(1, "Unknown fixup type\n");
                 return 0;
@@ -2315,6 +2330,8 @@ fixup_pack(Interp* interpreter, struct P
                 cursor = PF_store_cstring(cursor, ft->fixups[i]->name);
                 *cursor++ = ft->fixups[i]->offset;
                 break;
+            case enum_fixup_none:
+                break;
             default:
                 internal_exception(1, "Unknown fixup type\n");
                 return 0;
@@ -2400,6 +2417,8 @@ fixup_unpack(Interp *interpreter,
                 self->fixups[i]->name = PF_fetch_cstring(pf, &cursor);
                 self->fixups[i]->offset = PF_fetch_opcode(pf, &cursor);
                 break;
+            case enum_fixup_none:
+                break;
             default:
                 PIO_eprintf(interpreter,
                         "PackFile_FixupTable_unpack: Unknown fixup type %d!\n",

Modified: branches/leo-ctx5/t/pmc/hash.t
==============================================================================
--- branches/leo-ctx5/t/pmc/hash.t      (original)
+++ branches/leo-ctx5/t/pmc/hash.t      Fri Aug 19 02:51:08 2005
@@ -19,7 +19,7 @@ well.
 
 =cut
 
-use Parrot::Test tests => 36;
+use Parrot::Test tests => 37;
 use Test::More;
 
 output_is(<<CODE, <<OUTPUT, "Initial Hash tests");
@@ -1338,4 +1338,61 @@ CODE
 a
 OUTPUT
 
-1;
+pir_output_is(<< 'CODE', << 'OUTPUT', "broken delete, thx to azuroth on irc");
+.include "iterator.pasm"
+
+.sub main @MAIN
+  .local pmc thash
+
+  # just put in some dummy data...
+  thash = new Hash
+  thash["a"] = "b"
+  thash["c"] = "d"
+  thash["e"] = "f"
+
+  .local pmc iter
+  iter = new Iterator, thash
+  iter = .ITERATE_FROM_START
+
+  .local string key
+
+  # go through the hash, print out all the keys: should be a c and e
+preit_loop:
+  unless iter goto preit_end
+
+  key = shift iter
+  print key
+  print "\n"
+
+  branch preit_loop
+preit_end:
+
+  # get rid of the c element?
+  delete thash["c"]
+
+  print "after deletion\n"
+
+  iter = new Iterator, thash
+  iter = .ITERATE_FROM_START
+
+  # go through the hash, print out all the keys... I believe it should be a 
and e?
+  # it actually outputs a, c and e.
+postit_loop:
+  unless iter goto postit_end
+
+  key = shift iter
+  print key
+  print "\n"
+
+  branch postit_loop
+postit_end:
+
+.end
+CODE
+a
+c
+e
+after deletion
+a
+e
+OUTPUT

Modified: branches/leo-ctx5/t/pmc/sub.t
==============================================================================
--- branches/leo-ctx5/t/pmc/sub.t       (original)
+++ branches/leo-ctx5/t/pmc/sub.t       Fri Aug 19 02:51:08 2005
@@ -17,7 +17,7 @@ C<Continuation> PMCs.
 
 =cut
 
-use Parrot::Test tests => 48;
+use Parrot::Test tests => 49;
 use Test::More;
 use Parrot::Config;
 
@@ -1278,3 +1278,21 @@ l21
 l22
 main 3
 OUTPUT
+
+pir_output_is(<<'CODE', <<'OUTPUT', "immediate code as const");
+.sub make_pi @IMMEDIATE, @ANON
+    $N0 = atan 1.0, 1.0
+    $N0 *= 4
+    $P0 = new .Float
+    $P0 = $N0
+    .return ($P0)
+.end
+
+.sub main @MAIN
+    .const .Sub pi = "make_pi"
+    print pi
+    print "\n"
+.end
+CODE
+3.14159
+OUTPUT

Reply via email to