mirror of
https://github.com/janet-lang/janet
synced 2024-12-25 07:50:27 +00:00
Remove check for function calls to enable all types,
even nil. Now any value can be called as a function, usually looking itself up in an associative data structure.
This commit is contained in:
parent
6f3bc3d577
commit
2a79d2e749
@ -150,7 +150,7 @@ Janet janet_get(Janet ds, Janet key) {
|
||||
Janet value;
|
||||
switch (janet_type(ds)) {
|
||||
default:
|
||||
janet_panicf("get: expected %T, got %v", JANET_TFLAG_LENGTHABLE, ds);
|
||||
janet_panicf("expected %T, got %v", JANET_TFLAG_LENGTHABLE, ds);
|
||||
value = janet_wrap_nil();
|
||||
break;
|
||||
case JANET_STRUCT:
|
||||
@ -226,7 +226,7 @@ Janet janet_getindex(Janet ds, int32_t index) {
|
||||
if (index < 0) janet_panic("expected non-negative index");
|
||||
switch (janet_type(ds)) {
|
||||
default:
|
||||
janet_panicf("get: expected %T, got %v", JANET_TFLAG_LENGTHABLE, ds);
|
||||
janet_panicf("expected %T, got %v", JANET_TFLAG_LENGTHABLE, ds);
|
||||
value = janet_wrap_nil();
|
||||
break;
|
||||
case JANET_STRING:
|
||||
|
@ -223,10 +223,6 @@ static void *op_lookup[255] = {
|
||||
static Janet call_nonfn(JanetFiber *fiber, Janet callee) {
|
||||
int32_t argn = fiber->stacktop - fiber->stackstart;
|
||||
Janet ds, key;
|
||||
if (!janet_checktypes(callee, JANET_TFLAG_FUNCLIKE)) {
|
||||
janet_panicf("attempted to call %v, expected %T", callee,
|
||||
JANET_TFLAG_CALLABLE);
|
||||
}
|
||||
if (argn != 1) janet_panicf("%v called with arity %d, expected 1", callee, argn);
|
||||
if (janet_checktypes(callee, JANET_TFLAG_INDEXED | JANET_TFLAG_DICTIONARY)) {
|
||||
ds = callee;
|
||||
@ -566,7 +562,7 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
||||
if (janet_fiber_funcframe(fiber, func)) {
|
||||
int32_t n = fiber->stacktop - fiber->stackstart;
|
||||
janet_panicf("%v called with %d argument%s, expected %d",
|
||||
callee, n, n > 1 ? "s" : "", func->def->arity);
|
||||
callee, n, n == 1 ? "s" : "", func->def->arity);
|
||||
}
|
||||
stack = fiber->data + fiber->frame;
|
||||
pc = func->def->bytecode;
|
||||
@ -594,9 +590,10 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
||||
if (janet_checktype(callee, JANET_FUNCTION)) {
|
||||
func = janet_unwrap_function(callee);
|
||||
if (janet_fiber_funcframe_tail(fiber, func)) {
|
||||
janet_stack_frame(fiber->data + fiber->frame)->pc = pc;
|
||||
int32_t n = fiber->stacktop - fiber->stackstart;
|
||||
janet_panicf("%v called with %d argument%s, expected %d",
|
||||
callee, n, n > 1 ? "s" : "", func->def->arity);
|
||||
callee, n, n == 1 ? "s" : "", func->def->arity);
|
||||
}
|
||||
stack = fiber->data + fiber->frame;
|
||||
pc = func->def->bytecode;
|
||||
|
@ -323,8 +323,6 @@ typedef enum JanetType {
|
||||
#define JANET_TFLAG_DICTIONARY (JANET_TFLAG_TABLE | JANET_TFLAG_STRUCT)
|
||||
#define JANET_TFLAG_LENGTHABLE (JANET_TFLAG_BYTES | JANET_TFLAG_INDEXED | JANET_TFLAG_DICTIONARY)
|
||||
#define JANET_TFLAG_CALLABLE (JANET_TFLAG_FUNCTION | JANET_TFLAG_CFUNCTION)
|
||||
#define JANET_TFLAG_FUNCLIKE (JANET_TFLAG_CALLABLE | JANET_TFLAG_INDEXED | JANET_TFLAG_DICTIONARY | \
|
||||
JANET_TFLAG_KEYWORD | JANET_TFLAG_SYMBOL)
|
||||
|
||||
/* We provide three possible implementations of Janets. The preferred
|
||||
* nanboxing approach, for 32 or 64 bits, and the standard C version. Code in the rest of the
|
||||
|
Loading…
Reference in New Issue
Block a user