aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2021-11-18 23:04:38 +0900
committerShinya Sato <shinnya.sato@gmail.com>2021-11-18 23:04:38 +0900
commit4bf7e08b5c77c3b69af8a1c742d549470b2baff7 (patch)
tree69a0b281e405c10dc13f0818053450a68bbd558c
parent2a03c3ae277778ac960a140bb599c5678aa1a476 (diff)
downloadinpla-4bf7e08b5c77c3b69af8a1c742d549470b2baff7.tar.gz
inpla-4bf7e08b5c77c3b69af8a1c742d549470b2baff7.zip
v0.5.4
Diffstat (limited to '')
-rw-r--r--.gitignore2
-rw-r--r--Changelog.md27
-rw-r--r--src/inpla.y78
3 files changed, 66 insertions, 41 deletions
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 0793f52..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-
-comparison/Inpla/src/msort-800000-reuse.in~
diff --git a/Changelog.md b/Changelog.md
index 272c73e..837574d 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,7 +1,11 @@
# Change log
+### v0.5.4 (released on 18 November 2021)
+#### Bug Fix (minor):
+- A name `x` which occurs as a sub-term will be replaced with a term `s` when there is a connection between `x~s` before all of evaluations, as one of optimisations. It was done only if the `x` occurs not as a sub-term.
+
### v0.5.3 (released on 14 November 2021)
-#### New Features:
+#### New Features (for constants):
- Constants are also specified by an execution option switch `-d` in the format *NAME*=*i*. For instance, when Inpla is invoked with `-d ELEM=1000`, then the `ELEM` is replaced with `1000` during the execution.
- Constants are defined as immutable, so these values cannot be changed. When a file specified by the `-f` option has constant names specified by the `-d` options, these names are bound to the values in the `-d` options.
@@ -9,12 +13,12 @@
### v0.5.2 (released on 10 November 2021)
-#### Bug Fix (minor)
+#### Bug Fix (minor):
- `Free` command did not work for integer numbers, due to the change by v0.5.1, but it was fixed.
### v0.5.1 (released on 2 November 2021)
-#### Bug Fix
+#### Bug Fix:
- Terms in which the same name occurs twice, such as `A(x,x)`, can be freed safely by the `free` command.
@@ -64,36 +68,33 @@
### v0.4.2 (released on 16 October 2021)
-#### Improved
+#### Improved:
- Line edit was improved to support multi-line paste, according to the following suggestion: https://github.com/antirez/linenoise/issues/43
- History in Line edit becomes available.
-#### Bug Fix
+#### Bug Fix:
- Long length lists are printed out as abbreviation of 14-length lists, though these were printed out as 1-length lists after putting long lists.
### v0.4.1 (released on 24 September 2021)
-#### Improved
+#### Improved:
- Line edit is improved so that history can be handled by linenoise:
https://github.com/antirez/linenoise
- The priority of rules are changed so that user defined rules can be taken before built-in rules.
-#### Bug Fix
+#### Bug Fix:
- Constants were consumed when they are referred to, but these should be kept and it was fixed as so.
-
-- A global name that has evaluated and occurred twice already was able to be defined. Now it is prevented.
-
- A global name that has evaluated and occurred twice already was able to be defined. Now it is prevented.
### v0.4.0 (released on 17 September 2021)
-#### New Feature:
+#### New Features:
- Nested guards are supported. As shown in below, nested guards are supported now:
@@ -122,7 +123,7 @@
### v0.3.2 (released on 3 August 2021)
-#### New Feature:
+#### New Features:
- WHNF strategy is supported with -w option. Weak Head Normal Form strategy is available when the Inpla is invoked with -w option. The following is an execution log:
@@ -150,7 +151,7 @@
### v0.3.1 (released on 7 May 2021)
-#### New Feature:
+#### New Features:
- New notation for the built-in Cons agent, h:t. The built-in Cons agent is also written as h:t, besides [h|t]. For instance, a reverse list operation is written as follows:
diff --git a/src/inpla.y b/src/inpla.y
index 3796165..db0304c 100644
--- a/src/inpla.y
+++ b/src/inpla.y
@@ -48,8 +48,8 @@ int ActiveThreadNum=0;
//#define YYDEBUG 1
-#define VERSION "0.5.3"
-#define BUILT_DATE "14 Nov. 2021"
+#define VERSION "0.5.4"
+#define BUILT_DATE "18 Nov. 2021"
extern FILE *yyin;
@@ -3020,12 +3020,13 @@ int CompileStmListFromAst(Ast *at) {
// --- RewriteEQListOnAst ---
-
Ast* SubstAst(char *sym, Ast *aterm, Ast *target, int *result) {
// target is astterm: (AST asttermL asttermR)
// this function replaces sym with aterm in target, i.e. tgs[aterm/sym].
- if (target->id == AST_NAME) {
+ switch (target->id) {
+ case AST_NAME:
+
if (strcmp(target->left->sym, sym) == 0) {
*result = 1;
return aterm;
@@ -3033,12 +3034,13 @@ Ast* SubstAst(char *sym, Ast *aterm, Ast *target, int *result) {
} else {
return target;
}
+ break;
- } else if (target->id == AST_OPCONS) {
+ case AST_OPCONS:
target->right = SubstAst(sym, aterm, target->right, result);
return target;
- } else if (target->id == AST_CONS) {
+ case AST_CONS:
target->left = SubstAst(sym, aterm, target->left, result);
if (*result) {
return target;
@@ -3047,34 +3049,51 @@ Ast* SubstAst(char *sym, Ast *aterm, Ast *target, int *result) {
return target;
}
- } else if ((target->id == AST_TUPLE) ||
- (target->id == AST_AGENT)) {
- // (AST_AGENT (ID_SYM sym NULL) paramlist)
- Ast *port = target->right;
+ case AST_ANNOTATION_L:
+ case AST_ANNOTATION_R:
+
- for(int i=0; i< MAX_PORT; i++) {
- if (port == NULL) break;
+ case AST_TUPLE:
+ case AST_AGENT:
+ {
+ Ast *port;
+ if ((target->id == AST_ANNOTATION_L) ||
+ (target->id == AST_ANNOTATION_R)) {
- port = SubstAst(sym, aterm, port, result);
- if (*result) break;
+ // (AST_ANNOTATION (AST_AGENT (ID_SYM sym NULL) paramlist) NULL)
+ port = target->left->right;
+ } else {
+
+ // (AST_AGENT (ID_SYM sym NULL) paramlist)
+ port = target->right;
+ }
+ for(int i=0; i< MAX_PORT; i++) {
+ if (port == NULL) break;
+
+ port->left = SubstAst(sym, aterm, port->left, result);
+ if (*result) break;
+
port = ast_getTail(port);
+ }
}
return target;
+
+ case AST_LIST:
+ {
+ Ast *elem = target->right;
- } else if (target->id == AST_LIST) {
- Ast *elem = target->right;
-
- while (elem != NULL) {
- elem = SubstAst(sym, aterm, elem, result);
- if (*result) break;
-
- elem = ast_getTail(elem);
+ while (elem != NULL) {
+ elem = SubstAst(sym, aterm, elem, result);
+ if (*result) break;
+
+ elem = ast_getTail(elem);
+ }
}
return target;
- } else {
+ default:
return target;
}
@@ -3099,12 +3118,14 @@ int SubstASTList(int nth, char *sym, Ast *aterm, Ast *eqs) {
result=0;
eq->left = SubstAst(sym, aterm, eq->left, &result);
+
if (result) {
return 1;
}
result=0;
eq->right = SubstAst(sym, aterm, eq->right, &result);
+
if (result) {
return 1;
}
@@ -3134,16 +3155,19 @@ void RewriteEQListOnAST(Ast *eqs) {
// at : (AST_LIST, x1, (AST_LIST, x2, NULL))
target = at->left;
- // printf("\n[target] "); ast_puts(target);
- // printf("\n%dnth in ", nth); ast_puts(eqs); printf("\n\n");
+ // printf("\n[target] "); ast_puts(target);
+ // printf("\n%dnth in ", nth); ast_puts(eqs); printf("\n\n");
if (target->left->id == AST_NAME) {
+
sym = target->left->left->sym;
term = target->right;
+ // printf("%s~",sym); ast_puts(term);
+
if (SubstASTList(nth, sym, term, eqs)) {
- // printf("=== hit %dth\n", nth);
+ // printf("=== hit %dth\n", nth);
if (prev != at) {
@@ -3208,6 +3232,8 @@ void RewriteEQListOnAST(Ast *eqs) {
+
+
int CompileBodyFromAst(Ast *body) {
Ast *stms, *eqs;