Skip to content

Commit

Permalink
merge branch pmc_freeze_cleanup
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/trunk@43434 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
plobsing committed Jan 13, 2010
1 parent a27c6a0 commit 1137b41
Show file tree
Hide file tree
Showing 37 changed files with 778 additions and 1,141 deletions.
1 change: 1 addition & 0 deletions PBC_COMPAT
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# please insert tab separated entries at the top of the list

5.6 2009.12.12 bacek merge CallSignature and Context
5.5 2010.01.01 plobsing change prophash handling
5.4 2009.12.02 bacek remove CallSignatureReturns
5.3 2009.10.23 bacek add CallSignatureReturns
5.2 2009.09.16 darbelo remove pic.ops
Expand Down
4 changes: 4 additions & 0 deletions compilers/pirc/src/bcgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ opcode_t /*@alt void@*/
emit_opcode(ARGIN(bytecode * const bc), opcode_t op)
__attribute__nonnull__(1);

int emit_pbc_key(ARGIN(bytecode * const bc), ARGIN(key * const k))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

FLOATVAL get_num_const(ARGIN(bytecode * const bc), unsigned index)
__attribute__nonnull__(1);

Expand Down
6 changes: 3 additions & 3 deletions include/parrot/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,11 @@ void Parrot_pmc_array_unshift(PARROT_INTERP,
PARROT_EXPORT
void Parrot_pmc_array_visit(PARROT_INTERP,
ARGIN(List *list),
ARGMOD(void *pinfo))
ARGMOD(visit_info *info))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*pinfo);
FUNC_MODIFIES(*info);

PARROT_WARN_UNUSED_RESULT
PARROT_PURE_FUNCTION
Expand Down Expand Up @@ -284,7 +284,7 @@ INTVAL Parrot_pmc_array_length(SHIM_INTERP, ARGIN(const List *list))
#define ASSERT_ARGS_Parrot_pmc_array_visit __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(list) \
, PARROT_ASSERT_ARG(pinfo))
, PARROT_ASSERT_ARG(info))
#define ASSERT_ARGS_Parrot_pmc_array_length __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(list))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
Expand Down
1 change: 1 addition & 0 deletions include/parrot/packfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
# define PFOPT_ALIGN 8
# define PFOPT_VALUE 16
#endif
#define PFOPT_PMC_FREEZE_ONLY 32

#if TRACE_PACKFILE
/* Here we pass multipe args to a macro so the args may not be bracketed here! */
Expand Down
2 changes: 1 addition & 1 deletion include/parrot/parrot.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ typedef struct PackFile_ByteCode PackFile_ByteCode;
#include "parrot/string.h"
#include "parrot/string_primitives.h"
#include "parrot/hash.h"
#include "parrot/list.h"
#include "parrot/pmc_freeze.h"
#include "parrot/list.h"
#include "parrot/vtable.h"
#include "parrot/context.h"
#include "parrot/exceptions.h"
Expand Down
132 changes: 100 additions & 32 deletions include/parrot/pmc_freeze.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,137 @@
*/

#ifndef PARROT_PMC_FREEZE_H_GUARD
#define PARROT_PMC_FREEZE_H_GUARD
#define PARROT_PMC_FREEZE_H_GUARD

struct _visit_info;
typedef void (*visit_f)(PARROT_INTERP, ARGIN_NULLOK(PMC*), ARGIN(struct _visit_info*));

typedef enum {
VISIT_FREEZE_NORMAL,
VISIT_FREEZE_AT_DESTRUCT,
VISIT_FREEZE_SIZE,
VISIT_THAW_NORMAL,
VISIT_THAW_CONSTANTS,
VISIT_CLONE,
VISIT_DESTRUCTION_ORDER
} visit_enum_type;

struct _image_io;
#define IMAGE_IO struct _image_io
typedef void (*push_integer_f) (PARROT_INTERP, IMAGE_IO*, INTVAL);
typedef void (*push_string_f) (PARROT_INTERP, IMAGE_IO*, STRING*);
typedef void (*push_number_f) (PARROT_INTERP, IMAGE_IO*, FLOATVAL);
typedef INTVAL (*shift_integer_f) (PARROT_INTERP, IMAGE_IO*);
typedef STRING* (*shift_string_f) (PARROT_INTERP, IMAGE_IO*);
typedef FLOATVAL (*shift_number_f) (PARROT_INTERP, IMAGE_IO*);
VISIT_HOW_PMC_TO_VISITOR = 0x00, /* push to visitor */
VISIT_HOW_VISITOR_TO_PMC = 0x01, /* shift from visitor */
VISIT_HOW_PMC_TO_PMC = 0x02, /* push to visitor; then shift from visitor */
VISIT_HOW_VISITOR_TO_VISITOR = 0x03, /* shift from visitor; then push to visitor */
} visit_how_enum_t;

