aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2021-03-19 15:18:19 -0500
committerCalvin Rose <calsrose@gmail.com>2021-03-19 15:18:19 -0500
commitb3e80308d49d2bf63b3a11913df2d9dfb75a4d6a (patch)
tree74f87c35367aaff31d92b1c5300383ff867a54ca /src
parent(#667) Add constant inlining for tuples and structs. (diff)
Change inheritance rule.
Diffstat (limited to 'src')
-rw-r--r--src/boot/boot.janet6
-rw-r--r--src/core/vm.c15
2 files changed, 16 insertions, 5 deletions
diff --git a/src/boot/boot.janet b/src/boot/boot.janet
index db072394..292832b6 100644
--- a/src/boot/boot.janet
+++ b/src/boot/boot.janet
@@ -3127,6 +3127,7 @@
(put nextenv :debug-level level)
(put nextenv :signal x)
(merge-into nextenv debugger-env)
+ (eprint (fiber/status f) ": " x)
(debug/stacktrace f x)
(eflush)
(defn debugger-chunks [buf p]
@@ -3142,14 +3143,15 @@
(nextenv :resume-value))
(fn [f x]
- (if (= :dead (fiber/status f))
+ (def fs (fiber/status f))
+ (if (= :dead fs)
(do
(put e '_ @{:value x})
(printf (get e :pretty-format "%q") x)
(flush))
(if (e :debug)
(enter-debugger f x)
- (do (debug/stacktrace f x) (eflush))))))
+ (do (eprint fs ": " x) (debug/stacktrace f x) (eflush))))))
(run-context {:env env
:chunks chunks
diff --git a/src/core/vm.c b/src/core/vm.c
index 31f7465e..4a613a37 100644
--- a/src/core/vm.c
+++ b/src/core/vm.c
@@ -275,11 +275,21 @@ static Janet call_nonfn(JanetFiber *fiber, Janet callee) {
return janet_method_invoke(callee, argc, fiber->data + fiber->stacktop);
}
+static Janet method_to_fun(Janet method, Janet obj) {
+ if (janet_checktype(obj, JANET_TABLE)) {
+ JanetTable *proto = janet_unwrap_table(obj)->proto;
+ if (NULL == proto) return janet_wrap_nil();
+ return janet_table_get(proto, method);
+ } else {
+ return janet_get(obj, method);
+ }
+}
+
/* Get a callable from a keyword method name and ensure that it is valid. */
static Janet resolve_method(Janet name, JanetFiber *fiber) {
int32_t argc = fiber->stacktop - fiber->stackstart;
if (argc < 1) janet_panicf("method call (%v) takes at least 1 argument, got 0", name);
- Janet callee = janet_get(fiber->data[fiber->stackstart], name);
+ Janet callee = method_to_fun(name, fiber->data[fiber->stackstart]);
if (janet_checktype(callee, JANET_NIL))
janet_panicf("unknown method %v invoked on %v", name, fiber->data[fiber->stackstart]);
return callee;
@@ -287,8 +297,7 @@ static Janet resolve_method(Janet name, JanetFiber *fiber) {
/* Lookup method on value x */
static Janet janet_method_lookup(Janet x, const char *name) {
- Janet kname = janet_ckeywordv(name);
- return janet_get(x, kname);
+ return method_to_fun(janet_ckeywordv(name), x);
}
/* Call a method first on the righthand side, and then on the left hand side with a prefix */