Skip to content

Commit

Permalink
Start to stub in the new binder a bit. We add a dynop and also a few …
Browse files Browse the repository at this point in the history
…other little bits, plus a place for the binding logic, since we'll want to use it from the ops and dynpmcs.
  • Loading branch information
jnthn committed Oct 9, 2009
1 parent f99cc4b commit 3a4d149
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 12 deletions.
17 changes: 9 additions & 8 deletions build/Makefile.in
Expand Up @@ -206,6 +206,7 @@ CLEANUPS = \
$(OPS_DIR)/*.c \
$(OPS_DIR)/*$(O) \
$(OPS_DIR)/*$(LOAD_EXT) \
binder/*$(O) \

# NOTE: eventually, we should remove --keep-exit-code and --fudge
# as the goal is that all tests must pass without fudge
Expand Down Expand Up @@ -419,7 +420,10 @@ $(DYNEXT_TARGET): $(DYNPMC) $(DYNOPS)
# spaces and some compilers/linkers forbid a (forced) space.
# See RT #66558 and TT #700.

$(DYNPMC): $(PMC_SOURCES) src/pmc/sigguts.h
src/binder/bind$(O):
cd src/ops && $(CC) -c @cc_o_out@../binder/bind$(O) -I$(PMC_DIR) $(CINCLUDES) $(CFLAGS) ../binder/bind.c

$(DYNPMC): $(PMC_SOURCES) src/binder/sigguts.h
$(PMC2C) --no-lines --dump $(PMC2C_INCLUDES) src/pmc/objectref.pmc
$(PMC2C) --no-lines --dump $(PMC2C_INCLUDES) $(PMC_SOURCES)
$(PMC2C) --no-lines --c $(PMC2C_INCLUDES) $(PMC_SOURCES)
Expand All @@ -428,15 +432,12 @@ $(DYNPMC): $(PMC_SOURCES) src/pmc/sigguts.h
cd $(PMC_DIR) && $(CC) -c $(CINCLUDES) $(CFLAGS) *.c
$(LD) @ld_out@$(DYNPMC) $(GROUP)$(O) src/pmc/*$(O) $(LINKARGS)

$(OPS_DIR)/$(OPS)$(LOAD_EXT): $(OPS_DIR)/$(OPS_SOURCE) src/pmc/sigguts.h
$(OPS_DIR)/$(OPS)$(LOAD_EXT): $(OPS_DIR)/$(OPS_SOURCE) src/binder/sigguts.h src/binder/bind$(O)
cd $(OPS_DIR) && $(OPS2C) C --dynamic $(OPS_SOURCE)
cd $(OPS_DIR) && $(CC) -c @cc_o_out@$(OPS)$(O) $(CINCLUDES) $(CFLAGS) $(OPS).c
cd $(OPS_DIR) && $(LD) @ld_out@$(OPS)$(LOAD_EXT) $(OPS)$(O) $(LINKARGS)
cd $(OPS_DIR) && $(LD) @ld_out@$(OPS)$(LOAD_EXT) $(OPS)$(O) ../binder/bind$(O) $(LINKARGS)

$(OPS_DIR)/$(OPS)_switch$(LOAD_EXT): $(OPS_DIR)/$(OPS_SOURCE) src/pmc/sigguts.h
$(OPS_DIR)/$(OPS)_switch$(LOAD_EXT): $(OPS_DIR)/$(OPS_SOURCE) src/binder/sigguts.h src/binder/bind$(O)
cd $(OPS_DIR) && $(OPS2C) CSwitch --dynamic $(OPS_SOURCE)
cd $(OPS_DIR) && $(CC) -c @cc_o_out@$(OPS)_switch$(O) $(CINCLUDES) $(CFLAGS) $(OPS)_switch.c
cd $(OPS_DIR) && $(LD) @ld_out@$(OPS)_switch$(LOAD_EXT) $(OPS)_switch$(O) $(LINKARGS)



cd $(OPS_DIR) && $(LD) @ld_out@$(OPS)_switch$(LOAD_EXT) $(OPS)_switch$(O) ../binder/bind$(O) $(LINKARGS)
2 changes: 1 addition & 1 deletion build/PARROT_REVISION
@@ -1 +1 @@
41447
41772
34 changes: 34 additions & 0 deletions src/binder/bind.c
@@ -0,0 +1,34 @@
/*
$Id$
Copyright (C) 2009, The Perl Foundation.
*/

#include "parrot/parrot.h"
#include "sigguts.h"