#define VISIT_HOW_MASK 0x03

typedef enum {
VISIT_WHAT_PMC = 0x04,
VISIT_WHAT_STRING = 0x08,
VISIT_WHAT_FLOATVAL = 0x10,
VISIT_WHAT_INTVAL = 0x20,
} visit_what_enum_t;

#define VISIT_WHAT_MASK 0x3c

/* backwards-compat defns */
#define visit_enum_type INTVAL
#define VISIT_FREEZE_NORMAL (VISIT_HOW_PMC_TO_VISITOR | VISIT_WHAT_PMC)
#define VISIT_THAW_NORMAL (VISIT_HOW_VISITOR_TO_PMC | VISIT_WHAT_PMC)
#define VISIT_THAW_CONSTANTS VISIT_THAW_NORMAL

struct _visit_info;
typedef INTVAL (*get_integer_f) (PARROT_INTERP, struct _visit_info*);
typedef void (*push_integer_f) (PARROT_INTERP, struct _visit_info*, INTVAL);
typedef void (*push_string_f) (PARROT_INTERP, struct _visit_info*, STRING*);
typedef void (*push_number_f) (PARROT_INTERP, struct _visit_info*, FLOATVAL);
typedef void (*push_pmc_f) (PARROT_INTERP, struct _visit_info*, PMC*);
typedef INTVAL (*shift_integer_f) (PARROT_INTERP, struct _visit_info*);
typedef STRING* (*shift_string_f) (PARROT_INTERP, struct _visit_info*);
typedef FLOATVAL (*shift_number_f) (PARROT_INTERP, struct _visit_info*);
typedef PMC* (*shift_pmc_f) (PARROT_INTERP, struct _visit_info*);

typedef struct _image_funcs {
get_integer_f get_integer;
push_integer_f push_integer;
push_string_f push_string;
push_number_f push_float;
push_pmc_f push_pmc;
shift_integer_f shift_integer;
shift_string_f shift_string;
shift_number_f shift_float;
shift_pmc_f shift_pmc;
} image_funcs;

typedef struct _image_io {
STRING *image;
struct PackFile *pf;
const image_funcs *vtable;
} image_io;

typedef enum {
EXTRA_IS_NULL,
EXTRA_IS_UNUSED,
EXTRA_IS_PROP_HASH,
EXTRA_CLASS_EXISTS
} extra_flags_enum;

typedef struct _visit_info {
visit_f visit_pmc_now;
visit_f visit_action; /* freeze, thaw ... */
size_t pos; /* current read/write position in buffer */
Buffer *buffer;
size_t input_length; /* */
INTVAL what;
STRING *image;
PMC **thaw_ptr; /* where to thaw a new PMC */
INTVAL last_type;
PMC *seen; /* seen hash */
PMC *todo; /* todo list */
PMC *id_list; /* seen list used by thaw */
UINTVAL id; /* freze ID of PMC */
void *extra; /* PMC specific */
INTVAL extra_flags; /* concerning to extra */
PMC *thaw_result; /* 1st thawed */
IMAGE_IO *image_io;
struct PackFile *pf;
const image_funcs *vtable;
struct _visit_info *image_io; /* dummy backwards-compat pointer. */
} visit_info;

#define IMAGE_IO visit_info

#define VISIT_PMC(interp, visit, pmc) do {\
const INTVAL _visit_pmc_flags = VTABLE_get_integer((interp), (visit)); \
if (_visit_pmc_flags & VISIT_WHAT_PMC) { \
switch (_visit_pmc_flags & VISIT_HOW_MASK) { \
case VISIT_HOW_PMC_TO_VISITOR: \
VTABLE_push_pmc((interp), (visit), (pmc)); \
break; \
case VISIT_HOW_VISITOR_TO_PMC: \
(pmc) = VTABLE_shift_pmc((interp), (visit)); \
break; \
case VISIT_HOW_PMC_TO_PMC: \
VTABLE_push_pmc((interp), (visit), (pmc)); \
(pmc) = VTABLE_shift_pmc((interp), (visit)); \
break; \
case VISIT_HOW_VISITOR_TO_VISITOR: \
(pmc) = VTABLE_shift_pmc((interp), (visit)); \
VTABLE_push_pmc((interp), (visit), (pmc)); \
break; \
default: \
do_panic((interp), "Bad VISIT_HOW in VISIT_PMC", __FILE__, __LINE__); \
} \
} \
} while (0)

