A lot of work

This commit is contained in:
2026-01-19 05:57:18 -08:00
parent c7af58f674
commit c63b104bc6
12 changed files with 217 additions and 13 deletions
+48
View File
@@ -146,6 +146,9 @@ void parse_lambda_list(LambdaListParseResult *result, LispVal *list) {
++out->n_req;
}
}
if ((seen & KEY) == 0 && out->allow_other_keys) {
RETURN_ERROR(LLPS_SYNTAX, list);
}
out->req = Fnreverse(out->req);
out->opt = Fnreverse(out->opt);
out->kw = Fnreverse(out->kw);
@@ -185,8 +188,53 @@ LispVal *make_builtin_function(LispVal *name, LispVal *(*cfunc)(),
}
// Calling functions
// A simple function has only required args
static ALWAYS_INLINE bool SIMPLE_FUNCTION_P(LispFunction *fobj) {
return !fobj->args.n_opt && !fobj->args.n_kw && NILP(fobj->args.rest);
}
static ALWAYS_INLINE LispVal *
call_simple_native(LispVal *orig_func, LispFunction *fobj, LispVal *args) {
assert(fobj->args.n_req <= MAX_NATIVE_FUNCTION_ARGS);
push_stack_frame(orig_func, fobj, args);
if (!list_length_eq(args, fobj->args.n_req)) {
// TODO incorrect arg count
fprintf(stderr, "Wrong arg count!!\n");
abort();
}
FOREACH(args, arg) {
add_local_reference(arg);
}
LispVal *retval;
switch (fobj->args.n_req) {
case 0:
retval = fobj->impl.native.zero();
case 1:
retval = fobj->impl.native.one(FIRST(args));
case 2:
retval = fobj->impl.native.two(FIRST(args), SECOND(args));
case 3:
retval =
fobj->impl.native.three(FIRST(args), SECOND(args), THIRD(args));
case 4:
retval = fobj->impl.native.four(FIRST(args), SECOND(args), THIRD(args),
FOURTH(args));
case 5:
retval = fobj->impl.native.five(FIRST(args), SECOND(args), THIRD(args),
FOURTH(args), FIFTH(args));
default:
abort();
}
pop_stack_frame();
// TODO probably need to protect retval from GC here
return retval;
}
static ALWAYS_INLINE LispVal *call_native(LispVal *orig_func,
LispFunction *fobj, LispVal *args) {
if (SIMPLE_FUNCTION_P(fobj)) {
return call_simple_native(orig_func, fobj, args);
}
return Qnil;
}