Global generation

This commit is contained in:
2026-01-18 03:11:17 -08:00
parent 94d5749d31
commit c0b18cda5a
16 changed files with 571 additions and 57 deletions

View File

@ -2,15 +2,22 @@
#define INCLUDED_FUNCTION_H
#include "base.h"
#include "lisp_string.h"
DECLARE_SYMBOL(and_optional);
DECLARE_SYMBOL(and_rest);
DECLARE_SYMBOL(and_key);
DECLARE_SYMBOL(and_allow_other_keys);
struct LambdaList {
size_t n_req;
size_t n_opt;
size_t n_kw;
bool allow_other_keys;
LispVal *req; // list of symbols
LispVal *opt; // list of lists of (name default has-p-name)
LispVal *kw; // ditto opt
LispVal *rest; // symbom (non-nil if we have a rest arg)
LispVal *rest; // symbol (non-nil if we have a rest arg)
};
union native_function {
@ -23,11 +30,45 @@ union native_function {
};
DEFOBJTYPE(Function, FUNCTION, FUNCTIONP, {
LispVal *name; // symbol (or nil for a lambda)
bool is_native;
struct LambdaList args;
LispVal *docstr;
union {
union native_function native;
} impl;
});
typedef enum {
LLPS_OK,
LLPS_DOTTED,
LLPS_REPEAT_SECTION,
LLPS_REPEAT_NAME,
LLPS_SYNTAX,
LLPS_BAD_NAME,
LLPS_N_ERROS,
} LambdaListParseStatus;
const char *llps_strerror(LambdaListParseStatus status);
typedef struct {
struct LambdaList lambda_list;
LambdaListParseStatus status;
LispVal *err_obj; // the object the caused the above status
} LambdaListParseResult;
void parse_lambda_list(LambdaListParseResult *out, LispVal *list);
// This will cause the program to exit if an error occurs while parsing
// LISP_ARGS!
LispVal *make_builtin_function(LispVal *name, LispVal *(*func)(),
const char *lisp_args, size_t args_len,
LispVal *docstr);
#define BUILTIN_FUNCTION_OBJ(cname) \
make_builtin_function( \
Q##cname, (LispVal * (*) ()) F##cname, internal_F##cname##_argstr, \
internal_F##cname##_argstr_len, \
make_lisp_string(internal_F##cname##_docstr, \
internal_F##cname##_docstr_len, false, false))
#endif