implement method/function call
Some checks failed
CI / test-core (14, ubuntu-latest, 3.x, js) (push) Successful in 48s
CI / test-core (14, ubuntu-latest, 3.x, interp) (push) Successful in 1m2s
CI / test-core (14, ubuntu-latest, 3.x, nodejs) (push) Successful in 57s
CI / test-core (14, ubuntu-latest, 3.x, cpp) (push) Successful in 1m49s
CI / test-core (14, ubuntu-latest, 3.x, py) (push) Failing after 1m19s
Some checks failed
CI / test-core (14, ubuntu-latest, 3.x, js) (push) Successful in 48s
CI / test-core (14, ubuntu-latest, 3.x, interp) (push) Successful in 1m2s
CI / test-core (14, ubuntu-latest, 3.x, nodejs) (push) Successful in 57s
CI / test-core (14, ubuntu-latest, 3.x, cpp) (push) Successful in 1m49s
CI / test-core (14, ubuntu-latest, 3.x, py) (push) Failing after 1m19s
This commit is contained in:
@@ -47,6 +47,17 @@
|
||||
// Special form call
|
||||
((when (specialForms.exists form) (CallExp (object def (Symbol form)) args))
|
||||
((dictGet specialForms form) args cc))
|
||||
// Method/function call
|
||||
((CallExp callable args)
|
||||
(evalCC callable ->f
|
||||
(_evalAllCC args ->values
|
||||
(case callable
|
||||
// Method call
|
||||
((object def (FieldExp field obj safe))
|
||||
(evalCC obj ->o
|
||||
(cc (Reflect.callMethod o f values))))
|
||||
// Function call
|
||||
(otherwise (cc (Reflect.callMethod null f values)))))))
|
||||
// Field access
|
||||
((FieldExp field obj safe)
|
||||
(evalCC obj ->v
|
||||
@@ -80,4 +91,13 @@
|
||||
(return))))
|
||||
(cc (dictGet globals ident)))
|
||||
(never otherwise)))
|
||||
(otherwise (throw "Can't interpret ${input}"))))
|
||||
(otherwise (throw "Can't interpret ${input}"))))
|
||||
|
||||
(method :Void _evalAllCC [:Array<Dynamic> inputs :Array<Dynamic>->Void cc &opt :Array<Dynamic> outputs]
|
||||
(unless outputs (set outputs []))
|
||||
(if inputs
|
||||
(evalCC (inputs.shift) ->v {
|
||||
(outputs.push v)
|
||||
(_evalAllCC inputs cc outputs)
|
||||
})
|
||||
(cc outputs)))
|
@@ -22,4 +22,7 @@ class KissInterp2TestCase extends Test {
|
||||
function testField() {
|
||||
_testField();
|
||||
}
|
||||
function testCallMethod() {
|
||||
_testCallMethod();
|
||||
}
|
||||
}
|
@@ -16,3 +16,10 @@
|
||||
(dictSet interp.globals "obj" (object a 5 b (object c 3)))
|
||||
(assertEval 5 "obj.a")
|
||||
(assertEval 3 "obj.b.c")))
|
||||
|
||||
(function _testCallMethod []
|
||||
(let [interp (new Interp)]
|
||||
(dictSet interp.globals "f" ->[a b] (+ a b))
|
||||
(dictSet interp.globals "o" (object f ->[a b] (- a b)))
|
||||
(assertEval 2 "(f -1 3)")
|
||||
(assertEval 2 "(o.f 5 3)")))
|
||||
|
Reference in New Issue
Block a user