cvsuser 05/03/14 05:20:55
Modified: config/gen/makefiles root.in
editor imc.vim.in
src mmd.c
Log:
MMD 1 - stub in some MMD search functions
* parts of MMD search according to A12
Revision Changes Path
1.282 +10 -9 parrot/config/gen/makefiles/root.in
Index: root.in
===================================================================
RCS file: /cvs/public/parrot/config/gen/makefiles/root.in,v
retrieving revision 1.281
retrieving revision 1.282
diff -u -r1.281 -r1.282
--- root.in 5 Mar 2005 22:47:43 -0000 1.281
+++ root.in 14 Mar 2005 13:20:51 -0000 1.282
@@ -1,5 +1,5 @@
# Copyright: 2001-2005 The Perl Foundation. All Rights Reserved.
-# $Id: root.in,v 1.281 2005/03/05 22:47:43 bernhard Exp $
+# $Id: root.in,v 1.282 2005/03/14 13:20:51 leo Exp $
###############################################################################
#
@@ -36,7 +36,7 @@
# current directory
CUR_DIR = .
-
+
# directory for the intermediate code compiler
IMCC_DIR = imcc
@@ -499,6 +499,7 @@
$(SRC_DIR)/inter_misc.str \
$(SRC_DIR)/global.str \
$(SRC_DIR)/library.str \
+ $(SRC_DIR)/mmd.str \
$(SRC_DIR)/pmc.str \
$(SRC_DIR)/py_func.str \
$(SRC_DIR)/objects.str \
@@ -720,7 +721,7 @@
#
###############################################################################
-examples-clean: hello-clean
+examples-clean: hello-clean
# hello
hello: test_prep examples/assembly/hello$(EXE)
@@ -859,7 +860,7 @@
$(SRC_DIR)/pic$(O) : $(GENERAL_H_FILES)
-$(SRC_DIR)/mmd$(O) : $(GENERAL_H_FILES)
+$(SRC_DIR)/mmd$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/mmd.str
$(SRC_DIR)/mmd_fallback$(O) : $(GENERAL_H_FILES)
@@ -1090,7 +1091,7 @@
# Test various run cores and other stuff
# 'testC', 'testg' and 'testj' are tested only,
-# when the needed runcores are available
+# when the needed runcores are available
fulltest : testb \
#CONDITIONED_LINE(cg_flag): testC \
testf \
@@ -1099,7 +1100,7 @@
testr \
testS \
src_tests \
- testbench
+ testbench
# bounds checking, slow core
testb : test_prep
@@ -1130,7 +1131,7 @@
$(PERL) t/harness $(EXTRA_TEST_ARGS) $(PARROT_ARGS) -S $(TEST_FILES)
# test the EXEC stuff
-testexec: test_prep
+testexec: test_prep
$(PERL) t/harness $(EXTRA_TEST_ARGS) $(PARROT_ARGS) --run-exec
$(TEST_FILES)
# Test that need to be compiled by the C-compiler
@@ -1156,7 +1157,7 @@
# Run IMCC tests with various command line options
fulltest_imcc : testb_imcc testC_imcc testf_imcc testg_imcc \
- testj_imcc testr_imcc testS_imcc testexec_imcc
+ testj_imcc testr_imcc testS_imcc testexec_imcc
# slow core, bounds checking
testb_imcc : test_prep
@@ -1410,5 +1411,5 @@
# test the EXEC stuff
-testexec: hello
+testexec: hello
1.6 +1 -1 parrot/editor/imc.vim.in
Index: imc.vim.in
===================================================================
RCS file: /cvs/public/parrot/editor/imc.vim.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- imc.vim.in 15 Aug 2004 04:33:40 -0000 1.5
+++ imc.vim.in 14 Mar 2005 13:20:54 -0000 1.6
@@ -32,7 +32,7 @@
syn match imcDirective /\.\(sub\|pcc_sub\|macro\|endm\|end\|emit\|eom\)/
syn match imcDirective /\.\(local\|sym\|const\)/
syn match imcDirective /\.\(namespace\|endnamespace\)/
-syn match imcDirective /\.\(param\|result\|arg\|return\)/
+syn match imcDirective /\.\(param\|result\|arg\|return\|invocant\)/
syn match imcDirective /\.\(include|pcc_begin|pcc_end\)/
syn match imcDirective /\.\(pcc_begin_return|pcc_end_return\)/
syn match imcDirective /\.\(pcc_begin_yield|pcc_end_yield\)/
1.50 +299 -2 parrot/src/mmd.c
Index: mmd.c
===================================================================
RCS file: /cvs/public/parrot/src/mmd.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- mmd.c 13 Mar 2005 12:16:14 -0000 1.49
+++ mmd.c 14 Mar 2005 13:20:55 -0000 1.50
@@ -1,6 +1,6 @@
/*
Copyright: 2003 The Perl Foundation. All Rights Reserved.
-$Id: mmd.c,v 1.49 2005/03/13 12:16:14 leo Exp $
+$Id: mmd.c,v 1.50 2005/03/14 13:20:55 leo Exp $
=head1 NAME
@@ -41,6 +41,7 @@
*/
#include "parrot/parrot.h"
+#include "mmd.str"
#include <assert.h>
typedef void (*mmd_f_v_ppp)(Interp *, PMC *, PMC *, PMC *);
@@ -657,13 +658,309 @@
return f;
}
+
+static PMC* mmd_arg_tuple_inline(Interp *, STRING *signature, va_list args);
+static PMC* mmd_arg_tuple_func(Interp *, STRING *signature, va_list args);
+static PMC* mmd_search_default(Interp *, STRING *meth, PMC *arg_tuple);
+static PMC* mmd_search_scopes(Interp *, STRING *meth, PMC *arg_tuple);
+static int mmd_search_lexical(Interp *, STRING *meth, PMC *arg_tuple, PMC
*);
+static int mmd_search_package(Interp *, STRING *meth, PMC *arg_tuple, PMC
*);
+static int mmd_search_global(Interp *, STRING *meth, PMC *arg_tuple, PMC *);
+static int mmd_search_builtin(Interp *, STRING *meth, PMC *arg_tuple, PMC
*);
+
+/*
+
+=item C<PMC *Parrot_MMD_search_default_inline(Interp *, STRING *meth, STRING
*signature, ...)>
+
+Default implementation of MMD lookup. The singature contains the letters
+"INSP" for the argument types. B<PMC> arguments are given in the function
call.
+
+=item C<PMC *Parrot_MMD_search_default_func(Interp *, STRING *meth, STRING
*signature)>
+
+Default implementation of MMD lookup. The singature contains the letters
+"INSP" for the argument types. B<PMC> arguments are taken from registers
+C<P5> and up according to calling conventions.
+
+=cut
+
+*/
+
+/*
+ * TODO move to header, when API is sane
+ */
+
+PMC *
+Parrot_MMD_search_default_inline(Interp *interpreter, STRING *meth,
+ STRING *signature, ...);
+
+PMC *
+Parrot_MMD_search_default_inline(Interp *interpreter, STRING *meth,
+ STRING *signature, ...)
+{
+ va_list args;
+ PMC* arg_tuple;
+ /*
+ * 1) create argument tuple
+ */
+ va_start(args, signature);
+ arg_tuple = mmd_arg_tuple_inline(interpreter, signature, args);
+ va_end(args);
+
+ return mmd_search_default(interpreter, meth, arg_tuple);
+}
+
+/*
+
+=item C<
+static PMC* mmd_arg_tuple_inline(Interp *, STRING *signature, va_list args)>
+
+Return a list of argument types. PMC arguments are specifiec as function
+arguments.
+
+=cut
+
+*/
+
+static PMC*
+mmd_arg_tuple_inline(Interp *interpreter, STRING *signature, va_list args)
+{
+ INTVAL sig_len, i, type;
+ PMC* arg_tuple, *arg;
+
+ arg_tuple = pmc_new(interpreter, enum_class_FixedIntegerArray);
+ sig_len = string_length(interpreter, signature);
+ if (!sig_len)
+ return arg_tuple;
+ for (i = 0; i < sig_len; ++i) {
+ type = string_index(interpreter, signature, i);
+ switch (type) {
+ case 'I':
+ VTABLE_push_integer(interpreter, arg_tuple,
enum_type_INTVAL);
+ break;
+ case 'N':
+ VTABLE_push_integer(interpreter, arg_tuple,
enum_type_FLOATVAL);
+ break;
+ case 'S':
+ VTABLE_push_integer(interpreter, arg_tuple,
enum_type_STRING);
+ break;
+ case 'P':
+ arg = va_arg(args, PMC *);
+ type = VTABLE_type(interpreter, arg);
+ VTABLE_push_integer(interpreter, arg_tuple, type);
+ break;
+ default:
+ internal_exception(1,
+ "Unknown signature type %d in mmd_arg_tuple", type);
+ break;
+ }
+
+ }
+ return arg_tuple;
+}
+
+/*
+
+=item C<static PMC* mmd_search_default(Interp *, STRING *meth, PMC
*arg_tuple)>
+
+Default implementation of MMD search. Search scopes for candidates, walk the
+class hierarchy, sort all candidates by their manhattan distance, and return
+result
+
+=cut
+
+*/
+
+static PMC*
+mmd_search_default(Interp *interpreter, STRING *meth, PMC *arg_tuple)
+{
+ PMC *candidate_list;
+
+ candidate_list = mmd_search_scopes(interpreter, meth, arg_tuple);
+ return NULL;
+}
+
+/*
+
+=item C<static PMC* mmd_search_scopes(Interp *, STRING *meth, PMC
*arg_tuple)>
+
+Search all scopes for MMD candidates matching the arguments given in
+C<arg_tuple>.
+
+=cut
+
+*/
+
+static PMC*
+mmd_search_scopes(Interp *interpreter, STRING *meth, PMC *arg_tuple)
+{
+ PMC *candidate_list;
+ int stop;
+
+ candidate_list = pmc_new(interpreter, enum_class_ResizablePMCArray);
+ stop = mmd_search_lexical(interpreter, meth, arg_tuple, candidate_list);
+ if (stop)
+ return candidate_list;
+ mmd_search_package(interpreter, meth, arg_tuple, candidate_list);
+ if (stop)
+ return candidate_list;
+ mmd_search_global(interpreter, meth, arg_tuple, candidate_list);
+ if (stop)
+ return candidate_list;
+ mmd_search_builtin(interpreter, meth, arg_tuple, candidate_list);
+ return candidate_list;
+}
+
+/*
+
+=item C<static int mmd_is_hidden(Interp *, PMC *multi, PMC *cl)>
+
+Check if the given multi sub is hidden by any inner multi sub (already in
+the candidate list C<cl>.
+
+=cut
+
+*/
+
+static int
+mmd_is_hidden(Interp *interpreter, PMC *multi, PMC *cl)
+{
+ /*
+ * if the candidate list already has the a sub with the same
+ * signature (long name), the outer multi is hidden
+ *
+ * TODO
+ */
+ return 0;
+}
+
+/*
+
+=item C<static int mmd_maybe_candidate(Interp *, PMC *pmc, PMC *arg_tuple,
PMC *cl)>
+
+If the candidate C<pmc> is a Sub PMC, push it on the candidate list and
+return TRUE to stop further search.
+
+If the candidate is a MultiSub remember all matching Subs and return FALSE
+to continue searching outer scopes.
+
+*/
+
+static int
+mmd_maybe_candidate(Interp *interpreter, PMC *pmc, PMC *arg_tuple, PMC *cl)
+{
+ STRING *_sub, *_multi_sub;
+ INTVAL i, n;
+
+ _sub = CONST_STRING(interpreter, "Sub");
+ _multi_sub = CONST_STRING(interpreter, "Multi_Sub");
+
+ if (VTABLE_isa(interpreter, pmc, _sub)) {
+ /* a plain sub stops outer searches */
+ /* TODO check arity of sub */
+ VTABLE_push_pmc(interpreter, cl, pmc);
+ return 1;
+ }
+ if (!VTABLE_isa(interpreter, pmc, _multi_sub)) {
+ /* not a Sub or MultiSub - ignore */
+ return 0;
+ }
+ /*
+ * ok we have a multi sub pmc, which is an array of candidates
+ */
+ n = VTABLE_elements(interpreter, pmc);
+ for (i = 0; i < n; ++i) {
+ PMC *multi_sub;
+
+ multi_sub = VTABLE_get_pmc_keyed_int(interpreter, pmc, i);
+ if (!mmd_is_hidden(interpreter, multi_sub, cl))
+ VTABLE_push_pmc(interpreter, cl, multi_sub);
+ }
+ return 0;
+}
+
+/*
+
+=item C<static int mmd_search_lexical(Interp *, STRING *meth, PMC
*arg_tuple, PMC *cl)>
+
+Search the current lexical pad for matching candidates. Return TRUE if the
+MMD search should stop.
+
+*/
+
+static int
+mmd_search_lexical(Interp *interpreter, STRING *meth, PMC *arg_tuple, PMC
*cl)
+{
+ PMC *pad = scratchpad_get_current(interpreter);
+ PMC *pmc;
+ INTVAL depth, i;
+
+ if (!pad)
+ return 0;
+ depth = PMC_int_val(pad);
+ for (i = -1; depth; --i, --depth) {
+ pmc = scratchpad_get_by_name(interpreter, pad, i, meth);
+ if (pmc) {
+ if (mmd_maybe_candidate(interpreter, pmc, arg_tuple, cl))
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/*
+
+=item C<static int mmd_search_package(Interp *, STRING *meth, PMC
*arg_tuple, PMC *cl)>
+
+Search the current package namespace for matching candidates. Return TRUE if
+the MMD search should stop.
+
+*/
+
+static int
+mmd_search_package(Interp *interpreter, STRING *meth, PMC *arg_tuple, PMC
*cl)
+{
+ return 0;
+}
+
+/*
+
+=item C<static int mmd_search_global(Interp *, STRING *meth, PMC *arg_tuple,
PMC *cl)>
+
+Search the global namespace for matching candidates. Return TRUE if
+the MMD search should stop.
+
+*/
+
+static int
+mmd_search_global(Interp *interpreter, STRING *meth, PMC *arg_tuple, PMC *cl)
+{
+ return 0;
+}
+
+/*
+
+=item C<static int mmd_search_builtin(Interp *, STRING *meth, PMC
*arg_tuple, PMC *cl)>
+
+Search the builtin namespace for matching candidates. Return TRUE if
+the MMD search should stop.
+
+*/
+
+static int
+mmd_search_builtin(Interp *interpreter, STRING *meth, PMC *arg_tuple, PMC
*cl)
+{
+ return 0;
+}
+
/*
=back
=head1 SEE ALSO
-F<include/parrot/mmd.h>.
+F<include/parrot/mmd.h>,
+F<$perl6/doc/trunk/design/apo/A12.pod>,
+F<$perl6/doc/trunk/design/syn/S12.pod>
=cut