diff --git a/eval.py b/eval.py index 23b3a73..3451174 100644 --- a/eval.py +++ b/eval.py @@ -109,8 +109,8 @@ def pushvalue(self, value): def pushword(self, word, closure): if isinstance(word, Closure): - for name in word.node.arguments.children: - word.setlocal(name.value, self.popvalue()) + for name in word.node.arguments: + word.setlocal(name, self.popvalue()) return word.body, word elif callable(word): return word(self, closure) @@ -154,9 +154,21 @@ def getnextupnode(self, node, closure): p.closure.setlocal(p.countername, item) return p.body elif isinstance(node, ConditionClause): - if isinstance(p, (WhileStatement, IfClause, ElseIfClause)): + if isinstance(p, WhileStatement): if self.popvalue(): return p.body + elif isinstance(p, (IfClause, ElseIfClause)): + if self.popvalue() + return p.children[0] + else: + c = p.parent.elseifclauses + i = p in c and c.index(p) or -1 + if i < len(c) - 1: + return c[i+1] + elif p.parent.elseclause: + return p.parent.elseclause + node = p.parent + continue elif isinstance(p, ForStatement): item = self.popvalue() hidden = self.popvalue() @@ -180,7 +192,7 @@ def getnextupnode(self, node, closure): if self.gettype(p.func) == 'ident': p.func = closure.getword(p.func) return self.pushword(p.func, closure) - elif isinstance(p, (IfClause, ElseIfClause)): + elif isinstance(node, (IfClause, ElseIfClause)): node = p.parent continue elif isinstance(p, LabdaStatement): diff --git a/func.py b/func.py index 3a35a42..3c76857 100644 --- a/func.py +++ b/func.py @@ -3,7 +3,7 @@ class LabdaStatement(SimpleStatement): def __init__(self, parent, arguments, linenr): SimpleStatement.__init__(self, parent, linenr) - self.arguments = ArgumentList(self, arguments) + self.arguments = arguments class FuncStatement(LabdaStatement): def __init__(self, parent, arguments, linenr): @@ -13,10 +13,3 @@ def __init__(self, parent, arguments, linenr): class LocalFuncStatement(FuncStatement): def __init__(self, parent, arguments, linenr): FuncStatement.__init__(self, parent, arguments, linenr) - -class ArgumentList(Clause): - def __init__(self, parent, tokens): - Node.__init__(self, None) - self.parent = parent - for token in tokens: - WordList.gettokenclass(token)(self, token)