lazyness
This commit is contained in:
11
labubu.c
11
labubu.c
@@ -279,7 +279,7 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) {
|
||||
case AST_FUNCTION:
|
||||
f = malloc(sizeof (labubu_ast));
|
||||
f->tag = AST_FUNCTION;
|
||||
f->data.AST_FUNCTION.body = reduce(ast->data.AST_FUNCTION.body, env);
|
||||
f->data.AST_FUNCTION.body = ast->data.AST_FUNCTION.body;
|
||||
f->data.AST_FUNCTION.lambda = ast->data.AST_FUNCTION.lambda;
|
||||
return f;
|
||||
case AST_VARIABLE:
|
||||
@@ -299,17 +299,15 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) {
|
||||
*ast1 = *ast;
|
||||
return ast1;
|
||||
case AST_APPLICATION:
|
||||
v = reduce(ast->data.AST_APPLICATION.v, env);
|
||||
|
||||
f = reduce(ast->data.AST_APPLICATION.f, env);
|
||||
|
||||
if (f->tag == AST_FUNCTION) {
|
||||
push(env, f->data.AST_FUNCTION.lambda, v);
|
||||
|
||||
push(env, f->data.AST_FUNCTION.lambda, ast->data.AST_APPLICATION.v);
|
||||
labubu_ast* ast1 = reduce(f->data.AST_FUNCTION.body, env);
|
||||
pop(env);
|
||||
return ast1;
|
||||
} else {
|
||||
v = reduce(ast->data.AST_APPLICATION.v, env);
|
||||
labubu_ast* ast1 = malloc(sizeof (labubu_ast));
|
||||
*ast1 = (labubu_ast) {
|
||||
.tag = AST_APPLICATION,
|
||||
@@ -348,5 +346,6 @@ int main (void) {
|
||||
read("(\\x.x x)");
|
||||
read("(\\x.x \\y.y)");
|
||||
read("((\\a.\\b.((a b) \\x.\\y.y) \\x.\\y.y) \\x.\\y.x)");
|
||||
read("(\\n.\\f.\\x.(f ((n f) x)) \\f.\\x.(f (f (f x))))");
|
||||
read("\\f.(\\x.(f (x x)) \\x.(f (x x)))");
|
||||
read("\\f.(\\x.(f(x x))\\x.(f(x x)))");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user