Browse Source

Updated Iterated function API

Yann Weber 4 years ago
parent
commit
c9afb5d5f2
6 changed files with 43 additions and 42 deletions
  1. 3
    16
      rpn_if.c
  2. 6
    18
      rpn_if.h
  3. 15
    3
      rpn_ifs.c
  4. 15
    3
      rpn_ifs.h
  5. 2
    1
      rpn_jit.c
  6. 2
    1
      rpn_jit.h

+ 3
- 16
rpn_if.c View File

@@ -18,8 +18,7 @@
18 18
  */
19 19
 #include "rpn_if.h"
20 20
 
21
-rpn_if_t* rpn_if_new(const rpn_if_param_t *params, rpn_expr_t *rpn,
22
-	rpn_value_t *memmap)
21
+rpn_if_t* rpn_if_new(const rpn_if_param_t *params, rpn_value_t *memmap)
23 22
 {
24 23
 	rpn_if_t *res;
25 24
 	size_t i;
@@ -133,19 +132,7 @@ size_t rpn_if_step(rpn_if_t *rif, size_t pos)
133 132
 	return newpos;
134 133
 }
135 134
 
136
-int rpn_if_rpn_upd(rpn_if_t *rif, rpn_tokenized_t *rpns)
135
+rpn_expr_t **rpn_if_rpn_get(rpn_if_t *rif)
137 136
 {
138
-	return rpn_if_rpn_upd_rng(rif, rpns, rif->params->rpn_sz, 0);
137
+	return &(rif->rpn);
139 138
 }
140
-
141
-int rpn_if_rpn_upd_rng(rpn_if_t *rif, rpn_tokenized_t *rpns, size_t sz,
142
-	size_t offset)
143
-{
144
-	size_t i;
145
-	for(i=offset; i<offset+sz; i++)
146
-	{
147
-		/**@todo continue implementation */
148
-	}
149
-	return 0;
150
-}
151
-

+ 6
- 18
rpn_if.h View File

@@ -98,8 +98,7 @@ struct rpn_if_s
98 98
  * @todo Delete rpn argument : rpn expressions are initialized and
99 99
  * have to be compiled later
100 100
  */
101
-rpn_if_t* rpn_if_new(const rpn_if_param_t *params, rpn_expr_t *rpn,
102
-	rpn_value_t *memmap);
101
+rpn_if_t* rpn_if_new(const rpn_if_param_t *params, rpn_value_t *memmap);
103 102
 
104 103
 /**@brief Deallocate an @ref rpn_if_s and its ressources and close associated 
105 104
  * @ref rpn_expr_s
@@ -114,23 +113,12 @@ void rpn_if_free(rpn_if_t *rif);
114 113
  */
115 114
 size_t rpn_if_step(rpn_if_t *rif, size_t pos);
116 115
 
117
-/**@brief Update all RPN expressions
118
- * @param rif The concerned IF
119
- * @param rpns A list of tokenized expressions (must be of rif->rpn_sz size)
120
- * @return 0 if no error else -1
121
- * @note Shortcut for @ref rpn_if_rpn_upd_rng(rif, rpns, rif->rpn_sz, 0);
122
- */
123
-int rpn_if_rpn_upd(rpn_if_t *rif, rpn_tokenized_t *rpns);
124
-
125
-/**@brief Update a range of RPN expressions
126
- * @param rif The concerned IF
127
- * @param rpns A list of tokenized expressions
128
- * @param sz Number of rpn expression in rpn argument
129
- * @param offset Start updating expressions from this offset
130
- * @return 0 if no error else -1
116
+
117
+/**@brief Returns the list of RPN expression : allowing to recompile them
118
+ * @return A list of RPN expressions
119
+ * @note The memory area returned must not be freed !
131 120
  */
132
-int rpn_if_rpn_upd_rng(rpn_if_t *rif, rpn_tokenized_t *rpns, size_t sz,
133
-	size_t offset);
121
+rpn_expr_t **rpn_if_rpn_get(rpn_if_t *rif);
134 122
 
