aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2022-03-10 21:10:34 +0900
committerShinya Sato <shinnya.sato@gmail.com>2022-03-10 21:10:34 +0900
commitadd49f1df854ed333252b494d1899c8c899991dd (patch)
tree81f4eab532e12070f07f06afa6b7383a2453810b /src
parent986915e6c6ee455cd0592aefb770c86e75d24e64 (diff)
downloadinpla-add49f1df854ed333252b494d1899c8c899991dd.tar.gz
inpla-add49f1df854ed333252b494d1899c8c899991dd.zip
v0.8.1-1
Diffstat (limited to '')
-rw-r--r--src/ast.c41
-rw-r--r--src/ast.h2
-rw-r--r--src/config.h90
-rw-r--r--src/inpla.y58
4 files changed, 148 insertions, 43 deletions
diff --git a/src/ast.c b/src/ast.c
index 8b894f6..88a40ff 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -308,9 +308,9 @@ void ast_puts(Ast *p) {
}
-Ast *ast_unfoldABR(Ast *left, char *sym, Ast *paramlist) {
+Ast *ast_unfoldABR(Ast *left_params, char *sym, Ast *paramlist) {
// input:
- // left << (AST_AGENT, sym, paramlist)
+ // left_params << (AST_AGENT, sym, paramlist)
// output:
// p1,p2,...,pn << (AST_AGENT, sym, params @ [param])
@@ -318,6 +318,16 @@ Ast *ast_unfoldABR(Ast *left, char *sym, Ast *paramlist) {
// where left = (AST_AGENT sym, p1,p2,...,pn,params)
// right = (AST_NAME param)
+ if (!strcmp(sym, "Merger")) {
+ // left << Merger(paramlist) ==> Merger(left) ~ (paramlist)
+ Ast *agent_left = ast_makeAST(AST_AGENT, ast_makeSymbol("Merger"),
+ left_params);
+ Ast *agent_right = ast_makeTuple(paramlist);
+ Ast *cnct = ast_makeAST(AST_CNCT, agent_left, agent_right);
+ return cnct;
+ }
+
+
if (!strcmp(sym, "Append")) {
// paramlist: [a,b] => [b,a]
if (paramlist->right != NULL) {
@@ -325,13 +335,8 @@ Ast *ast_unfoldABR(Ast *left, char *sym, Ast *paramlist) {
paramlist->left = paramlist->right->left; // a := b
paramlist->right->left = tmp; // b := a
}
- } else if (!strcmp(sym, "Merger")) {
- // left << Merger(paramlist) ==> Merger(left) ~ (paramlist)
- Ast *agent_left = ast_makeAST(AST_AGENT, ast_makeSymbol("Merger"), left);
- Ast *agent_right = ast_makeTuple(paramlist);
- Ast *cnct = ast_makeAST(AST_CNCT, agent_left, agent_right);
- return cnct;
}
+
//ast_puts(left);puts("");
//ast_puts(paramlist);puts("");
@@ -363,19 +368,23 @@ Ast *ast_unfoldABR(Ast *left, char *sym, Ast *paramlist) {
// ast_puts(param);puts("");
- // make left as left@params
- at = left;
- while (at != NULL) {
- if (at->right == NULL) {
- at->right = params;
- break;
+ // make left_params as left_params @ params
+ at = left_params;
+ if (at == NULL) {
+ at = params;
+ } else {
+ while (at != NULL) {
+ if (at->right == NULL) {
+ at->right = params;
+ break;
+ }
+ at = at->right;
}
- at = at->right;
}
// ast_puts(left);puts("");
- Ast *agent_left = ast_makeAST(AST_AGENT, ast_makeSymbol(sym), left);
+ Ast *agent_left = ast_makeAST(AST_AGENT, ast_makeSymbol(sym), left_params);
Ast *agent_right = param;
Ast *cnct = ast_makeAST(AST_CNCT, agent_left, agent_right);
diff --git a/src/ast.h b/src/ast.h
index 5f7fe16..5d759fa 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -51,7 +51,7 @@ void ast_puts(Ast *p);
Ast *ast_paramToCons(Ast *ast);
int ast_recordConst(char *name, int val);
Ast *ast_remove_tuple1(Ast *p);
-Ast *ast_unfoldABR(Ast *left, char *sym, Ast *paramlist);
+Ast *ast_unfoldABR(Ast *left_params, char *sym, Ast *paramlist);
int ast_getRecordedVal(int entry);
#define ast_makeCons(x1,x2) ast_makeAST(AST_LIST,x1,x2)
diff --git a/src/config.h b/src/config.h
index 0a46711..1f878e0 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1,46 +1,86 @@
// Configurations ---------------------------------------------------
-/* Heaps ------------------------------------------
- Choose one among the following three definitions:
- -------------------------------------------------- */
-#define FLEX_EXPANDABLE_HEAP // Inserted heaps size can be flexible.
-//#define EXPANDABLE_HEAP // Expandable heaps for agents and names
-//#define FIXED_HEAP // The heap size is fixed. (Default)
-
-
+// ------------------------------------------------
+// Heaps
+// ------------------------------------------------
+// There are three methods for agents and names heaps:
+// - Fixed-size ring buffers (default)
+// The size is specified by an execution option -c
+//
+// - Expandable ring buffers
+// Automatically new buffers are inserted when all are run up.
+//
+// - Ring buffers whose Initial size and newly inserted size
+// are flexibly changed.
+// The initial size and the expansion magnification are
+// specified by execution options -Xms, -Xmt, respectively.
+//
+// Choose one among the following three definitions with uncomment.
+
+
+//#define FIXED_HEAP
+//#define EXPANDABLE_HEAP
+#define FLEX_EXPANDABLE_HEAP
+
+
+//
+// For the expandable ring buffer, the unit size HOOP_SIZE can be changed.
+// We note that HOOP_SIZE must be two to power.
+//
#ifdef EXPANDABLE_HEAP
-// HOOP_SIZE must be two to power
-#define HOOP_SIZE (1 << 18)
+//#define HOOP_SIZE (1 << 12) // good for small heaps such as fib
+#define HOOP_SIZE (1 << 18) // good for large heaps such as msort-80000
#endif
+
+
+// ------------------------------------------------
+// RuleTable
+// ------------------------------------------------
+// There are two implementation for the rule table:
+// - Hashed linear table (default)
+// - Simple array table
+// To use the hashed one, comment out the following RULETABLE_SIMPLE definition.
+
+//#define RULETABLE_SIMPLE
+
+
+
+
+
-/* Optimisation ------------------------------------
- Comment out definitions if not needed.
- ------------------------------------------------- */
+// ------------------------------------------------
+// Optimisation
+// ------------------------------------------------
+// Comment out definitions if not needed.
+//
// Optimisation inspired by Tail Recursion Optimisation
+//
#define OPTIMISE_IMCODE_TRO
-
+//
// Optimisation of the intermediate codes
-/*
- * Assign registers as little as possible with expecting cache works.
- * Copy propagation and Dead code elimination for LOAD are performed.
- * Reg0 is used as a special one that stores results of comparison.
- * Some combinations are rewritten.
- For instance, `SUBI src $1 dest' becomes `DEC src dest'.
-*/
+//
+//
+// - Assign registers as little as possible with expecting cache works.
+// - Copy propagation and Dead code elimination for LOAD are performed.
+// - Reg0 is used as a special one that stores results of comparison.
+// - Some combinations are rewritten.
+// For instance, `SUBI src $1 dest' becomes `DEC src dest'.
+//
#define OPTIMISE_IMCODE
#ifdef OPTIMISE_IMCODE
-// Furthermore optimisations for codes:
+// Furthermore optimisations on virtual machine codes:
// the following can work when the OPTIMISE_IMCODE is defined:
-
+//
// Generate virtual machine codes with two-address notation
+//
#define OPTIMISE_TWO_ADDRESS
#ifdef OPTIMISE_TWO_ADDRESS
@@ -52,7 +92,9 @@
#endif
-// END Optimisation configuration --------------
+// -------------------------------------------------
+
+
#define COUNT_INTERACTION // Count interaction.
diff --git a/src/inpla.y b/src/inpla.y
index ea533f0..cb06e67 100644
--- a/src/inpla.y
+++ b/src/inpla.y
@@ -33,8 +33,8 @@
//#define COUNT_MKAGENT // count of execution fo mkagent
-#define VERSION "0.8.1"
-#define BUILT_DATE "3 Mar. 2022"
+#define VERSION "0.8.1-1"
+#define BUILT_DATE "10 Mar. 2022"
// ------------------------------------------------------------------
@@ -468,9 +468,13 @@ ap
//
| astparams ABR AGENT LP astparams RP
{ $$ = ast_unfoldABR($1, $3, $5); }
+| ABR AGENT LP astparams RP
+{ $$ = ast_unfoldABR(NULL, $2, $4); }
//
| astparams ABR NAME LP astparams RP
{ $$ = ast_unfoldABR($1, $3, $5); }
+| ABR NAME LP astparams RP
+{ $$ = ast_unfoldABR(NULL, $2, $4); }
;
@@ -6687,6 +6691,8 @@ int Compile_rule_mainbody_on_ast(Ast *mainbody) {
// ------------------------------------------------------------
// TABLE for RULES
// ------------------------------------------------------------
+#ifndef RULETABLE_SIMPLE
+
typedef struct RuleList {
int sym;
int available;
@@ -6864,6 +6870,54 @@ void RuleTable_get_code_for_Int(VALUE heap_syml, void ***code) {
return;
}
+#else
+// ------------------------------------------
+// RuleTable: simple realisation with arrays
+// ------------------------------------------
+//
+// codes for alpha><beta is stored in
+// RuleTable[id_Beta][id_alpha]
+
+static void* RuleTable[NUM_AGENTS][NUM_AGENTS];
+
+void RuleTable_init(void) {
+ for (int i=0; i<NUM_AGENTS; i++) {
+ for (int j=0; j<NUM_AGENTS; j++) {
+ RuleTable[i][j] = NULL;
+ }
+ }
+}
+
+void RuleTable_record(int symlID, int symrID, void **code, int byte) {
+ if (RuleTable[symrID][symlID] == NULL) {
+ RuleTable[symrID][symlID] = malloc(MAX_VMCODE_SEQUENCE * sizeof(void *));
+ }
+ CmEnv_copy_VMCode(byte, code, RuleTable[symrID][symlID]);
+
+}
+
+
+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 *code = RuleTable[symrID][symlID];
+ if (code == NULL) {
+ *result = 0;
+ } else {
+ *result = 1;
+ }
+
+ return code;
+}
+
+static inline
+void RuleTable_get_code_for_Int(VALUE heap_syml, void ***code) {
+ int symlID = AGENT(heap_syml)->basic.id;
+ *code = RuleTable[ID_INT][symlID];
+}
+
+#endif