import java.util.ArrayList;
import java.util.List;

public class Call extends Stmt {
	public Node op;
	public Argument args;

	public Call(Node op, Argument args) {
		super();
		this.op = op;
		this.args = args;
	}

	@Override
	public Value interp(Scope s) {
		Value opv = op.interp(s);
		if (opv instanceof Closure) {
			Closure closure = (Closure) opv;
			Scope funScope = new Scope(closure.env);
			for (int i = 0; i < closure.fun.params.size(); i++) {
				Value v = args.elements.get(i).interp(s);
				funScope.putValue(closure.fun.params.get(i).id, v);
			}
			return closure.fun.body.interp(funScope);
		} else if (opv instanceof BuiltinFun) {
			BuiltinFun fun = (BuiltinFun) opv;
			List<Value> args = new ArrayList<>(this.args.elements.size());
			for (Node node : this.args.elements) {
				args.add(node.interp(s));
			}
			return fun.apply(args);
		} else {
			S.error("不支持的调用" + opv);
			return Value.VOID; // never touch
		}
	}

	@Override
	public Value typecheck(Scope s) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String toString() {
		return op + "(" + U.join(", ", args) + ")";
	}

}

@@ -87,18 +87,18 @@
 public N
-od
+am
 e op;%0A%09p
@@ -133,18 +133,18 @@
 c Call(N
-od
+am
 e op, Ar
@@ -348,16 +348,43 @@
 e) opv;%0A
+%09%09%09//%E6%B3%A8%E6%84%8F%E7%BB%A7%E6%89%BF%E6%AF%8F%E4%B8%AA%E5%87%BD%E6%95%B0%E5%85%B1%E4%BA%AB%E7%9A%84%E5%88%9D%E5%A7%8BenvScope%0A
 %09%09%09Scope
@@ -1014,57 +1014,181 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09return null;
+Value opv = op.interp(s);%0A%09%09if (opv instanceof BuiltinFun %7C%7C opv instanceof Closure)%0A%09%09%09return opv;%0A%09%09else%0A%09%09%09S.error(%22%E4%B8%8D%E6%94%AF%E6%8C%81%E7%9A%84%E8%B0%83%E7%94%A8%E7%B1%BB%E5%9E%8B%EF%BC%9A%22 + opv);%0A%09%09return Value.VOID; // never touch
 %0A%09%7D%0A
@@ -1250,27 +1250,13 @@
 (%22 +
- U.join(%22, %22,
  args
-)
  + %22

support Name type only