#define VISIT_PMC_ATTR(interp, visit, self, pmclass, attr_name) do {\
const INTVAL _visit_pmc_attr_flags = VTABLE_get_integer((interp), (visit)); \
if (_visit_pmc_attr_flags & VISIT_WHAT_PMC) { \
PMC *_visit_pmc_attr; \
switch (_visit_pmc_attr_flags & VISIT_HOW_MASK) { \
case VISIT_HOW_PMC_TO_VISITOR: \
GETATTR_ ## pmclass ## _ ## attr_name((interp), (self), _visit_pmc_attr); \
VTABLE_push_pmc((interp), (visit), _visit_pmc_attr); \
break; \
case VISIT_HOW_VISITOR_TO_PMC: \
_visit_pmc_attr = VTABLE_shift_pmc((interp), (visit)); \
SETATTR_ ## pmclass ## _ ## attr_name((interp), (self), _visit_pmc_attr); \
break; \
case VISIT_HOW_PMC_TO_PMC: \
GETATTR_ ## pmclass ## _ ## attr_name((interp), (self), _visit_pmc_attr); \
VTABLE_push_pmc((interp), (visit), _visit_pmc_attr); \
_visit_pmc_attr = VTABLE_shift_pmc((interp), (visit)); \
SETATTR_ ## pmclass ## _ ## attr_name((interp), (self), _visit_pmc_attr); \
break; \
case VISIT_HOW_VISITOR_TO_VISITOR: \
_visit_pmc_attr = VTABLE_shift_pmc((interp), (visit)); \
SETATTR_ ## pmclass ## _ ## attr_name((interp), (self), _visit_pmc_attr); \
GETATTR_ ## pmclass ## _ ## attr_name((interp), (self), _visit_pmc_attr); \
VTABLE_push_pmc((interp), (visit), _visit_pmc_attr); \
break; \
default: \
do_panic((interp), "Bad VISIT_HOW in VISIT_PMC_ATTR", __FILE__, __LINE__); \
} \
} \
} while (0)

