[svn:parrot] r44844 - in trunk: include/parrot src src/ops

tewk at svn.parrot.org tewk at svn.parrot.org
Wed Mar 10 02:32:59 UTC 2010


Author: tewk
Date: Wed Mar 10 02:32:58 2010
New Revision: 44844
URL: https://trac.parrot.org/parrot/changeset/44844

Log:
VTABLE_init_int

Modified:
   trunk/include/parrot/pmc.h
   trunk/src/ops/experimental.ops
   trunk/src/pmc.c
   trunk/src/vtable.tbl

Modified: trunk/include/parrot/pmc.h
==============================================================================
--- trunk/include/parrot/pmc.h	Wed Mar 10 02:29:21 2010	(r44843)
+++ trunk/include/parrot/pmc.h	Wed Mar 10 02:32:58 2010	(r44844)
@@ -89,6 +89,13 @@
 
 PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
+PMC * Parrot_pmc_new_init_int(PARROT_INTERP,
+    INTVAL base_type,
+    INTVAL init)
+        __attribute__nonnull__(1);
+
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
 PMC * Parrot_pmc_new_noinit(PARROT_INTERP, INTVAL base_type)
         __attribute__nonnull__(1);
 

Modified: trunk/src/ops/experimental.ops
==============================================================================
--- trunk/src/ops/experimental.ops	Wed Mar 10 02:29:21 2010	(r44843)
+++ trunk/src/ops/experimental.ops	Wed Mar 10 02:32:58 2010	(r44844)
@@ -235,6 +235,62 @@
     }
 }
 
+=over 4
+
+=item B<new>(out PMC, in STR, in INT)
+
+=item B<new>(out PMC, in PMC, in INT)
+
+=back
+
+=cut
+
+
+op new(out PMC, in STR, in INT) {
+    STRING * const name   = $2;
+    PMC    * const _class = Parrot_pcc_get_HLL(interp, CURRENT_CONTEXT(interp))
+                          ? Parrot_oo_get_class_str(interp, name)
+                          : PMCNULL;
+
+    if (!PMC_IS_NULL(_class)) {
+        PMC *initial = Parrot_pmc_new(interp, Parrot_get_ctx_HLL_type(interp, enum_class_Integer));
+        VTABLE_set_integer_native(interp, initial, $3);
+        $1 = VTABLE_instantiate(interp, _class, initial);
+    }
+    else {
+        const INTVAL type = Parrot_pmc_get_type_str(interp, name);
+        if (type <= 0) {
+            opcode_t *dest = Parrot_ex_throw_from_op_args(interp, expr NEXT(),
+                EXCEPTION_NO_CLASS,
+                "Class '%Ss' not found", name);
+            goto ADDRESS(dest);
+        }
+        $1 = Parrot_pmc_new_init_int(interp, type, $3);
+    }
+}
+
+
+op new(out PMC, in PMC, in INT) {
+    PMC * const name_key = $2;
+    PMC * const _class   = Parrot_oo_get_class(interp, name_key);
+
+    if (!PMC_IS_NULL(_class)) {
+        PMC *initial = Parrot_pmc_new(interp, Parrot_get_ctx_HLL_type(interp, enum_class_Integer));
+        VTABLE_set_integer_native(interp, initial, $3);
+        $1 = VTABLE_instantiate(interp, _class, initial);
+    }
+    else {
+        const INTVAL type = Parrot_pmc_get_type(interp, name_key);
+        if (type <= 0) {
+            opcode_t *dest = Parrot_ex_throw_from_op_args(interp, expr NEXT(),
+                EXCEPTION_NO_CLASS,
+                "Class '%Ss' not found", VTABLE_get_repr(interp, name_key));
+            goto ADDRESS(dest);
+        }
+        $1 = Parrot_pmc_new_init_int(interp, type, $3);
+    }
+}
+
 =head1 COPYRIGHT
 
 Copyright (C) 2001-2009, Parrot Foundation.

Modified: trunk/src/pmc.c
==============================================================================
--- trunk/src/pmc.c	Wed Mar 10 02:29:21 2010	(r44843)
+++ trunk/src/pmc.c	Wed Mar 10 02:32:58 2010	(r44844)
@@ -564,6 +564,35 @@
 
 /*
 
+=item C<PMC * Parrot_pmc_new_init(PARROT_INTERP, INTVAL base_type, INTVAL init)>
+
+As C<Parrot_pmc_new()>, but passes C<init> to the PMC's C<init_int()> vtable entry.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+PMC *
+Parrot_pmc_new_init_int(PARROT_INTERP, INTVAL base_type, INTVAL init)
+{
+    ASSERT_ARGS(Parrot_pmc_new_init)
+    PMC *const classobj = interp->vtables[base_type]->pmc_class;
+
+    if (!PMC_IS_NULL(classobj) && PObj_is_class_TEST(classobj))
+        return VTABLE_instantiate(interp, classobj, init);
+    else {
+        PMC * const pmc = get_new_pmc_header(interp, base_type, 0);
+        VTABLE_init_int(interp, pmc, init);
+        return pmc;
+    }
+}
+
+
+
+/*
+
 =item C<PMC * Parrot_pmc_new_constant_init(PARROT_INTERP, INTVAL base_type, PMC
 *init)>
 

Modified: trunk/src/vtable.tbl
==============================================================================
--- trunk/src/vtable.tbl	Wed Mar 10 02:29:21 2010	(r44843)
+++ trunk/src/vtable.tbl	Wed Mar 10 02:32:58 2010	(r44844)
@@ -281,3 +281,5 @@
 void share()
 
 PMC* share_ro()
+
+void init_int(INTVAL initializer)


More information about the parrot-commits mailing list