diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2024-06-06 17:20:45 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2024-06-06 17:20:45 +0900 |
| commit | a8fd9188c743eceadb12ccdc95865f285d28723d (patch) | |
| tree | c5de0fec007531f59f28e30d545bd62cd6966df9 | |
| parent | bf1ee36299bb34a932d6edbd026808e912219a24 (diff) | |
| download | inpla-a8fd9188c743eceadb12ccdc95865f285d28723d.tar.gz inpla-a8fd9188c743eceadb12ccdc95865f285d28723d.zip | |
v0.12.4
| -rw-r--r-- | Changelog.md | 35 | ||||
| -rw-r--r-- | Gentle_introduction_Inpla.md | 10 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | src/inpla.y | 95 | ||||
| -rw-r--r-- | src/lex.l | 1 |
5 files changed, 118 insertions, 25 deletions
diff --git a/Changelog.md b/Changelog.md index 513a249..8268419 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,40 @@ # Change log +### v0.12.4 (released on 6 June 2024) + +#### New Features + +- **A command to get memory usage information**: A new command `memstat` is has been prepared to show memory usage information. This is only available in the single thread mode. Below is an example of this command: + + ``` + Inpla 0.12.4 : Interaction nets as a programming language [built: 6 June 2024] + >>> n~S(Z); + (0 interactions, 0.00 sec) + >>> memstat; + Using 2 agent nodes and 1 name nodes. + + >>> + ``` + + Inpla can handle cyclic nets that cannot be observed from the interface. These nets are invisible, but still there. This command shows this as follows: + + ``` + >>> free ifce; + >>> memstat; + Using 0 agent nodes and 0 name nodes. + + >>> x~A(x); + (0 interactions, 0.00 sec) + >>> ifce; + <NO-INTERFACE> + >>> memstat; + Using 1 agent nodes and 1 name nodes. + + >>> + ``` + + + ### v0.12.3 (released on 18 Apr 2024) #### Polished (minor) diff --git a/Gentle_introduction_Inpla.md b/Gentle_introduction_Inpla.md index 747f190..9fa0a3d 100644 --- a/Gentle_introduction_Inpla.md +++ b/Gentle_introduction_Inpla.md @@ -612,14 +612,18 @@ Inpla has the following commands: The *name1* ... *name_n* and connected terms from these are disposed. To dispose all living names and connected terms, type `free ifce;`, where the `ifce` is an abbreviation of *interface* that is called for the set of names that live and occur once. * *name1* ... *name_n* `;` - Put terms connected from the *name1* ... *name_n*. + Output terms connected from the *name1* ... *name_n*. * `ifce;` - Put every term connected from the interface. + Output every term connected from the interface. * `prnat` *name*`;` - Put a term connected from the *name* as a natural number. + Output a term connected from the *name* as a natural number. + +* `memstat`; + + Output memory usage information for agent and name nodes. Only available in the single thread mode. * `use` `"`*filename*`";` Read the file whose name is *filename*. @@ -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.12.3, released on **18 Apr 2024**. (See [Changelog.md](Changelog.md) for details.) +* The current version is 0.12.4, released on **6 June 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/src/inpla.y b/src/inpla.y index f5da2a8..435584e 100644 --- a/src/inpla.y +++ b/src/inpla.y @@ -22,8 +22,8 @@ // ---------------------------------------------- -#define VERSION "0.12.3" -#define BUILT_DATE "18 Apr 2024" +#define VERSION "0.12.4" +#define BUILT_DATE "6 June 2024" // ------------------------------------------------------------------ @@ -36,6 +36,15 @@ +// For global optionss --------------------------------- +typedef struct { + int verbose_memory_use; // default is 0 (NOT enable) +} GlobalOptions_t; + +static GlobalOptions_t GlobalOptions = { + .verbose_memory_use = 0, +}; + @@ -88,6 +97,9 @@ int exec(Ast *st); int destroy(void); +void puts_memory_stat(void); + + //#define YYDEBUG 1 @@ -178,7 +190,7 @@ static char *Errormsg = NULL; %token NOT AND OR %token INT LET IN END IF THEN ELSE WHERE RAND DEF -%token INTERFACE IFCE PRNAT FREE EXIT +%token INTERFACE IFCE PRNAT FREE EXIT MEMSTAT %token END_OF_FILE USE %type <ast> body astterm astterm_item nameterm agentterm astparam astparams @@ -391,6 +403,11 @@ command: fflush(stdout); } } + +| MEMSTAT ';' +{ + puts_memory_stat(); +} ; @@ -1472,6 +1489,21 @@ void myfree2(VALUE ptr, VALUE ptr2) { #endif + +void puts_memory_usage(Heap *agent_heap, Heap *name_heap) { + // printf("Using a total of %lu agent nodes and %lu name nodes.\n\n", + printf("Using %lu agent nodes and %lu name nodes.\n\n", + Heap_GetNum_Usage_forAgent(agent_heap), + Heap_GetNum_Usage_forName(name_heap)); +} + + + + + + + + //----------------------------------------------------------- // Pretty printing for terms //----------------------------------------------------------- @@ -2244,14 +2276,14 @@ void flush_name_port0(VALUE ptr) { } -#ifdef VERBOSE_NODE_USE -#ifndef THREAD - printf("(%lu agents and %lu names nodes are used.)\n", - Heap_GetNum_Usage_forAgent(&VM.agentHeap), - Heap_GetNum_Usage_forName(&VM.nameHeap)); -#endif +#ifndef THREAD + if (GlobalOptions.verbose_memory_use) { + puts_memory_usage(&VM.agentHeap, &VM.nameHeap); + } #endif + + } void free_Names_ast(Ast *ast) { @@ -2270,6 +2302,14 @@ void free_Names_ast(Ast *ast) { +void puts_memory_stat(void) { +#ifndef THREAD + puts_memory_usage(&VM.agentHeap, &VM.nameHeap); +#else + puts("Not supported in the multi-threaded version."); +#endif +} + @@ -11076,14 +11116,14 @@ typedef struct { EQ *eqs; int eqs_index; int size; - int enabled; // 0: not Enabled, 1: Enabled. + int enable; // 0: not Enable, 1: Enable. } WHNF_Info; WHNF_Info WHNFinfo; void Init_WHNFinfo(void) { WHNFinfo.eqs_index = 0; WHNFinfo.size = WHNF_UNUSED_STACK_SIZE; - WHNFinfo.enabled = 0; // not Enabled + WHNFinfo.enable = 0; // not Enable WHNFinfo.eqs = malloc(sizeof(EQ) * WHNF_UNUSED_STACK_SIZE); if (WHNFinfo.eqs == NULL) { @@ -11254,7 +11294,7 @@ int exec(Ast *at) { // WHNF: Unused equations are stacked to be execution targets again. - if (WHNFinfo.enabled) { + if (WHNFinfo.enable) { for (int i=0; i < WHNFinfo.eqs_index ; i++) { MYPUSH(&VM, WHNFinfo.eqs[i].l, WHNFinfo.eqs[i].r); } @@ -11273,7 +11313,7 @@ int exec(Ast *at) { // EXECUTION LOOP - if (!WHNFinfo.enabled) { + if (!WHNFinfo.enable) { // no-stategy execution VALUE t1, t2; @@ -11300,12 +11340,13 @@ int exec(Ast *at) { printf("(%d mkAgent calls)\n", NumberOfMkAgent); #endif -#ifdef VERBOSE_NODE_USE - printf("(%lu agents and %lu names nodes are used.)\n", - Heap_GetNum_Usage_forAgent(&VM.agentHeap), - Heap_GetNum_Usage_forName(&VM.nameHeap)); -#endif + if (GlobalOptions.verbose_memory_use) { + puts_memory_usage(&VM.agentHeap, &VM.nameHeap); + } + + + #ifdef COUNT_CNCT printf("JMP_CNCT:%d true:%d ratio:%.2f%%\n", Count_cnct, Count_cnct_true, Count_cnct_true*100.0/Count_cnct); @@ -11715,8 +11756,13 @@ int main(int argc, char *argv[]) printf(" -h Print this help message\n"); - printf(" -foptimise-tail-calls Enable tail call optimisation (Default: disable)\n"); + printf(" -foptimise-tail-calls Enable tail call optimisation (Default: disable)\n"); + +#ifndef THREAD + printf(" -fverbose-memory-usage Show memory usage (Default: disable)\n"); +#endif + puts(""); @@ -11863,6 +11909,13 @@ int main(int argc, char *argv[]) } +#ifndef THREAD + if (!strcmp(argv[i], "-fverbose-memory-usage")) { + GlobalOptions.verbose_memory_use = 1; + break; + } +#endif + // for files if (strcmp(argv[i], "-f")) { printf("ERROR: Unknown option: `%s'\n", argv[i]); @@ -11920,7 +11973,7 @@ int main(int argc, char *argv[]) break; #else case 'w': - WHNFinfo.enabled = 1; + WHNFinfo.enable = 1; break; #endif @@ -11962,7 +12015,7 @@ int main(int argc, char *argv[]) } #ifndef THREAD - if (WHNFinfo.enabled) { + if (WHNFinfo.enable) { printf("Inpla %s (Weak Strategy) : Interaction nets as a programming language", VERSION); printf(" [%s]\n", BUILT_DATE); } else { @@ -117,6 +117,7 @@ int yycolumn = 1; <INITIAL>"prnat" return(PRNAT); <INITIAL>"free" return(FREE); +<INITIAL>"memstat" return(MEMSTAT); <INITIAL>"exit" return(EXIT); <INITIAL>"rand" return(RAND); |
