From 5b3df939bb8b399dc48102cf0c9f84e8f8702ea4 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Thu, 3 Feb 2022 03:09:08 -0500 Subject: Move builtins to a separate file Probably want to add more builtins in the future, so pulling it out of `parser.c` seems like the reasonable thing to do --- src/parser.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index 13878d1..f412c79 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,5 +1,6 @@ #include "parser.h" #include "utils.h" +#include "builtins.h" #include #include #include @@ -69,34 +70,6 @@ void dump_block_stack() } } -Node *builtin_print; -Node *builtin_putc; - -void initialize_builtins() -{ - // FIXME: The `TYPE_ANY` is a hack - builtin_print = Node_new(AST_BUILTIN); - builtin_print->func.name = "print"; - builtin_print->func.return_type = type_new(TYPE_INT); - builtin_print->func.num_args = 1; - builtin_print->func.args = (Variable *)calloc(sizeof(Variable), 1); - builtin_print->func.args[0] = (Variable){"val", type_new(TYPE_ANY), 0}; - - builtin_putc = Node_new(AST_BUILTIN); - builtin_putc->func.name = "putc"; - builtin_putc->func.return_type = type_new(TYPE_INT); - builtin_putc->func.num_args = 1; - builtin_putc->func.args = (Variable *)calloc(sizeof(Variable), 2); - builtin_putc->func.args[0] = (Variable){"arg", type_new(TYPE_ANY), 0}; -} - -Node *find_builtin_function(Token *token) -{ - if (strcmp(token->value.as_string, "putc") == 0) { return builtin_putc; } - if (strcmp(token->value.as_string, "print") == 0) { return builtin_print; } - return NULL; -} - Variable *find_local_variable(Token *token) { if (current_function == NULL) -- cgit v1.2.3