[svn:parrot] r49159 - in branches/typesafe_consttable: compilers/imcc compilers/opsc/src/Ops/Trans include/parrot src src/call src/ops src/pmc src/runcore
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Sun Sep 19 16:51:23 UTC 2010
Author: plobsing
Date: Sun Sep 19 16:51:22 2010
New Revision: 49159
URL: https://trac.parrot.org/parrot/changeset/49159
Log:
separate num, str, and pmc constants
miniparrot fails. apparently there's still some bugs to work out.
Modified:
branches/typesafe_consttable/compilers/imcc/pbc.c
branches/typesafe_consttable/compilers/opsc/src/Ops/Trans/C.pm
branches/typesafe_consttable/include/parrot/call.h
branches/typesafe_consttable/include/parrot/context.h
branches/typesafe_consttable/include/parrot/packfile.h
branches/typesafe_consttable/src/call/context.c
branches/typesafe_consttable/src/call/context_accessors.c
branches/typesafe_consttable/src/debug.c
branches/typesafe_consttable/src/embed.c
branches/typesafe_consttable/src/ops/core_ops.c
branches/typesafe_consttable/src/packfile.c
branches/typesafe_consttable/src/packout.c
branches/typesafe_consttable/src/pmc/callcontext.pmc
branches/typesafe_consttable/src/pmc/eval.pmc
branches/typesafe_consttable/src/pmc/imageiothaw.pmc
branches/typesafe_consttable/src/pmc/packfileconstanttable.pmc
branches/typesafe_consttable/src/pmc/sub.pmc
branches/typesafe_consttable/src/runcore/trace.c
Modified: branches/typesafe_consttable/compilers/imcc/pbc.c
==============================================================================
--- branches/typesafe_consttable/compilers/imcc/pbc.c Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/compilers/imcc/pbc.c Sun Sep 19 16:51:22 2010 (r49159)
@@ -10,6 +10,7 @@
#include "pmc/pmc_sub.h"
#include "pmc/pmc_callcontext.h"
#include "parrot/oplib/core_ops.h"
+#include "pmc/pmc_key.h"
/* HEADERIZER HFILE: compilers/imcc/pbc.h */
@@ -338,44 +339,6 @@
/*
-=item C<static int add_const_table(PARROT_INTERP)>
-
-Adds an empty item to constant table, returning its position.
-
-=cut
-
-*/
-
-static int
-add_const_table(PARROT_INTERP)
-{
- ASSERT_ARGS(add_const_table)
- const size_t oldcount = interp->code->const_table->const_count;
- const size_t newcount = oldcount + 1;
-
- /* Update the constant count and reallocate */
- if (interp->code->const_table->constants) {
- interp->code->const_table->constants =
- mem_gc_realloc_n_typed_zeroed(interp, interp->code->const_table->constants,
- newcount, oldcount, PackFile_Constant);
- }
- else {
- /* initialize rlookup cache */
- interp->code->const_table->string_hash = parrot_create_hash(interp,
- enum_type_INTVAL,
- Hash_key_type_STRING_enc);
- interp->code->const_table->constants =
- mem_gc_allocate_n_zeroed_typed(interp, newcount, PackFile_Constant);
- }
-
- interp->code->const_table->const_count = newcount;
-
- return oldcount;
-}
-
-
-/*
-
=item C<static int add_const_table_pmc(PARROT_INTERP, PMC *pmc)>
Adds a PMC to the const table, returning its position.
@@ -388,37 +351,20 @@
add_const_table_pmc(PARROT_INTERP, ARGIN(PMC *pmc))
{
ASSERT_ARGS(add_const_table_pmc)
- const int newitem = add_const_table(interp);
- PackFile_Constant * const constant = &interp->code->const_table->constants[newitem];
-
- constant->type = PFC_PMC;
- constant->u.key = pmc;
+ PackFile_ConstTable *ct = interp->code->const_table;
- return newitem;
-}
-
-
-/*
-
-=item C<static int add_const_table_key(PARROT_INTERP, PMC *key)>
+ if (!ct->pmc.constants)
+ ct->pmc.constants =
+ mem_gc_allocate_n_zeroed_typed(interp, 1, PMC *);
+ else
+ ct->pmc.constants =
+ mem_gc_realloc_n_typed_zeroed(interp, ct->pmc.constants,
+ ct->pmc.const_count + 1, ct->pmc.const_count, PMC *);
-Adds a key to the const table, returning its position.
-=cut
+ ct->pmc.constants[ct->pmc.const_count++] = pmc;
-*/
-
-static int
-add_const_table_key(PARROT_INTERP, ARGIN(PMC *key))
-{
- ASSERT_ARGS(add_const_table_key)
- const int newitem = add_const_table(interp);
- PackFile_Constant * const constant = &interp->code->const_table->constants[newitem];
-
- constant->type = PFC_KEY;
- constant->u.key = key;
-
- return newitem;
+ return ct->pmc.const_count - 1;
}
@@ -1128,8 +1074,8 @@
ASSERT_ARGS(add_const_str)
PMC *s_pmc = key_new_string(interp, s);
- PackFile_ConstTable *table = interp->code->const_table;
- int i = PackFile_ConstTable_rlookup(interp, table, s_pmc, PFC_STRING);
+ PackFile_ConstTable *ct = interp->code->const_table;
+ int i = PackFile_ConstTable_rlookup(interp, ct, s_pmc, PFC_STRING);
if (i >= 0)
return i;
@@ -1137,14 +1083,27 @@
/* otherwise... */
{
- int k = add_const_table(interp);
- PackFile_Constant *constant = &table->constants[k];
- constant->type = PFC_STRING;
- constant->u.string = s;
+ if (!ct->str.constants) {
+ ct->str.constants =
+ mem_gc_allocate_n_zeroed_typed(interp, 1, STRING *);
+
+ /* initialize rlookup cache */
+ ct->string_hash = parrot_create_hash(interp,
+ enum_type_INTVAL,
+ Hash_key_type_STRING_enc);
+ }
+ else {
+ ct->str.constants =
+ mem_gc_realloc_n_typed_zeroed(interp, ct->str.constants,
+ ct->str.const_count + 1, ct->str.const_count, STRING *);
+ }
- parrot_hash_put(interp, table->string_hash, s, (void *)k);
+ ct->str.constants[ct->str.const_count] = s;
- return k;
+ parrot_hash_put(interp, ct->string_hash, s,
+ (void *)ct->str.const_count);
+
+ return ct->str.const_count++;
}
}
@@ -1164,15 +1123,20 @@
add_const_num(PARROT_INTERP, ARGIN_NULLOK(const char *buf))
{
ASSERT_ARGS(add_const_num)
- const int k = add_const_table(interp);
- STRING * const s = Parrot_str_new(interp, buf, 0);
+ PackFile_ConstTable *ct = interp->code->const_table;
+ STRING * const s = Parrot_str_new(interp, buf, 0);
- PackFile_Constant * const constant = &interp->code->const_table->constants[k];
+ if (!ct->num.constants)
+ ct->num.constants =
+ mem_gc_allocate_n_zeroed_typed(interp, 1, FLOATVAL);
+ else
+ ct->num.constants =
+ mem_gc_realloc_n_typed_zeroed(interp, ct->num.constants,
+ ct->num.const_count + 1, ct->num.const_count, FLOATVAL);
- constant->type = PFC_NUMBER;
- constant->u.number = Parrot_str_to_num(interp, s);
+ ct->num.constants[ct->num.const_count] = Parrot_str_to_num(interp, s);
- return k;
+ return ct->num.const_count++;
}
@@ -1212,7 +1176,7 @@
r = pcc_sub->multi[i];
if (r->set == 'S') {
- STRING * const type_name = ct->constants[r->color].u.string;
+ STRING * const type_name = ct->str.constants[r->color];
const INTVAL type_num = Parrot_pmc_get_type_str(interp, type_name);
if (type_num == enum_type_undef) {
@@ -1225,7 +1189,7 @@
}
else {
PARROT_ASSERT(r->set == 'K');
- sig_pmc = ct->constants[r->color].u.key;
+ sig_pmc = ct->pmc.constants[r->color];
}
VTABLE_set_pmc_keyed_int(interp, multi_sig, i, sig_pmc);
@@ -1256,10 +1220,10 @@
int need_lex)
{
ASSERT_ARGS(create_lexinfo)
- PMC *lex_info = NULL;
- SymHash *hsh = &unit->hash;
- PackFile_Constant *constants = interp->code->const_table->constants;
- const INTVAL lex_info_id = Parrot_get_ctx_HLL_type(interp,
+ PMC *lex_info = NULL;
+ SymHash *hsh = &unit->hash;
+ PackFile_ConstTable *ct = interp->code->const_table;
+ const INTVAL lex_info_id = Parrot_get_ctx_HLL_type(interp,
enum_class_LexInfo);
unsigned int i;
@@ -1284,7 +1248,7 @@
Parrot_Sub_attributes *sub;
PARROT_ASSERT(k >= 0);
- lex_name = constants[k].u.string;
+ lex_name = ct->str.constants[k];
PARROT_ASSERT(PObj_is_string_TEST(lex_name));
PMC_get_sub(interp, sub_pmc, sub);
@@ -1411,9 +1375,9 @@
int i;
int ns_const = -1;
+ SymReg * const ns = unit->_namespace ? unit->_namespace->reg : NULL;
if (unit->_namespace) {
- SymReg * const ns = unit->_namespace->reg;
/* strip namespace off from front */
static const char ns_sep[] = "@@@";
@@ -1479,7 +1443,7 @@
Sub_comp_get_FLAGS(sub) |= (r->pcc_sub->pragma & SUB_COMP_FLAG_MASK);
r->color = add_const_str(interp, IMCC_string_from_reg(interp, r));
- sub->name = ct->constants[r->color].u.string;
+ sub->name = ct->str.constants[r->color];
/* If the unit has no subid, set the subid to match the name. */
if (!unit->subid)
@@ -1496,18 +1460,21 @@
IMCC_string_from_reg(interp, unit->subid));
}
- sub->subid = ct->constants[unit->subid->color].u.string;
+ sub->subid = ct->str.constants[unit->subid->color];
ns_pmc = NULL;
- if (ns_const >= 0 && ns_const < ct->const_count) {
- switch (ct->constants[ns_const].type) {
- case PFC_KEY:
- ns_pmc = ct->constants[ns_const].u.key;
+ if (ns) {
+ switch (ns->set) {
+ case 'K':
+ if (ns_const >= 0 && ns_const < ct->pmc.const_count)
+ ns_pmc = ct->pmc.constants[ns_const];
break;
- case PFC_STRING:
- ns_pmc = Parrot_pmc_new_constant(interp, enum_class_String);
- VTABLE_set_string_native(interp, ns_pmc,
- ct->constants[ns_const].u.string);
+ case 'S':
+ if (ns_const >= 0 && ns_const < ct->str.const_count) {
+ ns_pmc = Parrot_pmc_new_constant(interp, enum_class_String);
+ VTABLE_set_string_native(interp, ns_pmc,
+ ct->str.constants[ns_const]);
+ }
break;
default:
break;
@@ -1600,11 +1567,7 @@
/* store the sub */
{
- const int k = add_const_table(interp);
- PackFile_Constant * const pfc = &ct->constants[k];
-
- pfc->type = PFC_PMC;
- pfc->u.key = sub_pmc;
+ const int k = add_const_table_pmc(interp, sub_pmc);
unit->sub_pmc = sub_pmc;
IMCC_INFO(interp)->globals->cs->subs->pmc_const = k;
@@ -1647,7 +1610,7 @@
*/
static int
-add_const_key(PARROT_INTERP, ARGIN(const opcode_t *key), int size, ARGIN(const char *s_key))
+add_const_key(PARROT_INTERP, const opcode_t *key, int size, const char *s_key)
{
ASSERT_ARGS(add_const_key)
const SymReg * const r =
@@ -1659,9 +1622,11 @@
if (r)
return r->color;
+#if 0
pfc = mem_gc_allocate_typed(interp, PackFile_Constant);
rc = PackFile_Constant_unpack_key(interp,
interp->code->const_table, pfc, key);
+#endif
if (!rc) {
mem_sys_free(pfc);
@@ -1669,7 +1634,7 @@
"add_const_key: PackFile_Constant error\n");
}
- k = add_const_table_key(interp, pfc->u.key);
+ k = add_const_table_pmc(interp, pfc->u.key);
store_key_const(interp, s_key, k);
@@ -1703,30 +1668,22 @@
build_key(PARROT_INTERP, ARGIN(SymReg *key_reg))
{
ASSERT_ARGS(build_key)
-#define MAX_KEY_LEN 10
-#define MAX_KEYNAME_LEN 20
- SymReg *reg = key_reg->set == 'K' ? key_reg->nextkey : key_reg;
-
- char s_key[MAX_KEY_LEN * MAX_KEYNAME_LEN];
- opcode_t key[MAX_KEY_LEN * 2 + 1];
- opcode_t size;
- int key_length = 0; /* P0["hi;there"; S0; 2] has length 3 */
- int k;
-
- /* 0 is length */
- opcode_t *pc = key + 1;
-
- /* stringified key */
- char *s = s_key;
- *s = 0;
+ PackFile_ConstTable *ct = interp->code->const_table;
+ SymReg *reg = key_reg->set == 'K' ? key_reg->nextkey : key_reg;
+ PMC *head, *tail;
+ opcode_t regno, k;
- for (key_length = 0; reg ; reg = reg->nextkey, key_length++) {
+ for (; reg; reg = reg->nextkey) {
SymReg *r = reg;
- if (key_length >= MAX_KEY_LEN)
- IMCC_fatal(interp, 1, "build_key:"
- "Key too long, increase MAX_KEY_LEN.\n");
+ if (tail) {
+ SETATTR_Key_next_key(interp, tail, Parrot_pmc_new_constant(interp, enum_class_Key));
+ GETATTR_Key_next_key(interp, tail, tail);
+ }
+ else {
+ head = tail = Parrot_pmc_new_constant(interp, enum_class_Key);
+ }
switch (r->type) {
case VTIDENTIFIER: /* P[S0] */
@@ -1737,21 +1694,16 @@
if (r->reg)
r = r->reg;
+ /* don't emit mapped regs in key parts */
+ regno = r->color >= 0 ? r->color : -1 - r->color;
+
if (r->set == 'I')
- *pc++ = PARROT_ARG_I; /* register type */
+ key_set_register(interp, tail, regno, KEY_integer_FLAG);
else if (r->set == 'S')
- *pc++ = PARROT_ARG_S;
+ key_set_register(interp, tail, regno, KEY_string_FLAG);
else
IMCC_fatal(interp, 1, "build_key: wrong register set\n");
- /* don't emit mapped regs in key parts */
- if (r->color < 0)
- *pc++ = -1 - r->color;
- else
- *pc++ = r->color;
-
- sprintf(s+strlen(s), "%c%d", r->set, (int)r->color);
-
IMCC_debug(interp, DEBUG_PBC_CONST,
" keypart reg %s %c%d\n",
r->name, r->set, (int)r->color);
@@ -1764,30 +1716,15 @@
switch (r->set) {
case 'S': /* P["key"] */
/* str constant */
- *pc++ = PARROT_ARG_SC;
-
- /* constant idx */
- *pc++ = r->color;
-
- IMCC_debug(interp, DEBUG_PBC_CONST,
- " keypart SC %s #%d\n",
- r->name, r->color);
+ key_set_string(interp, tail, ct->str.constants[r->color]);
break;
case 'I': /* P[;42;..] */
/* int constant */
- *pc++ = PARROT_ARG_IC;
-
- /* value */
- *pc++ = r->color = atol(r->name);
-
- IMCC_debug(interp, DEBUG_PBC_CONST,
- " keypart IC %s #%d\n",
- r->name, r->color);
+ key_set_integer(interp, tail, atol(r->name));
break;
default:
IMCC_fatal(interp, 1, "build_key: unknown set\n");
}
- sprintf(s+strlen(s), "%cc" INTVAL_FMT, r->set, r->color);
break;
default:
IMCC_fatal(interp, 1, "build_key: "
@@ -1795,13 +1732,7 @@
}
}
- key[0] = key_length;
- size = pc - key;
-
- /* now we have a packed key, which packfile can work on */
- /* XXX endianess? probably no, we pack/unpack on the very
- * same computer */
- k = add_const_key(interp, key, size, s_key);
+ k = add_const_table_pmc(interp, head);
/* single 'S' keys already have their color assigned */
if (key_reg->set == 'K')
@@ -2226,7 +2157,7 @@
{
ASSERT_ARGS(verify_signature)
PMC *changed_sig = NULL;
- PMC * const sig_arr = interp->code->const_table->constants[pc[-1]].u.key;
+ PMC * const sig_arr = interp->code->const_table->pmc.constants[pc[-1]];
op_lib_t *core_ops = PARROT_GET_CORE_OPLIB(interp);
int needed = 0;
int no_consts = (ins->op == &core_ops->op_info_table[PARROT_OP_get_results_pc]
Modified: branches/typesafe_consttable/compilers/opsc/src/Ops/Trans/C.pm
==============================================================================
--- branches/typesafe_consttable/compilers/opsc/src/Ops/Trans/C.pm Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/compilers/opsc/src/Ops/Trans/C.pm Sun Sep 19 16:51:22 2010 (r49159)
@@ -115,10 +115,10 @@
#define PREG(i) (CUR_CTX->bp_ps.regs_p[-1L - cur_opcode[i]])
#define SREG(i) (CUR_CTX->bp_ps.regs_s[cur_opcode[i]])
#define ICONST(i) cur_opcode[i]
-#define NCONST(i) Parrot_pcc_get_num_constants(interp, interp->ctx)[cur_opcode[i]].u.number
-#define SCONST(i) Parrot_pcc_get_str_constants(interp, interp->ctx)[cur_opcode[i]].u.string
+#define NCONST(i) Parrot_pcc_get_num_constants(interp, interp->ctx)[cur_opcode[i]]
+#define SCONST(i) Parrot_pcc_get_str_constants(interp, interp->ctx)[cur_opcode[i]]
#undef PCONST
-#define PCONST(i) Parrot_pcc_get_pmc_constants(interp, interp->ctx)[cur_opcode[i]].u.key
+#define PCONST(i) Parrot_pcc_get_pmc_constants(interp, interp->ctx)[cur_opcode[i]]
static int get_op(PARROT_INTERP, const char * name, int full);
|;
Modified: branches/typesafe_consttable/include/parrot/call.h
==============================================================================
--- branches/typesafe_consttable/include/parrot/call.h Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/include/parrot/call.h Sun Sep 19 16:51:22 2010 (r49159)
@@ -308,7 +308,7 @@
|| OPCODE_IS((interp), (seg), *(pc), _core_ops, PARROT_OP_get_results_pc) \
|| OPCODE_IS((interp), (seg), *(pc), _core_ops, PARROT_OP_get_params_pc) \
|| OPCODE_IS((interp), (seg), *(pc), _core_ops, PARROT_OP_set_returns_pc)) { \
- PMC * const sig = (seg)->const_table->constants[(pc)[1]].u.key; \
+ PMC * const sig = (seg)->const_table->pmc.constants[(pc)[1]]; \
(n) += VTABLE_elements((interp), sig); \
} \
} while (0)
Modified: branches/typesafe_consttable/include/parrot/context.h
==============================================================================
--- branches/typesafe_consttable/include/parrot/context.h Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/include/parrot/context.h Sun Sep 19 16:51:22 2010 (r49159)
@@ -12,7 +12,7 @@
#include "parrot/string.h"
#include "parrot/compiler.h"
-struct PackFile_Constant;
+struct PackFile_ConstTable;
typedef union {
PMC **regs_p;
@@ -148,8 +148,7 @@
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_PURE_FUNCTION
-struct PackFile_Constant * Parrot_pcc_get_num_constants_func(SHIM_INTERP,
- ARGIN(PMC *ctx))
+FLOATVAL * Parrot_pcc_get_num_constants_func(SHIM_INTERP, ARGIN(PMC *ctx))
__attribute__nonnull__(2);
PARROT_EXPORT
@@ -181,8 +180,7 @@
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_PURE_FUNCTION
-struct PackFile_Constant * Parrot_pcc_get_pmc_constants_func(SHIM_INTERP,
- ARGIN(PMC *ctx))
+PMC ** Parrot_pcc_get_pmc_constants_func(SHIM_INTERP, ARGIN(PMC *ctx))
__attribute__nonnull__(2);
PARROT_EXPORT
@@ -199,8 +197,7 @@
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_PURE_FUNCTION
-struct PackFile_Constant * Parrot_pcc_get_str_constants_func(SHIM_INTERP,
- ARGIN(PMC *ctx))
+STRING ** Parrot_pcc_get_str_constants_func(SHIM_INTERP, ARGIN(PMC *ctx))
__attribute__nonnull__(2);
PARROT_EXPORT
@@ -226,8 +223,9 @@
PARROT_CAN_RETURN_NULL
void Parrot_pcc_set_constants_func(SHIM_INTERP,
ARGIN(PMC *ctx),
- ARGIN_NULLOK(struct PackFile_Constant *constants))
- __attribute__nonnull__(2);
+ ARGIN(struct PackFile_ConstTable *ct))
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
PARROT_EXPORT
void Parrot_pcc_set_continuation_func(SHIM_INTERP,
@@ -384,7 +382,8 @@
PARROT_ASSERT_ARG(ctx) \
, PARROT_ASSERT_ARG(caller_ctx))
#define ASSERT_ARGS_Parrot_pcc_set_constants_func __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(ctx))
+ PARROT_ASSERT_ARG(ctx) \
+ , PARROT_ASSERT_ARG(ct))
#define ASSERT_ARGS_Parrot_pcc_set_continuation_func \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(ctx))
@@ -432,7 +431,11 @@
# define Parrot_pcc_get_num_constants(i, c) (CONTEXT_STRUCT(c)->constants)
# define Parrot_pcc_get_str_constants(i, c) (CONTEXT_STRUCT(c)->constants)
# define Parrot_pcc_get_pmc_constants(i, c) (CONTEXT_STRUCT(c)->constants)
-# define Parrot_pcc_set_constants(i, c, value) (CONTEXT_STRUCT(c)->constants = (value))
+# define Parrot_pcc_set_constants(i, c, ct) do { \
+ CONTEXT_STRUCT(c)->num_constants = (ct)->num.constants; \
+ CONTEXT_STRUCT(c)->str_constants = (ct)->str.constants; \
+ CONTEXT_STRUCT(c)->pmc_constants = (ct)->pmc.constants; \
+} while (0)
# define Parrot_pcc_get_continuation(i, c) (CONTEXT_STRUCT(c)->current_cont)
# define Parrot_pcc_set_continuation(i, c, value) (CONTEXT_STRUCT(c)->current_cont = (value))
Modified: branches/typesafe_consttable/include/parrot/packfile.h
==============================================================================
--- branches/typesafe_consttable/include/parrot/packfile.h Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/include/parrot/packfile.h Sun Sep 19 16:51:22 2010 (r49159)
@@ -16,8 +16,8 @@
#include "parrot/parrot.h"
-#define PF_NCONST(pf) ((pf)->const_table->const_count)
-#define PF_CONST(pf, i) ((pf)->const_table->constants[(i)])
+#define PF_NCONST(pf, type) ((pf)->const_table-> type .const_count)
+#define PF_CONST(pf, type, i) ((pf)->const_table-> type .constants[(i)])
#define DIRECTORY_SEGMENT_NAME Parrot_str_new_constant(interp, "DIRECTORY")
#define FIXUP_TABLE_SEGMENT_NAME Parrot_str_new_constant(interp, "FIXUP")
@@ -259,10 +259,20 @@
typedef struct PackFile_ConstTable {
PackFile_Segment base;
- opcode_t const_count;
- PackFile_Constant *constants;
- PackFile_ByteCode *code; /* where this segment belongs to */
- Hash *string_hash; /* Hash for lookup strings and numbers */
+ struct {
+ opcode_t const_count;
+ FLOATVAL *constants;
+ } num;
+ struct {
+ opcode_t const_count;
+ STRING **constants;
+ } str;
+ struct {
+ opcode_t const_count;
+ PMC **constants;
+ } pmc;
+ PackFile_ByteCode *code; /* where this segment belongs to */
+ Hash *string_hash; /* Hash for lookup strings and numbers */
} PackFile_ConstTable;
typedef struct PackFile_ByteCode_OpMappingEntry {
@@ -387,19 +397,6 @@
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
PARROT_EXPORT
-PARROT_CANNOT_RETURN_NULL
-PARROT_WARN_UNUSED_RESULT
-opcode_t * PackFile_Constant_pack(PARROT_INTERP,
- ARGIN(const PackFile_ConstTable *const_table),
- ARGIN(const PackFile_Constant *self),
- ARGOUT(opcode_t *cursor))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- __attribute__nonnull__(4)
- FUNC_MODIFIES(*cursor);
-
-PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
opcode_t * PackFile_ConstTable_pack(PARROT_INTERP,
@@ -450,11 +447,6 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*self);
-#define ASSERT_ARGS_PackFile_Constant_pack __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(const_table) \
- , PARROT_ASSERT_ARG(self) \
- , PARROT_ASSERT_ARG(cursor))
#define ASSERT_ARGS_PackFile_ConstTable_pack __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(seg) \
@@ -529,54 +521,6 @@
__attribute__nonnull__(1);
PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-size_t PackFile_Constant_pack_size(PARROT_INTERP,
- ARGIN(const PackFile_Constant *self),
- ARGIN(const PackFile_ConstTable *ct))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3);
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-const opcode_t * PackFile_Constant_unpack(PARROT_INTERP,
- ARGIN(PackFile_ConstTable *constt),
- ARGOUT(PackFile_Constant *self),
- ARGIN(const opcode_t *cursor))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- __attribute__nonnull__(4)
- FUNC_MODIFIES(*self);
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-const opcode_t * PackFile_Constant_unpack_key(PARROT_INTERP,
- ARGIN(PackFile_ConstTable *constt),
- ARGMOD(PackFile_Constant *self),
- ARGIN(const opcode_t *cursor))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- __attribute__nonnull__(4)
- FUNC_MODIFIES(*self);
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CANNOT_RETURN_NULL
-const opcode_t * PackFile_Constant_unpack_pmc(PARROT_INTERP,
- ARGIN(PackFile_ConstTable *constt),
- ARGMOD(PackFile_Constant *self),
- ARGIN(const opcode_t *cursor))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3)
- __attribute__nonnull__(4)
- FUNC_MODIFIES(*self);
-
-PARROT_EXPORT
void PackFile_ConstTable_clear(PARROT_INTERP,
ARGMOD(PackFile_ConstTable *self))
__attribute__nonnull__(1)
@@ -883,25 +827,6 @@
, PARROT_ASSERT_ARG(self))
#define ASSERT_ARGS_PackFile_Annotations_new __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_PackFile_Constant_pack_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(self) \
- , PARROT_ASSERT_ARG(ct))
-#define ASSERT_ARGS_PackFile_Constant_unpack __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(constt) \
- , PARROT_ASSERT_ARG(self) \
- , PARROT_ASSERT_ARG(cursor))
-#define ASSERT_ARGS_PackFile_Constant_unpack_key __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(constt) \
- , PARROT_ASSERT_ARG(self) \
- , PARROT_ASSERT_ARG(cursor))
-#define ASSERT_ARGS_PackFile_Constant_unpack_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(constt) \
- , PARROT_ASSERT_ARG(self) \
- , PARROT_ASSERT_ARG(cursor))
#define ASSERT_ARGS_PackFile_ConstTable_clear __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(self))
Modified: branches/typesafe_consttable/src/call/context.c
==============================================================================
--- branches/typesafe_consttable/src/call/context.c Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/call/context.c Sun Sep 19 16:51:22 2010 (r49159)
@@ -277,7 +277,9 @@
ctx->current_sub = PMCNULL;
if (PMC_IS_NULL(pmcold)) {
- ctx->constants = NULL;
+ ctx->num_constants = NULL;
+ ctx->str_constants = NULL;
+ ctx->pmc_constants = NULL;
ctx->warns = 0;
ctx->errors = 0;
ctx->trace_flags = 0;
@@ -288,7 +290,9 @@
else {
Parrot_Context *old = CONTEXT_STRUCT(pmcold);
/* some items should better be COW copied */
- ctx->constants = old->constants;
+ ctx->num_constants = old->num_constants;
+ ctx->str_constants = old->str_constants;
+ ctx->pmc_constants = old->pmc_constants;
ctx->warns = old->warns;
ctx->errors = old->errors;
ctx->trace_flags = old->trace_flags;
Modified: branches/typesafe_consttable/src/call/context_accessors.c
==============================================================================
--- branches/typesafe_consttable/src/call/context_accessors.c Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/call/context_accessors.c Sun Sep 19 16:51:22 2010 (r49159)
@@ -49,17 +49,14 @@
/*
-=item C<struct PackFile_Constant *
-Parrot_pcc_get_num_constants_func(PARROT_INTERP, PMC *ctx)>
+=item C<FLOATVAL * Parrot_pcc_get_num_constants_func(PARROT_INTERP, PMC *ctx)>
-=item C<struct PackFile_Constant *
-Parrot_pcc_get_str_constants_func(PARROT_INTERP, PMC *ctx)>
+=item C<STRING ** Parrot_pcc_get_str_constants_func(PARROT_INTERP, PMC *ctx)>
-=item C<struct PackFile_Constant *
-Parrot_pcc_get_pmc_constants_func(PARROT_INTERP, PMC *ctx)>
+=item C<PMC ** Parrot_pcc_get_pmc_constants_func(PARROT_INTERP, PMC *ctx)>
=item C<void Parrot_pcc_set_constants_func(PARROT_INTERP, PMC *ctx, struct
-PackFile_Constant *constants)>
+PackFile_ConstTable *ct)>
Get/set constants from context.
@@ -70,42 +67,44 @@
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_PURE_FUNCTION
-struct PackFile_Constant *
+FLOATVAL *
Parrot_pcc_get_num_constants_func(SHIM_INTERP, ARGIN(PMC *ctx))
{
ASSERT_ARGS(Parrot_pcc_get_num_constants_func)
- return CONTEXT_STRUCT(ctx)->constants;
+ return CONTEXT_STRUCT(ctx)->num_constants;
}
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_PURE_FUNCTION
-struct PackFile_Constant *
+STRING **
Parrot_pcc_get_str_constants_func(SHIM_INTERP, ARGIN(PMC *ctx))
{
ASSERT_ARGS(Parrot_pcc_get_str_constants_func)
- return CONTEXT_STRUCT(ctx)->constants;
+ return CONTEXT_STRUCT(ctx)->str_constants;
}
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_PURE_FUNCTION
-struct PackFile_Constant *
+PMC **
Parrot_pcc_get_pmc_constants_func(SHIM_INTERP, ARGIN(PMC *ctx))
{
ASSERT_ARGS(Parrot_pcc_get_pmc_constants_func)
- return CONTEXT_STRUCT(ctx)->constants;
+ return CONTEXT_STRUCT(ctx)->pmc_constants;
}
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
void
Parrot_pcc_set_constants_func(SHIM_INTERP, ARGIN(PMC *ctx),
- ARGIN_NULLOK(struct PackFile_Constant *constants))
+ ARGIN(struct PackFile_ConstTable *ct))
{
ASSERT_ARGS(Parrot_pcc_set_constants_func)
Parrot_Context * const c = CONTEXT_STRUCT(ctx);
- c->constants = constants;
+ c->num_constants = ct->num.constants;
+ c->str_constants = ct->str.constants;
+ c->pmc_constants = ct->pmc.constants;
}
/*
@@ -704,8 +703,7 @@
{
ASSERT_ARGS(Parrot_pcc_get_num_constant_func)
const Parrot_Context * const c = CONTEXT_STRUCT(ctx);
- PARROT_ASSERT(c->constants[idx].type == 'n');
- return c->constants[idx].u.number;
+ return c->num_constants[idx];
}
PARROT_EXPORT
@@ -716,8 +714,7 @@
{
ASSERT_ARGS(Parrot_pcc_get_string_constant_func)
const Parrot_Context * const c = CONTEXT_STRUCT(ctx);
- PARROT_ASSERT(c->constants[idx].type == 's');
- return c->constants[idx].u.string;
+ return c->str_constants[idx];
}
PARROT_EXPORT
@@ -728,9 +725,7 @@
{
ASSERT_ARGS(Parrot_pcc_get_pmc_constant_func)
const Parrot_Context * const c = CONTEXT_STRUCT(ctx);
- PARROT_ASSERT((c->constants[idx].type == 'k')
- || (c->constants[idx].type == 'p'));
- return c->constants[idx].u.key;
+ return c->pmc_constants[idx];
}
/*
Modified: branches/typesafe_consttable/src/debug.c
==============================================================================
--- branches/typesafe_consttable/src/debug.c Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/debug.c Sun Sep 19 16:51:22 2010 (r49159)
@@ -2344,29 +2344,30 @@
case PARROT_ARG_NC:
{
/* Convert the float to a string */
- const FLOATVAL f = interp->code->const_table->constants[op[j]].u.number;
+ const FLOATVAL f = interp->code->const_table->num.constants[op[j]];
Parrot_snprintf(interp, buf, sizeof (buf), FLOATVAL_FMT, f);
strcpy(&dest[size], buf);
size += strlen(buf);
}
break;
case PARROT_ARG_SC:
- dest[size++] = '"';
- if (interp->code->const_table->constants[op[j]].u.string->strlen) {
- char * const unescaped =
- Parrot_str_to_cstring(interp, interp->code->
- const_table->constants[op[j]].u.string);
- char * const escaped =
- PDB_escape(interp, unescaped, interp->code->const_table->
- constants[op[j]].u.string->strlen);
- if (escaped) {
- strcpy(&dest[size], escaped);
- size += strlen(escaped);
- mem_gc_free(interp, escaped);
+ {
+ const STRING *s = interp->code->const_table->str.constants[op[j]];
+ dest[size++] = '"';
+ if (s->strlen) {
+ char * const unescaped =
+ Parrot_str_to_cstring(interp, s);
+ char * const escaped =
+ PDB_escape(interp, unescaped, s->strlen);
+ if (escaped) {
+ strcpy(&dest[size], escaped);
+ size += strlen(escaped);
+ mem_gc_free(interp, escaped);
+ }
+ Parrot_str_free_cstring(unescaped);
}
- Parrot_str_free_cstring(unescaped);
+ dest[size++] = '"';
}
- dest[size++] = '"';
break;
case PARROT_ARG_PC:
Parrot_snprintf(interp, buf, sizeof (buf), "PMC_CONST(%d)", op[j]);
@@ -2382,7 +2383,7 @@
break;
case PARROT_ARG_KC:
{
- PMC * k = interp->code->const_table->constants[op[j]].u.key;
+ PMC * k = interp->code->const_table->pmc.constants[op[j]];
dest[size - 1] = '[';
while (k) {
switch (PObj_get_FLAGS(k)) {
@@ -2486,7 +2487,7 @@
if (specialop > 0) {
char buf[1000];
- PMC * const sig = interp->code->const_table->constants[op[1]].u.key;
+ PMC * const sig = interp->code->const_table->pmc.constants[op[1]];
const int n_values = VTABLE_elements(interp, sig);
/* The flag_names strings come from Call_bits_enum_t (with which it
should probably be colocated); they name the bits from LSB to MSB.
Modified: branches/typesafe_consttable/src/embed.c
==============================================================================
--- branches/typesafe_consttable/src/embed.c Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/embed.c Sun Sep 19 16:51:22 2010 (r49159)
@@ -730,7 +730,7 @@
for (i = 0; i < ft->fixup_count; ++i) {
if (ft->fixups[i].type == enum_fixup_sub) {
const opcode_t ci = ft->fixups[i].offset;
- PMC * const sub_pmc = ct->constants[ci].u.key;
+ PMC * const sub_pmc = ct->pmc.constants[ci];
Parrot_Sub_attributes *sub;
PMC_get_sub(interp, sub_pmc, sub);
@@ -807,7 +807,7 @@
main_sub = set_current_sub(interp);
Parrot_pcc_set_sub(interp, CURRENT_CONTEXT(interp), NULL);
- Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table->constants);
+ Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table);
Parrot_ext_call(interp, main_sub, "P->", userargv);
}
@@ -870,83 +870,65 @@
print_constant_table(PARROT_INTERP, ARGIN(PMC *output))
{
ASSERT_ARGS(print_constant_table)
- const INTVAL numconstants = interp->code->const_table->const_count;
+ const PackFile_ConstTable *ct = interp->code->const_table;
INTVAL i;
/* TODO: would be nice to print the name of the file as well */
Parrot_io_fprintf(interp, output, "=head1 Constant-table\n\n");
- for (i = 0; i < numconstants; ++i) {
- const PackFile_Constant * const c = &interp->code->const_table->constants[i];
+ for (i = 0; i < ct->num.const_count; i++)
+ Parrot_io_fprintf(interp, output, "NUM_CONST(%d): %f\n", i, ct->num.constants[i]);
- switch (c->type) {
- case PFC_NUMBER:
- Parrot_io_fprintf(interp, output, "PMC_CONST(%d): %f\n", i, c->u.number);
- break;
- case PFC_STRING:
- Parrot_io_fprintf(interp, output, "PMC_CONST(%d): %S\n", i, c->u.string);
- break;
- case PFC_KEY:
- Parrot_io_fprintf(interp, output, "PMC_CONST(%d): ", i);
- /* XXX */
- /* Parrot_print_p(interp, c->u.key); */
- Parrot_io_fprintf(interp, output, "(PMC constant)");
- Parrot_io_fprintf(interp, output, "\n");
- break;
- case PFC_PMC:
- {
- Parrot_io_fprintf(interp, output, "PMC_CONST(%d): ", i);
-
- switch (c->u.key->vtable->base_type) {
- /* each PBC file has a ParrotInterpreter, but it can't
- * stringify by itself */
- case enum_class_ParrotInterpreter:
- Parrot_io_fprintf(interp, output, "'ParrotInterpreter'");
- break;
+ for (i = 0; i < ct->str.const_count; i++)
+ Parrot_io_fprintf(interp, output, "STR_CONST(%d): %S\n", i, ct->str.constants[i]);
- /* FixedIntegerArrays used for signatures, handy to print */
- case enum_class_FixedIntegerArray:
- {
- const INTVAL n = VTABLE_elements(interp, c->u.key);
- INTVAL j;
- Parrot_io_fprintf(interp, output, "[");
-
- for (j = 0; j < n; ++j) {
- const INTVAL val = VTABLE_get_integer_keyed_int(interp, c->u.key, j);
- Parrot_io_fprintf(interp, output, "%d", val);
- if (j < n - 1)
- Parrot_io_fprintf(interp, output, ",");
- }
- Parrot_io_fprintf(interp, output, "]");
- break;
- }
- case enum_class_NameSpace:
- case enum_class_String:
- case enum_class_Key:
- case enum_class_ResizableStringArray:
- {
- /*Parrot_print_p(interp, c->u.key);*/
- STRING * const s = VTABLE_get_string(interp, c->u.key);
- if (s)
- Parrot_io_fprintf(interp, output, "%Ss", s);
- break;
+ for (i = 0; i < ct->pmc.const_count; i++) {
+ PMC *c = ct->pmc.constants[i];
+ Parrot_io_fprintf(interp, output, "PMC_CONST(%d): ", i);
+
+ switch (c->vtable->base_type) {
+ /* each PBC file has a ParrotInterpreter, but it can't
+ * stringify by itself */
+ case enum_class_ParrotInterpreter:
+ Parrot_io_fprintf(interp, output, "'ParrotInterpreter'");
+ break;
+
+ /* FixedIntegerArrays used for signatures, handy to print */
+ case enum_class_FixedIntegerArray:
+ {
+ const INTVAL n = VTABLE_elements(interp, c);
+ INTVAL j;
+ Parrot_io_fprintf(interp, output, "[");
+
+ for (j = 0; j < n; ++j) {
+ const INTVAL val = VTABLE_get_integer_keyed_int(interp, c, j);
+ Parrot_io_fprintf(interp, output, "%d", val);
+ if (j < n - 1)
+ Parrot_io_fprintf(interp, output, ",");
}
- case enum_class_Sub:
- Parrot_io_fprintf(interp, output, "%S", VTABLE_get_string(interp, c->u.key));
+ Parrot_io_fprintf(interp, output, "]");
break;
- default:
- Parrot_io_fprintf(interp, output, "(PMC constant)");
+ }
+ case enum_class_NameSpace:
+ case enum_class_String:
+ case enum_class_Key:
+ case enum_class_ResizableStringArray:
+ {
+ STRING * const s = VTABLE_get_string(interp, c);
+ if (s)
+ Parrot_io_fprintf(interp, output, "%Ss", s);
break;
}
-
- Parrot_io_fprintf(interp, output, "\n");
+ case enum_class_Sub:
+ Parrot_io_fprintf(interp, output, "%S", VTABLE_get_string(interp, c));
+ break;
+ default:
+ Parrot_io_fprintf(interp, output, "(PMC constant)");
break;
- }
- default:
- Parrot_io_fprintf(interp, output, "wrong constant type in constant table!\n");
- /* XXX throw an exception? Is it worth the trouble? */
- break;
}
+
+ Parrot_io_fprintf(interp, output, "\n");
+ break;
}
Parrot_io_fprintf(interp, output, "\n=cut\n\n");
@@ -1024,7 +1006,7 @@
const int filename_const_offset =
interp->code->debugs->mappings[curr_mapping].filename;
Parrot_io_fprintf(interp, output, "# Current Source Filename '%Ss'\n",
- interp->code->const_table->constants[filename_const_offset].u.string);
+ interp->code->const_table->str.constants[filename_const_offset]);
++curr_mapping;
}
}
@@ -1103,7 +1085,7 @@
run_native = func;
if (interp->code && interp->code->const_table)
- Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table->constants);
+ Parrot_pcc_set_constants(interp, interp->ctx, interp->code->const_table);
runops(interp, interp->resume_offset);
}
Modified: branches/typesafe_consttable/src/ops/core_ops.c
==============================================================================
--- branches/typesafe_consttable/src/ops/core_ops.c Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/ops/core_ops.c Sun Sep 19 16:51:22 2010 (r49159)
@@ -23,10 +23,10 @@
#define PREG(i) (CUR_CTX->bp_ps.regs_p[-1L - cur_opcode[i]])
#define SREG(i) (CUR_CTX->bp_ps.regs_s[cur_opcode[i]])
#define ICONST(i) cur_opcode[i]
-#define NCONST(i) Parrot_pcc_get_num_constants(interp, interp->ctx)[cur_opcode[i]].u.number
-#define SCONST(i) Parrot_pcc_get_str_constants(interp, interp->ctx)[cur_opcode[i]].u.string
+#define NCONST(i) Parrot_pcc_get_num_constants(interp, interp->ctx)[cur_opcode[i]]
+#define SCONST(i) Parrot_pcc_get_str_constants(interp, interp->ctx)[cur_opcode[i]]
#undef PCONST
-#define PCONST(i) Parrot_pcc_get_pmc_constants(interp, interp->ctx)[cur_opcode[i]].u.key
+#define PCONST(i) Parrot_pcc_get_pmc_constants(interp, interp->ctx)[cur_opcode[i]]
static int get_op(PARROT_INTERP, const char * name, int full);
Modified: branches/typesafe_consttable/src/packfile.c
==============================================================================
--- branches/typesafe_consttable/src/packfile.c Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/packfile.c Sun Sep 19 16:51:22 2010 (r49159)
@@ -298,6 +298,15 @@
ARGIN_NULLOK(const char *filename))
__attribute__nonnull__(1);
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+static PMC * PackFile_Constant_unpack_pmc(PARROT_INTERP,
+ ARGIN(PackFile_ConstTable *constt),
+ ARGIN(const opcode_t **cursor))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
static void PackFile_set_header(ARGOUT(PackFile_Header *header))
__attribute__nonnull__(1)
FUNC_MODIFIES(*header);
@@ -484,6 +493,10 @@
, PARROT_ASSERT_ARG(ct))
#define ASSERT_ARGS_PackFile_append_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_PackFile_Constant_unpack_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(constt) \
+ , PARROT_ASSERT_ARG(cursor))
#define ASSERT_ARGS_PackFile_set_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(header))
#define ASSERT_ARGS_pf_debug_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -736,7 +749,7 @@
PMC *retval = PMCNULL;
Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp),
- interp->code->const_table->constants);
+ interp->code->const_table);
Parrot_ext_call(interp, sub_pmc, "->P", &retval);
interp->run_core = old_core;
@@ -855,29 +868,13 @@
mark_1_seg(PARROT_INTERP, ARGMOD(PackFile_ConstTable *ct))
{
ASSERT_ARGS(mark_1_seg)
- PackFile_Constant * const constants = find_constants(interp, ct);
opcode_t i;
- for (i = 0; i < ct->const_count; ++i) {
- switch (constants[i].type) {
- case PFC_PMC:
- case PFC_KEY:
- {
- PMC * const pmc = constants[i].u.key;
- Parrot_gc_mark_PMC_alive(interp, pmc);
- break;
- }
- case PFC_STRING:
- {
- STRING * const string = constants[i].u.string;
- Parrot_gc_mark_STRING_alive(interp, string);
- break;
- }
- default:
- /* Do nothing. */
- break;
- }
- }
+ for (i = 0; i < ct->str.const_count; i++)
+ Parrot_gc_mark_STRING_alive(interp, ct->str.constants[i]);
+
+ for (i = 0; i < ct->pmc.const_count; i++)
+ Parrot_gc_mark_PMC_alive(interp, ct->pmc.constants[i]);
}
@@ -983,11 +980,11 @@
Parrot_Sub_attributes *sub;
const opcode_t ci = ft->fixups[i].offset;
- if (ci < 0 || ci >= ct->const_count)
+ if (ci < 0 || ci >= ct->pmc.const_count)
Parrot_ex_throw_from_c_args(interp, NULL, 1,
"Illegal fixup offset (%d) in enum_fixup_sub");
- sub_pmc = ct->constants[ci].u.key;
+ sub_pmc = ct->pmc.constants[ci];
PMC_get_sub(interp, sub_pmc, sub);
sub->eval_pmc = eval_pmc;
@@ -999,8 +996,8 @@
/* replace Sub PMC with computation results */
if (action == PBC_IMMEDIATE && !PMC_IS_NULL(result)) {
- ft->fixups[i].type = enum_fixup_none;
- ct->constants[ci].u.key = result;
+ ft->fixups[i].type = enum_fixup_none;
+ ct->pmc.constants[ci] = result;
}
}
@@ -3082,7 +3079,7 @@
Parrot_io_printf(interp, " OFFSET => %d,\n",
debug->mappings[i].offset);
Parrot_io_printf(interp, " FILENAME => %Ss\n",
- PF_CONST(debug->code, debug->mappings[i].filename).u.string);
+ PF_CONST(debug->code, str, debug->mappings[i].filename));
Parrot_io_printf(interp, " ],\n");
}
@@ -3167,9 +3164,9 @@
if (debug->num_mappings) {
prev_filename_n = debug->mappings[debug->num_mappings-1].filename;
filename_pstr = Parrot_str_new(interp, filename, 0);
- if (ct->constants[prev_filename_n].type == PFC_STRING &&
+ if (ct->str.constants[prev_filename_n] &&
Parrot_str_equal(interp, filename_pstr,
- ct->constants[prev_filename_n].u.string)) {
+ ct->str.constants[prev_filename_n])) {
return;
}
}
@@ -3203,15 +3200,14 @@
PackFile_DebugFilenameMapping *mapping = debug->mappings + insert_pos;
STRING *namestr = Parrot_str_new_init(interp, filename, strlen(filename),
Parrot_default_encoding_ptr, 0);
- size_t count = ct->const_count;
+ size_t count = ct->str.const_count;
size_t i;
mapping->offset = offset;
/* Check if there is already a constant with this filename */
for (i= 0; i < count; ++i) {
- if (ct->constants[i].type == PFC_STRING &&
- Parrot_str_equal(interp, namestr, ct->constants[i].u.string))
+ if (Parrot_str_equal(interp, namestr, ct->str.constants[i]))
break;
}
if (i < count) {
@@ -3220,14 +3216,11 @@
}
else {
/* Not found, create a new one */
- PackFile_Constant *fnconst;
- ct->const_count = ct->const_count + 1;
- ct->constants = mem_gc_realloc_n_typed_zeroed(interp, ct->constants,
- ct->const_count, ct->const_count - 1, PackFile_Constant);
-
- fnconst = &ct->constants[ct->const_count - 1];
- fnconst->type = PFC_STRING;
- fnconst->u.string = Parrot_str_new_init(interp, filename, strlen(filename),
+ ct->str.const_count++;
+ ct->str.constants = mem_gc_realloc_n_typed_zeroed(interp, ct->str.constants,
+ ct->str.const_count, ct->str.const_count - 1, STRING *);
+ ct->str.constants[ct->str.const_count - 1] =
+ Parrot_str_new_init(interp, filename, strlen(filename),
Parrot_default_encoding_ptr,
PObj_constant_FLAG);
}
@@ -3268,8 +3261,8 @@
if (i + 1 == debug->num_mappings
|| (debug->mappings[i].offset <= pc
&& debug->mappings[i + 1].offset > pc))
- return PF_CONST(debug->code,
- debug->mappings[i].filename).u.string;
+ return PF_CONST(debug->code, str,
+ debug->mappings[i].filename);
}
/* Otherwise, no mappings == no filename. */
@@ -3349,9 +3342,13 @@
}
interp->code = new_cs;
+
+#if 0
Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp), really
? find_constants(interp, new_cs->const_table)
- : new_cs->const_table->constants);
+ : new_cs->const_table);
+#endif
+ Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp), new_cs->const_table);
if (really)
prepare_for_run(interp);
@@ -3415,6 +3412,7 @@
*/
+#if 0
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
static PackFile_Constant *
@@ -3456,6 +3454,7 @@
return new_consts;
}
}
+#endif
/*
@@ -3476,6 +3475,9 @@
UINTVAL i;
Hash *hash;
+ return;
+
+#if 0
if (!interp->thread_data)
return;
@@ -3490,6 +3492,7 @@
PackFile_Constant * const consts = (PackFile_Constant *) _bucket->value;
mem_gc_free(interp, consts););
parrot_hash_destroy(interp, hash);
+#endif
}
@@ -3905,12 +3908,17 @@
ASSERT_ARGS(PackFile_ConstTable_clear)
opcode_t i;
- if (self->constants) {
- mem_gc_free(interp, self->constants);
- self->constants = NULL;
- }
-
- self->const_count = 0;
+#define EMPTY_CONSTS(type) do { \
+ if (self-> type .constants) { \
+ mem_gc_free(interp, self-> type .constants); \
+ self-> type .constants = NULL; \
+ } \
+ self-> type .const_count = 0; \
+} while (0)
+
+ EMPTY_CONSTS(num);
+ EMPTY_CONSTS(str);
+ EMPTY_CONSTS(pmc);
if (self->string_hash) {
parrot_hash_destroy(interp, self->string_hash);
@@ -3951,33 +3959,47 @@
PackFile_ConstTable_clear(interp, self);
- self->const_count = PF_fetch_opcode(pf, &cursor);
-
- TRACE_PRINTF(("PackFile_ConstTable_unpack: Unpacking %ld constants\n",
- self->const_count));
+ self->num.const_count = PF_fetch_opcode(pf, &cursor);
+ self->str.const_count = PF_fetch_opcode(pf, &cursor);
+ self->pmc.const_count = PF_fetch_opcode(pf, &cursor);
- if (self->const_count == 0)
- return cursor;
+ if (self->num.const_count) {
+ self->num.constants = mem_gc_allocate_n_zeroed_typed(interp,
+ self->num.const_count, FLOATVAL);
+ if (!self->num.constants)
+ goto err;
+ }
- self->constants = mem_gc_allocate_n_zeroed_typed(interp, self->const_count,
- PackFile_Constant);
+ if (self->str.const_count) {
+ self->str.constants = mem_gc_allocate_n_zeroed_typed(interp,
+ self->str.const_count, STRING *);
+ if (!self->str.constants)
+ goto err;
+ }
- if (!self->constants) {
- Parrot_io_eprintf(interp,
- "PackFile_ConstTable_unpack: Could not allocate memory for array!\n");
- self->const_count = 0;
- return NULL;
+ if (self->pmc.const_count) {
+ self->pmc.constants = mem_gc_allocate_n_zeroed_typed(interp,
+ self->pmc.const_count, PMC *);
+ if (!self->pmc.constants)
+ goto err;
}
- for (i = 0; i < self->const_count; ++i) {
- TRACE_PRINTF(("PackFile_ConstTable_unpack(): Unpacking constant %ld/%ld\n",
- i, self->const_count));
+ for (i = 0; i < self->num.const_count; i++)
+ self->num.constants[i] = PF_fetch_number(pf, &cursor);
- cursor = PackFile_Constant_unpack(interp, self, &self->constants[i],
- cursor);
- }
+ for (i = 0; i < self->str.const_count; i++)
+ self->str.constants[i] = PF_fetch_string(interp, pf, &cursor);
+
+ for (i = 0; i < self->pmc.const_count; i++)
+ self->pmc.constants[i] = PackFile_Constant_unpack_pmc(interp, self, &cursor);
return cursor;
+
+ err:
+ Parrot_io_eprintf(interp,
+ "PackFile_ConstTable_unpack: Could not allocate memory for array!\n");
+ PackFile_ConstTable_clear(interp, self);
+ return NULL;
}
@@ -4026,124 +4048,8 @@
/*
-=item C<size_t PackFile_Constant_pack_size(PARROT_INTERP, const
-PackFile_Constant *self, const PackFile_ConstTable *ct)>
-
-Determines the size of the buffer needed in order to pack the PackFile Constant
-into a contiguous region of memory.
-
-=cut
-
-*/
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-size_t
-PackFile_Constant_pack_size(PARROT_INTERP, ARGIN(const PackFile_Constant *self), ARGIN(const
- PackFile_ConstTable *ct))
-{
- ASSERT_ARGS(PackFile_Constant_pack_size)
- PMC *component;
- size_t packed_size;
-
- switch (self->type) {
- case PFC_NUMBER:
- packed_size = PF_size_number();
- break;
-
- case PFC_STRING:
- packed_size = PF_size_string(self->u.string);
- break;
-
- case PFC_KEY:
- packed_size = 1;
-
- for (component = self->u.key; component;){
- packed_size += 2;
- GETATTR_Key_next_key(interp, component, component);
- }
- break;
-
- case PFC_PMC:
- component = self->u.key; /* the pmc (Sub, ...) */
- packed_size = PF_size_strlen(Parrot_freeze_pbc_size(interp, component, ct)) - 1;
- break;
-
- default:
- Parrot_io_eprintf(NULL,
- "Constant_packed_size: Unrecognized type '%c'!\n",
- (char)self->type);
- return 0;
- }
-
- /* Tack on space for the initial type field */
- return packed_size + 1;
-}
-
-
-/*
-
-=item C<const opcode_t * PackFile_Constant_unpack(PARROT_INTERP,
-PackFile_ConstTable *constt, PackFile_Constant *self, const opcode_t *cursor)>
-
-Unpacks a PackFile Constant from a block of memory. The format is:
-
- opcode_t type
- * data
-
-Returns cursor if everything is okay, else NULL.
-
-=cut
-
-*/
-
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-const opcode_t *
-PackFile_Constant_unpack(PARROT_INTERP, ARGIN(PackFile_ConstTable *constt),
- ARGOUT(PackFile_Constant *self), ARGIN(const opcode_t *cursor))
-{
- ASSERT_ARGS(PackFile_Constant_unpack)
- PackFile * const pf = constt->base.pf;
- const opcode_t type = PF_fetch_opcode(pf, &cursor);
-
- TRACE_PRINTF(("PackFile_Constant_unpack(): Type is %ld ('%c')...\n",
- type, (char)type));
-
- switch (type) {
- case PFC_NUMBER:
- self->u.number = PF_fetch_number(pf, &cursor);
- self->type = PFC_NUMBER;
- break;
-
- case PFC_STRING:
- self->u.string = PF_fetch_string(interp, pf, &cursor);
- self->type = PFC_STRING;
- break;
-
- case PFC_KEY:
- cursor = PackFile_Constant_unpack_key(interp, constt, self, cursor);
- break;
-
- case PFC_PMC:
- cursor = PackFile_Constant_unpack_pmc(interp, constt, self, cursor);
- break;
- default:
- Parrot_io_eprintf(NULL,
- "Constant_unpack: Unrecognized type '%c' during unpack!\n",
- (char)type);
- return NULL;
- }
-
- return cursor;
-}
-
-
-/*
-
-=item C<const opcode_t * PackFile_Constant_unpack_pmc(PARROT_INTERP,
-PackFile_ConstTable *constt, PackFile_Constant *self, const opcode_t *cursor)>
+=item C<static PMC * PackFile_Constant_unpack_pmc(PARROT_INTERP,
+PackFile_ConstTable *constt, const opcode_t **cursor)>
Unpacks a constant PMC.
@@ -4151,114 +4057,95 @@
*/
-PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
-const opcode_t *
+static PMC *
PackFile_Constant_unpack_pmc(PARROT_INTERP, ARGIN(PackFile_ConstTable *constt),
- ARGMOD(PackFile_Constant *self), ARGIN(const opcode_t *cursor))
+ ARGIN(const opcode_t **cursor))
{
ASSERT_ARGS(PackFile_Constant_unpack_pmc)
- PackFile * const pf = constt->base.pf;
- STRING *_sub = CONST_STRING(interp, "Sub");
- PMC *pmc;
-
- /* thawing the PMC needs the real packfile in place */
- PackFile_ByteCode * const cs_save = interp->code;
- interp->code = pf->cur_cs;
- pmc = Parrot_thaw_pbc(interp, constt, &cursor);
-
- /* place item in const_table */
- self->type = PFC_PMC;
- self->u.key = pmc;
-
- /* finally place the sub into some namespace stash
- * XXX place this code in Sub.thaw ? */
- if (VTABLE_isa(interp, pmc, _sub))
- Parrot_ns_store_sub(interp, pmc);
-
- /* restore code */
- interp->code = cs_save;
-
- return cursor;
-}
-
-
-/*
+ PackFile * const pf = constt->base.pf;
+ STRING *_sub = CONST_STRING(interp, "Sub");
+ const opcode_t const_type = PF_fetch_opcode(pf, cursor);
-=item C<const opcode_t * PackFile_Constant_unpack_key(PARROT_INTERP,
-PackFile_ConstTable *constt, PackFile_Constant *self, const opcode_t *cursor)>
+ switch (const_type) {
+ case PFC_KEY:
+ {
+ PMC *head = NULL;
+ PMC *tail = NULL;
+ INTVAL components = (INTVAL)PF_fetch_opcode(pf, cursor);
+
+ while (components-- > 0) {
+ opcode_t type = PF_fetch_opcode(pf, cursor);
+ opcode_t op;
+
+ if (tail) {
+ SETATTR_Key_next_key(interp, tail, Parrot_pmc_new_constant(interp,
+ enum_class_Key));
+ GETATTR_Key_next_key(interp, tail, tail);
+ }
+ else
+ head = tail = Parrot_pmc_new_constant(interp, enum_class_Key);
-Unpacks a PackFile Constant from a block of memory. The format consists of a
-sequence of key atoms, each with the following format:
+ op = PF_fetch_opcode(pf, cursor);
- opcode_t type
- opcode_t value
+ switch (type) {
+ case PARROT_ARG_IC:
+ key_set_integer(interp, tail, op);
+ break;
+ case PARROT_ARG_NC:
+ key_set_number(interp, tail, constt->num.constants[op]);
+ break;
+ case PARROT_ARG_SC:
+ key_set_string(interp, tail, constt->str.constants[op]);
+ break;
+ case PARROT_ARG_I:
+ key_set_register(interp, tail, op, KEY_integer_FLAG);
+ break;
+ case PARROT_ARG_N:
+ key_set_register(interp, tail, op, KEY_number_FLAG);
+ break;
+ case PARROT_ARG_S:
+ key_set_register(interp, tail, op, KEY_string_FLAG);
+ break;
+ case PARROT_ARG_P:
+ key_set_register(interp, tail, op, KEY_pmc_FLAG);
+ break;
+ default:
+ *cursor = NULL;
+ return PMCNULL;
+ }
+ }
-Returns cursor if everything is OK, else NULL.
+ return head;
+ }
-=cut
+ case PFC_PMC:
+ {
+ PMC *pmc;
+ /* thawing the PMC needs the real packfile in place */
+ PackFile_ByteCode * const cs_save = interp->code;
+ interp->code = pf->cur_cs;
+ pmc = Parrot_thaw_pbc(interp, constt, cursor);
+
+ /* finally place the sub into some namespace stash
+ * XXX place this code in Sub.thaw ? */
+ if (VTABLE_isa(interp, pmc, _sub))
+ Parrot_ns_store_sub(interp, pmc);
-*/
+ /* restore code */
+ interp->code = cs_save;
-PARROT_EXPORT
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-const opcode_t *
-PackFile_Constant_unpack_key(PARROT_INTERP, ARGIN(PackFile_ConstTable *constt),
- ARGMOD(PackFile_Constant *self), ARGIN(const opcode_t *cursor))
-{
- ASSERT_ARGS(PackFile_Constant_unpack_key)
- PackFile * const pf = constt->base.pf;
- PMC *head = NULL;
- PMC *tail = NULL;
- INTVAL components = (INTVAL)PF_fetch_opcode(pf, &cursor);
- int pmc_enum = enum_class_Key;
-
- while (components-- > 0) {
- opcode_t type = PF_fetch_opcode(pf, &cursor);
- opcode_t op;
-
- if (tail) {
- SETATTR_Key_next_key(interp, tail, Parrot_pmc_new_constant(interp, pmc_enum));
- GETATTR_Key_next_key(interp, tail, tail);
+ return pmc;
}
- else
- head = tail = Parrot_pmc_new_constant(interp, pmc_enum);
-
- op = PF_fetch_opcode(pf, &cursor);
- switch (type) {
- case PARROT_ARG_IC:
- key_set_integer(interp, tail, op);
- break;
- case PARROT_ARG_NC:
- key_set_number(interp, tail, constt->constants[op].u.number);
- break;
- case PARROT_ARG_SC:
- key_set_string(interp, tail, constt->constants[op].u.string);
- break;
- case PARROT_ARG_I:
- key_set_register(interp, tail, op, KEY_integer_FLAG);
- break;
- case PARROT_ARG_N:
- key_set_register(interp, tail, op, KEY_number_FLAG);
- break;
- case PARROT_ARG_S:
- key_set_register(interp, tail, op, KEY_string_FLAG);
- break;
- case PARROT_ARG_P:
- key_set_register(interp, tail, op, KEY_pmc_FLAG);
- break;
- default:
- return NULL;
- }
+ default:
+ Parrot_io_eprintf(NULL,
+ "Constant_unpack: Unrecognized type '%c' during unpack!\n",
+ (char)const_type);
+ *cursor = NULL;
+ return PMCNULL;
}
-
- self->type = PFC_KEY;
- self->u.key = head;
-
- return cursor;
}
@@ -4516,7 +4403,7 @@
const PackFile_Annotations_Key * const key = self->keys + i;
Parrot_io_printf(interp, " #%d\n [\n", i);
Parrot_io_printf(interp, " NAME => %Ss\n",
- PF_CONST(self->code, key->name).u.string);
+ PF_CONST(self->code, str, key->name));
Parrot_io_printf(interp, " TYPE => %s\n",
key->type == PF_ANNOTATION_KEY_TYPE_INT ? "integer" :
key->type == PF_ANNOTATION_KEY_TYPE_STR ? "string" :
@@ -4621,12 +4508,12 @@
{
ASSERT_ARGS(PackFile_Annotations_add_entry)
/* See if we already have this key. */
- STRING * const key_name = PF_CONST(self->code, key).u.string;
+ STRING * const key_name = PF_CONST(self->code, str, key);
opcode_t key_id = -1;
INTVAL i;
for (i = 0; i < self->num_keys; ++i) {
- STRING * const test_key = PF_CONST(self->code, self->keys[i].name).u.string;
+ STRING * const test_key = PF_CONST(self->code, str, self->keys[i].name);
if (Parrot_str_equal(interp, test_key, key_name)) {
key_id = i;
break;
@@ -4701,12 +4588,12 @@
case PF_ANNOTATION_KEY_TYPE_NUM:
result = Parrot_pmc_new(interp, enum_class_Float);
VTABLE_set_number_native(interp, result,
- PF_CONST(self->code, value).u.number);
+ PF_CONST(self->code, num, value));
break;
default:
result = Parrot_pmc_new(interp, enum_class_String);
VTABLE_set_string_native(interp, result,
- PF_CONST(self->code, value).u.string);
+ PF_CONST(self->code, str, value));
}
return result;
@@ -4743,7 +4630,7 @@
if (!STRING_IS_NULL(key)) {
for (i = 0; i < self->num_keys; ++i) {
- STRING * const test_key = PF_CONST(self->code, self->keys[i].name).u.string;
+ STRING * const test_key = PF_CONST(self->code, str, self->keys[i].name);
if (Parrot_str_equal(interp, test_key, key)) {
key_id = i;
break;
@@ -4782,7 +4669,7 @@
for (i = 0; i < self->num_keys; ++i) {
if (have_values[i]) {
- STRING * const key_name = PF_CONST(self->code, self->keys[i].name).u.string;
+ STRING * const key_name = PF_CONST(self->code, str, self->keys[i].name);
VTABLE_set_pmc_keyed_str(interp, result, key_name,
make_annotation_value_pmc(interp, self, self->keys[i].type,
latest_values[i]));
Modified: branches/typesafe_consttable/src/packout.c
==============================================================================
--- branches/typesafe_consttable/src/packout.c Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/packout.c Sun Sep 19 16:51:22 2010 (r49159)
@@ -25,6 +25,28 @@
#include "pmc/pmc_key.h"
/* HEADERIZER HFILE: include/parrot/packfile.h */
+/* HEADERIZER BEGIN: static */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+static opcode_t * PackFile_Constant_pack_key(PARROT_INTERP,
+ ARGIN(PMC *self),
+ ARGIN(const PackFile_ConstTable *const_table),
+ ARGOUT(opcode_t *cursor))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ __attribute__nonnull__(4)
+ FUNC_MODIFIES(*cursor);
+
+#define ASSERT_ARGS_PackFile_Constant_pack_key __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(const_table) \
+ , PARROT_ASSERT_ARG(cursor))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+/* HEADERIZER END: static */
/*
@@ -160,16 +182,25 @@
ASSERT_ARGS(PackFile_ConstTable_pack_size)
opcode_t i;
PackFile_ConstTable* const self = (PackFile_ConstTable *) seg;
- const opcode_t n_constants = self->const_count;
- size_t size = 1; /* const_count */
+ size_t size = 3; /* const_counts */
- for (i = 0; i < n_constants; ++i) {
- /* only constants up to the current one will be valid on unpack */
- self->const_count = i;
- size += PackFile_Constant_pack_size(interp, &self->constants[i], self);
- }
+ size += self->num.const_count * PF_size_number();
- self->const_count = i;
+ for (i = 0; i < self->str.const_count; i++)
+ size += PF_size_string(self->str.constants[i]);
+
+ for (i = 0; i < self->pmc.const_count; i++) {
+ PMC *c = self->pmc.constants[i];
+ if (c->vtable->base_type == enum_class_Key) {
+ while (c) {
+ size += 2;
+ GETATTR_Key_next_key(interp, c, c);
+ }
+ }
+ else {
+ size += PF_size_strlen(Parrot_freeze_pbc_size(interp, c, self)) - 1;
+ }
+ }
return size;
}
@@ -200,19 +231,30 @@
{
ASSERT_ARGS(PackFile_ConstTable_pack)
PackFile_ConstTable * const self = (PackFile_ConstTable *)seg;
- const opcode_t n_constants = self->const_count;
opcode_t i;
- *cursor++ = self->const_count;
-
- for (i = 0; i < n_constants; ++i) {
- /* only constants up to the current one will be valid on unpack */
- self->const_count = i;
- cursor = PackFile_Constant_pack(interp, self, &self->constants[i], cursor);
+ *cursor++ = self->num.const_count;
+ *cursor++ = self->str.const_count;
+ *cursor++ = self->pmc.const_count;
+
+ for (i = 0; i < self->num.const_count; i++)
+ cursor = PF_store_number(cursor, &self->num.constants[i]);
+
+ for (i = 0; i < self->str.const_count; i++)
+ cursor = PF_store_string(cursor, self->str.constants[i]);
+
+ for (i = 0; i < self->pmc.const_count; i++) {
+ PMC *c = self->pmc.constants[i];
+ if (c->vtable->base_type == enum_class_Key) {
+ *cursor++ = PFC_KEY;
+ cursor = PackFile_Constant_pack_key(interp, c, self, cursor);
+ }
+ else {
+ *cursor++ = PFC_PMC;
+ cursor = Parrot_freeze_pbc(interp, c, self, cursor);
+ }
}
- self->const_count = n_constants;
-
return cursor;
}
@@ -278,35 +320,32 @@
key_str);
if (bucket) {
i = (int)PTR2INTVAL(bucket->value);
- if (i < ct->const_count) /* only consider constants that have already occured */
- return i;
+ return i;
}
return -1;
}
- for (i = 0; i < ct->const_count; ++i) {
- PackFile_Constant *constant = &ct->constants[i];
-
- switch (type) {
- case PFC_STRING:
- if (constant->type == PFC_STRING) {
- STRING * const sc = constant->u.string;
- if (Parrot_str_equal(interp, key_str, sc)
- && key_str->encoding == sc->encoding) {
- return i;
- }
+ switch (type) {
+ case PFC_STRING:
+ for (i = 0; i < ct->str.const_count; i++) {
+ STRING *sc = ct->str.constants[i];
+ if (Parrot_str_equal(interp, key_str, sc)
+ && key_str->encoding == sc->encoding) {
+ return i;
}
- break;
-
- case PFC_NUMBER:
- if (constant->type == PFC_NUMBER)
- if (constant->u.number == key_num)
- return i;
- break;
+ }
+ break;
- default:
- PANIC(interp, "Universe imploded. Did you divide by zero?");
+ case PFC_NUMBER:
+ for (i = 0; i < ct->num.const_count; i++) {
+ if (ct->num.constants[i] == key_num)
+ return i;
}
+ break;
+
+
+ default:
+ PANIC(interp, "Universe imploded. Did you divide by zero?");
}
/* not found */
@@ -334,92 +373,68 @@
*/
-PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
-opcode_t *
-PackFile_Constant_pack(PARROT_INTERP,
+static opcode_t *
+PackFile_Constant_pack_key(PARROT_INTERP,
+ ARGIN(PMC *self),
ARGIN(const PackFile_ConstTable *const_table),
- ARGIN(const PackFile_Constant *self), ARGOUT(opcode_t *cursor))
+ ARGOUT(opcode_t *cursor))
{
- ASSERT_ARGS(PackFile_Constant_pack)
- PMC *key;
+ ASSERT_ARGS(PackFile_Constant_pack_key)
size_t i;
+ PMC *key;
- *cursor++ = self->type;
-
- switch (self->type) {
-
- case PFC_NUMBER:
- cursor = PF_store_number(cursor, &self->u.number);
- break;
-
- case PFC_STRING:
- cursor = PF_store_string(cursor, self->u.string);
- break;
-
- case PFC_PMC:
- cursor = Parrot_freeze_pbc(interp, self->u.key, const_table, cursor);
- break;
+ for (i = 0, key = self; key; ++i){
+ GETATTR_Key_next_key(interp, key, key);
+ }
- case PFC_KEY:
- for (i = 0, key = self->u.key; key; ++i){
- GETATTR_Key_next_key(interp, key, key);
- }
+ /* number of key components */
+ *cursor++ = i;
+ /* and now type / value per component */
+ for (key = self; key;) {
+ const opcode_t type = PObj_get_FLAGS(key);
+
+ switch (type & KEY_type_FLAGS) {
+ case KEY_integer_FLAG:
+ *cursor++ = PARROT_ARG_IC;
+ GETATTR_Key_int_key(interp, key, *cursor++);
+ break;
+ case KEY_number_FLAG:
+ *cursor++ = PARROT_ARG_NC;
+ /* Argh */
+ *cursor++ = PackFile_find_in_const(interp, const_table, key, PFC_NUMBER);
+ break;
+ case KEY_string_FLAG:
+ *cursor++ = PARROT_ARG_SC;
+ /* Argh */
+ *cursor++ = PackFile_find_in_const(interp, const_table, key, PFC_STRING);
+ break;
- /* number of key components */
- *cursor++ = i;
- /* and now type / value per component */
- for (key = self->u.key; key;) {
- const opcode_t type = PObj_get_FLAGS(key);
-
- switch (type & KEY_type_FLAGS) {
- case KEY_integer_FLAG:
- *cursor++ = PARROT_ARG_IC;
- GETATTR_Key_int_key(interp, key, *cursor++);
- break;
- case KEY_number_FLAG:
- *cursor++ = PARROT_ARG_NC;
- /* Argh */
- *cursor++ = PackFile_find_in_const(interp, const_table, key, PFC_NUMBER);
- break;
- case KEY_string_FLAG:
- *cursor++ = PARROT_ARG_SC;
- /* Argh */
- *cursor++ = PackFile_find_in_const(interp, const_table, key, PFC_STRING);
- break;
-
- case KEY_integer_FLAG | KEY_register_FLAG:
- *cursor++ = PARROT_ARG_I;
- GETATTR_Key_int_key(interp, key, *cursor++);
- break;
- case KEY_number_FLAG | KEY_register_FLAG:
- *cursor++ = PARROT_ARG_N;
- GETATTR_Key_int_key(interp, key, *cursor++);
- break;
- case KEY_string_FLAG | KEY_register_FLAG:
- *cursor++ = PARROT_ARG_S;
- GETATTR_Key_int_key(interp, key, *cursor++);
- break;
- case KEY_pmc_FLAG | KEY_register_FLAG:
- *cursor++ = PARROT_ARG_P;
- GETATTR_Key_int_key(interp, key, *cursor++);
- break;
- default:
- Parrot_io_eprintf(NULL, "PackFile_Constant_pack: "
- "unsupported constant type\n");
- Parrot_exit(interp, 1);
- }
- GETATTR_Key_next_key(interp, key, key);
+ case KEY_integer_FLAG | KEY_register_FLAG:
+ *cursor++ = PARROT_ARG_I;
+ GETATTR_Key_int_key(interp, key, *cursor++);
+ break;
+ case KEY_number_FLAG | KEY_register_FLAG:
+ *cursor++ = PARROT_ARG_N;
+ GETATTR_Key_int_key(interp, key, *cursor++);
+ break;
+ case KEY_string_FLAG | KEY_register_FLAG:
+ *cursor++ = PARROT_ARG_S;
+ GETATTR_Key_int_key(interp, key, *cursor++);
+ break;
+ case KEY_pmc_FLAG | KEY_register_FLAG:
+ *cursor++ = PARROT_ARG_P;
+ GETATTR_Key_int_key(interp, key, *cursor++);
+ break;
+ default:
+ Parrot_io_eprintf(NULL, "PackFile_Constant_pack: "
+ "unsupported constant type\n");
+ Parrot_exit(interp, 1);
}
-
- break;
-
- default:
- Parrot_io_eprintf(NULL, "PackFile_Constant_pack: unsupported constant\n");
- Parrot_exit(interp, 1);
- break;
+ GETATTR_Key_next_key(interp, key, key);
}
+
return cursor;
}
Modified: branches/typesafe_consttable/src/pmc/callcontext.pmc
==============================================================================
--- branches/typesafe_consttable/src/pmc/callcontext.pmc Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/pmc/callcontext.pmc Sun Sep 19 16:51:22 2010 (r49159)
@@ -526,8 +526,10 @@
ATTR opcode_t *current_pc; /* program counter of Sub invocation */
ATTR PMC *current_sig; /* temporary CallContext PMC for active call */
- /* deref the constants - we need it all the time */
- ATTR struct PackFile_Constant *constants;
+ /* deref the constants - we need them all the time */
+ ATTR FLOATVAL *num_constants;
+ ATTR STRING **str_constants;
+ ATTR PMC **pmc_constants;
ATTR INTVAL current_HLL; /* see also src/hll.c */
Modified: branches/typesafe_consttable/src/pmc/eval.pmc
==============================================================================
--- branches/typesafe_consttable/src/pmc/eval.pmc Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/pmc/eval.pmc Sun Sep 19 16:51:22 2010 (r49159)
@@ -78,10 +78,8 @@
PackFile_FixupEntry * const e = ft->fixups + i;
if (e->type == enum_fixup_sub) {
- opcode_t ci = e->offset;
-
- ct->constants[ci].u.key = NULL;
- e->type = 0;
+ opcode_t ci = e->offset;
+ ct->pmc.constants[ci] = NULL;
}
}
}
@@ -123,7 +121,7 @@
opcode_t ci = e->offset;
if (n++ == idx)
- return ct->constants[ci].u.key;
+ return ct->pmc.constants[ci];
}
}
}
@@ -163,7 +161,7 @@
if (e->type == enum_fixup_sub) {
opcode_t ci = e->offset;
- PMC *sub = ct->constants[ci].u.key;
+ PMC *sub = ct->pmc.constants[ci];
Parrot_gc_mark_PMC_alive(interp, sub);
}
Modified: branches/typesafe_consttable/src/pmc/imageiothaw.pmc
==============================================================================
--- branches/typesafe_consttable/src/pmc/imageiothaw.pmc Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/pmc/imageiothaw.pmc Sun Sep 19 16:51:22 2010 (r49159)
@@ -261,12 +261,7 @@
if (i >= 0) {
PackFile_ConstTable *table = PARROT_IMAGEIOTHAW(SELF)->pf_ct;
-
- if (!table->constants[i].type)
- Parrot_ex_throw_from_c_args(interp, NULL,
- EXCEPTION_MALFORMED_PACKFILE,
- "Reference to constant not yet unpacked %d", i);
- return table->constants[i].u.string;
+ return table->str.constants[i];
}
/* XXX
Modified: branches/typesafe_consttable/src/pmc/packfileconstanttable.pmc
==============================================================================
--- branches/typesafe_consttable/src/pmc/packfileconstanttable.pmc Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/pmc/packfileconstanttable.pmc Sun Sep 19 16:51:22 2010 (r49159)
@@ -95,6 +95,8 @@
opcode_t i;
/* Preallocate required amount of memory */
+#if 0
+ /* XXX TODO */
VTABLE_set_integer_native(INTERP, attrs->constants, table->const_count);
VTABLE_set_integer_native(INTERP, attrs->types, table->const_count);
@@ -120,6 +122,7 @@
"Unknown PackFile constant type: %d", val->type);
}
}
+#endif
}
/*
@@ -138,6 +141,8 @@
pftable->base.type = PF_CONST_SEG;
/* Copy all constanst with respect of type */
+#if 0
+ /* XXX TODO */
pftable->const_count = VTABLE_get_integer(INTERP, attrs->constants);
pftable->constants = mem_gc_allocate_n_typed(INTERP,
pftable->const_count, PackFile_Constant);
@@ -167,6 +172,7 @@
"Unknown PackFile constant type: %d", value->type);
}
}
+#endif
return pftable;
}
Modified: branches/typesafe_consttable/src/pmc/sub.pmc
==============================================================================
--- branches/typesafe_consttable/src/pmc/sub.pmc Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/pmc/sub.pmc Sun Sep 19 16:51:22 2010 (r49159)
@@ -435,7 +435,7 @@
Parrot_pcc_set_sub(INTERP, context, SELF);
Parrot_pcc_set_continuation(INTERP, context, ccont);
- Parrot_pcc_set_constants(INTERP, context, sub->seg->const_table->constants);
+ Parrot_pcc_set_constants(INTERP, context, sub->seg->const_table);
/* check recursion/call depth */
if (Parrot_pcc_inc_recursion_depth(INTERP, context) > INTERP->recursion_limit)
@@ -873,7 +873,7 @@
/* If the first instruction is a get_params... */
if (OPCODE_IS(INTERP, sub->seg, *pc, core_ops, PARROT_OP_get_params_pc)) {
/* Get the signature (the next thing in the bytecode). */
- PMC * const sig = PF_CONST(sub->seg, *(++pc)).u.key;
+ PMC * const sig = PF_CONST(sub->seg, pmc, *(++pc));
/* Iterate over the signature and compute argument counts. */
const INTVAL sig_length = VTABLE_elements(INTERP, sig);
Modified: branches/typesafe_consttable/src/runcore/trace.c
==============================================================================
--- branches/typesafe_consttable/src/runcore/trace.c Sun Sep 19 09:04:51 2010 (r49158)
+++ branches/typesafe_consttable/src/runcore/trace.c Sun Sep 19 16:51:22 2010 (r49159)
@@ -313,7 +313,7 @@
|| *pc == PARROT_OP_get_results_pc
|| *pc == PARROT_OP_get_params_pc
|| *pc == PARROT_OP_set_returns_pc) {
- sig = interp->code->const_table->constants[pc[1]].u.key;
+ sig = interp->code->const_table->pmc.constants[pc[1]];
if (!sig)
Parrot_ex_throw_from_c_args(interp, NULL, 1,
More information about the parrot-commits
mailing list