From 6d4925e61687c2221ab20a4dd2371d1a3e7acb2d Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Wed, 9 Oct 2019 14:26:04 +0100 Subject: Implement function definitions Functions can now be defined using the "def" construct. A "main" function has to be defined for LLVM to compile the program. Recursive function definitions are not supported, since all values are eagerly evaluated, causing infinite recursion of the non-base case. Recursive definitions can be supported either by including an if primitive that does not evaluate both sides, or by implementing support for lazy evalution. I'm interested in exploring the latter, but will probably implement the former for now. Similar to the if primitive above, the def primitive is currently an implementation which could potentially be altered into a function that manipulates meta-variables at compile time. This would require compile-time evaluation of functions, which would be really cool, but is also superfluous to the current goal. I might return to this idea after I'm happy with the base implementation of the language. --- parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index 2f302fb..6b03339 100644 --- a/parse.y +++ b/parse.y @@ -32,7 +32,7 @@ void yyerror(char *s, ...); %% cmds: - | cmds sexpr { codegen($2); } + | cmds sexpr { fprint_sexpr(stderr, $2); codegen($2); } sexpr: '(' sexpr ';' sexpr ')' { $$ = new_node($2, $4); } | '(' sexpr sexpr ')' { $$ = new_node($2, $3); } -- cgit v1.2.1