Updated to use the builtin functions list.
Wow, the type declaration for builtin_fns[] is cursed. Also, first commit from zed :D.
This commit is contained in:
parent
018404eea1
commit
d699f492fa
@ -18,6 +18,13 @@ AST* exec_start(AST* ast) {
|
|||||||
|
|
||||||
HTab* global = htab_init();
|
HTab* global = htab_init();
|
||||||
|
|
||||||
|
for (int i = 0; i < NBUILTIN_FNS; i++)
|
||||||
|
htab_ins(
|
||||||
|
global, builtin_fns_names[i],
|
||||||
|
ast_init(AST_TYPE_BIF, ast_bif_data_init(builtin_fns[i]))
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
htab_ins(
|
htab_ins(
|
||||||
global, "sum", ast_init(AST_TYPE_BIF, ast_bif_data_init(builtin_sum))
|
global, "sum", ast_init(AST_TYPE_BIF, ast_bif_data_init(builtin_sum))
|
||||||
);
|
);
|
||||||
@ -32,7 +39,7 @@ AST* exec_start(AST* ast) {
|
|||||||
|
|
||||||
htab_ins(
|
htab_ins(
|
||||||
global, "div", ast_init(AST_TYPE_BIF, ast_bif_data_init(builtin_div))
|
global, "div", ast_init(AST_TYPE_BIF, ast_bif_data_init(builtin_div))
|
||||||
);
|
);*/
|
||||||
|
|
||||||
// Push global namespace to `scope`.
|
// Push global namespace to `scope`.
|
||||||
stack_push(scope, global);
|
stack_push(scope, global);
|
||||||
|
@ -15,9 +15,14 @@ AST* builtin_mul(size_t argc, AST** argv);
|
|||||||
// Divide nums.
|
// Divide nums.
|
||||||
AST* builtin_div(size_t argc, AST** argv);
|
AST* builtin_div(size_t argc, AST** argv);
|
||||||
|
|
||||||
|
#define NBUILTIN_FNS 4
|
||||||
// The list of built-in functions.
|
// The list of built-in functions.
|
||||||
static AST* (*builtin_fns[])(size_t argc, AST** argv) = {
|
static AST* (*builtin_fns[NBUILTIN_FNS])(size_t argc, AST** argv) = {
|
||||||
builtin_sum, builtin_sub, builtin_mul, builtin_div
|
builtin_sum, builtin_sub, builtin_mul, builtin_div
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static char* builtin_fns_names[NBUILTIN_FNS] = {
|
||||||
|
"sum", "sub", "mul", "div"
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user