Compare commits
2 Commits
8924818ec4
...
b7b90f528b
Author | SHA1 | Date | |
---|---|---|---|
b7b90f528b | |||
0ef44be808 |
6
TODO.md
6
TODO.md
@@ -1,5 +1,7 @@
|
|||||||
1. Differentiate parameters and arguments -- params for function definitions,
|
EXCEPTION HANDLING: exception ast type should have as data a giant enum of
|
||||||
arguments for function calls
|
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.
|
Change editor to GNU Readline.
|
||||||
Make variables persist through lines in the editor.
|
Make variables persist through lines in the editor.
|
||||||
|
@@ -28,7 +28,8 @@ AST* builtin_sum(size_t argc, AST** argv, Scope* parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AST* builtin_sub(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);
|
AST* first = exec_exp(*argv, parent);
|
||||||
if (first->type == AST_TYPE_EXC)
|
if (first->type == AST_TYPE_EXC)
|
||||||
return ast_init(
|
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) {
|
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);
|
AST* first = exec_exp(*argv, parent);
|
||||||
if (first->type == AST_TYPE_EXC)
|
if (first->type == AST_TYPE_EXC)
|
||||||
return ast_init(
|
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) {
|
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);
|
AST* first = exec_exp(*argv, parent);
|
||||||
if (first->type == AST_TYPE_EXC)
|
if (first->type == AST_TYPE_EXC)
|
||||||
return ast_init(
|
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));
|
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));
|
||||||
|
}
|
||||||
|
@@ -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.
|
// Function definitions. Convert to VDef of Lambda.
|
||||||
| WORD GROUPS arg GROUPE exp {
|
| WORD GROUPS arg GROUPE exp {
|
||||||
size_t parc = $3->ln;
|
size_t parc = $3->ln;
|
||||||
|
@@ -15,6 +15,9 @@ AST* builtin_mul(size_t argc, AST** argv, Scope* parent);
|
|||||||
// Divide nums.
|
// Divide nums.
|
||||||
AST* builtin_div(size_t argc, AST** argv, Scope* parent);
|
AST* builtin_div(size_t argc, AST** argv, Scope* parent);
|
||||||
|
|
||||||
|
// Die.
|
||||||
|
AST* builtin_die(size_t argc, AST** argv, Scope* parent);
|
||||||
|
|
||||||
struct builtin_data {
|
struct builtin_data {
|
||||||
char* name;
|
char* name;
|
||||||
AST* (*fn)(size_t argc, AST** argv, Scope* parent);
|
AST* (*fn)(size_t argc, AST** argv, Scope* parent);
|
||||||
@@ -25,6 +28,7 @@ static struct builtin_data BUILTIN_FNS[] = {
|
|||||||
{ "sub", builtin_sub },
|
{ "sub", builtin_sub },
|
||||||
{ "mul", builtin_mul },
|
{ "mul", builtin_mul },
|
||||||
{ "div", builtin_div },
|
{ "div", builtin_div },
|
||||||
|
{ "die", builtin_die },
|
||||||
};
|
};
|
||||||
#define BUILTIN_FNS_LN (arrln(BUILTIN_FNS))
|
#define BUILTIN_FNS_LN (arrln(BUILTIN_FNS))
|
||||||
|
|
||||||
|
@@ -62,6 +62,13 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
AST* eval = exec_start(root);
|
AST* eval = exec_start(root);
|
||||||
ast_print(eval);
|
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();
|
gc_hack_free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user