/* Takes a signature along with positional and named arguments and binds them
* into the provided lexpad (actually, anything that has a Hash interface will
* do). Returns 0 if binding fails, and non-zero otherwise. */
INTVAL
Rakudo_binding_bind_signature(PARROT_INTERP, PMC *lexpad, PMC *signature,
PMC *pos_args, PMC *named_args,
INTVAL no_nom_type_check, STRING **error) {
return 0;
}


/* Binds a single argument into the lexpad, after doing any checks that are
* needed. Also handles any type captures. If there is a sub signature, then
* re-enters the binder. Returns 0 if binding fails, and non-zero otherwise. */
INTVAL
Rakudo_binding_bind_one_param(PARROT_INTERP, PMC *lexpad, llsig_element *sig_info,
PMC *value, INTVAL no_nom_type_check, STRING **error) {
return 0;
}

/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/
22 changes: 22 additions & 0 deletions src/pmc/sigguts.h → src/binder/sigguts.h
Expand Up @@ -23,3 +23,25 @@ typedef struct llsig_element {
PMC *post_constraints; /* Junction of any extra constraints. */
PMC *sub_signature; /* Any nested signature. */
} llsig_element;


/* Flags we can set on the Context PMC.
*
* ALREADY_CHECKED indicates that we have determined that all of the arguments
* can be bound to positional parameters without any further type checking
* (because the multi-dispatch cache told us so) and any named parameters are
* automatically going into the named slurpy variable.
*
* ALREADY_BOUND indicates that the variables have already been bound into the
* lexpad and means the bind_signature op is thus a no-op. This happens if we
* had to do a bindability check in the multi-dispatch anyway.
*/
#define PObj_P6S_ALREADY_CHECKED_FLAG PObj_private0_FLAG
#define PObj_P6S_ALREADY_BOUND_FLAG PObj_private1_FLAG


/* A function we want to share to provide the interface to the binder. */
INTVAL
Rakudo_binding_bind_signature(PARROT_INTERP, PMC *lexpad, PMC *signature,
PMC *pos_args, PMC *named_args,
INTVAL no_nom_type_check, STRING **error);
35 changes: 34 additions & 1 deletion src/ops/perl6.ops
Expand Up @@ -8,7 +8,7 @@ BEGIN_OPS_PREAMBLE
#include "parrot/dynext.h"
#include "pmc_object.h"
#include "../pmc/pmc_p6lowlevelsig.h"
#include "../pmc/sigguts.h"
#include "../binder/sigguts.h"

#if PARROT_HAS_ICU
# include <unicode/uchar.h>
Expand Down Expand Up @@ -560,6 +560,39 @@ inline op get_signature_elem(in PMC, in INT, out STR, out INT, out PMC, out PMC,
}
}


/*

=item bind_signature(in PMC, in PMC)

This is emitted into a sub to cause it's Perl 6 signature to be bound. $1 is
an array of positional arguments (obtained by using :flat) and $2 is a hash of
named arguments (obtained using :flat :slurpy). Eventually, after Parrot
refactors are complete, it will take one argument - the CallSignature.

=cut

*/
inline op bind_signature(in PMC, in PMC) :base_core {
PMC *ctx = CURRENT_CONTEXT(interp);

/* If we aren't already bound, enter the appropriate binder. */
if (!PObj_flag_TEST(P6S_ALREADY_BOUND, ctx)) {
PMC *lexpad = Parrot_pcc_get_lex_pad(interp, ctx);
PMC *sub = Parrot_pcc_get_sub(interp, ctx);
PMC *signature = VTABLE_getprop(interp, sub, string_from_literal(interp, "$!signature"));
INTVAL noms_checked = PObj_flag_TEST(P6S_ALREADY_CHECKED, ctx);
STRING *error = NULL;
if (!Rakudo_binding_bind_signature(interp, lexpad, signature, $1, $2, noms_checked, &error)) {
opcode_t *handler = Parrot_ex_throw_from_op_args(interp, NULL,
EXCEPTION_INVALID_OPERATION, Parrot_str_to_cstring(interp, error));
goto ADDRESS(handler);
}
}

goto NEXT();
}

/*
* Local variables:
* c-file-style: "parrot"
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/p6lowlevelsig.pmc
Expand Up @@ -21,7 +21,7 @@ from the outside.

*/

#include "sigguts.h"
#include "../binder/sigguts.h"

/*

Expand Down
2 changes: 1 addition & 1 deletion src/pmc/perl6multisub.pmc
Expand Up @@ -45,7 +45,7 @@ access during a dispatch.
*/

#include "parrot/oplib/ops.h"
#include "sigguts.h"
#include "../binder/sigguts.h"
#include "pmc_p6lowlevelsig.h"


Expand Down

0 comments on commit 3a4d149

Please sign in to comment.