!752 please include function bigint. // callable function/method names static L callable = litlist("bigint", "compareTo"); p { printStructure(eval([[ bigint("123") ]])); boolean oops = false; try { eval([[ print("test") ]]); // not callable oops = true; } catch (Exception e) { /* ok */ } assertFalse(oops); assertEquals(-1, eval([[ bigint("123").compareTo(bigint("234")) ]])); assertEquals(1, eval([[ bigint("567").compareTo(bigint("-123")) ]])); print("All OK!"); } static O eval(S text) { L e = jparse(text, "exp"); printStructure(e); L tok = javaTok(text); // XX: better get from parser ret evalExp(e, tok); } static O evalExp(L e, L tok) { // e == [1, 9, "call", " ( )", [1, 3, "identifier"], [5, 7, "quoted"]] S cl = getString(e, 2); if (eq(cl, "quoted")) ret unquote(get(tok, (int) get(e, 0))); if (eq(cl, "call")) { ret evalCall(e, tok, getMainClass()); } if (eq(cl, "methodcall")) { L e_exp = cast get(e, 4); // submatch 1 L e_call = cast get(e, 5); // submatch 2 O obj = evalExp(e_exp, tok); ret evalCall(e_call, tok, obj); } throw fail("woot exp: " + structure(e)); } static O evalCall(L e, L tok, O obj) { L e_name = cast get(e, 4); // submatch 1 L e_args = cast get(e, 5); // submatch 2 S fname = get(tok, (int) get(e_name, 0)); L args = evalArgs(e_args, tok); ret callMethod(obj, fname, args); } static L evalArgs(L e, L tok) { ret litlist(evalExp(e, tok)); // todo... } static L jparse(S text, S className) { O parser = run("#1002369"); //setOpt(parser, "debug", true); O parseResult = call(parser, "jparse", text); ret (L) call(parseResult, "explain", className); } static O callMethod(O obj, S fname, L args) { boolean mayCall = mayCallFunction(fname); if (!hasMethodNamed(obj, fname)) throw fail("Method not defined in " + getClassName(obj) + (mayCall ? "" : ", also not callable") + ": " + fname); if (!mayCallFunction(fname)) throw fail("Not allowed to call method: " + fname); ret call(obj, fname, toObjectArray(args)); } static boolean mayCallFunction(S fname) { ret callable.contains(fname); }