Commit c0e8b23d authored by Kevin Modzelewski's avatar Kevin Modzelewski

Start work on more elaborate argument handling

- Support parsing (but not running) **kw in function definitions
- more consistent assertion of what parts handle non-simple arguments or not
parent 82866799
......@@ -232,7 +232,7 @@ public:
}
virtual bool visit_arguments(AST_arguments* node) {
if (node->kwarg)
if (node->kwarg.size())
_doSet(node->kwarg);
if (node->vararg.size())
_doSet(node->vararg);
......
......@@ -267,15 +267,26 @@ private:
}
virtual void* visit_call(AST_Call* node) {
assert(!node->starargs);
assert(!node->kwargs);
assert(node->keywords.size() == 0);
CompilerType* func = getType(node->func);
std::vector<CompilerType*> arg_types;
for (int i = 0; i < node->args.size(); i++) {
arg_types.push_back(getType(node->args[i]));
}
std::vector<std::pair<const std::string&, CompilerType*> > kw_types;
for (AST_keyword* kw : node->keywords) {
kw_types.push_back(std::make_pair<const std::string&, CompilerType*>(kw->arg, getType(kw->value)));
}
CompilerType* starargs = node->starargs ? getType(node->starargs) : NULL;
CompilerType* kwargs = node->kwargs ? getType(node->kwargs) : NULL;
if (starargs || kwargs || kw_types.size()) {
// Bail out for anything but simple calls, for now:
return UNKNOWN;
}
CompilerType* rtn_type = func->callType(arg_types);
// Should be unboxing things before getting here:
......
......@@ -139,6 +139,13 @@ static CompiledFunction* _doCompile(CLFunction* f, FunctionSignature* sig, Effor
const std::vector<AST_expr*>& arg_names = source->getArgNames();
AST_arguments* args = source->getArgsAST();
if (args) {
// args object can be NULL if this is a module scope
assert(!args->vararg.size());
assert(!args->kwarg.size());
assert(!args->defaults.size());
}
if (VERBOSITY("irgen") >= 1) {
std::string s;
llvm::raw_string_ostream ss(s);
......
......@@ -623,6 +623,10 @@ private:
CompilerVariable* evalCall(AST_Call* node, ExcInfo exc_info) {
assert(state != PARTIAL);
assert(!node->starargs);
assert(!node->kwargs);
assert(!node->keywords.size());
bool is_callattr;
bool callattr_clsonly = false;
std::string* attr = NULL;
......
......@@ -123,9 +123,7 @@ def convert(n, f):
if k.startswith('_'):
continue
if k == "vararg" and v is None:
v = ""
if k == "asname" and v is None:
if k in ("vararg", "kwarg", "asname") and v is None:
v = ""
# elif k in ('col_offset', 'lineno'):
# continue
......
......@@ -159,9 +159,8 @@ AST_arguments* read_arguments(BufferedReader* reader) {
readExprVector(rtn->args, reader);
rtn->col_offset = -1;
readExprVector(rtn->defaults, reader);
rtn->kwarg = readASTExpr(reader);
rtn->kwarg = readString(reader);
rtn->lineno = -1;
// rtn->vararg = readASTExpr(reader);
rtn->vararg = readString(reader);
return rtn;
}
......@@ -856,7 +855,7 @@ AST_Module* parse(const char* fn) {
return ast_cast<AST_Module>(rtn);
}
#define MAGIC_STRING "a\ncg"
#define MAGIC_STRING "a\nch"
#define MAGIC_STRING_LENGTH 4
#define LENGTH_SUFFIX_LENGTH 4
......
......@@ -201,8 +201,6 @@ void AST_arguments::accept(ASTVisitor* v) {
visitVector(defaults, v);
visitVector(args, v);
if (kwarg)
kwarg->accept(v);
}
void AST_Assert::accept(ASTVisitor* v) {
......
......@@ -176,8 +176,10 @@ class AST_arguments : public AST {
public:
// no lineno, col_offset attributes
std::vector<AST_expr*> args, defaults;
AST_expr* kwarg;
std::string vararg;
// These are represented as strings, not names; not sure why.
// If they don't exist, the string is empty.
std::string kwarg, vararg;
virtual void accept(ASTVisitor* v);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment