Skip to content
/ janet Public
forked from janet-lang/janet

Commit

Permalink
Change inheritance rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
bakpakin committed Mar 19, 2021
1 parent 3c63a48 commit b3e8030
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/boot/boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/core/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,29 @@ 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;
}

/* 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 */
Expand Down

0 comments on commit b3e8030

Please sign in to comment.