Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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: master
...
compare: pcc_reorder
Checking mergeability… Don't worry, you can still create the pull request.
  • 16 commits
  • 7 files changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 15, 2012
@bacek bacek Create new CallContext inside Sub.invoke
4646b11
@bacek bacek Workaround for handling tailcalls in Subs.
eeaf8b3
@bacek bacek Break the build horribly. Use current CallContext as "signature"
b38b9c2
Commits on Mar 26, 2012
@bacek bacek Add new Parrot_Signature struct.
Signature will hold parameters for PCC call. This allows us:
1. Encapsulate handling of signatures with proper functions instead of
tight VTABLE interface.
2. Move signature between different CallContexts.
3. Properly implement allocation of CallContext on callee side. Which is
free performance boost for tailcalls due reduced GC pressure.
4. Split Singature using VTABLE-like interface for OpSingature and
CSignature. Which should give us some performance boost with avoiding
unnessesary marshalling.
7d30fef
Commits on Mar 27, 2012
@bacek bacek Borrow some stuff from CallContext
0e76dec
@bacek bacek Borrow signature free and reset from CallContext
2798736
@bacek bacek Stylish reorder of perldoc
bd0312a
@bacek bacek Borrow pushing of positional parameters
8e1c54f
@bacek bacek Fix few typos
6458748
@bacek bacek Implement pushing of named parameters to Signature
fec6761
@bacek bacek Borrow fetching of positional arguments
722fcbb
@bacek bacek Implement fetching of named parameters and fix compilation errors
bc20be3
@bacek bacek Add couple of last required functions
d3630a9
Commits on Mar 28, 2012
@Whiteknight Whiteknight Move typedefs and macro defs into the header file. This fixes the bui…
…ld for me on clang
9206d7e
@bacek bacek Add more PCC related stuff to Singature.
66cea71
@bacek bacek Break the build to help Whiteknight with idea of next steps.
93f641b
View
5 config/gen/makefiles/root.in
@@ -407,6 +407,7 @@ PARROT_H_HEADERS = \
$(INC_DIR)/core_pmcs.h \
$(INC_DIR)/compiler.h \
$(INC_DIR)/cclass.h \
+ $(INC_DIR)/signature.h \
$(INC_PMC_DIR)/pmc_callcontext.h
CLASS_PMC_FILES = @TEMP_pmc_classes_pmc@
@@ -472,6 +473,7 @@ INTERP_O_FILES = \
src/call/ops$(O) \
src/call/context$(O) \
src/call/context_accessors$(O) \
+ src/call/signature$(O) \
src/key$(O) \
src/library$(O) \
src/list$(O) \
@@ -1591,6 +1593,9 @@ src/call/context$(O) : $(PARROT_H_HEADERS) \
$(INC_PMC_DIR)/pmc_sub.h \
$(INC_PMC_DIR)/pmc_continuation.h
+src/call/signature$(O) : $(PARROT_H_HEADERS) \
+ src/call/signature.c
+
src/interp/inter_cb$(O) : $(PARROT_H_HEADERS) \
$(INC_PMC_DIR)/pmc_parrotinterpreter.h \
$(EXTEND_HEADERS) \
View
297 include/parrot/signature.h
@@ -0,0 +1,297 @@
+/* signature.h
+ * Copyright (C) 2012, Parrot Foundation.
+ * Overview:
+ * This is the api header for the PCC Signatures
+ * Data Structure and Algorithms:
+ * PCC Signature incapsulate parameters passing in PCC.
+ * History:
+ * Notes:
+ * References:
+ */
+
+#ifndef PARROT_SIGNATURE_H_GUARD
+#define PARROT_SIGNATURE_H_GUARD
+
+typedef struct Pcc_cell
+{
+ union u {
+ PMC *p;
+ STRING *s;
+ INTVAL i;
+ FLOATVAL n;
+ } u;
+ INTVAL type;
+} Pcc_cell;
+
+#define NOCELL 0
+#define INTCELL 1
+#define FLOATCELL 2
+#define STRINGCELL 3
+#define PMCCELL 4
+
+#define ALLOC_CELL(i) \
+ (Pcc_cell *)Parrot_gc_allocate_fixed_size_storage((i), sizeof (Pcc_cell))
+
+#define FREE_CELL(i, c) \
+ Parrot_gc_free_fixed_size_storage((i), sizeof (Pcc_cell), (c))
+
+#define CLONE_CELL(i, c, c_new) do { \
+ (c_new) = ALLOC_CELL(i); \
+ *(c_new) = *(c); \
+} while (0)
+
+#define CELL_TYPE_MASK(c) (c)->type
+
+#define CELL_INT(c) (c)->u.i
+#define CELL_FLOAT(c) (c)->u.n
+#define CELL_STRING(c) (c)->u.s
+#define CELL_PMC(c) (c)->u.p
+
+typedef struct Parrot_Signature {
+ struct Pcc_cell *positionals; /* array of positionals */
+ INTVAL num_positionals; /* count of used positionals */
+ INTVAL allocated_positionals; /* count of allocated positionals */
+
+ Hash *hash; /* Hash of named arguments */
+
+ PMC *type_tuple; /* Cached argument types for MDD */
+ STRING *short_sig; /* Simple string sig args & returns */
+ PMC *arg_flags; /* Integer array of argument flags */
+ PMC *return_flags; /* Integer array of return flags */
+
+} Parrot_Signature ;
+
+/* HEADERIZER BEGIN: src/call/signature.c */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+
+PARROT_EXPORT
+void Parrot_pcc_signature_free(PARROT_INTERP,
+ ARGFREE(Parrot_Signature *self))
+ __attribute__nonnull__(1);
+
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+Parrot_Signature* Parrot_pcc_signature_new(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
+PARROT_EXPORT
+INTVAL Parrot_pcc_signature_num_positionals(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
+void Parrot_pcc_signature_reset(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+INTVAL Parrot_pcc_signature_exists_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+INTVAL Parrot_pcc_signature_get_integer(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ INTVAL key)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+INTVAL Parrot_pcc_signature_get_integer_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+FLOATVAL Parrot_pcc_signature_get_number(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ INTVAL key)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+FLOATVAL Parrot_pcc_signature_get_number_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+PARROT_CAN_RETURN_NULL
+PMC* Parrot_pcc_signature_get_pmc(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ INTVAL key)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CAN_RETURN_NULL
+PMC * Parrot_pcc_signature_get_pmc_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+PARROT_CAN_RETURN_NULL
+STRING* Parrot_pcc_signature_get_string(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ INTVAL key)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CAN_RETURN_NULL
+STRING * Parrot_pcc_signature_get_string_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+void Parrot_pcc_signature_push_float(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ FLOATVAL value)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+void Parrot_pcc_signature_push_integer(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ INTVAL value)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+void Parrot_pcc_signature_push_integer_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key),
+ INTVAL value)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+void Parrot_pcc_signature_push_number_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key),
+ FLOATVAL value)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+void Parrot_pcc_signature_push_pmc(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN_NULLOK(PMC *value))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+void Parrot_pcc_signature_push_pmc_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key),
+ ARGIN_NULLOK(PMC *value))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+void Parrot_pcc_signature_push_string(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN_NULLOK(STRING *value))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+void Parrot_pcc_signature_push_string_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key),
+ ARGIN_NULLOK(STRING *value))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+#define ASSERT_ARGS_Parrot_pcc_signature_free __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_pcc_signature_new __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_pcc_signature_num_positionals \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_reset __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_exists_named \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+#define ASSERT_ARGS_Parrot_pcc_signature_get_integer \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_get_integer_named \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+#define ASSERT_ARGS_Parrot_pcc_signature_get_number \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_get_number_named \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+#define ASSERT_ARGS_Parrot_pcc_signature_get_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_get_pmc_named \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+#define ASSERT_ARGS_Parrot_pcc_signature_get_string \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_get_string_named \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+#define ASSERT_ARGS_Parrot_pcc_signature_push_float \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_push_integer \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_push_integer_named \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+#define ASSERT_ARGS_Parrot_pcc_signature_push_number_named \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+#define ASSERT_ARGS_Parrot_pcc_signature_push_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_push_pmc_named \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+#define ASSERT_ARGS_Parrot_pcc_signature_push_string \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_Parrot_pcc_signature_push_string_named \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+/* HEADERIZER END: src/call/signature.c */
+
+#endif
View
823 src/call/signature.c
@@ -0,0 +1,823 @@
+/*
+Copyright (C) 2012, Parrot Foundation.
+
+=head1 NAME
+
+src/call/signature.c
+
+=head1 DESCRIPTION
+
+Signature for encapsulating PCC parameters passing.
+
+=head1 FUNCTIONS
+
+=over 4
+
+=cut
+
+*/
+
+#include "parrot/parrot.h"
+#include "parrot/signature.h"
+
+/* HEADERIZER HFILE: include/parrot/signature.h */
+
+/* HEADERIZER BEGIN: static */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+
+static FLOATVAL autobox_floatval(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+static INTVAL autobox_intval(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CANNOT_RETURN_NULL
+static PMC * autobox_pmc(PARROT_INTERP, ARGIN(Pcc_cell *cell))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CANNOT_RETURN_NULL
+static STRING * autobox_string(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+static void ensure_positionals_storage(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ INTVAL size)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CANNOT_RETURN_NULL
+static Pcc_cell* get_cell_at(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ INTVAL key)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CANNOT_RETURN_NULL
+static Pcc_cell* get_cell_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self),
+ ARGIN(STRING *key))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+PARROT_CANNOT_RETURN_NULL
+static Hash * get_hash(PARROT_INTERP, ARGIN(PMC *SELF))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+static void mark_cell(PARROT_INTERP, ARGIN(Pcc_cell *c))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+static void mark_hash(PARROT_INTERP, ARGIN(Hash *h))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+static void mark_positionals(PARROT_INTERP, ARGIN(Parrot_Signature *self))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+#define ASSERT_ARGS_autobox_floatval __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(cell))
+#define ASSERT_ARGS_autobox_intval __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(cell))
+#define ASSERT_ARGS_autobox_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(cell))
+#define ASSERT_ARGS_autobox_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(cell))
+#define ASSERT_ARGS_ensure_positionals_storage __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_get_cell_at __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_get_cell_named __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self) \
+ , PARROT_ASSERT_ARG(key))
+#define ASSERT_ARGS_get_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(SELF))
+#define ASSERT_ARGS_mark_cell __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(c))
+#define ASSERT_ARGS_mark_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(h))
+#define ASSERT_ARGS_mark_positionals __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(self))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+/* HEADERIZER END: static */
+
+/*
+=item C<Parrot_Signature* Parrot_pcc_signature_new(PARROT_INTERP)>
+
+Allocate new Signature. Caller mast call C<Parrot_pcc_signature_free>
+to free resources.
+
+=cut
+*/
+
+PARROT_EXPORT
+PARROT_CANNOT_RETURN_NULL
+Parrot_Signature*
+Parrot_pcc_signature_new(PARROT_INTERP)
+{
+ Parrot_Signature *sig = (Parrot_Signature *)Parrot_gc_allocate_fixed_size_storage(interp, sizeof(Parrot_Signature));
+ memset(sig, 1, sizeof (Parrot_Signature));
+
+ return sig;
+}
+
+/*
+=item C<void Parrot_pcc_signature_free(PARROT_INTERP, Parrot_Signature *self)>
+
+Free Signature
+
+=cut
+*/
+
+PARROT_EXPORT
+void
+Parrot_pcc_signature_free(PARROT_INTERP, ARGFREE(Parrot_Signature *self))
+{
+ if (self->allocated_positionals) {
+ Pcc_cell *c;
+
+ if (self->allocated_positionals > 8)
+ Parrot_gc_free_memory_chunk(interp, self->positionals);
+ else
+ Parrot_gc_free_fixed_size_storage(interp,
+ self->allocated_positionals * sizeof (Pcc_cell), self->positionals);
+ }
+
+ if (self->hash) {
+ parrot_hash_iterate(self->hash,
+ FREE_CELL(interp, (Pcc_cell *)_bucket->value););
+ Parrot_hash_destroy(interp, self->hash);
+ }
+
+ Parrot_gc_free_fixed_size_storage(interp, sizeof(Parrot_Signature), self);
+}
+
+/*
+=item C<void Parrot_pcc_signature_reset(PARROT_INTERP, Parrot_Signature *self)>
+
+Reset Signature for reuse.
+
+=cut
+*/
+PARROT_EXPORT
+void
+Parrot_pcc_signature_reset(PARROT_INTERP, ARGIN(Parrot_Signature *self))
+{
+ /* Don't free positionals. Just reuse them */
+ self->num_positionals = 0;
+
+ if (self->hash) {
+ parrot_hash_iterate(self->hash,
+ FREE_CELL(interp, (Pcc_cell *)_bucket->value););
+ Parrot_hash_destroy(interp, self->hash);
+ self->hash = NULL;
+ }
+}
+
+/*
+=item C<INTVAL Parrot_pcc_signature_num_positionals(PARROT_INTERP,
+Parrot_Signature *self)>
+
+Get number of positional arguments.
+
+=cut
+*/
+
+PARROT_EXPORT
+INTVAL
+Parrot_pcc_signature_num_positionals(PARROT_INTERP, ARGIN(Parrot_Signature *self))
+{
+ return self->num_positionals;
+}
+
+/*
+=back
+
+=head1 ACCESSOR FUNCTIONS
+
+=over 4
+
+=item C<void Parrot_pcc_signature_push_integer(PARROT_INTERP, Parrot_Signature
+*self, INTVAL value)>
+
+=item C<void Parrot_pcc_signature_push_float(PARROT_INTERP, Parrot_Signature
+*self, FLOATVAL value)>
+
+=item C<void Parrot_pcc_signature_push_string(PARROT_INTERP, Parrot_Signature
+*self, STRING *value)>
+
+=item C<void Parrot_pcc_signature_push_pmc(PARROT_INTERP, Parrot_Signature
+*self, PMC *value)>
+
+Append positional parameter to Signature.
+
+=cut
+*/
+
+
+void
+Parrot_pcc_signature_push_integer(PARROT_INTERP, ARGIN(Parrot_Signature *self),
+ INTVAL value)
+{
+ INTVAL num_pos = self->num_positionals;
+
+ ensure_positionals_storage(interp, self, num_pos + 1);
+
+ self->positionals[num_pos].u.i = value;
+ self->positionals[num_pos].type = INTCELL;
+ self->num_positionals++;
+}
+
+void
+Parrot_pcc_signature_push_float(PARROT_INTERP, ARGIN(Parrot_Signature *self),
+ FLOATVAL value)
+{
+ INTVAL num_pos = self->num_positionals;
+
+ ensure_positionals_storage(interp, self, num_pos + 1);
+
+ self->positionals[num_pos].u.n = value;
+ self->positionals[num_pos].type = FLOATCELL;
+ self->num_positionals++;
+}
+
+void
+Parrot_pcc_signature_push_string(PARROT_INTERP, ARGIN(Parrot_Signature *self),
+ ARGIN_NULLOK(STRING *value))
+{
+ INTVAL num_pos = self->num_positionals;
+
+ ensure_positionals_storage(interp, self, num_pos + 1);
+
+ self->positionals[num_pos].u.s = value;
+ self->positionals[num_pos].type = STRINGCELL;
+ self->num_positionals++;
+}
+
+void
+Parrot_pcc_signature_push_pmc(PARROT_INTERP, ARGIN(Parrot_Signature *self),
+ ARGIN_NULLOK(PMC *value))
+{
+ INTVAL num_pos = self->num_positionals;
+
+ PARROT_ASSERT(!PObj_on_free_list_TEST(value)
+ || !"Push dead object into CallContext!");
+
+
+ ensure_positionals_storage(interp, self, num_pos + 1);
+
+ self->positionals[num_pos].u.p = value;
+ self->positionals[num_pos].type = PMCCELL;
+ self->num_positionals++;
+}
+
+/*
+=item C<INTVAL Parrot_pcc_signature_get_integer(PARROT_INTERP, Parrot_Signature
+*self, INTVAL key)>
+
+=item C<FLOATVAL Parrot_pcc_signature_get_number(PARROT_INTERP, Parrot_Signature
+*self, INTVAL key)>
+
+=item C<STRING* Parrot_pcc_signature_get_string(PARROT_INTERP, Parrot_Signature
+*self, INTVAL key)>
+
+=item C<PMC* Parrot_pcc_signature_get_pmc(PARROT_INTERP, Parrot_Signature *self,
+INTVAL key)>
+
+Get positional argument at position with autoboxing.
+
+=cut
+*/
+
+INTVAL
+Parrot_pcc_signature_get_integer(PARROT_INTERP, ARGIN(Parrot_Signature *self),
+ INTVAL key)
+{
+ if (key >= self->num_positionals || key < 0)
+ return 0;
+
+ return autobox_intval(interp, &self->positionals[key]);
+}
+
+FLOATVAL
+Parrot_pcc_signature_get_number(PARROT_INTERP, ARGIN(Parrot_Signature *self),
+ INTVAL key)
+{
+ if (key >= self->num_positionals || key < 0)
+ return 0.0;
+
+ return autobox_floatval(interp, &self->positionals[key]);
+}
+
+PARROT_CAN_RETURN_NULL
+STRING*
+Parrot_pcc_signature_get_string(PARROT_INTERP, ARGIN(Parrot_Signature *self),
+ INTVAL key)
+{
+ if (key >= self->num_positionals || key < 0)
+ return STRINGNULL;
+
+ return autobox_string(interp, &self->positionals[key]);
+}
+
+PARROT_CAN_RETURN_NULL
+PMC*
+Parrot_pcc_signature_get_pmc(PARROT_INTERP, ARGIN(Parrot_Signature *self),
+ INTVAL key)
+{
+ if (key >= self->num_positionals || key < 0)
+ return PMCNULL;
+
+ return autobox_pmc(interp, &self->positionals[key]);
+}
+
+
+/*
+=item C<void Parrot_pcc_signature_push_integer_named(PARROT_INTERP,
+Parrot_Signature *self, STRING *key, INTVAL value)>
+
+=item C<void Parrot_pcc_signature_push_number_named(PARROT_INTERP,
+Parrot_Signature *self, STRING *key, FLOATVAL value)>
+
+=item C<void Parrot_pcc_signature_push_string_named(PARROT_INTERP,
+Parrot_Signature *self, STRING *key, STRING *value)>
+
+=item C<void Parrot_pcc_signature_push_pmc_named(PARROT_INTERP, Parrot_Signature
+*self, STRING *key, PMC *value)>
+
+Append single named parameter to Signature.
+
+=cut
+*/
+
+void
+Parrot_pcc_signature_push_integer_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self), ARGIN(STRING *key), INTVAL value)
+{
+ Pcc_cell *cell = get_cell_named(interp, self, key);
+
+ cell->u.i = value;
+ cell->type = INTCELL;
+}
+
+void
+Parrot_pcc_signature_push_number_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self), ARGIN(STRING *key), FLOATVAL value)
+{
+ Pcc_cell *cell = get_cell_named(interp, self, key);
+
+ cell->u.n = value;
+ cell->type = FLOATCELL;
+}
+
+void
+Parrot_pcc_signature_push_string_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self), ARGIN(STRING *key), ARGIN_NULLOK(STRING *value))
+{
+ Pcc_cell *cell = get_cell_named(interp, self, key);
+
+ cell->u.s = value;
+ cell->type = STRINGCELL;
+}
+
+void
+Parrot_pcc_signature_push_pmc_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self), ARGIN(STRING *key), ARGIN_NULLOK(PMC *value))
+{
+ Pcc_cell *cell = get_cell_named(interp, self, key);
+
+ cell->u.p = value;
+ cell->type = PMCCELL;
+}
+
+/*
+=item C<INTVAL Parrot_pcc_signature_get_integer_named(PARROT_INTERP,
+Parrot_Signature *self, STRING *key)>
+
+=item C<FLOATVAL Parrot_pcc_signature_get_number_named(PARROT_INTERP,
+Parrot_Signature *self, STRING *key)>
+
+=item C<STRING * Parrot_pcc_signature_get_string_named(PARROT_INTERP,
+Parrot_Signature *self, STRING *key)>
+
+=item C<PMC * Parrot_pcc_signature_get_pmc_named(PARROT_INTERP, Parrot_Signature
+*self, STRING *key)>
+
+Get single named parameter with autoboxing.
+
+=cut
+*/
+
+INTVAL
+Parrot_pcc_signature_get_integer_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self), ARGIN(STRING *key))
+{
+ if (self->hash) {
+ void * const k = Parrot_hash_key_from_string(interp, self->hash, key);
+ Pcc_cell * const cell = (Pcc_cell *)Parrot_hash_get(interp, self->hash, k);
+
+ if (cell) {
+ if (CELL_TYPE_MASK(cell) == INTCELL)
+ return CELL_INT(cell);
+
+ return autobox_intval(interp, cell);
+ }
+ }
+
+ return 0;
+}
+
+FLOATVAL
+Parrot_pcc_signature_get_number_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self), ARGIN(STRING *key))
+{
+ if (self->hash) {
+ void * const k = Parrot_hash_key_from_string(interp, self->hash, key);
+ Pcc_cell * const cell = (Pcc_cell *)Parrot_hash_get(interp, self->hash, k);
+
+ if (cell)
+ return autobox_floatval(interp, cell);
+ }
+
+ return 0.0;
+}
+
+PARROT_CAN_RETURN_NULL
+STRING *
+Parrot_pcc_signature_get_string_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self), ARGIN(STRING *key))
+{
+ if (self->hash) {
+ void * const k = Parrot_hash_key_from_string(interp, self->hash, key);
+ Pcc_cell * const cell = (Pcc_cell *)Parrot_hash_get(interp, self->hash, k);
+
+ if (cell)
+ return autobox_string(interp, cell);
+ }
+
+ return STRINGNULL;
+}
+
+PARROT_CAN_RETURN_NULL
+PMC *
+Parrot_pcc_signature_get_pmc_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self), ARGIN(STRING *key))
+{
+ if (self->hash) {
+ void * const k = Parrot_hash_key_from_string(interp, self->hash, key);
+ Pcc_cell * const cell = (Pcc_cell *)Parrot_hash_get(interp, self->hash, k);
+
+ if (cell) {
+ if (CELL_TYPE_MASK(cell) == PMCCELL)
+ return CELL_PMC(cell);
+
+ return autobox_pmc(interp, cell);
+ }
+ }
+
+ return PMCNULL;
+}
+
+/*
+=item C<INTVAL Parrot_pcc_signature_exists_named(PARROT_INTERP, Parrot_Signature
+*self, STRING *key)>
+
+Check named parameter for existance.
+
+=cut
+*/
+
+INTVAL
+Parrot_pcc_signature_exists_named(PARROT_INTERP,
+ ARGIN(Parrot_Signature *self), ARGIN(STRING *key))
+{
+ if (self->hash) {
+ void * const k = Parrot_hash_key_from_string(interp, self->hash, key);
+
+ return Parrot_hash_exists(interp, self->hash, k);
+ }
+
+ return 0;
+}
+
+/*
+
+=back
+
+=head1 INTERNAL FUNCTIONS
+
+=over 4
+
+=item C<static void ensure_positionals_storage(PARROT_INTERP, Parrot_Signature
+*self, INTVAL size)>
+
+Ensure that we have enough space to store C<size> amount of positional elements.
+
+=cut
+
+*/
+
+static void
+ensure_positionals_storage(PARROT_INTERP, ARGIN(Parrot_Signature *self), INTVAL size)
+{
+ ASSERT_ARGS(ensure_positionals_storage)
+ Pcc_cell *new_array;
+
+ if (size <= self->allocated_positionals)
+ return;
+
+ if (size < 8)
+ size = 8;
+
+ 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 (self->positionals) {
+ memcpy(new_array, self->positionals, self->num_positionals * sizeof (Pcc_cell));
+
+ if (self->allocated_positionals > 8)
+ Parrot_gc_free_memory_chunk(interp, self->positionals);
+ else
+ Parrot_gc_free_fixed_size_storage(interp,
+ self->allocated_positionals * sizeof (Pcc_cell), self->positionals);
+ }
+
+ self->allocated_positionals = size;
+ self->positionals = new_array;
+}
+
+/*
+=item C<static Pcc_cell* get_cell_at(PARROT_INTERP, Parrot_Signature *self,
+INTVAL key)>
+
+=item C<static Pcc_cell* get_cell_named(PARROT_INTERP, Parrot_Signature *self,
+STRING *key)>
+
+Get cell at index with reallocating if nessesary.
+
+=cut
+*/
+
+PARROT_CANNOT_RETURN_NULL
+static Pcc_cell*
+get_cell_at(PARROT_INTERP, ARGIN(Parrot_Signature *self), INTVAL key)
+{
+ ASSERT_ARGS(get_cell_at)
+ ensure_positionals_storage(interp, self, key + 1);
+ return &self->positionals[key];
+}
+
+PARROT_CANNOT_RETURN_NULL
+static Pcc_cell*
+get_cell_named(PARROT_INTERP, ARGIN(Parrot_Signature *self), ARGIN(STRING *key))
+{
+ ASSERT_ARGS(get_cell_named)
+ Pcc_cell *cell = (Pcc_cell *)Parrot_hash_get(interp, self->hash, (void *)key);
+
+ if (!cell) {
+ cell = ALLOC_CELL(interp);
+ Parrot_hash_put(interp, self->hash, (void *)key, (void *)cell);
+ }
+
+ return cell;
+}
+
+
+/*
+=item C<static INTVAL autobox_intval(PARROT_INTERP, const Pcc_cell *cell)>
+
+=item C<static STRING * autobox_string(PARROT_INTERP, const Pcc_cell *cell)>
+
+=item C<static FLOATVAL autobox_floatval(PARROT_INTERP, const Pcc_cell *cell)>
+
+=item C<static PMC * autobox_pmc(PARROT_INTERP, Pcc_cell *cell)>
+
+Autobox stored value to required value.
+
+=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;
+}
+
+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;
+}
+
+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;
+}
+
+PARROT_CANNOT_RETURN_NULL
+static PMC *
+autobox_pmc(PARROT_INTERP, ARGIN(Pcc_cell *cell))
+{
+ ASSERT_ARGS(autobox_pmc)
+ PMC *result = PMCNULL;
+
+ switch (CELL_TYPE_MASK(cell)) {
+ case INTCELL:
+ result = Parrot_pmc_box_integer(interp, CELL_INT(cell));
+ break;
+ case FLOATCELL:
+ result = Parrot_pmc_box_number(interp, 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)>
+
+Lazily allocated Hash for named parameters.
+
+=cut
+*/
+
+PARROT_CANNOT_RETURN_NULL
+static Hash *
+get_hash(PARROT_INTERP, ARGIN(PMC *SELF))
+{
+ ASSERT_ARGS(get_hash)
+ Hash *hash;
+
+ GETATTR_CallContext_hash(interp, SELF, hash);
+
+ if (!hash) {
+ hash = Parrot_hash_create(interp,
+ enum_type_ptr,
+ Hash_key_type_STRING);
+
+ SETATTR_CallContext_hash(interp, SELF, hash);
+ }
+
+ return hash;
+}
+
+/*
+=item C<static void mark_cell(PARROT_INTERP, Pcc_cell *c)>
+
+Helper function for marking.
+
+=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, Parrot_Signature *self)>
+
+Helper function to mark positional arguments.
+
+=cut
+*/
+
+static void
+mark_positionals(PARROT_INTERP, ARGIN(Parrot_Signature *self))
+{
+ ASSERT_ARGS(mark_positionals)
+ INTVAL i;
+
+ for (i = 0; i < self->num_positionals; ++i)
+ mark_cell(interp, &self->positionals[i]);
+}
+
+/*
+=item C<static void mark_hash(PARROT_INTERP, Hash *h)>
+
+Helper to mark named parameters.
+
+=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););
+}
+
+
+/*
+
+=back
+
+=head1 SEE ALSO
+
+F<include/parrot/call.h>, F<src/call/ops.c>, F<src/call/pcc.c>.
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+ */
View
2  src/ops/core.ops
@@ -479,7 +479,7 @@ op set_args(inconst PMC) :flow {
opcode_t * const raw_args = CUR_OPCODE;
PMC * const signature = $1;
PMC * const call_sig = Parrot_pcc_build_sig_object_from_op(interp,
- PMCNULL, signature, raw_args);
+ CURRENT_CONTEXT(interp), signature, raw_args);
INTVAL argc;
GETATTR_FixedIntegerArray_size(interp, signature, argc);
Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), call_sig);
View
2  src/ops/core_ops.c
@@ -13767,7 +13767,7 @@ opcode_t *
Parrot_set_args_pc(opcode_t *cur_opcode, PARROT_INTERP) {
opcode_t * const raw_args = CUR_OPCODE;
PMC * const signature = PCONST(1);
- PMC * const call_sig = Parrot_pcc_build_sig_object_from_op(interp, PMCNULL, signature, raw_args);
+ PMC * const call_sig = Parrot_pcc_build_sig_object_from_op(interp, CURRENT_CONTEXT(interp), signature, raw_args);
INTVAL argc;
GETATTR_FixedIntegerArray_size(interp, signature, argc);
View
482 src/pmc/callcontext.pmc
@@ -18,489 +18,25 @@ information for a multiple dispatch call.
*/
-typedef struct Pcc_cell
-{
- union u {
- PMC *p;
- STRING *s;
- INTVAL i;
- FLOATVAL n;
- } u;
- INTVAL type;
-} Pcc_cell;
-
-#define NOCELL 0
-#define INTCELL 1
-#define FLOATCELL 2
-#define STRINGCELL 3
-#define PMCCELL 4
-
-#define ALLOC_CELL(i) \
- (Pcc_cell *)Parrot_gc_allocate_fixed_size_storage((i), sizeof (Pcc_cell))
-
-#define FREE_CELL(i, c) \
- Parrot_gc_free_fixed_size_storage((i), sizeof (Pcc_cell), (c))
-
-#define CLONE_CELL(i, c, c_new) do { \
- (c_new) = ALLOC_CELL(i); \
- *(c_new) = *(c); \
-} while (0)
-
-#define CELL_TYPE_MASK(c) (c)->type
-
-#define CELL_INT(c) (c)->u.i
-#define CELL_FLOAT(c) (c)->u.n
-#define CELL_STRING(c) (c)->u.s
-#define CELL_PMC(c) (c)->u.p
-
-#define HLL_TYPE(i) Parrot_hll_get_ctx_HLL_type(interp, (i))
-
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-static FLOATVAL autobox_floatval(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-static INTVAL autobox_intval(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_CANNOT_RETURN_NULL
-static PMC * autobox_pmc(PARROT_INTERP, ARGIN(Pcc_cell *cell), INTVAL type)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_CANNOT_RETURN_NULL
-static STRING * autobox_string(PARROT_INTERP, ARGIN(const Pcc_cell *cell))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-static void ensure_positionals_storage(PARROT_INTERP,
- ARGIN(PMC *self),
- INTVAL size)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-static void ensure_positionals_storage_ap(PARROT_INTERP,
- ARGIN(PMC *self),
- INTVAL size,
- INTVAL allocated_positionals)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_CANNOT_RETURN_NULL
-static Pcc_cell* get_cell_at(PARROT_INTERP, ARGIN(PMC *self), INTVAL key)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_CANNOT_RETURN_NULL
-static Hash * get_hash(PARROT_INTERP, ARGIN(PMC *SELF))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_CAN_RETURN_NULL
-static PMC * get_named_names(PARROT_INTERP, ARGIN(PMC *SELF))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-static void mark_cell(PARROT_INTERP, ARGIN(Pcc_cell *c))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-static void mark_hash(PARROT_INTERP, ARGIN(Hash *h))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-static void mark_positionals(PARROT_INTERP, ARGIN(PMC *self))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-#define ASSERT_ARGS_autobox_floatval __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(cell))
-#define ASSERT_ARGS_autobox_intval __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(cell))
-#define ASSERT_ARGS_autobox_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(cell))
-#define ASSERT_ARGS_autobox_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(cell))
-#define ASSERT_ARGS_ensure_positionals_storage __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(self))
-#define ASSERT_ARGS_ensure_positionals_storage_ap __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(self))
-#define ASSERT_ARGS_get_cell_at __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(self))
-#define ASSERT_ARGS_get_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(SELF))
-#define ASSERT_ARGS_get_named_names __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(SELF))
-#define ASSERT_ARGS_mark_cell __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(c))
-#define ASSERT_ARGS_mark_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(h))
-#define ASSERT_ARGS_mark_positionals __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(self))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
-/*
-
-=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_CallContext_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_CallContext_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_CallContext_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_CallContext_allocated_positionals(interp, self, size);
- SETATTR_CallContext_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_CallContext_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_CallContext_hash(interp, SELF, hash);
-
- if (!hash) {
- hash = Parrot_hash_create(interp,
- enum_type_ptr,
- Hash_key_type_STRING);
-
- SETATTR_CallContext_hash(interp, SELF, hash);
- }
- return hash;
-}
+BEGIN_PMC_HEADER_PREAMBLE
-/*
-
-=item C<static void mark_cell(PARROT_INTERP, Pcc_cell *c)>
-
-=cut
+#include "parrot/signature.h"
-*/
-
-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;
- }
+END_PMC_HEADER_PREAMBLE
-}
-
-/*
-
-=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_CallContext_num_positionals(interp, self, size);
-
- if (size) {
- Pcc_cell *cells;
- INTVAL i;
- GETATTR_CallContext_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_CallContext_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;
-}
#include "parrot/packfile.h"
#include "pmc/pmc_sub.h"
+
pmclass CallContext provides array provides hash auto_attrs {
/* Context attributes */
ATTR PMC *caller_ctx; /* caller context */
@@ -537,15 +73,7 @@ pmclass CallContext provides array provides hash auto_attrs {
ATTR UINTVAL recursion_depth; /* Sub call recursion depth */
/* 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 */
+ ATTR Parrot_Signature *signature;
ATTR PMC *continuation; /* Reusable continuation */
View
12 src/pmc/sub.pmc
@@ -380,7 +380,8 @@ Invokes the subroutine.
/* plain subroutine call
* create new context, place it in interpreter */
- PMC *context = Parrot_pcc_get_signature(INTERP, caller_ctx);
+ PMC *signature = Parrot_pcc_get_signature(INTERP, caller_ctx);
+ PMC *context = Parrot_pmc_new(INTERP, enum_class_CallContext);
Parrot_Sub_attributes *sub;
opcode_t *pc;
@@ -416,9 +417,6 @@ Invokes the subroutine.
PARROT_ASSERT(!PMC_IS_NULL(ccont));
- if (PMC_IS_NULL(context))
- context = Parrot_pmc_new(INTERP, enum_class_CallContext);
-
Parrot_pcc_set_context(INTERP, context);
Parrot_pcc_set_caller_ctx(INTERP, context, caller_ctx);
@@ -427,8 +425,10 @@ Invokes the subroutine.
Parrot_pcc_free_registers(INTERP, context);
Parrot_pcc_allocate_registers(INTERP, context, sub->n_regs_used);
- /* Preserve object */
- object = Parrot_pcc_get_object(INTERP, context);
+ /* Preserve object. If any. XXX We should always have it... */
+ if (!PMC_IS_NULL(signature))
+ object = Parrot_pcc_get_object(INTERP, signature);
+
Parrot_pcc_init_context(INTERP, context, caller_ctx);
Parrot_pcc_set_object(INTERP, context, object);

No commit comments for this range

Something went wrong with that request. Please try again.