/*
* public interfaces
*/
Expand Down
14 changes: 14 additions & 0 deletions include/parrot/string_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,17 @@ STRING * Parrot_str_new_COW(PARROT_INTERP, ARGMOD(STRING *s))
__attribute__nonnull__(2)
FUNC_MODIFIES(*s);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
STRING * Parrot_str_new_from_buffer(PARROT_INTERP,
ARGMOD(Buffer *buffer),
const UINTVAL len)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*buffer);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
Expand Down Expand Up @@ -629,6 +640,9 @@ STRING* Parrot_str_from_uint(PARROT_INTERP,
#define ASSERT_ARGS_Parrot_str_new_COW __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_Parrot_str_new_from_buffer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(buffer))
#define ASSERT_ARGS_Parrot_str_new_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(encoding) \
Expand Down
10 changes: 5 additions & 5 deletions src/frame_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,19 +647,19 @@ char * opt_mul(PARROT_INTERP, char *pc, int dest, INTVAL imm, int src);
#else /* NUMVAL_SIZE */

# define jit_emit_fload_m_n(interp, pc, address) \
emitm_fldt((pc), emit_None, emit_None, emit_None, (address))
emitm_fldt((interp), (pc), emit_None, emit_None, emit_None, (address))

# define jit_emit_fload_mb_n(interp, pc, base, offs) \
emitm_fldt((pc), (base), emit_None, 1, (offs))
emitm_fldt((interp), (pc), (base), emit_None, 1, (offs))

# define jit_emit_fstore_m_n(pc, address) \
emitm_fstpt((pc), emit_None, emit_None, emit_None, (address))
emitm_fstpt((interp), (pc), emit_None, emit_None, emit_None, (address))

# define jit_emit_fstore_mb_n(interp, pc, base, offs) \
emitm_fstpt((pc), (base), emit_None, 1, (offs))
emitm_fstpt((interp), (pc), (base), emit_None, 1, (offs))

# define jit_emit_fst_mb_n(interp, pc, base, offs) \
emitm_fstt((pc), (base), emit_None, 1, (offs))
emitm_fstt((interp), (pc), (base), emit_None, 1, (offs))

#endif /* NUMVAL_SIZE */

Expand Down
26 changes: 10 additions & 16 deletions src/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ static void
hash_thaw(PARROT_INTERP, ARGMOD(Hash *hash), ARGMOD(visit_info *info))
{
ASSERT_ARGS(hash_thaw)
IMAGE_IO * const io = info->image_io;

/* during thaw, info->extra is the key/value count */
const size_t num_entries = (size_t) hash->entries;
Expand All @@ -569,13 +568,13 @@ hash_thaw(PARROT_INTERP, ARGMOD(Hash *hash), ARGMOD(visit_info *info))
switch (hash->key_type) {
case Hash_key_type_STRING:
{
STRING * const s_key = VTABLE_shift_string(interp, io);
STRING * const s_key = VTABLE_shift_string(interp, info);
b = parrot_hash_put(interp, hash, s_key, NULL);
}
break;
case Hash_key_type_int:
{
const INTVAL i_key = VTABLE_shift_integer(interp, io);
const INTVAL i_key = VTABLE_shift_integer(interp, info);
b = parrot_hash_put(interp, hash, (void*)i_key, NULL);
}
break;
Expand All @@ -588,15 +587,13 @@ hash_thaw(PARROT_INTERP, ARGMOD(Hash *hash), ARGMOD(visit_info *info))
switch (hash->entry_type) {
case enum_hash_pmc:
{
/* this looks awful, but it avoids type-punning warnings */
void **ptr = &b->value;
info->thaw_ptr = (PMC **)ptr;
(info->visit_pmc_now)(interp, NULL, info);
PMC *p = VTABLE_shift_pmc(interp, info);
b->value = (void *)p;
break;
}
case enum_hash_int:
{
const INTVAL i = VTABLE_shift_integer(interp, io);
const INTVAL i = VTABLE_shift_integer(interp, info);
b->value = (void *)i;
break;
}
Expand Down Expand Up @@ -629,18 +626,17 @@ static void
hash_freeze(PARROT_INTERP, ARGIN(const Hash * const hash), ARGMOD(visit_info *info))
{
ASSERT_ARGS(hash_freeze)
IMAGE_IO * const io = info->image_io;
size_t i;

for (i = 0; i < hash->entries; i++) {
HashBucket * const b = hash->bs+i;

switch (hash->key_type) {
case Hash_key_type_STRING:
VTABLE_push_string(interp, io, (STRING *)b->key);
VTABLE_push_string(interp, info, (STRING *)b->key);
break;
case Hash_key_type_int:
VTABLE_push_integer(interp, io, (INTVAL)b->key);
VTABLE_push_integer(interp, info, (INTVAL)b->key);
break;
default:
Parrot_ex_throw_from_c_args(interp, NULL, 1,
Expand All @@ -650,10 +646,10 @@ hash_freeze(PARROT_INTERP, ARGIN(const Hash * const hash), ARGMOD(visit_info *in

switch (hash->entry_type) {
case enum_hash_pmc:
(info->visit_pmc_now)(interp, (PMC *)b->value, info);
VTABLE_push_pmc(interp, info, (PMC *)b->value);
break;
case enum_hash_int:
VTABLE_push_integer(interp, io, (INTVAL)b->value);
VTABLE_push_integer(interp, info, (INTVAL)b->value);
break;
default:
Parrot_ex_throw_from_c_args(interp, NULL, 1,
Expand Down Expand Up @@ -683,13 +679,11 @@ parrot_hash_visit(PARROT_INTERP, ARGMOD(Hash *hash), ARGMOD(void *pinfo))
ASSERT_ARGS(parrot_hash_visit)
visit_info* const info = (visit_info*) pinfo;

switch (info->what) {
switch (VTABLE_get_integer(interp, info)) {
case VISIT_THAW_NORMAL:
case VISIT_THAW_CONSTANTS:
hash_thaw(interp, hash, info);
break;
case VISIT_FREEZE_NORMAL:
case VISIT_FREEZE_AT_DESTRUCT:
hash_freeze(interp, hash, info);
break;
default:
Expand Down
Loading

0 comments on commit 1137b41

Please sign in to comment.