Compare commits

..

2 Commits

Author SHA1 Message Date
b7b90f528b Created an awful hack for a clean exit on die(). 2025-08-26 18:30:08 -04:00
0ef44be808 Fixed some builtin arithmetic logic. 2025-08-26 18:24:28 -04:00
5 changed files with 36 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
1. Differentiate parameters and arguments -- params for function definitions,
arguments for function calls
EXCEPTION HANDLING: exception ast type should have as data a giant enum of
possible types, rather than a char* message. A description of each type could be
handled under the exception type and print logic. For now, executor checks
message for special exceptions e.g. exit().
Change editor to GNU Readline.
Make variables persist through lines in the editor.

View File

@@ -28,7 +28,8 @@ AST* builtin_sum(size_t argc, AST** argv, Scope* parent) {
}
AST* builtin_sub(size_t argc, AST** argv, Scope* parent) {
log_dbg("Got here");
if (argc <= 0) return ast_init(AST_TYPE_NUM, ast_num_data_init(0));
AST* first = exec_exp(*argv, parent);
if (first->type == AST_TYPE_EXC)
return ast_init(
@@ -63,7 +64,8 @@ AST* builtin_sub(size_t argc, AST** argv, Scope* parent) {
}
AST* builtin_mul(size_t argc, AST** argv, Scope* parent) {
log_dbg("Got here");
if (argc <= 0) return ast_init(AST_TYPE_NUM, ast_num_data_init(0));
AST* first = exec_exp(*argv, parent);
if (first->type == AST_TYPE_EXC)
return ast_init(
@@ -98,7 +100,8 @@ AST* builtin_mul(size_t argc, AST** argv, Scope* parent) {
}
AST* builtin_div(size_t argc, AST** argv, Scope* parent) {
log_dbg("Got here");
if (argc <= 0) return ast_init(AST_TYPE_NUM, ast_num_data_init(0));
AST* first = exec_exp(*argv, parent);
if (first->type == AST_TYPE_EXC)
return ast_init(
@@ -131,3 +134,7 @@ AST* builtin_div(size_t argc, AST** argv, Scope* parent) {
return ast_init(AST_TYPE_NUM, ast_num_data_init(total));
}
AST* builtin_die(size_t argc, AST** argv, Scope* parent) {
return ast_init(AST_TYPE_EXC, ast_exc_data_init("8", NULL));
}

View File

@@ -158,6 +158,17 @@ exp:
));
}
// Call (hacky convenient form).
| WORD GROUPS GROUPE {
size_t argc = 0;
AST** argv = NULL;
$$ = ast_init(AST_TYPE_CALL, ast_call_data_init(
argc,
argv,
ast_init(AST_TYPE_VREF, ast_vref_data_init($1))
));
}
// Function definitions. Convert to VDef of Lambda.
| WORD GROUPS arg GROUPE exp {
size_t parc = $3->ln;

View File

@@ -15,6 +15,9 @@ AST* builtin_mul(size_t argc, AST** argv, Scope* parent);
// Divide nums.
AST* builtin_div(size_t argc, AST** argv, Scope* parent);
// Die.
AST* builtin_die(size_t argc, AST** argv, Scope* parent);
struct builtin_data {
char* name;
AST* (*fn)(size_t argc, AST** argv, Scope* parent);
@@ -25,6 +28,7 @@ static struct builtin_data BUILTIN_FNS[] = {
{ "sub", builtin_sub },
{ "mul", builtin_mul },
{ "div", builtin_div },
{ "die", builtin_die },
};
#define BUILTIN_FNS_LN (arrln(BUILTIN_FNS))

View File

@@ -62,6 +62,13 @@ int main(int argc, char** argv) {
AST* eval = exec_start(root);
ast_print(eval);
// Awful hack to exit when die() is called, until proper exception
// handling is implemented. TODO TODO TODO PLSFIX.
if (eval->type == AST_TYPE_EXC &&
((ASTExcData*)eval->data)->msg[0] == '8') {
gc_hack_free();
exit(1);
}
gc_hack_free();
}