repositories
/
lambda.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3b14b51
)
fix memory leak
author
Mart Lubbers
<mart@martlubbers.net>
Wed, 23 May 2018 08:40:49 +0000
(10:40 +0200)
committer
Mart Lubbers
<mart@martlubbers.net>
Wed, 23 May 2018 08:40:49 +0000
(10:40 +0200)
lambda.y
patch
|
blob
|
history
reduce.c
patch
|
blob
|
history
diff --git
a/lambda.y
b/lambda.y
index
b0fe73a
..
3aff9c1
100644
(file)
--- a/
lambda.y
+++ b/
lambda.y
@@
-148,7
+148,7
@@
lambda
struct lambda *t = $1;
printf(" ");
for(unsigned int i = 0; i<999; i++)
struct lambda *t = $1;
printf(" ");
for(unsigned int i = 0; i<999; i++)
- if(!lambda_reduce(&t, &t,
tru
e))
+ if(!lambda_reduce(&t, &t,
fals
e))
break;
lambda_print(t, NULL);
putchar('\n');
break;
lambda_print(t, NULL);
putchar('\n');
diff --git
a/reduce.c
b/reduce.c
index
91299fc
..
bbe52de
100644
(file)
--- a/
reduce.c
+++ b/
reduce.c
@@
-6,20
+6,15
@@
#include "print.h"
#include "mem.h"
#include "print.h"
#include "mem.h"
-#define binder(t) (*t)->data.identifier.binding
#define lhs(t) (*t)->data.application.expr1
#define rhs(t) (*t)->data.application.expr2
#define bdy(t) (*t)->data.abstraction.expr
void lambda_beta(struct lambda *binding, struct lambda **body, struct lambda *target, struct lambda *total)
{
#define lhs(t) (*t)->data.application.expr1
#define rhs(t) (*t)->data.application.expr2
#define bdy(t) (*t)->data.abstraction.expr
void lambda_beta(struct lambda *binding, struct lambda **body, struct lambda *target, struct lambda *total)
{
-// lambda_print(*body, NULL);
-// printf(" [%s=", binding->data.abstraction.ident);
-// lambda_print(target, NULL);
-// printf("]\n");
switch((*body)->which){
case lambda_ident:
switch((*body)->which){
case lambda_ident:
- if(
binder(body)
== binding){
+ if(
(*body)->data.identifier.binding
== binding){
lambda_free(*body);
*body = target;
target->refcount++;
lambda_free(*body);
*body = target;
target->refcount++;
@@
-47,8
+42,10
@@
bool lambda_reduce(struct lambda **t, struct lambda **total, bool applicative)
if(lhs(t)->data.abstraction.strict)
lambda_reduce(&rhs(t), total, true);
if(lhs(t)->data.abstraction.strict)
lambda_reduce(&rhs(t), total, true);
- if(lhs(t) == rhs(t))
+ if(lhs(t) == rhs(t)){
+ lhs(t)->refcount--;
rhs(t) = copy(rhs(t));
rhs(t) = copy(rhs(t));
+ }
//In this abstraction we substitute the result with the rhs
lambda_print(*total, *t);
//In this abstraction we substitute the result with the rhs
lambda_print(*total, *t);