Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/branches/context_pmc2@40654 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
bacek committed Aug 19, 2009
1 parent cc38a62 commit 852012c
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 163 deletions.
52 changes: 25 additions & 27 deletions include/parrot/call.h
Expand Up @@ -51,7 +51,7 @@ typedef struct call_state_item {
} op;
} u;

Parrot_Context *ctx; /* the source or destination context */
PMC *ctx; /* the source or destination context */
INTVAL used; /* src: whether this argument has been consumed
* (or: whether the previous arg has?) */
INTVAL i; /* number of args/params already processed */
Expand Down Expand Up @@ -111,7 +111,7 @@ int Parrot_fetch_arg_nci(PARROT_INTERP, ARGMOD(call_state *st))

PARROT_EXPORT
int Parrot_init_arg_indexes_and_sig_pmc(PARROT_INTERP,
ARGIN(Parrot_Context *ctx),
ARGIN(PMC *pmcctx),
ARGIN_NULLOK(opcode_t *indexes),
ARGIN_NULLOK(PMC *sig_pmc),
ARGMOD(call_state_item *sti))
Expand All @@ -131,7 +131,7 @@ void Parrot_init_arg_nci(PARROT_INTERP,

PARROT_EXPORT
int Parrot_init_arg_op(PARROT_INTERP,
ARGIN(Parrot_Context *ctx),
ARGIN(PMC *pmcctx),
ARGIN_NULLOK(opcode_t *pc),
ARGIN(call_state_item *sti))
__attribute__nonnull__(1)
Expand All @@ -140,7 +140,7 @@ int Parrot_init_arg_op(PARROT_INTERP,

PARROT_EXPORT
int Parrot_init_arg_sig(PARROT_INTERP,
ARGIN(Parrot_Context *ctx),
ARGIN(PMC *pmcctx),
ARGIN(const char *sig),
ARGIN_NULLOK(void *ap),
ARGMOD(call_state_item *sti))
Expand All @@ -161,16 +161,16 @@ void Parrot_init_ret_nci(PARROT_INTERP,

PARROT_EXPORT
void parrot_pass_args(PARROT_INTERP,
ARGMOD(Parrot_Context *src_ctx),
ARGMOD(Parrot_Context *dest_ctx),
ARGMOD(PMC *src_pmcctx),
ARGMOD(PMC *dest_pmcctx),
ARGMOD_NULLOK(opcode_t *src_indexes),
ARGMOD_NULLOK(opcode_t *dest_indexes),
arg_pass_t param_or_result)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3)
FUNC_MODIFIES(*src_ctx)
FUNC_MODIFIES(*dest_ctx)
FUNC_MODIFIES(*src_pmcctx)
FUNC_MODIFIES(*dest_pmcctx)
FUNC_MODIFIES(*src_indexes)
FUNC_MODIFIES(*dest_indexes);

Expand Down Expand Up @@ -242,7 +242,7 @@ PARROT_WARN_UNUSED_RESULT
opcode_t * parrot_pass_args_fromc(PARROT_INTERP,
ARGIN(const char *sig),
ARGMOD(opcode_t *dest),
ARGIN(Parrot_Context *old_ctxp),
ARGIN(PMC *old_ctxp),
va_list ap)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
Expand All @@ -252,29 +252,27 @@ opcode_t * parrot_pass_args_fromc(PARROT_INTERP,

PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
void * set_retval(PARROT_INTERP, int sig_ret, ARGIN(Parrot_Context *ctx))
void * set_retval(PARROT_INTERP, int sig_ret, ARGIN(PMC *pmcctx))
__attribute__nonnull__(1)
__attribute__nonnull__(3);

FLOATVAL set_retval_f(PARROT_INTERP,
int sig_ret,
ARGIN(Parrot_Context *ctx))
FLOATVAL set_retval_f(PARROT_INTERP, int sig_ret, ARGIN(PMC *pmcctx))
__attribute__nonnull__(1)
__attribute__nonnull__(3);

INTVAL set_retval_i(PARROT_INTERP, int sig_ret, ARGIN(Parrot_Context *ctx))
INTVAL set_retval_i(PARROT_INTERP, int sig_ret, ARGIN(PMC *pmcctx))
__attribute__nonnull__(1)
__attribute__nonnull__(3);

PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC* set_retval_p(PARROT_INTERP, int sig_ret, ARGIN(Parrot_Context *ctx))
PMC* set_retval_p(PARROT_INTERP, int sig_ret, ARGIN(PMC *pmcctx))
__attribute__nonnull__(1)
__attribute__nonnull__(3);

PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
STRING* set_retval_s(PARROT_INTERP, int sig_ret, ARGIN(Parrot_Context *ctx))
STRING* set_retval_s(PARROT_INTERP, int sig_ret, ARGIN(PMC *pmcctx))
__attribute__nonnull__(1)
__attribute__nonnull__(3);

Expand All @@ -290,19 +288,19 @@ STRING* set_retval_s(PARROT_INTERP, int sig_ret, ARGIN(Parrot_Context *ctx))
#define ASSERT_ARGS_Parrot_init_arg_indexes_and_sig_pmc \
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx) \
|| PARROT_ASSERT_ARG(pmcctx) \
|| PARROT_ASSERT_ARG(sti)
#define ASSERT_ARGS_Parrot_init_arg_nci __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(st) \
|| PARROT_ASSERT_ARG(sig)
#define ASSERT_ARGS_Parrot_init_arg_op __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx) \
|| PARROT_ASSERT_ARG(pmcctx) \
|| PARROT_ASSERT_ARG(sti)
#define ASSERT_ARGS_Parrot_init_arg_sig __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx) \
|| PARROT_ASSERT_ARG(pmcctx) \
|| PARROT_ASSERT_ARG(sig) \
|| PARROT_ASSERT_ARG(sti)
#define ASSERT_ARGS_Parrot_init_ret_nci __attribute__unused__ int _ASSERT_ARGS_CHECK = \
Expand All @@ -311,8 +309,8 @@ STRING* set_retval_s(PARROT_INTERP, int sig_ret, ARGIN(Parrot_Context *ctx))
|| PARROT_ASSERT_ARG(sig)
#define ASSERT_ARGS_parrot_pass_args __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(src_ctx) \
|| PARROT_ASSERT_ARG(dest_ctx)
|| PARROT_ASSERT_ARG(src_pmcctx) \
|| PARROT_ASSERT_ARG(dest_pmcctx)
#define ASSERT_ARGS_Parrot_pcc_build_sig_object_from_varargs \
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
Expand Down Expand Up @@ -350,19 +348,19 @@ STRING* set_retval_s(PARROT_INTERP, int sig_ret, ARGIN(Parrot_Context *ctx))
|| PARROT_ASSERT_ARG(old_ctxp)
#define ASSERT_ARGS_set_retval __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
|| PARROT_ASSERT_ARG(pmcctx)
#define ASSERT_ARGS_set_retval_f __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
|| PARROT_ASSERT_ARG(pmcctx)
#define ASSERT_ARGS_set_retval_i __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
|| PARROT_ASSERT_ARG(pmcctx)
#define ASSERT_ARGS_set_retval_p __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
|| PARROT_ASSERT_ARG(pmcctx)
#define ASSERT_ARGS_set_retval_s __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
|| PARROT_ASSERT_ARG(pmcctx)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/call/pcc.c */

Expand Down Expand Up @@ -475,7 +473,7 @@ Parrot_run_meth_fromc_args_reti(PARROT_INTERP,
PARROT_EXPORT
PARROT_IGNORABLE_RESULT
PARROT_CANNOT_RETURN_NULL
Parrot_Context * Parrot_runops_fromc(PARROT_INTERP, ARGIN(PMC *sub))
PMC * Parrot_runops_fromc(PARROT_INTERP, ARGIN(PMC *sub))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

Expand Down
40 changes: 0 additions & 40 deletions include/parrot/interpreter.h
Expand Up @@ -193,46 +193,6 @@ typedef union {
*/
#define CTX_LEAK_DEBUG 1

struct Parrot_Context {
/* common header with Interp_Context */
PMC *caller_ctx; /* caller context */
Regs_ni bp; /* pointers to FLOATVAL & INTVAL */
Regs_ps bp_ps; /* pointers to PMC & STR */

/* end common header */
INTVAL n_regs_used[4]; /* INSP in PBC points to Sub */
PMC *lex_pad; /* LexPad PMC */
PMC *outer_ctx; /* outer context, if a closure */

/* new call scheme and introspective variables */
PMC *current_sub; /* the Sub we are executing */

/* for now use a return continuation PMC */
PMC *handlers; /* local handlers for the context */
PMC *current_cont; /* the return continuation PMC */
PMC *current_object; /* current object if a method call */
PMC *current_namespace; /* The namespace we're currently in */
PMC *results_signature; /* non-const results signature PMC */
opcode_t *current_pc; /* program counter of Sub invocation */
opcode_t *current_results; /* ptr into code with get_results opcode */

/* deref the constants - we need it all the time */
struct PackFile_Constant **constants;

INTVAL current_HLL; /* see also src/hll.c */
size_t regs_mem_size; /* memory occupied by registers */

UINTVAL warns; /* Keeps track of what warnings
* have been activated */
UINTVAL errors; /* fatals that can be turned off */
UINTVAL trace_flags;
UINTVAL recursion_depth; /* Sub call recursion depth */

/* code->prederefed.code - code->base.data in opcodes
* to simplify conversion between code ptrs in e.g. invoke */
size_t pred_offset;
};

struct _Thread_data; /* in thread.h */
struct _Caches; /* caches .h */

Expand Down
16 changes: 12 additions & 4 deletions include/parrot/register.h
Expand Up @@ -58,8 +58,8 @@
(__CTX->n_regs_used[REGNO_PMC] - 1L - (x)))
#define REG_OFFS_STR(x) (sizeof (STRING*) * (x) + _SIZEOF_INTS + _SIZEOF_PMCS)


typedef struct Parrot_Context Parrot_Context; /* parrot/interpreter.h */
/* Forward declaration of Context PMC attributes */
typedef struct Parrot_Context_attributes Parrot_Context_attributes;

/* HEADERIZER BEGIN: src/gc/alloc_register.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
Expand Down Expand Up @@ -98,7 +98,7 @@ PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC * Parrot_alloc_context(PARROT_INTERP,
ARGIN(const INTVAL *number_regs_used),
ARGIN_NULLOK(Parrot_Context *old))
ARGIN_NULLOK(PMC *old))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

Expand All @@ -109,8 +109,13 @@ FLOATVAL * Parrot_ctx_FLOATVAL_reg(PARROT_INTERP,
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ctx_get_caller(PARROT_INTERP, ARGIN(PMC *ctx))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

PARROT_CAN_RETURN_NULL
Parrot_Context * Parrot_ctx_get_context_struct(PARROT_INTERP,
Parrot_Context_attributes * Parrot_ctx_get_context_struct(PARROT_INTERP,
ARGIN(PMC * context))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
Expand Down Expand Up @@ -158,6 +163,9 @@ PMC * Parrot_set_new_context(PARROT_INTERP,
#define ASSERT_ARGS_Parrot_ctx_FLOATVAL_reg __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
#define ASSERT_ARGS_Parrot_ctx_get_caller __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
#define ASSERT_ARGS_Parrot_ctx_get_context_struct __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(context)
Expand Down
25 changes: 12 additions & 13 deletions include/parrot/sub.h
Expand Up @@ -159,12 +159,12 @@ typedef struct Parrot_sub {
PMC *lex_info; /* LexInfo PMC */
PMC *outer_sub; /* :outer for closures */
PMC *eval_pmc; /* eval container / NULL */
Parrot_Context *ctx; /* the context this sub is in */
PMC *ctx; /* the context this sub is in */
UINTVAL comp_flags; /* compile time and additional flags */
Parrot_sub_arginfo *arg_info;/* Argument counts and flags. */

/* - end common */
struct Parrot_Context *outer_ctx; /* outer context, if a closure */
PMC *outer_ctx; /* outer context, if a closure */
} Parrot_sub;

#define PMC_get_sub(interp, pmc, sub) \
Expand Down Expand Up @@ -206,7 +206,7 @@ typedef struct Parrot_coro {
PMC *lex_info; /* LexInfo PMC */
PMC *outer_sub; /* :outer for closures */
PMC *eval_pmc; /* eval container / NULL */
struct Parrot_Context *ctx; /* coroutine context */
PMC *ctx; /* coroutine context */
UINTVAL comp_flags; /* compile time and additional flags */
Parrot_sub_arginfo arg_info; /* Argument counts and flags. */

Expand All @@ -219,10 +219,10 @@ typedef struct Parrot_coro {
typedef struct Parrot_cont {
/* continuation destination */
PackFile_ByteCode *seg; /* bytecode segment */
opcode_t *address; /* start of bytecode, addr to continue */
struct Parrot_Context *to_ctx; /* pointer to dest context */
opcode_t *address; /* start of bytecode, addr to continue */
PMC *to_ctx; /* pointer to dest context */
/* a Continuation keeps the from_ctx alive */
struct Parrot_Context *from_ctx; /* sub, this cont is returning from */
PMC *from_ctx; /* sub, this cont is returning from */
opcode_t *current_results; /* ptr into code with get_results opcode
full continuation only */
int runloop_id; /* id of the creating runloop. */
Expand Down Expand Up @@ -253,7 +253,7 @@ PMC * new_ret_continuation_pmc(PARROT_INTERP,

PARROT_EXPORT
int Parrot_Context_get_info(PARROT_INTERP,
ARGIN(const Parrot_Context *ctx),
ARGIN(const PMC *pmcctx),
ARGOUT(Parrot_Context_info *info))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
Expand All @@ -263,8 +263,7 @@ int Parrot_Context_get_info(PARROT_INTERP,
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
STRING* Parrot_Context_infostr(PARROT_INTERP,
ARGIN(const Parrot_Context *ctx))
STRING* Parrot_Context_infostr(PARROT_INTERP, ARGIN(const PMC *pmcctx))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

Expand Down Expand Up @@ -336,7 +335,7 @@ PARROT_CAN_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
PMC* Parrot_find_pad(PARROT_INTERP,
ARGIN(STRING *lex_name),
ARGIN(const Parrot_Context *ctx))
ARGIN(const PMC *pmcctx))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
Expand All @@ -345,11 +344,11 @@ PMC* Parrot_find_pad(PARROT_INTERP,
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_Context_get_info __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx) \
|| PARROT_ASSERT_ARG(pmcctx) \
|| PARROT_ASSERT_ARG(info)
#define ASSERT_ARGS_Parrot_Context_infostr __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(ctx)
|| PARROT_ASSERT_ARG(pmcctx)
#define ASSERT_ARGS_Parrot_full_sub_name __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_get_sub_pmc_from_subclass \
Expand Down Expand Up @@ -384,7 +383,7 @@ PMC* Parrot_find_pad(PARROT_INTERP,
#define ASSERT_ARGS_Parrot_find_pad __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(lex_name) \
|| PARROT_ASSERT_ARG(ctx)
|| PARROT_ASSERT_ARG(pmcctx)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/sub.c */

Expand Down
1 change: 1 addition & 0 deletions lib/Parrot/Ops2c/Utils.pm
Expand Up @@ -551,6 +551,7 @@ sub _print_preamble_source {
print $fh <<END_C;
#include "$self->{include}"
#include "../pmc/pmc_parrotlibrary.h"
#include "../pmc/pmc_context.h"
$self->{defines}
Expand Down
6 changes: 3 additions & 3 deletions src/call/ops.c
Expand Up @@ -134,7 +134,7 @@ runops(PARROT_INTERP, size_t offs)

/*
=item C<Parrot_Context * Parrot_runops_fromc(PARROT_INTERP, PMC *sub)>
=item C<PMC * Parrot_runops_fromc(PARROT_INTERP, PMC *sub)>
Runs the Parrot ops, called from C code. The function arguments are
already setup according to Parrot calling conventions, the C<sub> argument
Expand All @@ -147,7 +147,7 @@ is an invocable C<Sub> PMC.
PARROT_EXPORT
PARROT_IGNORABLE_RESULT
PARROT_CANNOT_RETURN_NULL
Parrot_Context *
PMC *
Parrot_runops_fromc(PARROT_INTERP, ARGIN(PMC *sub))
{
ASSERT_ARGS(Parrot_runops_fromc)
Expand All @@ -169,7 +169,7 @@ Parrot_runops_fromc(PARROT_INTERP, ARGIN(PMC *sub))
Parrot_ex_throw_from_c_args(interp, NULL, 1,
"Subroutine returned a NULL address");

ctx = CONTEXT(interp);
ctx = interp->ctx;
offset = dest - interp->code->base.data;
runops(interp, offset);
return ctx;
Expand Down

0 comments on commit 852012c

Please sign in to comment.