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:
|
case AST_FUNCTION:
|
||||||
f = malloc(sizeof (labubu_ast));
|
f = malloc(sizeof (labubu_ast));
|
||||||
f->tag = AST_FUNCTION;
|
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;
|
f->data.AST_FUNCTION.lambda = ast->data.AST_FUNCTION.lambda;
|
||||||
return f;
|
return f;
|
||||||
case AST_VARIABLE:
|
case AST_VARIABLE:
|
||||||
@@ -299,17 +299,15 @@ labubu_ast* reduce (labubu_ast* ast, labubu_variables* env) {
|
|||||||
*ast1 = *ast;
|
*ast1 = *ast;
|
||||||
return ast1;
|
return ast1;
|
||||||
case AST_APPLICATION:
|
case AST_APPLICATION:
|
||||||
v = reduce(ast->data.AST_APPLICATION.v, env);
|
|
||||||
|
|
||||||
f = reduce(ast->data.AST_APPLICATION.f, env);
|
f = reduce(ast->data.AST_APPLICATION.f, env);
|
||||||
|
|
||||||
if (f->tag == AST_FUNCTION) {
|
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);
|
labubu_ast* ast1 = reduce(f->data.AST_FUNCTION.body, env);
|
||||||
pop(env);
|
pop(env);
|
||||||
return ast1;
|
return ast1;
|
||||||
} else {
|
} else {
|
||||||
|
v = reduce(ast->data.AST_APPLICATION.v, env);
|
||||||
labubu_ast* ast1 = malloc(sizeof (labubu_ast));
|
labubu_ast* ast1 = malloc(sizeof (labubu_ast));
|
||||||
*ast1 = (labubu_ast) {
|
*ast1 = (labubu_ast) {
|
||||||
.tag = AST_APPLICATION,
|
.tag = AST_APPLICATION,
|
||||||
@@ -348,5 +346,6 @@ int main (void) {
|
|||||||
read("(\\x.x x)");
|
read("(\\x.x x)");
|
||||||
read("(\\x.x \\y.y)");
|
read("(\\x.x \\y.y)");
|
||||||
read("((\\a.\\b.((a b) \\x.\\y.y) \\x.\\y.y) \\x.\\y.x)");
|
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