impl a bunch of builtins

This commit is contained in:
2026-07-21 15:10:15 +02:00
parent b0fee03ec0
commit 0034fd79f5
3 changed files with 96 additions and 31 deletions
+15 -30
View File
@@ -15,39 +15,24 @@ static Node *scope_lookup(Scopes *scopes, Nob_String_View name) {
return NULL;
}
void build_scopes(Scopes *scopes) {
// clang-format off
Nob_String_View obj_name = (Nob_String_View){
.items = "+",
.count = 1
};
static void scope_add_function(Scope *scope, const char *name,
LispFunction function) {
Nob_String_View obj_name = nob_sv_from_cstr(name);
ScopeObject obj = (ScopeObject){
.name = obj_name,
.node = (Node){
.kind = NODE_KIND_FUNCTION,
.as_function = {
.name = obj_name,
.apply = lisp_function_addition
}
}
};
nob_da_append(&globalScope, obj);
.node = (Node){.kind = NODE_KIND_FUNCTION,
.as_function = {.name = obj_name, .apply = function}}};
nob_da_append(scope, obj);
}
obj_name = (Nob_String_View){
.items = "println",
.count = 7
};
obj = (ScopeObject){
.name = obj_name,
.node = (Node){
.kind = NODE_KIND_FUNCTION,
.as_function = {
.name = obj_name,
.apply = lisp_function_println
}
}
};
nob_da_append(&globalScope, obj);
void build_scopes(Scopes *scopes) {
// clang-format off
scope_add_function(&globalScope, "+", lisp_function_addition);
scope_add_function(&globalScope, "println", lisp_function_println);
scope_add_function(&globalScope, "list", lisp_function_list);
scope_add_function(&globalScope, "append", lisp_function_append);
scope_add_function(&globalScope, "length", lisp_function_length);
scope_add_function(&globalScope, "null?", lisp_function_isnull);
// clang-format on
nob_da_append(scopes, globalScope);