aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2022-09-17 22:25:50 +0900
committerShinya Sato <shinnya.sato@gmail.com>2022-09-17 22:25:50 +0900
commitd90c10cd95e399dd7614df76ee06acd1bf721833 (patch)
tree42fd557836de39d4a32a303c40f42393906a6e4c
parent4b0da2732d7adcaa7d85db2ee329f8a52ef88c42 (diff)
parentb10fccefe9a6435328ff9d554995fb5710f74f26 (diff)
downloadinpla-d90c10cd95e399dd7614df76ee06acd1bf721833.tar.gz
inpla-d90c10cd95e399dd7614df76ee06acd1bf721833.zip
Merge branch 'develop'
Diffstat (limited to '')
-rw-r--r--Changelog.md30
-rw-r--r--README.md28
-rw-r--r--comparison/Inpla/src/ack-stream_3-11-reuse.in6
-rw-r--r--comparison/Inpla/src/bsort-20000-reuse.in28
-rw-r--r--comparison/Inpla/src/bsort-20000.in10
-rw-r--r--comparison/Inpla/src/fib-38-reuse.in2
-rw-r--r--comparison/Inpla/src/isort-20000-reuse.in6
-rw-r--r--comparison/Inpla/src/msort-260000-reuse.in3
-rw-r--r--comparison/Inpla/src/msort-800000-reuse.in5
-rw-r--r--comparison/Inpla/src/msort-800000.in2
-rw-r--r--comparison/Inpla/src/qsort-260000-reuse.in5
-rw-r--r--comparison/Inpla/src/qsort-800000-reuse.in7
-rw-r--r--comparison/Inpla/src/qsort-800000.in2
-rw-r--r--pic/benchmark_reuse_v0.10.0.pngbin0 -> 40609 bytes
-rw-r--r--sample/nqueen.in2
-rw-r--r--src/ast.c2
-rw-r--r--src/config.h24
-rw-r--r--src/id_table.c2
-rw-r--r--src/inpla.y453
19 files changed, 498 insertions, 119 deletions
diff --git a/Changelog.md b/Changelog.md
index b693579..61cd225 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,4 +1,34 @@
# Change log
+
+### v0.10.0 (released on 17 September 2022)
+#### Polished (inner)
+* **New instruction set for reuse active pairs**: Inpla supports annotations to reuse active active pairs by putting (\*L) and (\*R) in front of agents in rules as an experiment implementation. New instruction set is released to reuse active pairs. It was just to reuse only nodes for active pairs, but now we can specify the reuse method in the level of ports. For instance, we take the following rule:
+
+ ```
+ A(r) >< B(a,b,c) => (*L)C(r) ~ (*R)B(a,b,c);
+ ```
+ This means that `C(r)` is created on the memory of `A(r)`, and `B(a,b,c)` is reused as it is. This compiled into the following result by the old instruction set. Actually, these active pair agents are reused, but the ID and all ports are specified again the same as MKAGENT.
+
+ ```
+ 0: REUSEAGENT1 var11 id:34 var1
+ 1: REUSEAGENT3 var12 id:32 var6 var7 var8
+ 2: PUSH var11 var12
+ 3: RET
+ ```
+ Now, it is compiled as follows:
+ ```
+ 0: CHID_L $34 // The idL is just changed.
+ 1: PUSH var11 var12
+ 2: RET
+ ```
+ There is no significant improvement in terms of execution speed than I expected, but it becomes useful to demonstrate the execution performance obtained by the theoretical analysis. To keep using the old version, make the following uncommented in `config.h`:
+
+ ```
+ //#define OLD_REUSEAGENT
+ ```
+
+
+
### v0.9.2-3 (released on 22 August 2022)
#### Bux fix
diff --git a/README.md b/README.md
index 89bd031..a557930 100644
--- a/README.md
+++ b/README.md
@@ -6,10 +6,10 @@
Inpla is a multi-threaded parallel interpreter of interaction nets. Once you write programs for sequential execution, it works also in multi-threaded parallel execution. Each thread is managed on each CPU-core with POSIX-thread library.
-* The current version is 0.9.2-3 (bugfix mainly), released on **22 August 2022**. (See [Changelog.md](Changelog.md) for details.)
+* The current version is 0.10.0, released on **17 September 2022**. (See [Changelog.md](Changelog.md) for details.)
* The below graph shows speed-up ratio to threads numbers for programs in the following benchmark table.
-![speedup-ratio](pic/benchmark_reuse_v0.9.2-3.png)
+![speedup-ratio](pic/benchmark_reuse_v0.10.0.png)
- **Comparison in execution time** with other implementations: **Haskell** (GHC version 8.10.7), **OCaml** (ocamlopt, the native-code compiler, version 4.08.1), **Standard ML of New Jersey** v110.74 (interpreter mode) and **Python** 3.8.5 in execution time.
@@ -17,13 +17,13 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri
| | Haskell | OCaml | SML | Python | Inpla8 | Inpla8r |
| -------------- | :------: | :------: | :----: | :----: | :------: | :------: |
-| n-queens 12 | [**0.23**](comparison/Haskell/nqueen-12.hs) | [0.44](comparison/OCaml/nqueen12.ml) | [0.60](comparison/SML/ack3-11.sml) | [3.85](comparison/Python/nqueen-12.py) | [0.53](comparison/Inpla/src/nqueen-12.in) | [0.36](comparison/Inpla/src/nqueen-12-reuse.in) |
-| ack(3,11) | [2.36](comparison/Haskell/ack3-11.hs) | [0.57](comparison/OCaml/ack3_11.ml) | [**0.41**](comparison/SML/ack3-11.sml) | [-](comparison/Python/ack3-11.py) | [0.90](comparison/Inpla/src/ack-stream_3-11.in) | [0.71](comparison/Inpla/src/ack-stream_3-11-reuse.in) |
-| fib 38 | [1.61](comparison/Haskell/fib-38.hs) | [**0.15**](comparison/OCaml/fib38.ml) | [0.27](comparison/SML/fib-38.sml) | [9.03](comparison/Python/fib-38.py) | [0.42](comparison/Inpla/src/fib-38.in) | [0.46](comparison/Inpla/src/fib-38-reuse.in) |
-| bsort 20000 | [4.98](comparison/Haskell/bsort-20000.hs) | [6.44](comparison/OCaml/bsort20000.ml) | [2.38](comparison/SML/bsort-20000.sml) | [20.64](comparison/Python/bsort-20000.py) | [2.26](comparison/Inpla/src/bsort-20000.in) | [**1.60**](comparison/Inpla/src/bsort-20000-reuse.in) |
-| isort 20000 | [2.18](comparison/Haskell/isort-20000.hs) | [1.48](comparison/OCaml/isort20000.ml) | [0.59](comparison/SML/isort-20000.sml) | [9.20](comparison/Python/isort-20000.py) | [**0.30**](comparison/Inpla/src/isort-20000.in) | [0.34](comparison/Inpla/src/isort-20000-reuse.in) |
-| qsort 260000 | [0.32](comparison/Haskell/qsort-800000.hs) | [0.22](comparison/OCaml/qsort260000.ml) | [0.27](comparison/SML/qsort-260000.sml) | [15.03](comparison/Python/qsort-260000.py) | [0.15](comparison/Inpla/src/qsort-260000.in) | [**0.12**](comparison/Inpla/src/qsort-260000-reuse.in) |
-| msort 260000 | [0.38](comparison/Haskell/msort-800000.hs) | [0.17](comparison/OCaml/msort260000.ml) | [0.28](comparison/SML/msort-260000.sml) | [15.57](comparison/Python/msort-260000.py) | [**0.15**](comparison/Inpla/src/msort-260000.in) | [**0.15**](comparison/Inpla/src/msort-260000-reuse.in) |
+| n-queens 12 | [**0.23**](comparison/Haskell/nqueen-12.hs) | [0.44](comparison/OCaml/nqueen12.ml) | [0.60](comparison/SML/ack3-11.sml) | [3.81](comparison/Python/nqueen-12.py) | [0.54](comparison/Inpla/src/nqueen-12.in) | [0.36](comparison/Inpla/src/nqueen-12-reuse.in) |
+| ack(3,11) | [2.36](comparison/Haskell/ack3-11.hs) | [0.57](comparison/OCaml/ack3_11.ml) | [**0.42**](comparison/SML/ack3-11.sml) | [-](comparison/Python/ack3-11.py) | [0.88](comparison/Inpla/src/ack-stream_3-11.in) | [0.76](comparison/Inpla/src/ack-stream_3-11-reuse.in) |
+| fib 38 | [1.61](comparison/Haskell/fib-38.hs) | [**0.15**](comparison/OCaml/fib38.ml) | [0.27](comparison/SML/fib-38.sml) | [9.17](comparison/Python/fib-38.py) | [0.42](comparison/Inpla/src/fib-38.in) | [0.43](comparison/Inpla/src/fib-38-reuse.in) |
+| bsort 20000 | [5.01](comparison/Haskell/bsort-20000.hs) | [6.44](comparison/OCaml/bsort20000.ml) | [2.37](comparison/SML/bsort-20000.sml) | [20.58](comparison/Python/bsort-20000.py) | [2.17](comparison/Inpla/src/bsort-20000.in) | [**1.49**](comparison/Inpla/src/bsort-20000-reuse.in) |
+| isort 20000 | [2.16](comparison/Haskell/isort-20000.hs) | [1.48](comparison/OCaml/isort20000.ml) | [0.60](comparison/SML/isort-20000.sml) | [9.34](comparison/Python/isort-20000.py) | [**0.30**](comparison/Inpla/src/isort-20000.in) | [0.33](comparison/Inpla/src/isort-20000-reuse.in) |
+| qsort 260000 | [0.36](comparison/Haskell/qsort-800000.hs) | [0.22](comparison/OCaml/qsort260000.ml) | [0.27](comparison/SML/qsort-260000.sml) | [15.04](comparison/Python/qsort-260000.py) | [0.16](comparison/Inpla/src/qsort-260000.in) | [**0.12**](comparison/Inpla/src/qsort-260000-reuse.in) |
+| msort 260000 | [0.38](comparison/Haskell/msort-800000.hs) | [0.17](comparison/OCaml/msort260000.ml) | [0.26](comparison/SML/msort-260000.sml) | [15.55](comparison/Python/msort-260000.py) | [0.16](comparison/Inpla/src/msort-260000.in) | [**0.15**](comparison/Inpla/src/msort-260000-reuse.in) |
@@ -81,7 +81,7 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri
```
$ ./inpla
- Inpla 0.9.2-3 : Interaction nets as a programming language [built: 22 August 2022]
+ Inpla 0.10.0 : Interaction nets as a programming language [built: 17 September 2022]
>>>
```
@@ -129,7 +129,7 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri
gcd(ret) >< (int a, int b)
| b==0 => ret ~ a
| _ => gcd(ret) ~ (b, a%b);
-
+
// Nets
gcd(r) ~ (14,21);
r; // it should be 7
@@ -139,7 +139,7 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri
```
$ ./inpla -f sample/gcd.in
- Inpla 0.9.2-3 : Interaction nets as a programming language [built: 22 August 2022]
+ Inpla 0.10.0 : Interaction nets as a programming language [built: 17 September 2022]
(4 interactions, 0.00 sec)
7
@@ -172,7 +172,7 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri
```
$ ./inpla -f sample/isort.in
- Inpla 0.9.2-3 : Interaction nets as a programming language [built: 22 August 2022]
+ Inpla 0.10.0 : Interaction nets as a programming language [built: 17 September 2022]
(16 interactions, 0.00 sec)
[1,2,3,6,9]
@@ -242,7 +242,7 @@ Inpla is a multi-threaded parallel interpreter of interaction nets. Once you wri
```
$ ./inpla -f sample/qsort.in
- Inpla 0.9.2-3 : Interaction nets as a programming language [built: 22 August 2022]
+ Inpla 0.10.0 : Interaction nets as a programming language [built: 17 September 2022]
(22 interactions, 0.00 sec)
[1,2,3,6,9]
diff --git a/comparison/Inpla/src/ack-stream_3-11-reuse.in b/comparison/Inpla/src/ack-stream_3-11-reuse.in
index 7d7c701..4a05f82 100644
--- a/comparison/Inpla/src/ack-stream_3-11-reuse.in
+++ b/comparison/Inpla/src/ack-stream_3-11-reuse.in
@@ -24,7 +24,7 @@ Ack(ret, n) >< (int m)
| _ => (*L)Ackm(ret, m)~n;
Ackm(ret, int m) >< (int n)
-| n==0 => Ack(ret,Inc(0)) ~ (m-1)
+| n==0 => (*L)Ack(ret,Inc(0)) ~ (m-1)
| _ => (*L)Ack(cnt,n-1)~m, Ack(ret,cnt)~(m-1);
Ackm(ret, int m) >< Inc(n)
@@ -34,8 +34,8 @@ Sumup(ret, int sum) >< Inc(x) => (*L)Sumup(ret, sum+1)~x;
Sumup(ret, int sum) >< (int n) => ret~sum+n;
-//AckMain(ret)><(int m, int n) => (*L)Ack(cnt,n)~m, (*R)Sumup(ret,0)~cnt;
-AckMain(ret)><(int m, int n) => Ack(cnt,n)~m, Sumup(ret,0)~cnt;
+AckMain(ret)><(int m, int n) => (*L)Ack(cnt,n)~m, (*R)Sumup(ret,0)~cnt;
+//AckMain(ret)><(int m, int n) => Ack(cnt,n)~m, Sumup(ret,0)~cnt;
AckMain(ret)~(3,11);
ret;
diff --git a/comparison/Inpla/src/bsort-20000-reuse.in b/comparison/Inpla/src/bsort-20000-reuse.in
index c5080fe..0b7e551 100644
--- a/comparison/Inpla/src/bsort-20000-reuse.in
+++ b/comparison/Inpla/src/bsort-20000-reuse.in
@@ -1,26 +1,16 @@
// Bubble sort with the same algorithm as others
-/*
-// length
-length_(r,n) >< [] => r~n;
-length_(r,int n) >< (int x):xs => length_(r,n+1)~xs;
-
-length(r) >< [] => r~0;
-length(r) >< x:xs => length_(r,0) ~ x:xs;
-*/
-
-
// stream length
len_stream_(len, list, int ct) >< [] => len~ct, list~(*R)[];
len_stream_(len, list, int ct) >< x:xs =>
list~(*R)(x:cnt),
- len_stream_(len, cnt, ct+1) ~ xs;
+ (*L)len_stream_(len, cnt, ct+1) ~ xs;
len_stream(len, list) >< [] => len~0, list~(*R)[];
len_stream(len, list) >< x:xs =>
- list~(x:cnt),
- len_stream_(len, cnt, 1)~xs;
+ list~(*R)(x:cnt),
+ (*L)len_stream_(len, cnt, 1)~xs;
// bubble sort
@@ -32,18 +22,18 @@ bs_Cons(r, int n)>< x:xs => (*L)bs_ConsCons(r, n, x) ~ xs;
bs_Cons(r, int n)>< [] => r~(*R)[];
bs_ConsCons(r, int n, int x) >< (int y):ys
-| x < y => r~x:cnt, (*L)bs(cnt, y:ys) ~(n-1)
-| _ => r~y:cnt, (*L)bs(cnt, x:ys)~(n-1);
+| x < y => r~x:cnt, (*L)bs(cnt, (*R)(y:ys)) ~(n-1)
+| _ => r~y:cnt, (*L)bs(cnt, (*R)(x:ys))~(n-1);
bs_ConsCons(r, int n, int x) >< [] => r~(*R)[x];
go(r,xs) >< (int n)
| n==0 => r~xs
-| _ => bs(cnt, xs)~n, (*L)go(r, cnt)~(n-1);
+| _ => (*L)bs(cnt, xs)~n, go(r, cnt)~(n-1);
-bsort(r) >< [] => r~[];
+bsort(r) >< [] => r~(*R)[];
bsort(r) >< x:xs =>
- (*L)len_stream(len, alist) ~ (*R)(x:xs),
- go(r, alist)~lengthDec1,
+ len_stream(len, alist) ~ (*R)(x:xs),
+ (*L)go(r, alist)~lengthDec1,
Sub(lengthDec1,len)~1;
diff --git a/comparison/Inpla/src/bsort-20000.in b/comparison/Inpla/src/bsort-20000.in
index e012bc6..8beb835 100644
--- a/comparison/Inpla/src/bsort-20000.in
+++ b/comparison/Inpla/src/bsort-20000.in
@@ -1,15 +1,5 @@
// Bubble sort with the same algorithm as others
-/*
-// length
-length_(r,n) >< [] => r~n;
-length_(r,int n) >< (int x):xs => length_(r,n+1)~xs;
-
-length(r) >< [] => r~0;
-length(r) >< x:xs => length_(r,0) ~ x:xs;
-*/
-
-
// stream length
len_stream_(len, list, int ct) >< [] => len~ct, list~[];
len_stream_(len, list, int ct) >< x:xs =>
diff --git a/comparison/Inpla/src/fib-38-reuse.in b/comparison/Inpla/src/fib-38-reuse.in
index e56fabd..c95127e 100644
--- a/comparison/Inpla/src/fib-38-reuse.in
+++ b/comparison/Inpla/src/fib-38-reuse.in
@@ -2,7 +2,7 @@
Fib(r) >< (int n)
| n == 0 => r~0
| n == 1 => r~1
-| _ => Fib(cnt1)~(n-1), Fib(cnt2)~(n-2), (*L)Add(r,cnt2)~cnt1;
+| _ => (*L)Fib(cnt1)~(n-1), Fib(cnt2)~(n-2), Add(r,cnt2)~cnt1;
Fib(r)~38;
diff --git a/comparison/Inpla/src/isort-20000-reuse.in b/comparison/Inpla/src/isort-20000-reuse.in
index 9d7c7ab..aa63652 100644
--- a/comparison/Inpla/src/isort-20000-reuse.in
+++ b/comparison/Inpla/src/isort-20000-reuse.in
@@ -1,11 +1,11 @@
// Insertion sort
-isort(ret) >< [] => ret~[];
-isort(ret) >< x:xs => (*L)I(ret, x)~cnt, (*R)isort(cnt)~xs;
+isort(ret) >< [] => ret~(*R)[];
+isort(ret) >< x:xs => (*R)I(ret, x)~cnt, (*L)isort(cnt)~xs;
I(ret, int x) >< [] => ret~[x];
I(ret, int x) >< (int y):ys
| x<=y => ret~(*L)(x:(*R)(y:ys))
-| _ => ret~(*L)(y:cnt), (*R)I(cnt, x)~ys;
+| _ => (*L)I(cnt, x)~ys, ret~(*R)(y:cnt);
// creates a random list
diff --git a/comparison/Inpla/src/msort-260000-reuse.in b/comparison/Inpla/src/msort-260000-reuse.in
index 7201ac7..14aa4a3 100644
--- a/comparison/Inpla/src/msort-260000-reuse.in
+++ b/comparison/Inpla/src/msort-260000-reuse.in
@@ -4,7 +4,7 @@ msort(ret) >< x:xs => (*L)msort_tail(ret, x)~xs;
msort_tail(ret, int n) >< [] => ret~[n];
msort_tail(ret, int n) >< x:xs =>
- split(left,right) ~ (*R)(n:x:xs),
+ split(left,right) ~ n:(*R)(x:xs),
msort(a)~left, msort(b)~right, (*L)merge(ret,b)~a;
merge(ret, snd) >< [] => ret~snd;
@@ -15,7 +15,6 @@ mergeCC(ret, int y, ys) >< (int x):xs
| x <= y => ret~(x:cnt), (*L)mergeCC(cnt, y, ys) ~ xs
| _ => ret~(y:cnt), (*L)mergeCC(cnt, x, xs) ~ ys;
-
split(right,left) >< [] => right~[], left~[];
split(right,left) >< x:xs =>
right~(*R)(x:cntl), left~cntr, (*L)split(cntr,cntl)~xs;
diff --git a/comparison/Inpla/src/msort-800000-reuse.in b/comparison/Inpla/src/msort-800000-reuse.in
index 4572623..f50f359 100644
--- a/comparison/Inpla/src/msort-800000-reuse.in
+++ b/comparison/Inpla/src/msort-800000-reuse.in
@@ -4,7 +4,7 @@ msort(ret) >< x:xs => (*L)msort_tail(ret, x)~xs;
msort_tail(ret, int n) >< [] => ret~[n];
msort_tail(ret, int n) >< x:xs =>
- split(left,right) ~ (*R)(n:x:xs),
+ split(left,right) ~ n:(*R)(x:xs),
msort(a)~left, msort(b)~right, (*L)merge(ret,b)~a;
merge(ret, snd) >< [] => ret~snd;
@@ -15,7 +15,6 @@ mergeCC(ret, int y, ys) >< (int x):xs
| x <= y => ret~(x:cnt), (*L)mergeCC(cnt, y, ys) ~ xs
| _ => ret~(y:cnt), (*L)mergeCC(cnt, x, xs) ~ ys;
-
split(right,left) >< [] => right~[], left~[];
split(right,left) >< x:xs =>
right~(*R)(x:cntl), left~cntr, (*L)split(cntr,cntl)~xs;
@@ -29,7 +28,7 @@ make_RandList(ret) >< (int n)
// validation checks
-valid(ret) >< [] => ret~False;
+valid(ret) >< [] => ret~True;
valid(ret) >< x:xs => (*L)valid_Cons(ret,x)~xs;
valid_Cons(ret, int x) >< [] => ret~True;
diff --git a/comparison/Inpla/src/msort-800000.in b/comparison/Inpla/src/msort-800000.in
index 3c43aa6..ab330a8 100644
--- a/comparison/Inpla/src/msort-800000.in
+++ b/comparison/Inpla/src/msort-800000.in
@@ -29,7 +29,7 @@ make_RandList(ret) >< (int n)
// validation checks
-valid(ret) >< [] => ret~False;
+valid(ret) >< [] => ret~True;
valid(ret) >< x:xs => valid_Cons(ret,x)~xs;
valid_Cons(ret, int x) >< [] => ret~True;
diff --git a/comparison/Inpla/src/qsort-260000-reuse.in b/comparison/Inpla/src/qsort-260000-reuse.in
index b44e958..33cd7dc 100644
--- a/comparison/Inpla/src/qsort-260000-reuse.in
+++ b/comparison/Inpla/src/qsort-260000-reuse.in
@@ -5,6 +5,7 @@ qsort(ret) >< (int x):xs =>
(*L)qsort(cntl)~left, qsort(cntr)~right,
Append(ret, x:cntl)~cntr;
+
// Note: `Append' is implemented as built-in.
@@ -12,6 +13,10 @@ part(int x, a, b) >< [] => a~(*L)[], b~(*R)[];
part(int x, a, b) >< (int y):ys
| y<x => b~(*R)(y:cnt), (*L)part(x, a, cnt)~ys
| _ => a~(*R)(y:cnt), (*L)part(x, cnt, b)~ys;
+//| y<x => (*L)part(x, a, cnt)~ys, b~(*R)(y:cnt) // quite BAD!
+//| _ => (*L)part(x, cnt, b)~ys, a~(*R)(y:cnt); // quite BAD!
+
+
// creates a random list
diff --git a/comparison/Inpla/src/qsort-800000-reuse.in b/comparison/Inpla/src/qsort-800000-reuse.in
index 7f41045..b1e2ae1 100644
--- a/comparison/Inpla/src/qsort-800000-reuse.in
+++ b/comparison/Inpla/src/qsort-800000-reuse.in
@@ -5,6 +5,7 @@ qsort(ret) >< (int x):xs =>
(*L)qsort(cntl)~left, qsort(cntr)~right,
Append(ret, x:cntl)~cntr;
+
// Note: `Append' is implemented as built-in.
@@ -12,6 +13,10 @@ part(int x, a, b) >< [] => a~(*L)[], b~(*R)[];
part(int x, a, b) >< (int y):ys
| y<x => b~(*R)(y:cnt), (*L)part(x, a, cnt)~ys
| _ => a~(*R)(y:cnt), (*L)part(x, cnt, b)~ys;
+//| y<x => (*L)part(x, a, cnt)~ys, b~(*R)(y:cnt) // quite BAD!
+//| _ => (*L)part(x, cnt, b)~ys, a~(*R)(y:cnt); // quite BAD!
+
+
// creates a random list
@@ -22,7 +27,7 @@ make_RandList(ret) >< (int n)
// validation checks
-valid(ret) >< [] => ret~False;
+valid(ret) >< [] => ret~True;
valid(ret) >< x:xs => (*L)valid_Cons(ret,x)~xs;
valid_Cons(ret, int x) >< [] => ret~True;
diff --git a/comparison/Inpla/src/qsort-800000.in b/comparison/Inpla/src/qsort-800000.in
index 6d28245..e1b9071 100644
--- a/comparison/Inpla/src/qsort-800000.in
+++ b/comparison/Inpla/src/qsort-800000.in
@@ -22,7 +22,7 @@ make_RandList(ret) >< (int n)
// validation checks
-valid(ret) >< [] => ret~False;
+valid(ret) >< [] => ret~True;
valid(ret) >< x:xs => valid_Cons(ret,x)~xs;
valid_Cons(ret, int x) >< [] => ret~True;
diff --git a/pic/benchmark_reuse_v0.10.0.png b/pic/benchmark_reuse_v0.10.0.png
new file mode 100644
index 0000000..5f04171
--- /dev/null
+++ b/pic/benchmark_reuse_v0.10.0.png
Binary files differ
diff --git a/sample/nqueen.in b/sample/nqueen.in
index 03b2463..dd50ad1 100644
--- a/sample/nqueen.in
+++ b/sample/nqueen.in
@@ -138,4 +138,4 @@ queen__chk_lastelem(r, b, int n, int m) >< (int len_ret)
// ----------------------------------------------------------
const N=8;
queen(ret)~N, len(count)~ret;
-count;
+count; // count ->92
diff --git a/src/ast.c b/src/ast.c
index 70b2d09..ca020f1 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -280,7 +280,7 @@ void ast_puts(Ast *p) {
switch(p->id) {
case AST_INT:
- printf("int %d", p->intval);
+ printf("int %ld", p->longval);
break;
case AST_SYM:
printf("%s", p->sym);
diff --git a/src/config.h b/src/config.h
index 17d50aa..83ba616 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1,7 +1,7 @@
// Configurations ---------------------------------------------------
-// To show the computation process:
-//#define DEBUG
+//#define DEBUG // Show the computation process.
+//#define DEBUG_MKRULE // Show compilation codes of rules.
// ------------------------------------------------
@@ -109,13 +109,27 @@
// -------------------------------------------------
+// ------------------------------------------------
+// For developers
+// ------------------------------------------------
+//#define OLD_REUSEAGENT // Use the old mechanism to reuse agents.
+// // Thus, `REUSEAGENT' is used
+// // instead of `CHID_L`, `LOADP_L` and so on.
+//#define DEBUG_MKRULE // Show compiled codes for rules.
+//#define DEBUG_NETS // Show compiled codes for nets.
-#define COUNT_INTERACTION // Count interaction.
-
-
//#define VERBOSE_NODE_USE // Put memory usage of agents and names.
//#define VERBOSE_HOOP_EXPANSION // Put messages when hoops are expanded.
//#define VERBOSE_EQSTACK_EXPANSION // Put messages when Eqstacks are expanded.
+//#define VERBOSE_TRO // Put message when TRO is enable.
+
+
+
+
+
+
+#define COUNT_INTERACTION // Count interaction.
+
diff --git a/src/id_table.c b/src/id_table.c
index fc22bb1..70072d6 100644
--- a/src/id_table.c
+++ b/src/id_table.c
@@ -60,7 +60,7 @@ void IdTable_init() {
IdTable[ID_DUP].aux.arity = 2;
- IdTable[ID_INT].name = "int";
+ IdTable[ID_INT].name = "Int";
IdTable[ID_TUPLE0].name = "Tuple0";
IdTable[ID_TUPLE1].name = "Tuple1";
IdTable[ID_TUPLE2].name = "Tuple2";
diff --git a/src/inpla.y b/src/inpla.y
index 71c39ea..7f960e6 100644
--- a/src/inpla.y
+++ b/src/inpla.y
@@ -22,8 +22,8 @@
// ----------------------------------------------
-#define VERSION "0.9.2-3"
-#define BUILT_DATE "22 August 2022"
+#define VERSION "0.10.0"
+#define BUILT_DATE "17 September 2022"
// ------------------------------------------------------------------
@@ -2337,7 +2337,7 @@ typedef enum {
OP_RET, OP_RET_FREE_LR, OP_RET_FREE_L, OP_RET_FREE_R,
- OP_LOADI, OP_LOAD, OP_LOADP,
+ OP_LOADI, OP_LOAD, OP_LOADP, OP_LOADP_L, OP_LOADP_R, OP_CHID_L, OP_CHID_R,
OP_ADD, OP_SUB, OP_ADDI, OP_SUBI, OP_MUL, OP_DIV, OP_MOD,
OP_LT, OP_LE, OP_EQ, OP_EQI, OP_NE,
@@ -2476,7 +2476,7 @@ void IMCode_puts(int n) {
"RET", "RET_FREE_LR", "RET_FREE_L", "RET_FREE_R",
- "LOADI", "LOAD", "OP_LOADP",
+ "LOADI", "LOAD", "LOADP", "LOADP_L", "LOADP_R", "CHID_L", "CHID_R",
"ADD", "SUB", "ADDI", "SUBI", "MUL", "DIV", "MOD",
"LT", "LE", "EQ", "EQI", "NE",
@@ -2669,6 +2669,23 @@ void IMCode_puts(int n) {
imcode->operand1, imcode->operand2, imcode->operand3);
break;
+ case OP_LOADP_L:
+ printf("%s var%ld $%ld\n", string_opcode[imcode->opcode],
+ imcode->operand1, imcode->operand2);
+ break;
+ case OP_LOADP_R:
+ printf("%s var%ld $%ld\n", string_opcode[imcode->opcode],
+ imcode->operand1, imcode->operand2);
+ break;
+ case OP_CHID_L:
+ printf("%s $%ld\n", string_opcode[imcode->opcode],
+ imcode->operand1);
+ break;
+ case OP_CHID_R:
+ printf("%s $%ld\n", string_opcode[imcode->opcode],
+ imcode->operand1);
+ break;
+
// arity is 2: opcode var1 $2
case OP_PUSHI:
@@ -2951,6 +2968,28 @@ void VMCode_puts(void **code, int n) {
(unsigned long)code[i+3]);
i+=3;
+ } else if (code[i] == CodeAddr[OP_LOADP_L]) {
+ printf("loadpl reg%lu $%ld\n",
+ (unsigned long)code[i+1],
+ (unsigned long)code[i+2]);
+ i+=2;
+
+ } else if (code[i] == CodeAddr[OP_LOADP_R]) {
+ printf("loadpr reg%lu $%ld\n",
+ (unsigned long)code[i+1],
+ (unsigned long)code[i+2]);
+ i+=2;
+
+ } else if (code[i] == CodeAddr[OP_CHID_L]) {
+ printf("chidl $%ld\n",
+ (unsigned long)code[i+1]);
+ i+=1;
+
+ } else if (code[i] == CodeAddr[OP_CHID_R]) {
+ printf("chidr $%ld\n",
+ (unsigned long)code[i+1]);
+ i+=1;
+
} else if (code[i] == CodeAddr[OP_LOOP]) {
puts("loop");
@@ -3770,6 +3809,16 @@ int CmEnv_Optimise_check_occurence_in_block(int localvar,
return 1;
}
break;
+
+ case OP_LOADP_L:
+ case OP_LOADP_R:
+ // OP src1 port
+ if (imcode->operand1 == localvar) {
+ return 1;
+ }
+ break;
+
+
case OP_MKNAME:
case OP_MKGNAME:
@@ -4150,6 +4199,16 @@ int CmEnv_Optimise_VMCode_CopyPropagation(int target_imcode_addr) {
}
break;
+ case OP_LOADP_L:
+ case OP_LOADP_R:
+ // LOADP_L src port
+ if (imcode->operand1 == load_to) {
+ imcode->operand1 = load_from;
+ IMCode[target_imcode_addr].opcode = OP_DEAD_CODE;
+ return 1;
+ }
+ break;
+
case OP_PUSH:
case OP_MYPUSH:
@@ -4854,6 +4913,33 @@ int CmEnv_generate_VMCode(void **code) {
}
+ case OP_LOADP_L:
+ case OP_LOADP_R: {
+ // OP_LOADP_L src port
+ long src1 = imcode->operand1;
+ long port = imcode->operand2;
+
+#ifdef OPTIMISE_IMCODE
+ src1 = CmEnv_using_reg(src1);
+ if (!CmEnv_Optimise_check_occurence_in_block(imcode->operand1, line_num))
+ CmEnv_free_reg(src1);
+ // dest = CmEnv_using_reg(dest);
+#endif
+
+ code[addr++] = CodeAddr[imcode->opcode];
+ code[addr++] = (void *)(unsigned long)src1;
+ code[addr++] = (void *)(unsigned long)port;
+ break;
+ }
+
+ case OP_CHID_L:
+ case OP_CHID_R: {
+ // OP_CHID_L id
+ code[addr++] = CodeAddr[imcode->opcode];
+ code[addr++] = (void *)(unsigned long)imcode->operand1;
+ break;
+ }
+
case OP_LOADI: {
// OP_LOADI int1 dest
@@ -5374,6 +5460,47 @@ int Ast_eqs_has_agentID(Ast *eqs, IDTYPE id) {
}
+int Ast_mainbody_has_agentID(Ast *mainbody, IDTYPE id) {
+
+ if (mainbody == NULL)
+ return 0;
+
+
+ if (mainbody->id == AST_BODY) {
+
+ Ast *body = mainbody;
+ Ast *eqs = body->right;
+
+ if (eqs == NULL) {
+ return 0;
+ }
+
+ if (Ast_eqs_has_agentID(eqs, id)) {
+ return 1;
+ }
+
+ return 0;
+
+ } else {
+ // if_sentence
+
+ Ast *if_sentence = mainbody;
+ Ast *then_branch = if_sentence->right->left;
+ Ast *else_branch = if_sentence->right->right;
+
+ if ((Ast_mainbody_has_agentID(then_branch, id))
+ || (Ast_mainbody_has_agentID(else_branch, id))) {
+ return 1;
+ }
+
+ return 0;
+ }
+
+
+}
+
+
+
int Ast_is_agent(Ast *ptr) {
if (ptr == NULL) {
return 0;
@@ -5666,9 +5793,39 @@ void Ast_RewriteOptimisation_eqlist(Ast *eqlist) {
}
// END: Rewrite Optimisation ------
+void Ast_remove_tuple1_in_mainbody(Ast *mainbody) {
+
+ if (mainbody == NULL)
+ return;
+
+ if (mainbody->id == AST_BODY) {
+ Ast *body = mainbody;
+ Ast *eqs = body->right;
+
+ while (eqs != NULL) {
+ Ast *eq = eqs->left;
+ eq->left = ast_remove_tuple1(eq->left);
+ eq->right = ast_remove_tuple1(eq->right);
+
+ eqs = ast_getTail(eqs);
+ }
+
+ } else {
+ Ast *if_sentence = mainbody;
+ Ast *then_branch = if_sentence->right->left;
+ Ast *else_branch = if_sentence->right->right;
+
+ Ast_remove_tuple1_in_mainbody(then_branch);
+ Ast_remove_tuple1_in_mainbody(else_branch);
+ }
+}
void Ast_undo_TRO_annotation(Ast *mainbody) {
+ // Make any kinds of CNCTs changed into just AST_CNCT
+ // in order to give it to compilation procedures safely.
+
+
if (mainbody == NULL)
return;
@@ -5693,6 +5850,8 @@ void Ast_undo_TRO_annotation(Ast *mainbody) {
// (AST_ANNOTATE Foo NULL) => Foo
eq->left = eq->left->left;
}
+
+
} else {
Ast *if_sentence = mainbody;
Ast *then_branch = if_sentence->right->left;
@@ -5706,6 +5865,10 @@ void Ast_undo_TRO_annotation(Ast *mainbody) {
int Ast_make_annotation_TailRecursionOptimisation(Ast *mainbody) {
// Return 1 when annotated.
+ //
+ // When there is an equation for TRO, its ID is changed from AST_CNCT into
+ // AST_CNCT_TRO_INTVAR or AST_CNCT_TRO.
+
if (mainbody == NULL)
return 0;
@@ -5744,9 +5907,11 @@ int Ast_make_annotation_TailRecursionOptimisation(Ast *mainbody) {
int available_TRO = 0;
AST_ID astID_of_TRO; // = idL; // idL is dummy
-
+
// --- recursion_agent ~ constructor_agent
- if (idL == NameTable_get_id(recursion_agent->left->sym)) {
+ if ((recursion_agent->left->id == AST_SYM) &&
+ (idL == NameTable_get_id(recursion_agent->left->sym))) {
+
if (Ast_is_expr(constructor_agent)) {
// --- CASE 1: rule_left_agent ~ expression
@@ -5792,7 +5957,7 @@ int Ast_make_annotation_TailRecursionOptimisation(Ast *mainbody) {
} else {
// if_sentence
- Ast *if_sentence = mainbody;
+ Ast *if_sentence = mainbody;
Ast *then_branch = if_sentence->right->left;
Ast *else_branch = if_sentence->right->right;
@@ -6073,8 +6238,36 @@ int Compile_term_on_ast(Ast *ptr, int target) {
IMCode_genCode4(mkagent, ID_CONS, alloc[0], alloc[1], result);
} else {
result = target;
+
+
+ // OLD Version with OP_REUSEAGENT2
+ //#definen OLD_REUSEAGENT
+#ifdef OLD_REUSEAGENT
mkagent = OP_REUSEAGENT2;
IMCode_genCode4(mkagent, result, ID_CONS, alloc[0], alloc[1]);
+#else
+
+ if (target == VM_OFFSET_ANNOTATE_L) {
+ if (CmEnv.idL != ID_CONS) {
+ IMCode_genCode1(OP_CHID_L, ID_CONS);
+ }
+ for (i=0; i<2; i++) {
+ if (alloc[i] != VM_OFFSET_METAVAR_L(i)) {
+ IMCode_genCode2(OP_LOADP_L, alloc[i], i);
+ }
+ }
+ } else {
+ if (CmEnv.idR != ID_CONS) {
+ IMCode_genCode1(OP_CHID_R, ID_CONS);
+ }
+ for (i=0; i<2; i++) {
+ if (alloc[i] != VM_OFFSET_METAVAR_R(i)) {
+ IMCode_genCode2(OP_LOADP_R, alloc[i], i);
+ }
+ }
+ }
+#endif
+
}
return result;
@@ -6225,6 +6418,44 @@ int Compile_term_on_ast(Ast *ptr, int target) {
IdTable_set_arity(id, arity);
+
+ // OLD_REUSEAGENT: Old version with REUSEAGENTn
+#ifndef OLD_REUSEAGENT
+ if (target != -1) {
+ // reuse agent by LOADP_L and LOADP_R
+ // if (CmEnv.reg_agentL == VM_OFFSET_ANNOTATE_L) {
+ if (target == VM_OFFSET_ANNOTATE_L) {
+ if (CmEnv.idL != id) {
+ IMCode_genCode1(OP_CHID_L, id);
+ }
+ for (i=0; i<arity; i++) {
+
+ // IMCode_genCode2(OP_LOADP_L, alloc[i], i);
+ if (alloc[i] != VM_OFFSET_METAVAR_L(i)) {
+
+ IMCode_genCode2(OP_LOADP_L, alloc[i], i);
+ } else {
+ IMCode_genCode0(OP_DEAD_CODE);
+ }
+ }
+ } else {
+
+ if (CmEnv.idR != id) {
+ IMCode_genCode1(OP_CHID_R, id);
+ }
+ for (i=0; i<arity; i++) {
+ if (alloc[i] != VM_OFFSET_METAVAR_R(i)) {
+ IMCode_genCode2(OP_LOADP_R, alloc[i], i);
+ } else {
+ IMCode_genCode0(OP_DEAD_CODE);
+ }
+ }
+ }
+ return result;
+ }
+#endif
+
+
switch (arity) {
case 0:
if (target == -1) {
@@ -6500,6 +6731,10 @@ int Compile_eqlist_on_ast(Ast *at) {
if (eq->id == AST_CNCT_TRO_INTVAR) {
// rule_left_agent ~ expression
+
+ // It always becomes loop operation
+ // because of the form `(*L) ~ expression'.
+
int var2 = Compile_term_on_ast(eq->right, -1);
@@ -6507,6 +6742,10 @@ int Compile_eqlist_on_ast(Ast *at) {
int alloc[MAX_PORT];
int arity = 0;
+ // The `rule_left_aget' is annotated by (*L) manually
+ // in the function `Ast_make_annotation_TailRecursionOptimisation'.
+
+ // So, first
// Pealing (*L)
Ast *eq_lhs = eq->left; // (*L)(AGENT(Fib, arglist))
Ast *deconst_term = eq_lhs->left; // (AGENT(Fib, arglist))
@@ -6591,8 +6830,8 @@ int Compile_eqlist_on_ast(Ast *at) {
IMCode_genCode0(OP_BEGIN_JMPCNCT_BLOCK);
#endif
- // int var1 = Compile_term_on_ast(deconst_term, -1);
- int var1 = Compile_term_on_ast(eq_lhs, -1);
+ int var1 = Compile_term_on_ast(deconst_term, -1);
+ //int var1 = Compile_term_on_ast(eq_lhs, -1);
IMCode_genCode2(OP_PUSH, var1, eq_rhs_name_reg);
Compile_gen_RET_for_rulebody();
@@ -7315,21 +7554,6 @@ int make_rule_oneway(Ast *ast) {
ruleAgent_L = ast->left->left;
ruleAgent_R = ast->left->right;
- if (ruleAgent_L->id == AST_NAME) {
- printf("ERROR: The name '%s' was specified as the left-hand side of rule agents. It should be an agent.\n", ruleAgent_L->left->sym);
- return 0;
- }
- if (ruleAgent_R->id == AST_NAME) {
- printf("ERROR: The name '%s' was specified as the right-hand side of rule agents. It should be an agent.\n", ruleAgent_R->left->sym);
- return 0;
- }
-
-
- rule_mainbody = ast->right;
-
- ruleAgent_L = ast_remove_tuple1(ruleAgent_L);
- ruleAgent_R = ast_remove_tuple1(ruleAgent_R);
-
// #define MYDEBUG1
#ifdef MYDEBUG1
@@ -7364,7 +7588,6 @@ int make_rule_oneway(Ast *ast) {
}
-
/*
// Annotation (*L)、(*R) の処理があるため
// 単純に ruleAgentL、ruleAgentR を入れ替えれば良いわけではない。
@@ -7461,15 +7684,35 @@ int make_rule_oneway(Ast *ast) {
CmEnv.idL = idL;
CmEnv.idR = idR;
-
+ rule_mainbody = ast->right;
+
+ //puts("Before:"); ast_puts(rule_mainbody); puts("");
+
#ifdef OPTIMISE_IMCODE_TRO
- int is_tro = Ast_make_annotation_TailRecursionOptimisation(rule_mainbody);
- // if (is_tro) {
- // puts("=== TRO ============================");
- // printf("Rule: %s(id:%d) >< %s(id:%d).\n",
- // IdTable_get_name(idL), idL,
- // IdTable_get_name(idR), idR);
- // }
+
+ int is_tro;
+ if (!Ast_mainbody_has_agentID(rule_mainbody, AST_ANNOTATION_L)) {
+
+ is_tro = Ast_make_annotation_TailRecursionOptimisation(rule_mainbody);
+
+ } else {
+
+ is_tro = 0;
+ }
+
+
+#ifdef VERBOSE_TRO
+ if (is_tro) {
+ printf("=== TRO is applied to ");
+ printf("Rule: %s(id:%d) >< %s(id:%d). ===\n",
+ IdTable_get_name(idL), idL,
+ IdTable_get_name(idR), idR);
+ }
+#endif
+
+
+
+
#endif
if (!Compile_rule_mainbody_on_ast(rule_mainbody)) return 0;
@@ -7489,15 +7732,15 @@ int make_rule_oneway(Ast *ast) {
#endif
- // #define MKRULE_DEBUG
-#ifndef MKRULE_DEBUG
+ // #define DEBUG_MKRULE
+#ifndef DEBUG_MKRULE
gencode_num += CmEnv_generate_VMCode(&code[2]);
#else
//int here_flag = is_tro;
int here_flag = 1;
if (here_flag) {
- puts("-----------------------------------");
+ puts("[1]. --- RAW codes --------------------------------");
printf("Rule: %s(id:%d) >< %s(id:%d).\n",
IdTable_get_name(idL), idL,
IdTable_get_name(idR), idR);
@@ -7508,7 +7751,9 @@ int make_rule_oneway(Ast *ast) {
if (here_flag) {
+ puts("[2].--- OPTMISED codes --------------------------------");
IMCode_puts(0);
+ puts("[3].---- Genarated bytecodes -------------------------------");
VMCode_puts(&code[2], gencode_num-2);
puts("-----------------------------------");
}
@@ -7587,17 +7832,41 @@ int make_rule(Ast *ast) {
// ast_puts(ast);puts("");
+ Ast *ruleAgent_L = ast->left->left;
+ Ast *ruleAgent_R = ast->left->right;
+
+ if (ruleAgent_L->id == AST_NAME) {
+ printf("ERROR: The name '%s' was specified as the left-hand side of rule agents. It should be an agent.\n", ruleAgent_L->left->sym);
+ return 0;
+ }
+ if (ruleAgent_R->id == AST_NAME) {
+ printf("ERROR: The name '%s' was specified as the right-hand side of rule agents. It should be an agent.\n", ruleAgent_R->left->sym);
+ return 0;
+ }
+
+
+ ast->left->left = ast_remove_tuple1(ruleAgent_L);
+ ast->left->right = ast_remove_tuple1(ruleAgent_R);
+
+
+ Ast *rule_mainbody = ast->right;
+ Ast_remove_tuple1_in_mainbody(rule_mainbody);
+
+
set_annotation_LR(VM_OFFSET_ANNOTATE_L, VM_OFFSET_ANNOTATE_R);
if (!make_rule_oneway(ast)) {
return 0;
}
+
- Ast *ruleAgent_L = ast->left->left;
- Ast *ruleAgent_R = ast->left->right;
+ // another way
+
+ ruleAgent_L = ast->left->left;
+ ruleAgent_R = ast->left->right;
ast->left->left = ruleAgent_R;
ast->left->right = ruleAgent_L;;
- // set_annotation_LR(VM_OFFSET_ANNOTATE_R, VM_OFFSET_ANNOTATE_L);
+ set_annotation_LR(VM_OFFSET_ANNOTATE_R, VM_OFFSET_ANNOTATE_L);
// ast_puts(ast);puts("");
@@ -7848,6 +8117,7 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
&&E_REUSEAGENT3, &&E_REUSEAGENT4, &&E_REUSEAGENT5,
&&E_RET, &&E_RET_FREE_LR, &&E_RET_FREE_L, &&E_RET_FREE_R,
&&E_LOADI, &&E_LOAD, &&E_LOADP,
+ &&E_LOADP_L, &&E_LOADP_R, &&E_CHID_L, &&E_CHID_R,
&&E_ADD, &&E_SUB, &&E_ADDI, &&E_SUBI, &&E_MUL, &&E_DIV, &&E_MOD,
&&E_LT, &&E_LE, &&E_EQ, &&E_EQI, &&E_NE,
&&E_UNM, &&E_RAND, &&E_INC, &&E_DEC,
@@ -7905,6 +8175,7 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
reg[(unsigned long)code[++pc]] = make_Agent(vm, i);
goto *code[++pc];
+
E_MKAGENT1:
#if !defined(OPTIMISE_TWO_ADDRESS) || !defined(OPTIMISE_TWO_ADDRESS_MKAGENT1)
// puts("mkagent1 id src1 dest");
@@ -7920,6 +8191,7 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
#endif
goto *code[++pc];
+
E_MKAGENT2:
#if !defined(OPTIMISE_TWO_ADDRESS) || !defined(OPTIMISE_TWO_ADDRESS_MKAGENT2)
@@ -7971,6 +8243,7 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
#endif
goto *code[++pc];
+
E_MKAGENT4:
// puts("mkagent4 id src1 src2 src3 src4 dest");
a1 = make_Agent(vm, (unsigned long)code[++pc]);
@@ -8072,7 +8345,17 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
// puts("push reg reg");
{
VALUE a1 = reg[(unsigned long)code[++pc]];
- VALUE a2 = reg[(unsigned long)code[++pc]];
+ VALUE a2 = reg[(unsigned long)code[++pc]];
+
+#ifdef DEBUG
+ puts("");
+ puts("E_PUSH is operating:");
+ puts_term(a1); puts("");
+ puts_term(a2); puts("");
+ puts("");
+#endif
+
+
PUSH(vm, a1, a2);
}
goto *code[++pc];
@@ -8159,7 +8442,7 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
free_Agent(reg[VM_OFFSET_ANNOTATE_R]);
E_LOOP_RREC1:
- // puts("looprrec reg ar");
+ // puts("looprrec1 reg");
a1 = reg[(unsigned long)code[pc+1]];
@@ -8175,7 +8458,11 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
free_Agent(reg[VM_OFFSET_ANNOTATE_R]);
E_LOOP_RREC2:
- // puts("looprrec reg ar");
+ // puts("looprrec2 reg);
+
+#ifdef DEBUG
+ puts("E_LOOP_REC2 is operating");
+#endif
a1 = reg[(unsigned long)code[pc+1]];
@@ -8205,6 +8492,30 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
AGENT(reg[(unsigned long)code[++pc]])->port[i] = a1;
goto *code[++pc];
+ E_LOADP_L:
+ // puts("loadp_L src port");
+ a1 = reg[(unsigned long)code[++pc]];
+ i = (unsigned long)code[++pc];
+ AGENT(reg[VM_OFFSET_ANNOTATE_L])->port[i] = a1;
+ goto *code[++pc];
+
+ E_LOADP_R:
+ // puts("loadp_R src port");
+ a1 = reg[(unsigned long)code[++pc]];
+ i = (unsigned long)code[++pc];
+ AGENT(reg[VM_OFFSET_ANNOTATE_R])->port[i] = a1;
+ goto *code[++pc];
+
+ E_CHID_L:
+ // puts("chid_L id");
+ BASIC(reg[VM_OFFSET_ANNOTATE_L])->id = (unsigned long)code[++pc];
+ goto *code[++pc];
+
+ E_CHID_R:
+ // puts("chid_R id");
+ BASIC(reg[VM_OFFSET_ANNOTATE_R])->id = (unsigned long)code[++pc];
+ goto *code[++pc];
+
E_ADD:
@@ -8493,6 +8804,9 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
Count_cnct++;
#endif
+
+
+
#ifdef THREAD
if (SleepingThreadsNum > 0) {
pc +=3;
@@ -8501,6 +8815,14 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
#endif
a1 = reg[(unsigned long)code[pc+1]];
+
+#ifdef DEBUG
+ puts("");
+ printf("E_JMPCNCT_CONS is now operating for reg%lu:\n", (unsigned long)code[pc+1]);
+ puts_term(a1); puts("");
+ puts("");
+#endif
+
if (IS_FIXNUM(a1)) {
pc +=3;
goto *code[pc];
@@ -8518,17 +8840,36 @@ void *exec_code(int mode, VirtualMachine * restrict vm, void * restrict *code) {
Count_cnct_indirect_op++;
#endif
VALUE a2 = NAME(a1)->port;
+
free_Name(a1);
a1 = a2;
reg[(unsigned long)code[pc+1]] = a2;
}
+
+#ifdef DEBUG
+ puts("===> ");
+ puts_term(a1);
+ printf(" reg%lu\n", (unsigned long)code[pc+1]);
+ puts_term(reg[(unsigned long)code[pc+1]]);
+ puts("");
+#endif
+
if (BASIC(a1)->id == ID_CONS) {
#ifdef COUNT_CNCT
Count_cnct_true++;
#endif
+
+#ifdef DEBUG
+ puts("");
+ printf("Success: E_JMPCNCT_CONS increased PC by %lu.\n", (unsigned long)code[pc+2]);
+ puts_term(reg[(unsigned long)code[pc+1]]); puts("");
+ puts("");
+#endif
+
+
pc += (unsigned long)code[pc+2];
pc +=3;
goto *code[pc];
@@ -10400,18 +10741,21 @@ int exec(Ast *at) {
return 0;
}
-
+#ifndef DEBUG_NETS
+ // for regular operation
CmEnv_retrieve_MKGNAME();
CmEnv_generate_VMCode(code);
- // // for debug
- // CmEnv_retrieve_MKGNAME();
- // IMCode_puts(0); //exit(1);
- //
- // int codenum = CmEnv_generate_VMCode(code);
- // VMCode_puts(code, codenum-2); //exit(1);
- // // end for debug
-
+#else
+ // for debug
+ CmEnv_retrieve_MKGNAME();
+ IMCode_puts(0); //exit(1);
+
+ int codenum = CmEnv_generate_VMCode(code);
+ VMCode_puts(code, codenum-2); //exit(1);
+ // end for debug
+#endif
+
#ifdef COUNT_MKAGENT
@@ -10689,10 +11033,12 @@ int exec(Ast *at) {
}
+#ifndef DEBUG_NETS
+ // for regular
CmEnv_retrieve_MKGNAME();
CmEnv_generate_VMCode(code);
- /*
+#else
// for debug
CmEnv_retrieve_MKGNAME();
IMCode_puts(0); //exit(1);
@@ -10700,7 +11046,7 @@ int exec(Ast *at) {
int codenum = CmEnv_generate_VMCode(code);
VMCode_puts(code, codenum-2); //exit(1);
// end for debug
- */
+#endif
exec_code(1, VMs[0], code);
@@ -10945,6 +11291,7 @@ int main(int argc, char *argv[])
param = atoi(argv[i]);
Hoop_increasing_magnitude = param;
+
}
#endif
break;