135 123
 /**@brief New @ref rpn_if_s and partial initialisation
136 124
  * @param mem_sz memory size in bytes

+ 15
- 3
rpn_ifs.c View File

@@ -60,9 +60,9 @@ void rpn_ifs_free(rpn_ifs_t *rifs)
60 60
 	}
61 61
 }
62 62
 
63
-size_t rpn_ifs_add_if(rpn_ifs_t *rifs, rpn_expr_t **exprs, unsigned int weight)
63
+size_t rpn_ifs_add_if(rpn_ifs_t *rifs, unsigned int weight)
64 64
 {
65
-	size_t res;
65
+	size_t res, i, first_flat;
66 66
 	void *tmp;
67 67
 
68 68
 	res = rifs->if_sz + 1;
@@ -81,11 +81,22 @@ size_t rpn_ifs_add_if(rpn_ifs_t *rifs, rpn_expr_t **exprs, unsigned int weight)
81 81
 
82 82
 	rifs->weight[rifs->if_sz] = weight;
83 83
 	//WRONG expr ARGUMENT !!!
84
-	rifs->rpn_if[rifs->if_sz] = rpn_if_new(&(rifs->params), *exprs, rifs->mem);
84
+	rifs->rpn_if[rifs->if_sz] = rpn_if_new(&(rifs->params), rifs->mem);
85 85
 	if(!rifs->rpn_if[rifs->if_sz])
86 86
 	{
87 87
 		return 0;
88 88
 	}
89
+	
90
+	first_flat = rifs->params.rpn_sz;
91
+	rifs->flat_sz += rifs->params.rpn_sz;
92
+	if(!(tmp = realloc(rifs->flat_rpn, sizeof(rpn_expr_t*) * rifs->flat_sz)))
93
+	{
94
+		return 0;
95
+	}
96
+	for(i=0; i<rifs->params.rpn_sz;i++)
97
+	{
98
+		rifs->flat_rpn[first_flat + i] = &(rifs->rpn_if[rifs->if_sz]->rpn[i]);
99
+	}
89 100
 
90 101
 	rifs->if_sz++;
91 102
 	if(rpn_ifs_weight_update(rifs) < 0)
@@ -95,3 +106,4 @@ size_t rpn_ifs_add_if(rpn_ifs_t *rifs, rpn_expr_t **exprs, unsigned int weight)
95 106
 	}
96 107
 	return res;
97 108
 }
109
+

+ 15
- 3
rpn_ifs.h View File

@@ -65,6 +65,12 @@ struct rpn_ifs_s
65 65
 	/** @brief Stores an array of 255 pointers on IF allowing fast
66 66
 	 * random choice */
67 67
 	rpn_if_t *if_proba[255];
68
+
69
+	/**@brief Stores the RPN expressions pointer of the IF contained in
70
+	 * the system */
71
+	rpn_expr_t **flat_rpn;
72
+	/**Number of rpn expression in the system */
73
+	size_t flat_sz;
68 74
 };
69 75
 
70 76
 /**@brief Initialize a new IFS struct given params
@@ -84,13 +90,12 @@ void rpn_ifs_free(rpn_ifs_t *rifs);
84 90
 
85 91
 /**@brief Add a new iterated function to the system
86 92
  * @param rifs The iterated function system
87
- * @param exprs Optionnal strings representing RPN expressions for
88
- * the new @ref rpn_if_s
93
+ * @param weight The new expression weight
89 94
  * @return 0 on error, else returns the new @ref rpn_if_s index
90 95
  * @note if epxrs is NULL empty RPN expressions are used
91 96
  * @todo change the exprs argument when if init will be updated
92 97
  */
93
-size_t rpn_ifs_add_if(rpn_ifs_t *rifs, rpn_expr_t **exprs, unsigned int weight);
98
+size_t rpn_ifs_add_if(rpn_ifs_t *rifs, unsigned int weight);
94 99
 
95 100
 /**@brief Delete an iterated function from the system given its index
96 101
  * @param rifs The iterated function system
@@ -106,6 +111,13 @@ int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx);
106 111
  */
107 112
 int rpn_ifs_weight_update(rpn_ifs_t *rifs);
108 113
 
114
+/**@brief Returns an array of pointer on all RPN expressions contained in the
115
+ * system, allowing to recompile/update them
116
+ * @param rifs The IF system
117
+ * @returns An array of pointer on @ref rpn_expr_s
118
+ */
119
+rpn_expr_t **rpn_ifs_flat_rpn(rpn_ifs_t *rifs);
120
+
109 121
 /**@brief Randomly choose an IF and make a step updating ifs current posisition
110 122
  * @return -1 on error else 0
111 123
  */

+ 2
- 1
rpn_jit.c View File

@@ -69,7 +69,7 @@ int rpn_expr_reinit(rpn_expr_t* expr)
69 69
 	}
70 70
 #endif
71 71
 	bzero(expr->code_map, expr->code_map_sz);
72
-	bzero(expr->stack, sizeof(unsigned long) * stack_sz);
72
+	bzero(expr->stack, sizeof(unsigned long) * expr->stack_sz);
73 73
 	if(_rpn_expr_init_map(expr) < 0)
74 74
 	{
75 75
 		snprintf(expr->err_reason, 128, 
@@ -78,6 +78,7 @@ int rpn_expr_reinit(rpn_expr_t* expr)
78 78
 		expr->state = RPN_ERROR;
79 79
 		return -1;
80 80
 	}
81
+	return 0;
81 82
 }
82 83
 
83 84
 int rpn_expr_compile(rpn_expr_t *expr, const char *code)

+ 2
- 1
rpn_jit.h View File

@@ -146,7 +146,8 @@ struct rpn_expr_s
146 146
 int rpn_expr_init(rpn_expr_t* expr, const unsigned char stack_sz,
147 147
 	  const size_t args_count);
148 148
 
149
-/**@brief Reinit an existing @ref rpn_expr_s
149
+/**@brief Reinit an existing @ref rpn_expr_s avoiding mmap and malloc
150
+ * for executable memory map and for stack
150 151
  * @param expr
151 152
  */
152 153
 int rpn_expr_reinit(rpn_expr_t* expr);

Loading…
Cancel
Save