Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 7bb3ef5974
...
compare: ff0768972a
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
5 include/parrot/context.h
@@ -464,7 +464,8 @@ UINTVAL Parrot_pcc_warnings_test_func(PARROT_INTERP,
# define Parrot_pcc_get_continuation(i, c) (CONTEXT_STRUCT(c)->current_cont)
# define Parrot_pcc_get_caller_ctx(i, c) (CONTEXT_STRUCT(c)->caller_ctx)
# define Parrot_pcc_get_namespace(i, c) (CONTEXT_STRUCT(c)->current_namespace)
-# define Parrot_pcc_get_object(i, c) (CONTEXT_STRUCT(c)->current_object)
+//# define Parrot_pcc_get_object(i, c) (CONTEXT_STRUCT(c)->current_object)
+# define Parrot_pcc_get_object(i, c) (PMCNULL)
# define Parrot_pcc_get_lex_pad(i, c) (CONTEXT_STRUCT(c)->lex_pad)
# define Parrot_pcc_get_handlers(i, c) (CONTEXT_STRUCT(c)->handlers)
@@ -568,7 +569,7 @@ UINTVAL Parrot_pcc_warnings_test_func(PARROT_INTERP,
PARROT_GC_WRITE_BARRIER((i), (c)); \
} while (0)
# define Parrot_pcc_set_object(i, c, value) do { \
- CONTEXT_STRUCT(c)->current_object = (value); \
+ //CONTEXT_STRUCT(c)->current_object = (value); \
PARROT_GC_WRITE_BARRIER((i), (c)); \
} while (0)
# define Parrot_pcc_set_lex_pad(i, c, value) do { \
View
11 src/call/context_accessors.c
@@ -480,8 +480,9 @@ PMC*
Parrot_pcc_get_object_func(SHIM_INTERP, ARGIN(const PMC *ctx))
{
ASSERT_ARGS(Parrot_pcc_get_object_func)
- PARROT_ASSERT(ctx->vtable->base_type == enum_class_Context);
- return CONTEXT_STRUCT(ctx)->current_object;
+ return PMCNULL;
+// PARROT_ASSERT(ctx->vtable->base_type == enum_class_Context);
+// return CONTEXT_STRUCT(ctx)->current_object;
}
PARROT_EXPORT
@@ -489,9 +490,9 @@ void
Parrot_pcc_set_object_func(PARROT_INTERP, ARGIN(PMC *ctx), ARGIN_NULLOK(PMC *object))
{
ASSERT_ARGS(Parrot_pcc_set_object_func)
- PARROT_ASSERT(ctx->vtable->base_type == enum_class_Context);
- PARROT_GC_WRITE_BARRIER(interp, ctx);
- CONTEXT_STRUCT(ctx)->current_object = object;
+// PARROT_ASSERT(ctx->vtable->base_type == enum_class_Context);
+// PARROT_GC_WRITE_BARRIER(interp, ctx);
+// CONTEXT_STRUCT(ctx)->current_object = object;
}
/*
View
1,094 src/pmc/callsignature.pmc
@@ -156,685 +156,343 @@ static void mark_positionals(PARROT_INTERP, ARGIN(PMC *self))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
+#include "parrot/packfile.h"
+#include "pmc/pmc_sub.h"
+
+pmclass CallSignature provides array provides hash auto_attrs {
+ /* Storage for arguments */
+ ATTR struct Pcc_cell *positionals; /* array of positionals */
+ ATTR INTVAL num_positionals; /* count of used positionals */
+ ATTR INTVAL allocated_positionals;/* count of allocated positionals */
+
+ ATTR PMC *type_tuple; /* Cached argument types for MDD */
+ ATTR STRING *short_sig; /* Simple string sig args & returns */
+ ATTR PMC *arg_flags; /* Integer array of argument flags */
+ ATTR PMC *return_flags; /* Integer array of return flags */
+ ATTR Hash *hash; /* Hash of named arguments */
+
/*
-=item C<static void ensure_positionals_storage(PARROT_INTERP, PMC *self, INTVAL
-size)>
+=item C<void init()>
+
+Initializes a newly created CallSignature object.
=cut
*/
-static void
-ensure_positionals_storage(PARROT_INTERP, ARGIN(PMC *self), INTVAL size)
-{
- ASSERT_ARGS(ensure_positionals_storage)
- INTVAL allocated_positionals;
-
- GETATTR_CallSignature_allocated_positionals(interp, self, allocated_positionals);
+ VTABLE void init() {
+ SET_ATTR_type_tuple(INTERP, SELF, PMCNULL);
- if (size <= allocated_positionals)
- return;
+ SET_ATTR_positionals(INTERP, SELF, NULL);
+ SET_ATTR_num_positionals(INTERP, SELF, 0);
- ensure_positionals_storage_ap(interp, self, size, allocated_positionals);
-}
+ PObj_custom_mark_destroy_SETALL(SELF);
+ }
/*
-=item C<static void ensure_positionals_storage_ap(PARROT_INTERP, PMC *self,
-INTVAL size, INTVAL allocated_positionals)>
+=item C<void mark()>
+
+Mark any referenced strings and PMCs.
=cut
*/
+ VTABLE void mark() {
+ Hash *hash;
-static void
-ensure_positionals_storage_ap(PARROT_INTERP,
- ARGIN(PMC *self), INTVAL size, INTVAL allocated_positionals)
-{
- ASSERT_ARGS(ensure_positionals_storage_ap)
- INTVAL num_positionals;
- Pcc_cell *array, *new_array;
-
- if (size < 8)
- size = 8;
-
- GETATTR_CallSignature_positionals(interp, self, array);
+ if (!PMC_data(SELF))
+ return;
- if (size > 8)
- new_array = (Pcc_cell *)Parrot_gc_allocate_memory_chunk(interp,
- size * sizeof (Pcc_cell));
- else
- new_array = (Pcc_cell *)Parrot_gc_allocate_fixed_size_storage(interp,
- size * sizeof (Pcc_cell));
+ mark_positionals(INTERP, SELF);
- if (array) {
- GETATTR_CallSignature_num_positionals(interp, self, num_positionals);
- memcpy(new_array, array, num_positionals * sizeof (Pcc_cell));
+ GET_ATTR_hash(INTERP, SELF, hash);
+ if (hash)
+ mark_hash(INTERP, hash);
- if (allocated_positionals > 8)
- Parrot_gc_free_memory_chunk(interp, array);
- else
- Parrot_gc_free_fixed_size_storage(interp,
- allocated_positionals * sizeof (Pcc_cell), array);
}
- SETATTR_CallSignature_allocated_positionals(interp, self, size);
- SETATTR_CallSignature_positionals(interp, self, new_array);
-}
-
/*
-=item C<static Pcc_cell* get_cell_at(PARROT_INTERP, PMC *self, INTVAL key)>
+=item C<void morph(PMC *type)>
+
+Morph the call signature into a return signature. (Currently ignores
+the type passed in, and resets the named and positional arguments
+stored.)
=cut
*/
+ VTABLE void morph(PMC *type) {
+ Hash *hash;
-PARROT_CANNOT_RETURN_NULL
-static Pcc_cell*
-get_cell_at(PARROT_INTERP, ARGIN(PMC *self), INTVAL key)
-{
- ASSERT_ARGS(get_cell_at)
- Pcc_cell *cells;
- ensure_positionals_storage(interp, self, key + 1);
- GETATTR_CallSignature_positionals(interp, self, cells);
- return &cells[key];
-}
-
-/*
+ if (!PMC_data(SELF))
+ return;
-=item C<static INTVAL autobox_intval(PARROT_INTERP, const Pcc_cell *cell)>
+ SET_ATTR_short_sig(INTERP, SELF, NULL);
+ SET_ATTR_arg_flags(INTERP, SELF, PMCNULL);
+ SET_ATTR_return_flags(INTERP, SELF, PMCNULL);
+ SET_ATTR_type_tuple(INTERP, SELF, PMCNULL);
-=cut
+ /* Don't free positionals. Just reuse them */
+ SET_ATTR_num_positionals(INTERP, SELF, 0);
-*/
+ GET_ATTR_hash(INTERP, SELF, hash);
-static INTVAL
-autobox_intval(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
-{
- ASSERT_ARGS(autobox_intval)
- switch (CELL_TYPE_MASK(cell)) {
- case INTCELL:
- return CELL_INT(cell);
- case FLOATCELL:
- return (INTVAL)CELL_FLOAT(cell);
- case STRINGCELL:
- return CELL_STRING(cell) ? Parrot_str_to_int(interp, CELL_STRING(cell)) : 0;
- case PMCCELL:
- return VTABLE_get_integer(interp, CELL_PMC(cell));
- default:
- break;
+ if (hash) {
+ parrot_hash_iterate(hash,
+ FREE_CELL(INTERP, (Pcc_cell *)_bucket->value););
+ Parrot_hash_destroy(INTERP, hash);
+ SET_ATTR_hash(INTERP, SELF, NULL);
+ }
}
- /* exception */
- return 0;
-}
+ VTABLE void destroy() {
+ INTVAL allocated_positionals;
+ Hash *hash;
-/*
+ if (!PMC_data(SELF))
+ return;
-=item C<static FLOATVAL autobox_floatval(PARROT_INTERP, const Pcc_cell *cell)>
+ GET_ATTR_hash(INTERP, SELF, hash);
+ GET_ATTR_allocated_positionals(INTERP, SELF, allocated_positionals);
-=cut
+ if (allocated_positionals) {
+ Pcc_cell *c;
-*/
+ GET_ATTR_positionals(INTERP, SELF, c);
+ if (allocated_positionals > 8)
+ Parrot_gc_free_memory_chunk(INTERP, c);
+ else
+ Parrot_gc_free_fixed_size_storage(INTERP,
+ allocated_positionals * sizeof (Pcc_cell), c);
+ }
-static FLOATVAL
-autobox_floatval(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
-{
- ASSERT_ARGS(autobox_floatval)
- switch (CELL_TYPE_MASK(cell)) {
- case INTCELL:
- return (FLOATVAL)CELL_INT(cell);
- case FLOATCELL:
- return CELL_FLOAT(cell);
- case STRINGCELL:
- return CELL_STRING(cell) ? Parrot_str_to_num(interp, CELL_STRING(cell)) : 0.0;
- case PMCCELL:
- return VTABLE_get_number(interp, CELL_PMC(cell));
- default:
- break;
+ if (hash) {
+ parrot_hash_iterate(hash,
+ FREE_CELL(INTERP, (Pcc_cell *)_bucket->value););
+ Parrot_hash_destroy(INTERP, hash);
+ }
}
- /* exception */
- return 0.0;
-}
-
/*
-=item C<static STRING * autobox_string(PARROT_INTERP, const Pcc_cell *cell)>
+=item C<void set_string_native(STRING *value)>
+
+Sets the short signature for the CallSignature.
=cut
*/
-PARROT_CANNOT_RETURN_NULL
-static STRING *
-autobox_string(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
-{
- ASSERT_ARGS(autobox_string)
- switch (CELL_TYPE_MASK(cell)) {
- case INTCELL:
- return Parrot_str_from_int(interp, CELL_INT(cell));
- case FLOATCELL:
- return Parrot_str_from_num(interp, CELL_FLOAT(cell));
- case STRINGCELL:
- return CELL_STRING(cell);
- case PMCCELL:
- return VTABLE_get_string(interp, CELL_PMC(cell));
- default:
- break;
+ VTABLE void set_string_native(STRING *value) {
+ SET_ATTR_short_sig(INTERP, SELF, value);
}
- /* exception */
- return STRINGNULL;
-}
-
/*
-=item C<static PMC * autobox_pmc(PARROT_INTERP, Pcc_cell *cell, INTVAL type)>
+=item C<STRING *get_string()>
+
+Returns the short signature for the CallSignature.
=cut
*/
-PARROT_CANNOT_RETURN_NULL
-static PMC *
-autobox_pmc(PARROT_INTERP, ARGIN(Pcc_cell *cell), INTVAL type)
-{
- ASSERT_ARGS(autobox_pmc)
- PMC *result = PMCNULL;
-
- switch (type) {
- case INTCELL:
- result = Parrot_pmc_new(interp, HLL_TYPE(enum_class_Integer));
- VTABLE_set_integer_native(interp, result, CELL_INT(cell));
- break;
- case FLOATCELL:
- result = Parrot_pmc_new(interp, HLL_TYPE(enum_class_Float));
- VTABLE_set_number_native(interp, result, CELL_FLOAT(cell));
- break;
- case STRINGCELL:
- result = Parrot_pmc_box_string(interp, CELL_STRING(cell));
- break;
- case PMCCELL:
- result = CELL_PMC(cell);
- default:
- /* exception */
- break;
- }
-
- return result;
-}
+ VTABLE STRING *get_string() {
+ STRING *res;
+ Pcc_cell *c;
+ INTVAL num_positionals, i;
-/*
+ GET_ATTR_short_sig(INTERP, SELF, res);
-=item C<static Hash * get_hash(PARROT_INTERP, PMC *SELF)>
+ if (res)
+ return res;
-=cut
+ GET_ATTR_positionals(INTERP, SELF, c);
+ GET_ATTR_num_positionals(INTERP, SELF, num_positionals);
-*/
+ res = Parrot_str_new(INTERP, NULL, num_positionals);
-PARROT_CANNOT_RETURN_NULL
-static Hash *
-get_hash(PARROT_INTERP, ARGIN(PMC *SELF))
-{
- ASSERT_ARGS(get_hash)
- Hash *hash;
-
- GETATTR_CallSignature_hash(interp, SELF, hash);
+ for (i = 0; i < num_positionals; ++i) {
+ switch (c[i].type) {
+ case INTCELL:
+ res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "I"));
+ break;
+ case FLOATCELL:
+ res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "N"));
+ break;
+ case STRINGCELL:
+ res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "S"));
+ break;
+ case PMCCELL:
+ res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "P"));
+ break;
+ default:
+ PARROT_FAILURE("Impossible flag");
+ break;
+ }
+ }
+ /* TODO Add named args to signature */
+ /* After fixind build_MMD_type_tuple to use raw arguments instead of signature */
- if (!hash) {
- hash = Parrot_hash_create(interp,
- enum_type_ptr,
- Hash_key_type_STRING);
+ SET_ATTR_short_sig(INTERP, SELF, res);
- SETATTR_CallSignature_hash(interp, SELF, hash);
+ return res;
}
- return hash;
-}
-
/*
-=item C<static void mark_cell(PARROT_INTERP, Pcc_cell *c)>
+=item C<void set_pmc(PMC *value)>
+
+Sets a fixed-size array of integer types (a type tuple) for the CallSignature.
=cut
*/
-static void
-mark_cell(PARROT_INTERP, ARGIN(Pcc_cell *c))
-{
- ASSERT_ARGS(mark_cell)
- switch (CELL_TYPE_MASK(c)) {
- case STRINGCELL:
- if (CELL_STRING(c))
- Parrot_gc_mark_STRING_alive(interp, CELL_STRING(c));
- break;
- case PMCCELL:
- if (!PMC_IS_NULL(CELL_PMC(c)))
- Parrot_gc_mark_PMC_alive(interp, CELL_PMC(c));
- break;
- case INTCELL:
- case FLOATCELL:
- default:
- break;
+ VTABLE void set_pmc(PMC *value) {
+ SET_ATTR_type_tuple(INTERP, SELF, value);
}
-}
-
/*
-=item C<static void mark_positionals(PARROT_INTERP, PMC *self)>
+=item C<PMC *get_pmc()>
+
+Returns a fixed-size array of integer types (a type tuple) for the
+CallSignature.
=cut
*/
-static void
-mark_positionals(PARROT_INTERP, ARGIN(PMC *self))
-{
- ASSERT_ARGS(mark_positionals)
- INTVAL size;
-
- GETATTR_CallSignature_num_positionals(interp, self, size);
+ VTABLE PMC *get_pmc() {
+ PMC *type_tuple;
- if (size) {
- Pcc_cell *cells;
- INTVAL i;
- GETATTR_CallSignature_positionals(interp, self, cells);
+ GET_ATTR_type_tuple(INTERP, SELF, type_tuple);
- for (i = 0; i < size; ++i)
- mark_cell(interp, &cells[i]);
- }
-}
+ if (PMC_IS_NULL(type_tuple)) {
+ Pcc_cell *c;
+ INTVAL num_positionals;
+ INTVAL i = 0;
-/*
+ GET_ATTR_positionals(INTERP, SELF, c);
+ GET_ATTR_num_positionals(INTERP, SELF, num_positionals);
-=item C<static void mark_hash(PARROT_INTERP, Hash *h)>
+ type_tuple = Parrot_pmc_new_init_int(INTERP,
+ enum_class_FixedIntegerArray, num_positionals);
-=cut
+ for (i = 0; i < num_positionals; ++i) {
+ INTVAL type;
-*/
+ switch (c[i].type) {
+ case INTCELL: type = -enum_type_INTVAL; break;
+ case FLOATCELL: type = -enum_type_FLOATVAL; break;
+ case STRINGCELL: type = -enum_type_STRING; break;
+ case PMCCELL:
+ type = PMC_IS_NULL(c[i].u.p)
+ ? (INTVAL)-enum_type_PMC
+ : VTABLE_type(INTERP, c[i].u.p);
+ break;
+ default:
+ Parrot_ex_throw_from_c_args(INTERP, NULL,
+ EXCEPTION_INVALID_OPERATION,
+ "Multiple Dispatch: invalid argument type!");
+ }
-/* don't look now, but here goes encapsulation.... */
-static void
-mark_hash(PARROT_INTERP, ARGIN(Hash *h))
-{
- ASSERT_ARGS(mark_hash)
- parrot_hash_iterate(h,
- Parrot_gc_mark_STRING_alive(interp, (STRING *)_bucket->key);
- mark_cell(interp, (Pcc_cell *)_bucket->value););
-}
+ VTABLE_set_integer_keyed_int(INTERP, type_tuple, i, type);
+ }
-/*
+ SET_ATTR_type_tuple(INTERP, SELF, type_tuple);
+ }
-=item C<static PMC * get_named_names(PARROT_INTERP, PMC *SELF)>
+ return type_tuple;
+ }
-=cut
-*/
+/*
-PARROT_CAN_RETURN_NULL
-static PMC *
-get_named_names(PARROT_INTERP, ARGIN(PMC *SELF))
-{
- ASSERT_ARGS(get_named_names)
- Hash *hash;
+=item C<void set_attr_str(STRING *key, PMC *value)>
- GETATTR_CallSignature_hash(interp, SELF, hash);
+Set a PMC value for an attribute by string name.
- /* yes, this *looks* risky, but it's a Parrot STRING hash internally */
- if (hash && hash->entries) {
- UINTVAL j = 0;
- PMC * const result =
- Parrot_pmc_new_init_int(interp, enum_class_FixedStringArray, hash->entries);
- parrot_hash_iterate(hash,
- VTABLE_set_string_keyed_int(interp, result, j++, (STRING *)_bucket->key););
- return result;
- }
+=over
- return PMCNULL;
-}
+=item results
-#include "parrot/packfile.h"
-#include "pmc/pmc_sub.h"
+Stores the return signature, an array of PMCs.
-pmclass CallSignature provides array provides hash auto_attrs {
- /* Storage for arguments */
- ATTR struct Pcc_cell *positionals; /* array of positionals */
- ATTR INTVAL num_positionals; /* count of used positionals */
- ATTR INTVAL allocated_positionals;/* count of allocated positionals */
+=item arg_flags
- ATTR PMC *type_tuple; /* Cached argument types for MDD */
- ATTR STRING *short_sig; /* Simple string sig args & returns */
- ATTR PMC *arg_flags; /* Integer array of argument flags */
- ATTR PMC *return_flags; /* Integer array of return flags */
- ATTR Hash *hash; /* Hash of named arguments */
+Stores a set of flags for the call signature arguments, an array of
+integers.
-/*
+=item return_flags
-=item C<void init()>
+Stores a set of flags for the call signature return arguments, an array
+of integers.
-Initializes a newly created CallSignature object.
+=back
=cut
*/
- VTABLE void init() {
- SET_ATTR_type_tuple(INTERP, SELF, PMCNULL);
-
- SET_ATTR_positionals(INTERP, SELF, NULL);
- SET_ATTR_num_positionals(INTERP, SELF, 0);
+ VTABLE void set_attr_str(STRING *key, PMC *value) {
- PObj_custom_mark_destroy_SETALL(SELF);
+ if (STRING_equal(INTERP, key, CONST_STRING(INTERP, "arg_flags"))) {
+ SET_ATTR_arg_flags(INTERP, SELF, value);
+ }
+ else if (STRING_equal(INTERP, key, CONST_STRING(INTERP, "return_flags"))) {
+ SET_ATTR_return_flags(INTERP, SELF, value);
+ }
+ else
+ Parrot_ex_throw_from_c_args(INTERP, NULL,
+ EXCEPTION_ATTRIB_NOT_FOUND, "No such attribute '%S'", key);
}
/*
-=item C<void mark()>
+=item C<PMC *get_attr_str(STRING *key)>
-Mark any referenced strings and PMCs.
+Get a PMC value for an attribute by string name.
-=cut
+=over
-*/
- VTABLE void mark() {
- Hash *hash;
+=item results
- if (!PMC_data(SELF))
- return;
+Retrieves the return signature, an array of PMCs.
- mark_positionals(INTERP, SELF);
+=item arg_flags
- GET_ATTR_hash(INTERP, SELF, hash);
- if (hash)
- mark_hash(INTERP, hash);
+Retrieves the flags for the call signature arguments, an array of
+integers.
- }
+=item return_flags
-/*
+Retrieves the flags for the call signature return arguments, an array of
+integers.
-=item C<void morph(PMC *type)>
+=item named
-Morph the call signature into a return signature. (Currently ignores
-the type passed in, and resets the named and positional arguments
-stored.)
+Retrieves the hash of named arguments.
-=cut
+=item caller_ctx
-*/
- VTABLE void morph(PMC *type) {
- Hash *hash;
+return Caller Context
- if (!PMC_data(SELF))
- return;
+=item lex_pad
- SET_ATTR_short_sig(INTERP, SELF, NULL);
- SET_ATTR_arg_flags(INTERP, SELF, PMCNULL);
- SET_ATTR_return_flags(INTERP, SELF, PMCNULL);
- SET_ATTR_type_tuple(INTERP, SELF, PMCNULL);
+return LexPad
- /* Don't free positionals. Just reuse them */
- SET_ATTR_num_positionals(INTERP, SELF, 0);
+=item outer_ctx
- GET_ATTR_hash(INTERP, SELF, hash);
+return Outer Context
- if (hash) {
- parrot_hash_iterate(hash,
- FREE_CELL(INTERP, (Pcc_cell *)_bucket->value););
- Parrot_hash_destroy(INTERP, hash);
- SET_ATTR_hash(INTERP, SELF, NULL);
- }
- }
+=item current_sub
- VTABLE void destroy() {
- INTVAL allocated_positionals;
- Hash *hash;
-
- if (!PMC_data(SELF))
- return;
-
- GET_ATTR_hash(INTERP, SELF, hash);
- GET_ATTR_allocated_positionals(INTERP, SELF, allocated_positionals);
-
- if (allocated_positionals) {
- Pcc_cell *c;
-
- GET_ATTR_positionals(INTERP, SELF, c);
- if (allocated_positionals > 8)
- Parrot_gc_free_memory_chunk(INTERP, c);
- else
- Parrot_gc_free_fixed_size_storage(INTERP,
- allocated_positionals * sizeof (Pcc_cell), c);
- }
-
- if (hash) {
- parrot_hash_iterate(hash,
- FREE_CELL(INTERP, (Pcc_cell *)_bucket->value););
- Parrot_hash_destroy(INTERP, hash);
- }
- }
-
-/*
-
-=item C<void set_string_native(STRING *value)>
-
-Sets the short signature for the CallSignature.
-
-=cut
-
-*/
-
- VTABLE void set_string_native(STRING *value) {
- SET_ATTR_short_sig(INTERP, SELF, value);
- }
-
-/*
-
-=item C<STRING *get_string()>
-
-Returns the short signature for the CallSignature.
-
-=cut
-
-*/
-
- VTABLE STRING *get_string() {
- STRING *res;
- Pcc_cell *c;
- INTVAL num_positionals, i;
-
- GET_ATTR_short_sig(INTERP, SELF, res);
-
- if (res)
- return res;
-
- GET_ATTR_positionals(INTERP, SELF, c);
- GET_ATTR_num_positionals(INTERP, SELF, num_positionals);
-
- res = Parrot_str_new(INTERP, NULL, num_positionals);
-
- for (i = 0; i < num_positionals; ++i) {
- switch (c[i].type) {
- case INTCELL:
- res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "I"));
- break;
- case FLOATCELL:
- res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "N"));
- break;
- case STRINGCELL:
- res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "S"));
- break;
- case PMCCELL:
- res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, "P"));
- break;
- default:
- PARROT_FAILURE("Impossible flag");
- break;
- }
- }
- /* TODO Add named args to signature */
- /* After fixind build_MMD_type_tuple to use raw arguments instead of signature */
-
- SET_ATTR_short_sig(INTERP, SELF, res);
-
- return res;
- }
-
-/*
-
-=item C<void set_pmc(PMC *value)>
-
-Sets a fixed-size array of integer types (a type tuple) for the CallSignature.
-
-=cut
-
-*/
-
- VTABLE void set_pmc(PMC *value) {
- SET_ATTR_type_tuple(INTERP, SELF, value);
- }
-
-/*
-
-=item C<PMC *get_pmc()>
-
-Returns a fixed-size array of integer types (a type tuple) for the
-CallSignature.
-
-=cut
-
-*/
-
- VTABLE PMC *get_pmc() {
- PMC *type_tuple;
-
- GET_ATTR_type_tuple(INTERP, SELF, type_tuple);
-
- if (PMC_IS_NULL(type_tuple)) {
- Pcc_cell *c;
- INTVAL num_positionals;
- INTVAL i = 0;
-
- GET_ATTR_positionals(INTERP, SELF, c);
- GET_ATTR_num_positionals(INTERP, SELF, num_positionals);
-
- type_tuple = Parrot_pmc_new_init_int(INTERP,
- enum_class_FixedIntegerArray, num_positionals);
-
- for (i = 0; i < num_positionals; ++i) {
- INTVAL type;
-
- switch (c[i].type) {
- case INTCELL: type = -enum_type_INTVAL; break;
- case FLOATCELL: type = -enum_type_FLOATVAL; break;
- case STRINGCELL: type = -enum_type_STRING; break;
- case PMCCELL:
- type = PMC_IS_NULL(c[i].u.p)
- ? (INTVAL)-enum_type_PMC
- : VTABLE_type(INTERP, c[i].u.p);
- break;
- default:
- Parrot_ex_throw_from_c_args(INTERP, NULL,
- EXCEPTION_INVALID_OPERATION,
- "Multiple Dispatch: invalid argument type!");
- }
-
- VTABLE_set_integer_keyed_int(INTERP, type_tuple, i, type);
- }
-
- SET_ATTR_type_tuple(INTERP, SELF, type_tuple);
- }
-
- return type_tuple;
- }
-
-
-/*
-
-=item C<void set_attr_str(STRING *key, PMC *value)>
-
-Set a PMC value for an attribute by string name.
-
-=over
-
-=item results
-
-Stores the return signature, an array of PMCs.
-
-=item arg_flags
-
-Stores a set of flags for the call signature arguments, an array of
-integers.
-
-=item return_flags
-
-Stores a set of flags for the call signature return arguments, an array
-of integers.
-
-=back
-
-=cut
-
-*/
-
- VTABLE void set_attr_str(STRING *key, PMC *value) {
-
- if (STRING_equal(INTERP, key, CONST_STRING(INTERP, "arg_flags"))) {
- SET_ATTR_arg_flags(INTERP, SELF, value);
- }
- else if (STRING_equal(INTERP, key, CONST_STRING(INTERP, "return_flags"))) {
- SET_ATTR_return_flags(INTERP, SELF, value);
- }
- else
- Parrot_ex_throw_from_c_args(INTERP, NULL,
- EXCEPTION_ATTRIB_NOT_FOUND, "No such attribute '%S'", key);
- }
-
-/*
-
-=item C<PMC *get_attr_str(STRING *key)>
-
-Get a PMC value for an attribute by string name.
-
-=over
-
-=item results
-
-Retrieves the return signature, an array of PMCs.
-
-=item arg_flags
-
-Retrieves the flags for the call signature arguments, an array of
-integers.
-
-=item return_flags
-
-Retrieves the flags for the call signature return arguments, an array of
-integers.
-
-=item named
-
-Retrieves the hash of named arguments.
-
-=item caller_ctx
-
-return Caller Context
-
-=item lex_pad
-
-return LexPad
-
-=item outer_ctx
-
-return Outer Context
-
-=item current_sub
-
-return current Sub
+return current Sub
=item handlers
@@ -1462,6 +1120,348 @@ Creates and returns a clone of the signature.
} /* end pmclass */
/*
+
+=item C<static void ensure_positionals_storage(PARROT_INTERP, PMC *self, INTVAL
+size)>
+
+=cut
+
+*/
+
+static void
+ensure_positionals_storage(PARROT_INTERP, ARGIN(PMC *self), INTVAL size)
+{
+ ASSERT_ARGS(ensure_positionals_storage)
+ INTVAL allocated_positionals;
+
+ GETATTR_CallSignature_allocated_positionals(interp, self, allocated_positionals);
+
+ if (size <= allocated_positionals)
+ return;
+
+ ensure_positionals_storage_ap(interp, self, size, allocated_positionals);
+}
+
+/*
+
+=item C<static void ensure_positionals_storage_ap(PARROT_INTERP, PMC *self,
+INTVAL size, INTVAL allocated_positionals)>
+
+=cut
+
+*/
+
+static void
+ensure_positionals_storage_ap(PARROT_INTERP,
+ ARGIN(PMC *self), INTVAL size, INTVAL allocated_positionals)
+{
+ ASSERT_ARGS(ensure_positionals_storage_ap)
+ INTVAL num_positionals;
+ Pcc_cell *array, *new_array;
+
+ if (size < 8)
+ size = 8;
+
+ GETATTR_CallSignature_positionals(interp, self, array);
+
+ if (size > 8)
+ new_array = (Pcc_cell *)Parrot_gc_allocate_memory_chunk(interp,
+ size * sizeof (Pcc_cell));
+ else
+ new_array = (Pcc_cell *)Parrot_gc_allocate_fixed_size_storage(interp,
+ size * sizeof (Pcc_cell));
+
+ if (array) {
+ GETATTR_CallSignature_num_positionals(interp, self, num_positionals);
+ memcpy(new_array, array, num_positionals * sizeof (Pcc_cell));
+
+ if (allocated_positionals > 8)
+ Parrot_gc_free_memory_chunk(interp, array);
+ else
+ Parrot_gc_free_fixed_size_storage(interp,
+ allocated_positionals * sizeof (Pcc_cell), array);
+ }
+
+ SETATTR_CallSignature_allocated_positionals(interp, self, size);
+ SETATTR_CallSignature_positionals(interp, self, new_array);
+}
+
+/*
+
+=item C<static Pcc_cell* get_cell_at(PARROT_INTERP, PMC *self, INTVAL key)>
+
+=cut
+
+*/
+
+PARROT_CANNOT_RETURN_NULL
+static Pcc_cell*
+get_cell_at(PARROT_INTERP, ARGIN(PMC *self), INTVAL key)
+{
+ ASSERT_ARGS(get_cell_at)
+ Pcc_cell *cells;
+ ensure_positionals_storage(interp, self, key + 1);
+ GETATTR_CallSignature_positionals(interp, self, cells);
+ return &cells[key];
+}
+
+/*
+
+=item C<static INTVAL autobox_intval(PARROT_INTERP, const Pcc_cell *cell)>
+
+=cut
+
+*/
+
+static INTVAL
+autobox_intval(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
+{
+ ASSERT_ARGS(autobox_intval)
+ switch (CELL_TYPE_MASK(cell)) {
+ case INTCELL:
+ return CELL_INT(cell);
+ case FLOATCELL:
+ return (INTVAL)CELL_FLOAT(cell);
+ case STRINGCELL:
+ return CELL_STRING(cell) ? Parrot_str_to_int(interp, CELL_STRING(cell)) : 0;
+ case PMCCELL:
+ return VTABLE_get_integer(interp, CELL_PMC(cell));
+ default:
+ break;
+ }
+
+ /* exception */
+ return 0;
+}
+
+/*
+
+=item C<static FLOATVAL autobox_floatval(PARROT_INTERP, const Pcc_cell *cell)>
+
+=cut
+
+*/
+
+static FLOATVAL
+autobox_floatval(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
+{
+ ASSERT_ARGS(autobox_floatval)
+ switch (CELL_TYPE_MASK(cell)) {
+ case INTCELL:
+ return (FLOATVAL)CELL_INT(cell);
+ case FLOATCELL:
+ return CELL_FLOAT(cell);
+ case STRINGCELL:
+ return CELL_STRING(cell) ? Parrot_str_to_num(interp, CELL_STRING(cell)) : 0.0;
+ case PMCCELL:
+ return VTABLE_get_number(interp, CELL_PMC(cell));
+ default:
+ break;
+ }
+
+ /* exception */
+ return 0.0;
+}
+
+/*
+
+=item C<static STRING * autobox_string(PARROT_INTERP, const Pcc_cell *cell)>
+
+=cut
+
+*/
+
+PARROT_CANNOT_RETURN_NULL
+static STRING *
+autobox_string(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
+{
+ ASSERT_ARGS(autobox_string)
+ switch (CELL_TYPE_MASK(cell)) {
+ case INTCELL:
+ return Parrot_str_from_int(interp, CELL_INT(cell));
+ case FLOATCELL:
+ return Parrot_str_from_num(interp, CELL_FLOAT(cell));
+ case STRINGCELL:
+ return CELL_STRING(cell);
+ case PMCCELL:
+ return VTABLE_get_string(interp, CELL_PMC(cell));
+ default:
+ break;
+ }
+
+ /* exception */
+ return STRINGNULL;
+}
+
+/*
+
+=item C<static PMC * autobox_pmc(PARROT_INTERP, Pcc_cell *cell, INTVAL type)>
+
+=cut
+
+*/
+
+PARROT_CANNOT_RETURN_NULL
+static PMC *
+autobox_pmc(PARROT_INTERP, ARGIN(Pcc_cell *cell), INTVAL type)
+{
+ ASSERT_ARGS(autobox_pmc)
+ PMC *result = PMCNULL;
+
+ switch (type) {
+ case INTCELL:
+ result = Parrot_pmc_new(interp, HLL_TYPE(enum_class_Integer));
+ VTABLE_set_integer_native(interp, result, CELL_INT(cell));
+ break;
+ case FLOATCELL:
+ result = Parrot_pmc_new(interp, HLL_TYPE(enum_class_Float));
+ VTABLE_set_number_native(interp, result, CELL_FLOAT(cell));
+ break;
+ case STRINGCELL:
+ result = Parrot_pmc_box_string(interp, CELL_STRING(cell));
+ break;
+ case PMCCELL:
+ result = CELL_PMC(cell);
+ default:
+ /* exception */
+ break;
+ }
+
+ return result;
+}
+
+/*
+
+=item C<static Hash * get_hash(PARROT_INTERP, PMC *SELF)>
+
+=cut
+
+*/
+
+PARROT_CANNOT_RETURN_NULL
+static Hash *
+get_hash(PARROT_INTERP, ARGIN(PMC *SELF))
+{
+ ASSERT_ARGS(get_hash)
+ Hash *hash;
+
+ GETATTR_CallSignature_hash(interp, SELF, hash);
+
+ if (!hash) {
+ hash = Parrot_hash_create(interp,
+ enum_type_ptr,
+ Hash_key_type_STRING);
+
+ SETATTR_CallSignature_hash(interp, SELF, hash);
+ }
+
+ return hash;
+}
+
+/*
+
+=item C<static void mark_cell(PARROT_INTERP, Pcc_cell *c)>
+
+=cut
+
+*/
+
+static void
+mark_cell(PARROT_INTERP, ARGIN(Pcc_cell *c))
+{
+ ASSERT_ARGS(mark_cell)
+ switch (CELL_TYPE_MASK(c)) {
+ case STRINGCELL:
+ if (CELL_STRING(c))
+ Parrot_gc_mark_STRING_alive(interp, CELL_STRING(c));
+ break;
+ case PMCCELL:
+ if (!PMC_IS_NULL(CELL_PMC(c)))
+ Parrot_gc_mark_PMC_alive(interp, CELL_PMC(c));
+ break;
+ case INTCELL:
+ case FLOATCELL:
+ default:
+ break;
+ }
+
+}
+
+/*
+
+=item C<static void mark_positionals(PARROT_INTERP, PMC *self)>
+
+=cut
+
+*/
+
+static void
+mark_positionals(PARROT_INTERP, ARGIN(PMC *self))
+{
+ ASSERT_ARGS(mark_positionals)
+ INTVAL size;
+
+ GETATTR_CallSignature_num_positionals(interp, self, size);
+
+ if (size) {
+ Pcc_cell *cells;
+ INTVAL i;
+ GETATTR_CallSignature_positionals(interp, self, cells);
+
+ for (i = 0; i < size; ++i)
+ mark_cell(interp, &cells[i]);
+ }
+}
+
+/*
+
+=item C<static void mark_hash(PARROT_INTERP, Hash *h)>
+
+=cut
+
+*/
+
+/* don't look now, but here goes encapsulation.... */
+static void
+mark_hash(PARROT_INTERP, ARGIN(Hash *h))
+{
+ ASSERT_ARGS(mark_hash)
+ parrot_hash_iterate(h,
+ Parrot_gc_mark_STRING_alive(interp, (STRING *)_bucket->key);
+ mark_cell(interp, (Pcc_cell *)_bucket->value););
+}
+
+/*
+
+=item C<static PMC * get_named_names(PARROT_INTERP, PMC *SELF)>
+
+=cut
+
+*/
+
+PARROT_CAN_RETURN_NULL
+static PMC *
+get_named_names(PARROT_INTERP, ARGIN(PMC *SELF))
+{
+ ASSERT_ARGS(get_named_names)
+ Hash *hash;
+
+ GETATTR_CallSignature_hash(interp, SELF, hash);
+
+ /* yes, this *looks* risky, but it's a Parrot STRING hash internally */
+ if (hash && hash->entries) {
+ UINTVAL j = 0;
+ PMC * const result =
+ Parrot_pmc_new_init_int(interp, enum_class_FixedStringArray, hash->entries);
+ parrot_hash_iterate(hash,
+ VTABLE_set_string_keyed_int(interp, result, j++, (STRING *)_bucket->key););
+ return result;
+ }
+
+ return PMCNULL;
+}
+
+/*
* Local variables:
* c-file-style: "parrot"
* End:

No commit comments for this range

Something went wrong with that request. Please try again.