aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2016-09-24 14:57:17 +0200
committerCamil Staps2016-09-24 14:57:49 +0200
commit11a550753ae31714fb4618c2cf6d2acd5e7ae712 (patch)
tree6e053f97c3ecbb34e8b6b537934a5e96bae9c227
parentFix memory leak with code (diff)
Removed strictness
-rw-r--r--examples/strict.fusp10
-rw-r--r--interpreter/eval.c21
-rw-r--r--interpreter/graphs.c1
-rw-r--r--interpreter/lex.c1
-rw-r--r--interpreter/parse.c5
-rw-r--r--interpreter/print.c4
-rw-r--r--interpreter/syntax.c1
-rw-r--r--interpreter/syntax.h2
8 files changed, 6 insertions, 39 deletions
diff --git a/examples/strict.fusp b/examples/strict.fusp
deleted file mode 100644
index 5795112..0000000
--- a/examples/strict.fusp
+++ /dev/null
@@ -1,10 +0,0 @@
-sub a b = code sub a b;
-
-take 0 _ = [];
-take _ [] = [];
-take n ![x:xs] = [x:take (sub 1 n) xs];
-
-repeat 0 x = [];
-repeat n x = [x:repeat (sub 1 n) x];
-
-main = take 1 (repeat 200 5);
diff --git a/interpreter/eval.c b/interpreter/eval.c
index f220435..080938c 100644
--- a/interpreter/eval.c
+++ b/interpreter/eval.c
@@ -11,7 +11,6 @@
typedef struct {
char* name;
struct node* node;
- unsigned is_strict;
} replacement;
typedef struct replacements {
@@ -21,12 +20,11 @@ typedef struct replacements {
void eval(fuspel* rules, struct node** node, unsigned to_rnf);
-void push_repl(replacements* repls, char* name, struct node* node, unsigned is_strict) {
+void push_repl(replacements* repls, char* name, struct node* node) {
while (repls->rest) repls = repls->rest;
repls->rest = my_calloc(1, sizeof(replacements));
repls->rest->replacement.name = name;
repls->rest->replacement.node = node;
- repls->rest->replacement.is_strict = is_strict;
repls->rest->rest = NULL;
}
@@ -39,7 +37,6 @@ void free_repls(replacements* repls) {
}
repls->replacement.name = NULL;
repls->replacement.node = NULL;
- repls->replacement.is_strict = 0;
}
}
@@ -77,10 +74,6 @@ void replace_all(fuspel *rules, replacements* repls, struct node** node) {
(*node)->var2 = NULL;
use_node(*node, org_used_count - 1);
}
- if (repls->replacement.is_strict) {
- eval(rules, node, 1);
- free_node(*node, 1, 0);
- }
break;
}
}
@@ -127,14 +120,12 @@ struct node*** flatten_app_args(struct node** from) {
}
unsigned match_expr(fuspel* rules, expression* expr, struct node** node,
- replacements* repls, unsigned is_strict) {
+ replacements* repls) {
replacements* _repls;
for (_repls = repls; _repls->rest; _repls = _repls->rest);
remove_redirects(*node);
- is_strict |= expr->is_strict;
-
if (expr->kind == EXPR_INT ||
expr->kind == EXPR_LIST ||
expr->kind == EXPR_TUPLE)
@@ -145,7 +136,7 @@ unsigned match_expr(fuspel* rules, expression* expr, struct node** node,
return *((int*) (*node)->var1) == *((int*) expr->var1);
case EXPR_NAME:
- push_repl(_repls, (char*) expr->var1, *node, is_strict);
+ push_repl(_repls, (char*) expr->var1, *node);
return 1;
case EXPR_LIST:
@@ -157,8 +148,8 @@ unsigned match_expr(fuspel* rules, expression* expr, struct node** node,
return (*node)->var1 == NULL;
return
- match_expr(rules, expr->var1, (struct node**) &(*node)->var1, _repls, is_strict) &&
- match_expr(rules, expr->var2, (struct node**) &(*node)->var2, _repls, is_strict);
+ match_expr(rules, expr->var1, (struct node**) &(*node)->var1, _repls) &&
+ match_expr(rules, expr->var2, (struct node**) &(*node)->var2, _repls);
default:
return 0;
@@ -186,7 +177,7 @@ int match_rule(fuspel* rules, rewrite_rule* rule, struct node** node,
printf("RULE: %s\n", rule->name);
while (!empty_args_list(args)) {
- if (!match_expr(rules, &args->elem, node, repls, 0)) {
+ if (!match_expr(rules, &args->elem, node, repls)) {
my_free(node_args);
return -1;
}
diff --git a/interpreter/graphs.c b/interpreter/graphs.c
index d793efb..1f0dcb4 100644
--- a/interpreter/graphs.c
+++ b/interpreter/graphs.c
@@ -119,7 +119,6 @@ void cpy_node_to_expression(expression* dst, struct node* src) {
return;
free_expression(dst);
- dst->is_strict = 0;
dst->kind = src->kind;
switch (src->kind) {
diff --git a/interpreter/lex.c b/interpreter/lex.c
index 8946252..94820ca 100644
--- a/interpreter/lex.c
+++ b/interpreter/lex.c
@@ -64,7 +64,6 @@ token_list* lex(token_list* list, char* input) {
case ']': list->elem.kind = TOKEN_CLOSE_SQ; break;
case '=': list->elem.kind = TOKEN_EQUALS; break;
case ',': list->elem.kind = TOKEN_COMMA; break;
- case '!': list->elem.kind = TOKEN_STRICT; break;
default:
if (input[0] == '/' && input[1] == '/') {
while (input && input[0] != '\n') input++;
diff --git a/interpreter/parse.c b/interpreter/parse.c
index f751321..3a611e8 100644
--- a/interpreter/parse.c
+++ b/interpreter/parse.c
@@ -21,11 +21,6 @@ token_list* parse_name(char** name, token_list* list) {
token_list* parse_simple_expression(expression* expr, token_list* list) {
expression* _expr;
- if (list->elem.kind == TOKEN_STRICT) {
- expr->is_strict = 1;
- list = list->rest;
- }
-
switch (list->elem.kind) {
case TOKEN_INT:
expr->kind = EXPR_INT;
diff --git a/interpreter/print.c b/interpreter/print.c
index 2fb6e4b..470f133 100644
--- a/interpreter/print.c
+++ b/interpreter/print.c
@@ -17,7 +17,6 @@ void print_token(token* tk) {
case TOKEN_CLOSE_SQ: c = ']'; break;
case TOKEN_EQUALS: c = '='; break;
case TOKEN_COMMA: c = ','; break;
- case TOKEN_STRICT: c = '!'; break;
case TOKEN_CODE: printf("code "); return;
case TOKEN_IMPORT: printf("import "); return;
case TOKEN_NAME:
@@ -42,9 +41,6 @@ void print_expression(expression* expr) {
if (!expr)
return;
- if (expr->is_strict)
- printf("!");
-
switch (expr->kind) {
case EXPR_INT:
printf("%d", *((int*) expr->var1));
diff --git a/interpreter/syntax.c b/interpreter/syntax.c
index 00c9554..03bc2d4 100644
--- a/interpreter/syntax.c
+++ b/interpreter/syntax.c
@@ -32,7 +32,6 @@ unsigned char len_arg_list(arg_list* list) {
void cpy_expression(expression* dst, expression* src) {
free_expression(dst);
dst->kind = src->kind;
- dst->is_strict = src->is_strict;
switch (dst->kind) {
case EXPR_INT:
dst->var1 = my_calloc(1, sizeof(int));
diff --git a/interpreter/syntax.h b/interpreter/syntax.h
index 9153492..7fae574 100644
--- a/interpreter/syntax.h
+++ b/interpreter/syntax.h
@@ -12,7 +12,6 @@ typedef enum {
TOKEN_CLOSE_P, /* ) */
TOKEN_COMMA, /* , */
TOKEN_COLON, /* : */
- TOKEN_STRICT, /* ! */
TOKEN_CODE, /* code */
TOKEN_IMPORT, /* import */
TOKEN_NAME,
@@ -46,7 +45,6 @@ typedef enum {
typedef struct {
expr_kind kind;
- unsigned is_strict;
void* var1;
void* var2;
} expression;