[svn:parrot] r44155 - in trunk: examples/pir src/pmc

cotto at svn.parrot.org cotto at svn.parrot.org
Fri Feb 19 02:41:58 UTC 2010


Author: cotto
Date: Fri Feb 19 02:41:57 2010
New Revision: 44155
URL: https://trac.parrot.org/parrot/changeset/44155

Log:
[oplib] add a VTABLE function to oplib, use it in make_hello_pbc instead of magic numbers

Modified:
   trunk/examples/pir/make_hello_pbc.pir
   trunk/src/pmc/oplib.pmc

Modified: trunk/examples/pir/make_hello_pbc.pir
==============================================================================
--- trunk/examples/pir/make_hello_pbc.pir	Fri Feb 19 02:38:01 2010	(r44154)
+++ trunk/examples/pir/make_hello_pbc.pir	Fri Feb 19 02:41:57 2010	(r44155)
@@ -2,7 +2,7 @@
 #$Id$
 # Sample creating of "Hello World" program using Packfile PMCs.
 .sub 'main'
-    .local pmc pf, pfdir, pffixup, pfbc, pfconst
+    .local pmc pf, pfdir, pffixup, pfbc, pfconst, oplib
 
     # Hello World is something like
     # .sub 'hello'
@@ -40,15 +40,19 @@
 
     # Generate bytecode
     pfbc = new 'PackfileRawSegment'
+    oplib = new 'OpLib'
 
-    # There is our function
-    pfbc[0] = 0x1d1 # say_sc
+    # Here is our function
+    $I0 = oplib['say_sc']
+    pfbc[0] = $I0 
     pfbc[1] = 0x002 # constant id.
 
-    pfbc[2] = 0x026 # set_return_pc
+    $I0 = oplib['set_returns_pc']
+    pfbc[2] = $I0
     pfbc[3] = 0x001 # id of FIA
 
-    pfbc[4] = 0x020 # returncc
+    $I0 = oplib['returncc']
+    pfbc[4] = $I0
 
     # Store bytecode
     pfdir['BYTECODE_hello.pir'] = pfbc

Modified: trunk/src/pmc/oplib.pmc
==============================================================================
--- trunk/src/pmc/oplib.pmc	Fri Feb 19 02:38:01 2010	(r44154)
+++ trunk/src/pmc/oplib.pmc	Fri Feb 19 02:41:57 2010	(r44155)
@@ -45,6 +45,11 @@
         return num;
     }
 
+    VTABLE INTVAL get_integer_keyed(PMC *key) {
+        STRING *str_key = key_string(INTERP, key);
+        return SELF.get_integer_keyed_str(str_key);
+    }
+
     VTABLE PMC* get_pmc_keyed_str(STRING *name) {
         PMC * const op = pmc_new_noinit(INTERP, enum_class_Opcode);
         VTABLE_set_string_native(INTERP, op, name);


More information about the parrot-commits mailing list