diff options
| -rw-r--r-- | Changelog.md | 88 | ||||
| -rw-r--r-- | Gentle_introduction_Inpla.md | 34 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | sample/lambda/245II.in (renamed from sample/245II.in) | 0 | ||||
| -rw-r--r-- | sample/lambda/245II_abbr.in (renamed from sample/245II_abbr.in) | 0 | ||||
| -rw-r--r-- | sample/lambda/245II_new.in (renamed from sample/245II_new.in) | 0 | ||||
| -rw-r--r-- | sample/lambda/linear-systemT.in (renamed from sample/linear-systemT.in) | 0 | ||||
| -rw-r--r-- | sample/process_networks/processnet1.in (renamed from sample/processnet1.in) | 0 | ||||
| -rw-r--r-- | sample/process_networks/processnet_fib.in (renamed from sample/processnet_fib.in) | 0 | ||||
| -rw-r--r-- | sample/pseudo_higher_order/map.in (renamed from sample/map.in) | 0 | ||||
| -rw-r--r-- | sample/pseudo_higher_order/reduce.in (renamed from sample/reduce.in) | 0 | ||||
| -rw-r--r-- | sample/puzzle/hanoi.in (renamed from sample/hanoi.in) | 0 | ||||
| -rw-r--r-- | sample/puzzle/nqueen.in (renamed from sample/nqueen.in) | 0 | ||||
| -rw-r--r-- | sample/recursive_functions/ack_3_5.in (renamed from sample/ack_3_5.in) | 0 | ||||
| -rw-r--r-- | sample/recursive_functions/fib-tail_9.in (renamed from sample/fib-tail_9.in) | 0 | ||||
| -rw-r--r-- | sample/recursive_functions/fib_9.in (renamed from sample/fib_9.in) | 0 | ||||
| -rw-r--r-- | sample/recursive_functions/fib_9_abbr.in (renamed from sample/fib_9_abbr.in) | 0 | ||||
| -rw-r--r-- | sample/recursive_functions/gcd.in (renamed from sample/gcd.in) | 0 | ||||
| -rw-r--r-- | sample/recursive_functions/gcd_another.in (renamed from sample/gcd_another.in) | 0 | ||||
| -rw-r--r-- | sample/recursive_functions/pow.in (renamed from sample/pow.in) | 0 | ||||
| -rw-r--r-- | sample/sort/bsort.in (renamed from sample/bsort.in) | 0 | ||||
| -rw-r--r-- | sample/sort/isort.in (renamed from sample/isort.in) | 0 | ||||
| -rw-r--r-- | sample/sort/msort.in (renamed from sample/msort.in) | 0 | ||||
| -rw-r--r-- | sample/sort/qsort.in (renamed from sample/qsort.in) | 0 | ||||
| -rw-r--r-- | sample/turing_machine/TuringMachine.in (renamed from sample/TuringMachine.in) | 8 | ||||
| -rw-r--r-- | sample/unary_numbers/AckSZ-3_5.in (renamed from sample/AckSZ-3_5.in) | 0 | ||||
| -rw-r--r-- | sample/unary_numbers/FibSZ_9.in (renamed from sample/FibSZ_9.in) | 0 | ||||
| -rw-r--r-- | sample/unary_numbers/hanoiSZ.in | 31 | ||||
| -rw-r--r-- | sample/unary_numbers/nqueenSZ.in (renamed from sample/nqueenSZ.in) | 8 | ||||
| -rw-r--r-- | src/id_table.c | 1 | ||||
| -rw-r--r-- | src/id_table.h | 22 | ||||
| -rw-r--r-- | src/inpla.y | 273 |
32 files changed, 362 insertions, 105 deletions
diff --git a/Changelog.md b/Changelog.md index 3892706..b8f6719 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,93 @@ # Change log +### v0.12.0 (released on 5 Mar 2024) + +#### New Features + +- **Wildcard agent in rule definitions**: In rule definitions, we can place a variable as a default match on the left or right side of an active pair. For example, we suppose that we define the following rules: + + ``` + reverse(r) >< [] => r~[]; + reverse(r) >< x:xs => rev_sub(r, [])~x:xs; + + rev_sub(r,ys) >< [] => r~ys; + rev_sub(r,ys) >< x:xs => rev_sub(r,x:ys)~xs; + ``` + + Using the wildcard agent notation, the `reverse` rule is simply written: + + ``` + reverse(r) >< [] => r~[]; + reverse(r) >< xs => rev_sub(r, [])~xs; + ``` + + The current process of searching for rules of active pairs is as follows: + + - First, user-defined rules are searched for, + - Next, built-in rules, + - Finally, rules containing the wildcards, + - Otherwise, runtime error. + +- **Compiled rule codes**: We can see compiled rule codes by invoking Inpla with `-c` option. + + ``` + $ ./inpla -c + Inpla 0.12.0 : Interaction nets as a programming language [built: 5 Mar 2024] + >>> Add(r,y) >< S(x) => Add(r,S(y))~x; + Rule: Add(id:20,arity:2) >< S(id:32,arity:1). + Line:Addr. + 0001:0000: mkagent id:32 reg13 + 0002:0003: loadp reg2 $0 reg13 + 0003:0007: mkagent id:20 reg14 + 0004:0010: loadp reg1 $0 reg14 + 0005:0014: loadp reg13 $1 reg14 + 0006:0018: push reg14 reg6 + 0007:0021: ret_free_lr + >>> + ``` + + With this option, we can also observe how the reuse annotations `(*L)`, `(*R)` work: + + ``` + >>> Add(r,y) >< S(x) => (*L)Add(r,(*R)S(y))~x; + Rule: Add(id:20,arity:2) >< S(id:32,arity:1). + Line:Addr. + 0001:0000: loadp_r reg2 $0 + 0002:0003: loadp_l reg12 $1 + 0003:0006: push reg11 reg6 + 0004:0009: ret + >>> + ``` + + +#### Bug Fix + +- **The reuse strategy for Nil**: `[]` was reused by the old method using the `reuseagent` instruction: + + ``` + >>> reverse(r) >< [] => r~(*R)[]; + Rule: reverse(id:32,arity:1) >< [](id:7,arity:0). + Line:Addr. + 0001:0000: reuseagent0 reg12 as id=7 + 0002:0003: push reg1 reg12 + 0003:0006: ret_free_l + ``` + + The reuse method has been improved; it's ID is changed by `chid`, and ports are reconnected by `loadp` if they are needed. This is now fixed: + + ``` + >>> reverse(r) >< [] => r~(*R)[]; + Rule: reverse(id:32,arity:1) >< [](id:7,arity:0). + Line:Addr. + 0001:0000: push reg1 reg12 + 0002:0003: ret_free_l + ``` + + + + + + ### v0.11.3 (released on 29 Feb 2024) #### Bug Fix diff --git a/Gentle_introduction_Inpla.md b/Gentle_introduction_Inpla.md index 7f60942..c8bfcb2 100644 --- a/Gentle_introduction_Inpla.md +++ b/Gentle_introduction_Inpla.md @@ -637,7 +637,7 @@ Inpla has the following macro: ``` $ ./inpla -h - Inpla version 0.8.0 + Inpla version 0.12.0 Usage: inpla [options] Options: @@ -648,7 +648,8 @@ Inpla has the following macro: 0: the same size heap is inserted when it runs up. 1: the twice (=2^1) size heap is inserted. -Xes <num> Set initial equation stack size (Default: 256) - -w Enable Weak Reduction strategy (Default: false) + -w Enable Weak Reduction strategy (Default: false) + -c Enable to output compiled codes (Default: disable) -t <num> Set the number of threads (Default: 8) -h Print this help message ``` @@ -661,7 +662,36 @@ Inpla has the following macro: ## Advanced topics +### Wildcard agent in rule definitions + +In rule definitions, we can place a variable as a default match on the left or right side of an active pair. For example, we suppose that we define the following rules: + +``` +reverse(r) >< [] => r~[]; +reverse(r) >< x:xs => rev_sub(r, [])~x:xs; + +rev_sub(r,ys) >< [] => r~ys; +rev_sub(r,ys) >< x:xs => rev_sub(r,x:ys)~xs; +``` + +Using the wildcard agent notation, the `reverse` rule is simply written: + +``` +reverse(r) >< [] => r~[]; +reverse(r) >< xs => rev_sub(r, [])~xs; +``` + +The process of searching for rules of active pairs is as follows: + +- First, user-defined rules are searched for, +- Next, built-in rules, +- Finally, rules containing the wildcards, +- Otherwise, runtime error. + + + ### Reuse annotations + In interaction rule definitions, we can specify how active pair agents are reused by putting annotations `(*L)` and `(*R)` before agents in the right-hand side net. This annotations promote in-place computing, and as a result performance can be improved well in parallel execution. * For instance, in the rule `gcd(ret) >< (int a, int b)`, we can reuse the `gcd` and `Tuple2` in nets as follows: @@ -6,7 +6,7 @@ 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.11.3, released on **29 Feb 2024**. (See [Changelog.md](Changelog.md) for details.) +* The current version is 0.12.0, released on **5 Mar 2024**. (See [Changelog.md](Changelog.md) for details.) * The below graph shows speed-up ratio to threads numbers for programs in the following benchmark table.  diff --git a/sample/245II.in b/sample/lambda/245II.in index 27910eb..27910eb 100644 --- a/sample/245II.in +++ b/sample/lambda/245II.in diff --git a/sample/245II_abbr.in b/sample/lambda/245II_abbr.in index c2084ec..c2084ec 100644 --- a/sample/245II_abbr.in +++ b/sample/lambda/245II_abbr.in diff --git a/sample/245II_new.in b/sample/lambda/245II_new.in index 2050179..2050179 100644 --- a/sample/245II_new.in +++ b/sample/lambda/245II_new.in diff --git a/sample/linear-systemT.in b/sample/lambda/linear-systemT.in index f0e3ccb..f0e3ccb 100644 --- a/sample/linear-systemT.in +++ b/sample/lambda/linear-systemT.in diff --git a/sample/processnet1.in b/sample/process_networks/processnet1.in index c648650..c648650 100644 --- a/sample/processnet1.in +++ b/sample/process_networks/processnet1.in diff --git a/sample/processnet_fib.in b/sample/process_networks/processnet_fib.in index ab19eec..ab19eec 100644 --- a/sample/processnet_fib.in +++ b/sample/process_networks/processnet_fib.in diff --git a/sample/map.in b/sample/pseudo_higher_order/map.in index c96daae..c96daae 100644 --- a/sample/map.in +++ b/sample/pseudo_higher_order/map.in diff --git a/sample/reduce.in b/sample/pseudo_higher_order/reduce.in index 90ba145..90ba145 100644 --- a/sample/reduce.in +++ b/sample/pseudo_higher_order/reduce.in diff --git a/sample/hanoi.in b/sample/puzzle/hanoi.in index 5be47c6..5be47c6 100644 --- a/sample/hanoi.in +++ b/sample/puzzle/hanoi.in diff --git a/sample/nqueen.in b/sample/puzzle/nqueen.in index dd50ad1..dd50ad1 100644 --- a/sample/nqueen.in +++ b/sample/puzzle/nqueen.in diff --git a/sample/ack_3_5.in b/sample/recursive_functions/ack_3_5.in index 19f92fa..19f92fa 100644 --- a/sample/ack_3_5.in +++ b/sample/recursive_functions/ack_3_5.in diff --git a/sample/fib-tail_9.in b/sample/recursive_functions/fib-tail_9.in index 58f4cc5..58f4cc5 100644 --- a/sample/fib-tail_9.in +++ b/sample/recursive_functions/fib-tail_9.in diff --git a/sample/fib_9.in b/sample/recursive_functions/fib_9.in index 7c4af1f..7c4af1f 100644 --- a/sample/fib_9.in +++ b/sample/recursive_functions/fib_9.in diff --git a/sample/fib_9_abbr.in b/sample/recursive_functions/fib_9_abbr.in index 57a8c62..57a8c62 100644 --- a/sample/fib_9_abbr.in +++ b/sample/recursive_functions/fib_9_abbr.in diff --git a/sample/gcd.in b/sample/recursive_functions/gcd.in index 5a57d8d..5a57d8d 100644 --- a/sample/gcd.in +++ b/sample/recursive_functions/gcd.in diff --git a/sample/gcd_another.in b/sample/recursive_functions/gcd_another.in index e616e28..e616e28 100644 --- a/sample/gcd_another.in +++ b/sample/recursive_functions/gcd_another.in diff --git a/sample/pow.in b/sample/recursive_functions/pow.in index a123b9f..a123b9f 100644 --- a/sample/pow.in +++ b/sample/recursive_functions/pow.in diff --git a/sample/bsort.in b/sample/sort/bsort.in index 7b2e2d6..7b2e2d6 100644 --- a/sample/bsort.in +++ b/sample/sort/bsort.in diff --git a/sample/isort.in b/sample/sort/isort.in index e637055..e637055 100644 --- a/sample/isort.in +++ b/sample/sort/isort.in diff --git a/sample/msort.in b/sample/sort/msort.in index 599990b..599990b 100644 --- a/sample/msort.in +++ b/sample/sort/msort.in diff --git a/sample/qsort.in b/sample/sort/qsort.in index 523d7d8..523d7d8 100644 --- a/sample/qsort.in +++ b/sample/sort/qsort.in diff --git a/sample/TuringMachine.in b/sample/turing_machine/TuringMachine.in index 2819d19..260f609 100644 --- a/sample/TuringMachine.in +++ b/sample/turing_machine/TuringMachine.in @@ -40,8 +40,8 @@ getRule(r) >< (int state, int sym) // resultTape << changeSym(headPos, sym, tape) // ----------------------------------------- -changeSym(resultTape, headPos, sym) >< t:ts => // <-- t:ts is tape - resultTape << changeSym_sub([], headPos, sym, t:ts); +changeSym(resultTape, headPos, sym) >< tape => // <-- tape is a list + resultTape << changeSym_sub([], headPos, sym, tape); changeSym_sub(r, done, int headPos, int sym) >< (int t):ts | headPos == 0 => r << Append(done, sym:ts) @@ -76,8 +76,8 @@ do(r, tape, int state, int head) >< Halt => // tapeDone << getSym(sym, int headPos, tape) // ----------------------------------------- -getSym(tapeDone, sym, int headPos) >< t:ts => // <- t:ts is tape - tapeDone << getSym_sub([], sym, headPos, t:ts); +getSym(tapeDone, sym, int headPos) >< tape => // <- tape is a list + tapeDone << getSym_sub([], sym, headPos, tape); getSym_sub(r, done, sym, int headPos) >< (int t):ts diff --git a/sample/AckSZ-3_5.in b/sample/unary_numbers/AckSZ-3_5.in index 4f41966..4f41966 100644 --- a/sample/AckSZ-3_5.in +++ b/sample/unary_numbers/AckSZ-3_5.in diff --git a/sample/FibSZ_9.in b/sample/unary_numbers/FibSZ_9.in index b5a65a8..b5a65a8 100644 --- a/sample/FibSZ_9.in +++ b/sample/unary_numbers/FibSZ_9.in diff --git a/sample/unary_numbers/hanoiSZ.in b/sample/unary_numbers/hanoiSZ.in new file mode 100644 index 0000000..a533d2d --- /dev/null +++ b/sample/unary_numbers/hanoiSZ.in @@ -0,0 +1,31 @@ +// Tower of Hanoi Puzzle + +// Rules +hanoi(return, source, target, aux) >< Z => + // Erase the source, target and aux + source ~ Eraser, + target ~ Eraser, + aux ~ Eraser, + + // result + return~[]; + +hanoi(return, source, target, aux) >< S(n) => + // Duplicate the source, target and aux + source ~ Dup(src1, Dup(src2, src3)), + target ~ Dup(tgt1, Dup(tgt2, tgt3)), + aux ~ Dup(aux1, aux2), + + + // recursive applications + n ~ Dup(nn1, Dup(nn2, nn3)), + hanoi(ret1, src1, aux1, tgt1)~nn1, + hanoi(ret2, aux2, tgt2, src2)~nn2, + + // result + return << Append(ret1, (nn3,src3,tgt3):ret2); + + +// Net +hanoi(result, A, C, B) ~ S(S(S(Z))); +result;
\ No newline at end of file diff --git a/sample/nqueenSZ.in b/sample/unary_numbers/nqueenSZ.in index c61515c..b83b89c 100644 --- a/sample/nqueenSZ.in +++ b/sample/unary_numbers/nqueenSZ.in @@ -88,8 +88,8 @@ len_list_(len, done, ct) >< x:xs => len(ret) >< [] => ret~Z; -len(ret) >< x:xs => - len_list(ret, Eraser)~x:xs; +len(ret) >< list => + len_list(ret, Eraser)~list; @@ -162,8 +162,8 @@ queen(ret, n) >< () => queen_(r, b, n) >< Z => r~[], Eraser~b, Eraser~n; -queen_(r, b, n) >< S(m) => - mem_ret, done_m, done_b << member(S(m), b), +queen_(r, b, n) >< m => + mem_ret, done_m, done_b << member(m, b), queen__chk_m_in_b(r, done_b, n, done_m)~mem_ret; diff --git a/src/id_table.c b/src/id_table.c index a7e0226..57189ba 100644 --- a/src/id_table.c +++ b/src/id_table.c @@ -70,6 +70,7 @@ void IdTable_init() { IdTable[ID_NIL].name = "[]"; IdTable[ID_CONS].name = "Cons"; IdTable[ID_INTAGENT].name = "Int"; + IdTable[ID_WILDCARD].name = "Wildcard"; IdTable[ID_APPEND].name = "Append"; IdTable[ID_ZIP].name = "Zip"; diff --git a/src/id_table.h b/src/id_table.h index c486975..2aa785f 100644 --- a/src/id_table.h +++ b/src/id_table.h @@ -9,26 +9,28 @@ // 257 .. : GNAME -#define ID_INT 0 +#define ID_INT 0 // NOTE: // For a NEW BUILT-IN AGENT, // STORE the ARITY on IdTable in the function IdTable_init()! -#define ID_TUPLE0 1 -#define ID_TUPLE1 2 -#define ID_TUPLE2 3 -#define ID_TUPLE3 4 -#define ID_TUPLE4 5 -#define ID_TUPLE5 6 +#define ID_TUPLE0 1 +#define ID_TUPLE1 2 +#define ID_TUPLE2 3 +#define ID_TUPLE3 4 +#define ID_TUPLE4 5 +#define ID_TUPLE5 6 #define GET_TUPLEID(arity) (ID_TUPLE0+arity) #define IS_TUPLEID(id) ((id >= ID_TUPLE0) && (id <= ID_TUPLE5)) #define GET_TUPLEARITY(id) (id - ID_TUPLE0) -#define ID_NIL 7 -#define ID_CONS 8 +#define ID_NIL 7 +#define ID_CONS 8 #define IS_LISTID(id) ((id == ID_NIL) && (id == ID_CONS)) +#define ID_WILDCARD 9 + #define ID_INTAGENT 10 // This is an experimental dummy agent // to show the use effect of Int agent. #define START_ID_OF_BUILTIN_CONSTRUCTOR_AGENT 10 @@ -54,7 +56,7 @@ #define ID_MAP 31 #define END_ID_OF_BUILTIN_OP_AGENT 31 -// ID_ERASER and ID_DUP was put as 254, 255 +// ID_ERASER and ID_DUP were put as 254, 255 // because these IDs are wanted larger like ID_DUP > any_agent.id diff --git a/src/inpla.y b/src/inpla.y index 27ad535..9c095fe 100644 --- a/src/inpla.y +++ b/src/inpla.y @@ -22,8 +22,8 @@ // ---------------------------------------------- -#define VERSION "0.11.3" -#define BUILT_DATE "29 Feb 2024" +#define VERSION "0.12.0" +#define BUILT_DATE "5 Mar 2024" // ------------------------------------------------------------------ @@ -1679,6 +1679,9 @@ void puts_term(VALUE ptr) { printf("%%"); printf("%s", IdTable_get_name(FIX2INT(AGENT(ptr)->port[0]))); + } else if (BASIC(ptr)->id == ID_WILDCARD) { + printf("Wildcard"); + } else { // Agent @@ -2624,42 +2627,42 @@ void IMCode_puts(int n) { break; case OP_MKGNAME: - printf("%s id:%ld var%ld; \"%s\"\n", string_opcode[imcode->opcode], + printf("%s id%ld var%ld; \"%s\"\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, IdTable_get_name(imcode->operand1)); break; case OP_MKAGENT0: - printf("%s id:%ld var%ld\n", string_opcode[imcode->opcode], + printf("%s id%ld var%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2); break; case OP_MKAGENT1: - printf("%s id:%ld var%ld var%ld\n", string_opcode[imcode->opcode], + printf("%s id%ld var%ld var%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3); break; case OP_MKAGENT2: - printf("%s id:%ld var%ld var%ld var%ld\n", string_opcode[imcode->opcode], + printf("%s id%ld var%ld var%ld var%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3, imcode->operand4); break; case OP_MKAGENT3: - printf("%s id:%ld var%ld var%ld var%ld var%ld\n", string_opcode[imcode->opcode], + printf("%s id%ld var%ld var%ld var%ld var%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3, imcode->operand4, imcode->operand5); break; case OP_MKAGENT4: - printf("%s id:%ld var%ld var%ld var%ld var%ld var%ld \n", string_opcode[imcode->opcode], + printf("%s id%ld var%ld var%ld var%ld var%ld var%ld \n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3, imcode->operand4, imcode->operand5, imcode->operand6); break; case OP_MKAGENT5: - printf("%s id:%ld var%ld var%ld var%ld var%ld var%ld var%ld \n", string_opcode[imcode->opcode], + printf("%s id%ld var%ld var%ld var%ld var%ld var%ld var%ld \n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3, imcode->operand4, imcode->operand5, imcode->operand6, imcode->operand7); @@ -2667,36 +2670,36 @@ void IMCode_puts(int n) { case OP_REUSEAGENT0: - printf("%s var%ld id:%ld\n", string_opcode[imcode->opcode], + printf("%s var%ld id%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2); break; case OP_REUSEAGENT1: - printf("%s var%ld id:%ld var%ld\n", string_opcode[imcode->opcode], + printf("%s var%ld id%ld var%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3); break; case OP_REUSEAGENT2: - printf("%s var%ld id:%ld var%ld var%ld\n", string_opcode[imcode->opcode], + printf("%s var%ld id%ld var%ld var%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3, imcode->operand4); break; case OP_REUSEAGENT3: - printf("%s var%ld id:%ld var%ld var%ld var%ld\n", string_opcode[imcode->opcode], + printf("%s var%ld id%ld var%ld var%ld var%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3, imcode->operand4, imcode->operand5); break; case OP_REUSEAGENT4: - printf("%s var%ld id:%ld var%ld var%ld var%ld var%ld\n", string_opcode[imcode->opcode], + printf("%s var%ld id%ld var%ld var%ld var%ld var%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3, imcode->operand4, imcode->operand5, imcode->operand6); break; case OP_REUSEAGENT5: - printf("%s var%ld id:%ld var%ld var%ld var%ld var%ld var%ld\n", + printf("%s var%ld id%ld var%ld var%ld var%ld var%ld var%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, imcode->operand3, imcode->operand4, imcode->operand5, @@ -2834,7 +2837,7 @@ void IMCode_puts(int n) { // arity is 3: opcode var1 id2 LABEL3 case OP_JMPCNCT: - printf("%s var%ld id:%ld %s%ld\n", string_opcode[imcode->opcode], + printf("%s var%ld id%ld %s%ld\n", string_opcode[imcode->opcode], imcode->operand1, imcode->operand2, string_opcode[OP_LABEL],imcode->operand3); break; @@ -2866,13 +2869,15 @@ void IMCode_puts(int n) { #define MAX_VMCODE_SEQUENCE 1024 void VMCode_puts(void **code, int n) { + int line = 0; - puts("[PutsCode]"); + //puts("[PutsCode]"); if (n==-1) n = MAX_VMCODE_SEQUENCE; - printf("Addr.\n"); + printf("Line:Addr.\n"); for (int i=0; i<n; i++) { - printf("%04d: ", i); + line++; + printf("%04d:%04d: ", line, i); if (code[i] == CodeAddr[OP_MKNAME]) { printf("mkname reg%lu\n", @@ -2880,27 +2885,34 @@ void VMCode_puts(void **code, int n) { i+=1; } else if (code[i] == CodeAddr[OP_MKGNAME]) { - printf("mkgname id:%lu reg%lu; \"%s\"\n", + printf("mkgname id%lu reg%lu; \"%s\"\n", (unsigned long)code[i+1], (unsigned long)code[i+2], IdTable_get_name((unsigned long)code[i+1])); i+=2; } else if (code[i] == CodeAddr[OP_MKAGENT0]) { - printf("mkagent0 id:%lu reg%lu\n", +#ifdef USE_MKAGENT_N + printf("mkagent0 id%lu reg%lu\n", + (unsigned long)code[i+1], + (unsigned long)code[i+2]); +#else + printf("mkagent id:%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2]); +#endif + i+=2; } else if (code[i] == CodeAddr[OP_MKAGENT1]) { #if !defined(OPTIMISE_TWO_ADDRESS) || !defined(OPTIMISE_TWO_ADDRESS_MKAGENT1) - printf("mkagent1 id:%lu reg%lu reg%lu\n", + printf("mkagent1 id%lu reg%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2], (unsigned long)code[i+3]); i+=3; #else - printf("mkagent1 id:%lu reg%lu\n", + printf("mkagent1 id%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2]); i+=2; @@ -2908,14 +2920,14 @@ void VMCode_puts(void **code, int n) { } else if (code[i] == CodeAddr[OP_MKAGENT2]) { #if !defined(OPTIMISE_TWO_ADDRESS) || !defined(OPTIMISE_TWO_ADDRESS_MKAGENT2) - printf("mkagent2 id:%lu reg%lu reg%lu reg%lu\n", + printf("mkagent2 id%lu reg%lu reg%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2], (unsigned long)code[i+3], (unsigned long)code[i+4]); i+=4; #else - printf("mkagent2 id:%lu reg%lu reg%lu\n", + printf("mkagent2 id%lu reg%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2], (unsigned long)code[i+3]); @@ -2924,7 +2936,7 @@ void VMCode_puts(void **code, int n) { } else if (code[i] == CodeAddr[OP_MKAGENT3]) { #if !defined(OPTIMISE_TWO_ADDRESS) || !defined(OPTIMISE_TWO_ADDRESS_MKAGENT3) - printf("mkagent3 id:%lu reg%lu reg%lu reg%lu reg%lu\n", + printf("mkagent3 id%lu reg%lu reg%lu reg%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2], (unsigned long)code[i+3], @@ -2932,7 +2944,7 @@ void VMCode_puts(void **code, int n) { (unsigned long)code[i+5]); i+=5; #else - printf("mkagent3 id:%lu reg%lu reg%lu reg%lu\n", + printf("mkagent3 id%lu reg%lu reg%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2], (unsigned long)code[i+3], @@ -2942,7 +2954,7 @@ void VMCode_puts(void **code, int n) { } else if (code[i] == CodeAddr[OP_MKAGENT4]) { #if !defined(OPTIMISE_TWO_ADDRESS) || !defined(OPTIMISE_TWO_ADDRESS_MKAGENT4) - printf("mkagent4 id:%lu reg%lu reg%lu reg%lu reg%lu reg%lu\n", + printf("mkagent4 id%lu reg%lu reg%lu reg%lu reg%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2], (unsigned long)code[i+3], @@ -2951,7 +2963,7 @@ void VMCode_puts(void **code, int n) { (unsigned long)code[i+6]); i+=6; #else - printf("mkagent4 id:%lu reg%lu reg%lu reg%lu reg%lu\n", + printf("mkagent4 id%lu reg%lu reg%lu reg%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2], (unsigned long)code[i+3], @@ -2961,7 +2973,7 @@ void VMCode_puts(void **code, int n) { #endif } else if (code[i] == CodeAddr[OP_MKAGENT5]) { - printf("mkagent5 id:%lu reg%lu reg%lu reg%lu reg%lu reg%lu reg%lu\n", + printf("mkagent5 id%lu reg%lu reg%lu reg%lu reg%lu reg%lu reg%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2], (unsigned long)code[i+3], @@ -3084,12 +3096,12 @@ void VMCode_puts(void **code, int n) { i+=2; } else if (code[i] == CodeAddr[OP_CHID_L]) { - printf("chgid_l $%ld\n", + printf("chgid_l id:%ld\n", (unsigned long)code[i+1]); i+=1; } else if (code[i] == CodeAddr[OP_CHID_R]) { - printf("chgid_r $%ld\n", + printf("chgid_r id:%ld\n", (unsigned long)code[i+1]); i+=1; @@ -3265,7 +3277,7 @@ void VMCode_puts(void **code, int n) { i+=2; } else if (code[i] == CodeAddr[OP_JMPCNCT]) { - printf("jmpcnct reg%lu id:%lu $%lu\n", + printf("jmpcnct reg%lu id%lu $%lu\n", (unsigned long)code[i+1], (unsigned long)code[i+2], (unsigned long)code[i+3]); @@ -3352,6 +3364,7 @@ typedef enum { NB_META_L, NB_META_R, NB_INTVAR, + NB_WILDCARD, } NB_TYPE; @@ -3365,7 +3378,7 @@ typedef struct { // >0: local name // (for the bind names: should be 1) // (for the int names: not paticular) - NB_TYPE type; // NB_NAME, NB_META_L, NB_META_R or NB_INTVAR + NB_TYPE type; // NB_NAME, NB_META_L (or R), NB_INTVAR, NB_WILDCARD } NameBind; @@ -3404,8 +3417,13 @@ typedef struct { // the amount of compilation error int count_compilation_errors; - // warning output for x:int~y:int and x:int~1 + // warning output for x~y and x~i + // where x and y are int modified names, and i is an integer such as 1 int put_warning_for_cnct_property; + + // a flag to output compiled codes + int put_compiled_codes; + } CmEnvironment; @@ -3414,11 +3432,13 @@ typedef struct { #define ANNOTATE_NOTHING 0 // The rule agent is not reused. #define ANNOTATE_REUSE 1 // Annotation (*L), (*R) is specified. #define ANNOTATE_INT_MODIFIER 2 // (int i), therefore it must not be freed. -#define ANNOTATE_TCO 3 // Annotated and reused as TCO. +#define ANNOTATE_WILDCARD 3 // Wildcard Agent, therefore it must not be freed. +#define ANNOTATE_TCO 4 // Annotated and reused as TCO. // Init for CmEnv static CmEnvironment CmEnv = { .put_warning_for_cnct_property = 1, // with warning + .put_compiled_codes = 0, // without outputting codes }; @@ -3511,11 +3531,14 @@ void CmEnv_clear_keeping_rule_properties(void) { // clear the information of names EXCEPT meta ones. CmEnv_clear_bind(CmEnv.bindPtr_metanames); - - if (CmEnv.annotateL != ANNOTATE_INT_MODIFIER) { + + // Except of ANNOTATE_INT and ANNOTATE_WILDCARD + if ((CmEnv.annotateL != ANNOTATE_INT_MODIFIER) + && (CmEnv.annotateL != ANNOTATE_WILDCARD)) { CmEnv.annotateL = ANNOTATE_NOTHING; } - if (CmEnv.annotateR != ANNOTATE_INT_MODIFIER) { + if ((CmEnv.annotateR != ANNOTATE_INT_MODIFIER) + && (CmEnv.annotateR != ANNOTATE_WILDCARD)) { CmEnv.annotateR = ANNOTATE_NOTHING; } @@ -3666,7 +3689,10 @@ int CmEnv_check_linearity_in_rule(void) { for (i=0; i<CmEnv.bindPtr; i++) { - if ((CmEnv.bind[i].type == NB_META_L) || (CmEnv.bind[i].type == NB_META_R)) { + if ((CmEnv.bind[i].type == NB_META_L) + || (CmEnv.bind[i].type == NB_META_R) + || (CmEnv.bind[i].type == NB_WILDCARD) + ) { if (CmEnv.bind[i].refnum != 1) { // Be just once! printf("%d:ERROR: `%s' is referred not once in the right-hand side ", yylineno, CmEnv.bind[i].name); @@ -3674,7 +3700,10 @@ int CmEnv_check_linearity_in_rule(void) { } } else if (CmEnv.bind[i].type == NB_NAME) { - if (CmEnv.bind[i].refnum != 1) { // Be just once in the RHS. + if (CmEnv.bind[i].refnum != 1) { + // It must occur twice. + // The first occurrence is just recorded and not counted as referred. + // So, be just once in the RHS. printf("%d:ERROR: `%s' is referred not twice in the right-hand side ", yylineno, CmEnv.bind[i].name); return 0; @@ -4541,7 +4570,7 @@ int CmEnv_generate_VMCode(void **code) { break; } case OP_MKAGENT1: { - // printf("OP_MKAGENT1 id:%d var%d var%d\n", + // printf("OP_MKAGENT1 id%d var%d var%d\n", // imcode->operand1, imcode->operand2, imcode->operand3); long src1 = imcode->operand2; long dest = imcode->operand3; @@ -4574,7 +4603,7 @@ int CmEnv_generate_VMCode(void **code) { break; } case OP_MKAGENT2: { - // printf("OP_MKAGENT2 id:%d var%d var%d var%d\n", + // printf("OP_MKAGENT2 id%d var%d var%d var%d\n", // imcode->operand1, imcode->operand2, // imcode->operand3, imcode->operand4); @@ -4620,7 +4649,7 @@ int CmEnv_generate_VMCode(void **code) { break; } case OP_MKAGENT3: { - // printf("OP_MKAGENT3 id:%d var%d var%d var%d var%d \n", + // printf("OP_MKAGENT3 id%d var%d var%d var%d var%d \n", // imcode->operand1, imcode->operand2, // imcode->operand3, imcode->operand4, imcode->operand5); long src1 = imcode->operand2; @@ -4671,7 +4700,7 @@ int CmEnv_generate_VMCode(void **code) { break; } case OP_MKAGENT4: { - // printf("OP_MKAGENT4 var%d id:%d var%d var%d var%d var%d\n", + // printf("OP_MKAGENT4 var%d id%d var%d var%d var%d var%d\n", // imcode->operand1, imcode->operand2, // imcode->operand3, imcode->operand4, imcode->operand5); long src1 = imcode->operand2; @@ -4729,7 +4758,7 @@ int CmEnv_generate_VMCode(void **code) { break; } case OP_MKAGENT5: { - // printf("OP_MKAGENT5 var%d id:%d var%d var%d var%d var%d\n", + // printf("OP_MKAGENT5 var%d id%d var%d var%d var%d var%d\n", // imcode->operand1, imcode->operand2, // imcode->operand3, imcode->operand4, imcode->operand5); long src1 = imcode->operand2; @@ -4786,7 +4815,7 @@ int CmEnv_generate_VMCode(void **code) { case OP_REUSEAGENT0: { - // printf("OP_REUSEAGENT0 var%d id:%d\n", + // printf("OP_REUSEAGENT0 var%d id%d\n", // imcode->operand1, imcode->operand2); int dest = imcode->operand1; @@ -4800,7 +4829,7 @@ int CmEnv_generate_VMCode(void **code) { } case OP_REUSEAGENT1: { - // printf("OP_REUSEAGENT1 var%d id:%d var%d\n", + // printf("OP_REUSEAGENT1 var%d id%d var%d\n", // imcode->operand1, imcode->operand2, imcode->operand3); long dest = imcode->operand1; long src1 = imcode->operand3; @@ -4846,7 +4875,7 @@ int CmEnv_generate_VMCode(void **code) { } case OP_REUSEAGENT3: { - // printf("OP_REUSEAGENT3 var%d id:%d var%d var%d var%d\n", + // printf("OP_REUSEAGENT3 var%d id%d var%d var%d var%d\n", // imcode->operand1, imcode->operand2, // imcode->operand3, imcode->operand4, imcode->operand5); long dest = imcode->operand1; @@ -4883,7 +4912,7 @@ int CmEnv_generate_VMCode(void **code) { } case OP_REUSEAGENT4: { - // printf("OP_REUSEAGENT3 var%d id:%d var%d var%d var%d\n", + // printf("OP_REUSEAGENT3 var%d id%d var%d var%d var%d\n", // imcode->operand1, imcode->operand2, // imcode->operand3, imcode->operand4, imcode->operand5); long dest = imcode->operand1; @@ -4927,7 +4956,7 @@ int CmEnv_generate_VMCode(void **code) { break; } case OP_REUSEAGENT5: { - // printf("OP_REUSEAGENT3 var%d id:%d var%d var%d var%d\n", + // printf("OP_REUSEAGENT3 var%d id%d var%d var%d var%d\n", // imcode->operand1, imcode->operand2, // imcode->operand3, imcode->operand4, imcode->operand5); long dest = imcode->operand1; @@ -5440,7 +5469,7 @@ int CmEnv_generate_VMCode(void **code) { case OP_JMPCNCT: { // OP_JMPCNCT var id label - // printf("OP_JMPCNCT var%d id:%d $%d\n", + // printf("OP_JMPCNCT var%d id%d $%d\n", // imcode->operand1, imcode->operand2, imcode->operand3); long src1 = imcode->operand1; @@ -6382,8 +6411,22 @@ int Compile_term_on_ast(Ast *ptr, int target) { IMCode_genCode2(mkagent, ID_NIL, result); } else { result = target; + +#ifdef OLD_REUSEAGENT mkagent = OP_REUSEAGENT0; IMCode_genCode2(mkagent, result, ID_NIL); +#else + if (target == VM_OFFSET_ANNOTATE_L) { + if (CmEnv.idL != ID_NIL) { + IMCode_genCode1(OP_CHID_L, ID_NIL); + } + } else { + if (CmEnv.idR != ID_NIL) { + IMCode_genCode1(OP_CHID_R, ID_NIL); + } + } +#endif + } return result; @@ -7606,13 +7649,14 @@ void RuleTable_delete(int symlID, int symrID) { } -void *RuleTable_get_code(VALUE heap_syml, VALUE heap_symr, int *result) { +//void *RuleTable_get_code(VALUE heap_syml, VALUE heap_symr, int *result) { +void *RuleTable_get_code(int syml, int symr, int *result) { // returns: // *code : for syml><symr // result : 1 for success, otherwise 0. - int syml = AGENT(heap_syml)->basic.id; - int symr = AGENT(heap_symr)->basic.id; + // int syml = AGENT(heap_syml)->basic.id; + // int symr = AGENT(heap_symr)->basic.id; //RuleList *add; @@ -7648,6 +7692,8 @@ void *RuleTable_get_code(VALUE heap_syml, VALUE heap_symr, int *result) { } + + //static inline void RuleTable_get_code_for_Int(VALUE heap_syml, void ***code) { int syml = AGENT(heap_syml)->basic.id; @@ -7700,9 +7746,9 @@ void RuleTable_record(int symlID, int symrID, void **code, int byte) { } -void *RuleTable_get_code(VALUE heap_syml, VALUE heap_symr, int *result) { - int symlID = AGENT(heap_syml)->basic.id; - int symrID = AGENT(heap_symr)->basic.id; +void *RuleTable_get_code(int symlID, int symrID, int *result) { + // int symlID = AGENT(heap_syml)->basic.id; + // int symrID = AGENT(heap_symr)->basic.id; void *code = RuleTable[symrID][symlID]; if (code == NULL) { @@ -7714,6 +7760,7 @@ void *RuleTable_get_code(VALUE heap_syml, VALUE heap_symr, int *result) { return code; } + static inline void RuleTable_get_code_for_Int(VALUE heap_syml, void ***code) { int symlID = AGENT(heap_syml)->basic.id; @@ -7802,15 +7849,24 @@ int set_metaR(Ast *ast) { return 1; } + void set_metaL_as_IntName(Ast *ast) { - // CmEnv_set_symbol_as_meta(ast->left->sym, CmEnv.reg_agentL, NB_INTVAR); CmEnv_set_symbol_as_meta(ast->left->sym, VM_OFFSET_ANNOTATE_L, NB_INTVAR); } void set_metaR_as_IntName(Ast *ast) { - // CmEnv_set_symbol_as_meta(ast->left->sym, CmEnv.reg_agentR, NB_INTVAR); - CmEnv_set_symbol_as_meta(ast->left->sym, VM_OFFSET_ANNOTATE_L, NB_INTVAR); + CmEnv_set_symbol_as_meta(ast->left->sym, VM_OFFSET_ANNOTATE_R, NB_INTVAR); +} + + +void set_metaL_as_AnyAgent(Ast *ast) { + CmEnv_set_symbol_as_meta(ast->left->sym, VM_OFFSET_ANNOTATE_L, NB_WILDCARD); + +} + +void set_metaR_as_AnyAgent(Ast *ast) { + CmEnv_set_symbol_as_meta(ast->left->sym, VM_OFFSET_ANNOTATE_R, NB_WILDCARD); } @@ -7840,6 +7896,9 @@ int get_ruleagentID(Ast *ruleAgent) { } else if (ruleAgent->id == AST_INTVAR) { id = ID_INT; + } else if (ruleAgent->id == AST_NAME) { + id = ID_WILDCARD; + } else if (strcmp((char *)ruleAgent->left->sym, "Int") == 0) { id = ID_INTAGENT; } else { @@ -7875,24 +7934,26 @@ int make_rule_oneway(Ast *ast) { int gencode_num=0; + CmEnv_clear_all(); + + + // #define PUT_RULE_COMPILATION_TIME #ifdef PUT_RULE_COMPILATION_TIME unsigned long long t, time; start_timer(&t); #endif - CmEnv_clear_all(); - ruleAgent_L = ast->left->left; ruleAgent_R = ast->left->right; - // #define MYDEBUG1 + // #define MYDEBUG1 #ifdef MYDEBUG1 - ast_puts(ruleAgent_L); puts(""); - ast_puts(ruleAgent_R); puts(""); + printf("MYDEBUG1"); ast_puts(ruleAgent_L); puts(""); + printf("MYDEBUG1"); ast_puts(ruleAgent_R); puts(""); // ast_puts(bodies); exit(1); #endif @@ -7957,13 +8018,11 @@ int make_rule_oneway(Ast *ast) { } */ - - int arity; // IMPORTANT: // The first two codes stores arities of idL and idR, respectively. - if (idL == ID_INT) { + if ((idL == ID_INT) || (idL == ID_WILDCARD)) { arity = 0; } else { arity = get_arity_on_ast(ruleAgent_L); @@ -7977,7 +8036,7 @@ int make_rule_oneway(Ast *ast) { IdTable_set_arity(idL, arity); code[0] = (void *)(unsigned long)arity; - if (idR == ID_INT) { + if ((idR == ID_INT) || (idR == ID_WILDCARD)) { arity = 0; } else { arity = get_arity_on_ast(ruleAgent_R); @@ -7995,11 +8054,13 @@ int make_rule_oneway(Ast *ast) { - // CmEnv_clear_all(); if (idL == ID_INT) { set_metaL_as_IntName(ruleAgent_L); CmEnv.annotateL = ANNOTATE_INT_MODIFIER; // to prevent putting Free_L + } else if (idL == ID_WILDCARD) { + set_metaL_as_AnyAgent(ruleAgent_L); + CmEnv.annotateL = ANNOTATE_WILDCARD; // to prevent putting Free_L } else { if (!set_metaL(ruleAgent_L)) { return 0; @@ -8009,6 +8070,9 @@ int make_rule_oneway(Ast *ast) { if (idR == ID_INT) { set_metaR_as_IntName(ruleAgent_R); CmEnv.annotateR = ANNOTATE_INT_MODIFIER; // to prevent putting Free_R + } else if (idR == ID_WILDCARD) { + set_metaR_as_AnyAgent(ruleAgent_R); + CmEnv.annotateR = ANNOTATE_WILDCARD; // to prevent putting Free_R } else { if (!set_metaR(ruleAgent_R)) { return 0; @@ -8065,7 +8129,7 @@ int make_rule_oneway(Ast *ast) { #endif - // #define DEBUG_MKRULE + // #define DEBUG_MKRULE #ifndef DEBUG_MKRULE gencode_num += CmEnv_generate_VMCode(&code[2]); #else @@ -8102,6 +8166,18 @@ int make_rule_oneway(Ast *ast) { // ast_puts(ruleAgent_R); puts(""); #endif + + if (CmEnv.put_compiled_codes) { + printf("Rule: %s(id:%d,arity:%lu) >< %s(id:%d,arity:%lu).\n", + IdTable_get_name(idL), idL, (unsigned long)code[0], + IdTable_get_name(idR), idR, (unsigned long)code[1]); + VMCode_puts(&code[2], gencode_num-2); + if (yyin != stdin) { + puts(""); + } + } + + // Record the rule code for idL >< idR RuleTable_record(idL, idR, code, gencode_num); @@ -8167,6 +8243,7 @@ int make_rule(Ast *ast) { Ast *ruleAgent_L = ast->left->left; Ast *ruleAgent_R = ast->left->right; + /* if (ruleAgent_L->id == AST_NAME) { printf("%d:ERROR: The name `%s' was specified as the left-hand side of rule agents. It should be an agent.\n", yylineno, ruleAgent_L->left->sym); return 0; @@ -8175,6 +8252,7 @@ int make_rule(Ast *ast) { printf("%d:ERROR: The name `%s' was specified as the right-hand side of rule agents. It should be an agent.\n", yylineno, ruleAgent_R->left->sym); return 0; } + */ ast->left->left = ast_remove_tuple1(ruleAgent_L); @@ -8194,21 +8272,33 @@ int make_rule(Ast *ast) { // another way - + int preserve_CmEnv_put_compiled_codes = CmEnv.put_compiled_codes; + CmEnv.put_compiled_codes = 0; // without outputting codes + CmEnv.put_warning_for_cnct_property = 0; // without warning - + Ast *tmp; + tmp = ast->left->left; + ast->left->left = ast->left->right; + ast->left->right = tmp; + + /* 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); // ast_puts(ast);puts(""); int result_make_rule = make_rule_oneway(ast); CmEnv.put_warning_for_cnct_property = 1; // retrieve warning + CmEnv.put_compiled_codes = preserve_CmEnv_put_compiled_codes; //retrieve + + return result_make_rule; } @@ -9546,6 +9636,7 @@ loop: if (IS_FIXNUM(a2)) { loop_a2IsFixnum: if (IS_FIXNUM(a1)) { + printf("Runtime ERROR: "); puts_term(a1); printf("~"); puts_term(a2); printf("\nInteger %ld >< %ld can not be used as an active pair\n", FIX2INT(a1), FIX2INT(a2)); @@ -9558,13 +9649,13 @@ loop_a2IsFixnum: #endif } - // a1 is agent + // a1 is an agent if (IS_AGENTID(BASIC(a1)->id)) { void **code = NULL; RuleTable_get_code_for_Int(a1, &code); - + if (code == NULL) { // built-in: BUILT-IN_OP >< int @@ -9849,7 +9940,7 @@ loop_a2IsAgent: int result; void **code; - code = RuleTable_get_code(a1, a2, &result); + code = RuleTable_get_code(BASIC(a1)->id, BASIC(a2)->id, &result); if (result == 0) { // there is no user-defined rule. @@ -10698,6 +10789,12 @@ loop_agent_a1_a2_this_order: } // end switch(BASIC(a1)->id) + // Wildcard Agents + code = RuleTable_get_code(BASIC(a1)->id, ID_WILDCARD, &result); + if (result != 0) { + // VMCode_puts(&code[0], 10); + goto label_exec_agent_a1_a2; + } if ((BASIC(a1)->id < BASIC(a2)->id) || (BASIC(a2)->id == ID_ERASER) @@ -10710,7 +10807,7 @@ loop_agent_a1_a2_this_order: } - printf("Runtime Error: There is no interaction rule for the following pair:\n "); + printf("Runtime Error: There is no interaction rule for the following pair:\n"); puts_term(a1); printf("~"); puts_term(a2); @@ -10735,6 +10832,7 @@ loop_agent_a1_a2_this_order: // return; +label_exec_agent_a1_a2: int i; unsigned long arity; arity = (unsigned long)code[0]; @@ -10795,6 +10893,7 @@ loop_agent_a1_a2_this_order: vm->reg[VM_OFFSET_ANNOTATE_L] = a1; vm->reg[VM_OFFSET_ANNOTATE_R] = a2; + //free_Agent(a1); //free_Agent(a2); @@ -11550,7 +11649,6 @@ int main(int argc, char *argv[]) printf(" -f <filename> Set input file name (Default: STDIN)\n"); printf(" -d <Name>=<val> Bind <val> to <Name>\n"); - #ifdef EXPANDABLE_HEAP #elif defined(FLEX_EXPANDABLE_HEAP) printf(" -Xms <num> Set initial heap size to 2^<num> (Defalut: %2u (=%4u))\n", @@ -11562,7 +11660,7 @@ int main(int argc, char *argv[]) printf(" 2: the size is four times (=2^2).\n"); #else //v0.5.6 - printf(" -c <num> Set size of heaps (Defalut: %10u)\n", heap_size); + printf(" -m <num> Set size of heaps (Defalut: %10u)\n", heap_size); #endif @@ -11577,6 +11675,8 @@ int main(int argc, char *argv[]) printf(" -w Enable Weak Reduction strategy (Default: disable)\n"); #endif + printf(" -c Enable to output compiled codes (Default: disable)\n"); + printf(" -h Print this help message\n\n"); @@ -11726,17 +11826,17 @@ int main(int argc, char *argv[]) #if !defined(EXPANDABLE_HEAP) && !defined(FLEX_EXPANDABLE_HEAP) - case 'c': + case 'm': // v0.5.6 i++; if (i < argc) { param = atoi(argv[i]); if (param == 0) { - printf("ERROR: `%s' is illegal parameter for -c\n", argv[i]); + printf("ERROR: `%s' is illegal parameter for -m\n", argv[i]); exit(-1); } } else { - printf("ERROR: The option `-c' needs a number as an argument."); + printf("ERROR: The option `-m' needs a number as an argument."); exit(-1); } heap_size=param; @@ -11767,7 +11867,12 @@ int main(int argc, char *argv[]) break; #endif - + + case 'c': + CmEnv.put_compiled_codes = 1; + break; + + default: printf("ERROR: Unrecognized option %s\n", argv[i]); printf("Use -h option for getting more information.\n\n"); |
