diff options
author | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
commit | 07274513e984f0b5544586c74508ccd16e7dcafa (patch) | |
tree | b32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/embryo/src/lib | |
parent | Added Irrlicht 1.8, but without all the Windows binaries. (diff) | |
download | SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2 SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz |
Remove EFL, since it's been released now.
Diffstat (limited to 'libraries/embryo/src/lib')
-rw-r--r-- | libraries/embryo/src/lib/Embryo.h | 901 | ||||
-rw-r--r-- | libraries/embryo/src/lib/Makefile.am | 36 | ||||
-rw-r--r-- | libraries/embryo/src/lib/Makefile.in | 686 | ||||
-rw-r--r-- | libraries/embryo/src/lib/embryo_amx.c | 1995 | ||||
-rw-r--r-- | libraries/embryo/src/lib/embryo_args.c | 128 | ||||
-rw-r--r-- | libraries/embryo/src/lib/embryo_float.c | 331 | ||||
-rw-r--r-- | libraries/embryo/src/lib/embryo_main.c | 36 | ||||
-rw-r--r-- | libraries/embryo/src/lib/embryo_private.h | 298 | ||||
-rw-r--r-- | libraries/embryo/src/lib/embryo_rand.c | 36 | ||||
-rw-r--r-- | libraries/embryo/src/lib/embryo_str.c | 498 | ||||
-rw-r--r-- | libraries/embryo/src/lib/embryo_time.c | 97 |
11 files changed, 0 insertions, 5042 deletions
diff --git a/libraries/embryo/src/lib/Embryo.h b/libraries/embryo/src/lib/Embryo.h deleted file mode 100644 index 4003f6b..0000000 --- a/libraries/embryo/src/lib/Embryo.h +++ /dev/null | |||
@@ -1,901 +0,0 @@ | |||
1 | /** | ||
2 | @brief Embryo Library | ||
3 | |||
4 | These routines are used for Embryo. | ||
5 | |||
6 | @mainpage Embryo Library Documentation | ||
7 | |||
8 | @image html e_big.png | ||
9 | |||
10 | @version 1.0.0 | ||
11 | @author Carsten Haitzler <raster\@rasterman.com> | ||
12 | @author Compuphase http://www.compuphase.com | ||
13 | @date 2004-2012 | ||
14 | |||
15 | @section intro What is Embryo? | ||
16 | |||
17 | Embryo is a tiny library designed to interpret limited Small programs | ||
18 | compiled by the included compiler, @c embryo_cc. It is mostly a cleaned | ||
19 | up and smaller version of the original Small abstract machine. The | ||
20 | compiler is mostly untouched. | ||
21 | |||
22 | Small was renamed to Pawn. | ||
23 | For more information about the Pawn language, see | ||
24 | @htmlonly <a href=http://www.compuphase.com/pawn/pawn.htm>Pawn</a> | ||
25 | @endhtmlonly | ||
26 | @latexonly http://www.compuphase.com/pawn/pawn.htm @endlatexonly | ||
27 | For the basics about the Small language, see @ref Small_Page. | ||
28 | |||
29 | @section How_to_Use How to Use Embryo? | ||
30 | |||
31 | To use Embryo in your code, you need to do at least the following: | ||
32 | |||
33 | @li Include @ref Embryo.h. | ||
34 | @li Load the Embryo program using one of the | ||
35 | @ref Embryo_Program_Creation_Group. | ||
36 | @li Set up the native calls with @ref embryo_program_native_call_add. | ||
37 | @li Create a virtual machine with @ref embryo_program_vm_push. | ||
38 | @li Then run the program with @ref embryo_program_run. | ||
39 | |||
40 | @todo Clean up compiler code. | ||
41 | @todo Proper overview of the operation of the interpreter, that is how | ||
42 | the heap, stack, virtual machines, etc fit together. | ||
43 | |||
44 | @page Small_Page Brief Introduction to Small | ||
45 | |||
46 | This section describes the basics of Small, as compiled and interpreted | ||
47 | with Embryo. | ||
48 | |||
49 | This summary assumes that you are familar with C. For a full list of | ||
50 | differences between C and Small, again, see the full documentation. | ||
51 | |||
52 | @section Small_Variables_Section Variables | ||
53 | |||
54 | @subsection Small_Type_Subsection Types | ||
55 | |||
56 | There is only one type, known as the "cell", which can hold an integer. | ||
57 | |||
58 | @subsection Small_Scope_Subsection Scope | ||
59 | |||
60 | The scope and usage of a variable depends on its declaration. | ||
61 | |||
62 | @li A local variable is normally declared with the @c new keyword. E.g. | ||
63 | @code new variable @endcode | ||
64 | @li A static function variable is defined within a function with the | ||
65 | @c static keyword. | ||
66 | @li A global static variable is one that is only available within the | ||
67 | file it was declared in. Again, use the @c static keyword, but outside | ||
68 | of any function. | ||
69 | @li A stock variable is one that may not be compiled into a program if it | ||
70 | is not used. It is declared using @c stock. | ||
71 | @li A public variable is one that can be read by the host program using | ||
72 | @ref embryo_program_variable_find. It is declared using @c public | ||
73 | keyword. | ||
74 | |||
75 | Remember that the keywords above are to be used on their own. That is, | ||
76 | for example: @code public testvar @endcode not: | ||
77 | @code new public testvar @endcode | ||
78 | |||
79 | @subsection Small_Constants_Subsection Constants | ||
80 | |||
81 | You can declare constants in two ways: | ||
82 | @li Using the preprocessor macro @c \#define. | ||
83 | @li By inserting @c const between the keyword and variable name of a | ||
84 | variable declaration. For example, to declare the variable @c var1 | ||
85 | constant, you type @code new const var1 = 2 @endcode Now @c var1 | ||
86 | cannot be changed. | ||
87 | |||
88 | @subsection Small_Arrays_Subsection Arrays | ||
89 | |||
90 | To declare an array, append square brackets to the end of the variable | ||
91 | name. The following examples show how to declare arrays. Note the | ||
92 | use of the ellipsis operator, which bases the array based on the last two | ||
93 | declared values: | ||
94 | |||
95 | @code | ||
96 | new msg[] = "A message." | ||
97 | new ints[] = {1, 3, 4} | ||
98 | new ints2[20] = {1, 3} // All other elements 0. | ||
99 | new ints3[10] = {1, ... } // All elements = 1 | ||
100 | new ints4[10] = {10, 20, ... } // Elements = 10 -> 100. | ||
101 | // The difference can be negative. | ||
102 | new ints5[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} | ||
103 | @endcode | ||
104 | |||
105 | @note Array initialisers need to be constant. | ||
106 | |||
107 | @section Small_Func_Calls_Section Function Calls | ||
108 | |||
109 | A typical function declaration is as follows: | ||
110 | |||
111 | @code | ||
112 | testfunc(param) { | ||
113 | // Do something ... | ||
114 | // over a couple of lines. | ||
115 | } | ||
116 | @endcode | ||
117 | |||
118 | You can pass by reference. That is, the parameter you pass is changed | ||
119 | outside of the function. For example: | ||
120 | |||
121 | @code | ||
122 | testfunc(¶m) { | ||
123 | param = 10 | ||
124 | // The passed variable will be set to 10 outside of the function. | ||
125 | } | ||
126 | @endcode | ||
127 | |||
128 | To pass an array: | ||
129 | |||
130 | @code | ||
131 | testfunc(param[]) { | ||
132 | // Do something to the array | ||
133 | } | ||
134 | @endcode | ||
135 | |||
136 | @note Arrays are passed by reference. | ||
137 | |||
138 | @section Small_Control_Subsection Control Structures. | ||
139 | |||
140 | Small has the following control structures, which similar to their C | ||
141 | counterparts: | ||
142 | @li @code if (expression) statement1 else statement2 @endcode | ||
143 | @li @code switch (expression) { | ||
144 | case 0: | ||
145 | statement1 // Can only be one statement. Look Ma, no breaks! | ||
146 | case 1..3: // For values between 1 and 3 inclusive. | ||
147 | statement2 | ||
148 | default: // Optional | ||
149 | statement3 | ||
150 | } | ||
151 | @endcode | ||
152 | @li @code while(expression) statement @endcode | ||
153 | @li @code do statement while (expression) @endcode | ||
154 | @li @code for (init_expression; before_iter_test_expression; after_iter_expression) statement @endcode | ||
155 | |||
156 | @section Small_Preprocessor_Section Preprocessor | ||
157 | |||
158 | The following preprocessor directives are available: | ||
159 | @li @code #assert constant_expression @endcode | ||
160 | @li @code #define pattern replacement @endcode | ||
161 | @li @code #define pattern(%1,%2,...) replacement @endcode | ||
162 | @li @code #include filename @endcode | ||
163 | @li @code #if constant_expression | ||
164 | // Various bits of code | ||
165 | #else | ||
166 | // Other bits of code | ||
167 | #endif | ||
168 | @endcode | ||
169 | @li @code #undef pattern @endcode | ||
170 | |||
171 | |||
172 | @page Available_Native_Calls_Page Available Calls | ||
173 | |||
174 | Embryo provides a minimal set of native calls that can be used within | ||
175 | any Embryo script. Those calls are detailed here. | ||
176 | |||
177 | @note Some of the "core" functions here are also described in the full | ||
178 | Small documentation given | ||
179 | |||
180 | @todo Finish this section. | ||
181 | |||
182 | @section Args_ANC_Section Argument Functions | ||
183 | |||
184 | @subsection Numargs_Desc numargs | ||
185 | |||
186 | Returns the number of arguments passed to a function. Useful | ||
187 | when dealing with variable argument lists. | ||
188 | |||
189 | @subsection Getargs_Desc getarg(arg, index=0) | ||
190 | |||
191 | Retrieves the argument number @c arg. If the argument is an array, | ||
192 | use @c index to specify the index of the array to return. | ||
193 | |||
194 | @subsection Setargs_Desc setargs(arg, index=0, value) | ||
195 | |||
196 | Sets the argument number @c arg to the given @c arg. @c index specifies | ||
197 | the index of @c arg to set if @c arg is an array. | ||
198 | |||
199 | @section String_ANC_Section String Functions | ||
200 | |||
201 | Functions that work on strings. | ||
202 | |||
203 | @subsection Atoi_Desc atoi | ||
204 | |||
205 | Translates an number in string form into an integer. | ||
206 | |||
207 | @subsection Fnmatch_Desc fnmatch | ||
208 | |||
209 | Buggered if I know what this does? | ||
210 | |||
211 | @subsection Strcmp_Desc strcmp | ||
212 | |||
213 | String comparing function. | ||
214 | |||
215 | |||
216 | @section Float_ANC_Section Float Functions | ||
217 | |||
218 | @subsection Float_Desc float | ||
219 | |||
220 | @subsection Atof_Desc atof | ||
221 | |||
222 | @subsection Float_Mul_Desc float_mul | ||
223 | |||
224 | @subsection Float_Div_Desc float_div | ||
225 | |||
226 | @subsection Float_Add_Desc float_add | ||
227 | |||
228 | @subsection Float_Sub_Desc float_sub | ||
229 | |||
230 | @subsection Fract_Desc fract | ||
231 | |||
232 | @subsection Round_Desc round | ||
233 | |||
234 | @subsection Float_Cmp_Desc float_cmp | ||
235 | |||
236 | @subsection Sqrt_Desc sqrt | ||
237 | |||
238 | @subsection Pow_Desc pow | ||
239 | |||
240 | @subsection Log_Desc log | ||
241 | |||
242 | @subsection Sin_Desc sin | ||
243 | |||
244 | @subsection Cos_Desc cos | ||
245 | |||
246 | @subsection Tan_Desc tan | ||
247 | |||
248 | @subsection Abs_Desc abs | ||
249 | |||
250 | Returns the absolute value of the given float. | ||
251 | |||
252 | @section Time_ANC_Section Time Functions | ||
253 | |||
254 | @subsection Seconds_Desc seconds() | ||
255 | |||
256 | @subsection Date_Desc date | ||
257 | |||
258 | |||
259 | @section Rand_ANC_Section Random Functions | ||
260 | |||
261 | @subsection Rand_Desc rand() | ||
262 | |||
263 | Returns a random integer. | ||
264 | |||
265 | @subsection Randf_Desc randf() | ||
266 | |||
267 | Returns a random float. | ||
268 | |||
269 | @file Embryo.h | ||
270 | @brief Embryo virtual machine library. | ||
271 | |||
272 | This file includes the routines needed for Embryo library interaction. | ||
273 | This is the @e only file you need to include. | ||
274 | |||
275 | */ | ||
276 | |||
277 | // The following definitions are in Embryo.h, but I did not want to | ||
278 | // mess up the formatting of the file | ||
279 | |||
280 | /** | ||
281 | @def EMBRYO_FUNCTION_NONE | ||
282 | An invalid/non-existent function. | ||
283 | */ | ||
284 | |||
285 | /** | ||
286 | @def EMBRYO_FUNCTION_MAIN | ||
287 | Start at program entry point. For use with @ref embryo_program_run. | ||
288 | */ | ||
289 | |||
290 | /** | ||
291 | @def EMBRYO_FUNCTION_CONT | ||
292 | Continue from last address. For use with @ref embryo_program_run. | ||
293 | */ | ||
294 | |||
295 | /** | ||
296 | @def EMBRYO_PROGRAM_OK | ||
297 | Program was run successfully. | ||
298 | */ | ||
299 | |||
300 | /** | ||
301 | @def EMBRYO_PROGRAM_SLEEP | ||
302 | The program's execution was interrupted by a Small @c sleep command. | ||
303 | */ | ||
304 | |||
305 | /** | ||
306 | @def EMBRYO_PROGRAM_FAIL | ||
307 | An error in the program caused it to fail. | ||
308 | */ | ||
309 | |||
310 | #ifndef _EMBRYO_H | ||
311 | #define _EMBRYO_H | ||
312 | |||
313 | #ifdef EAPI | ||
314 | # undef EAPI | ||
315 | #endif | ||
316 | |||
317 | #ifdef _WIN32 | ||
318 | # ifdef EFL_EMBRYO_BUILD | ||
319 | # ifdef DLL_EXPORT | ||
320 | # define EAPI __declspec(dllexport) | ||
321 | # else | ||
322 | # define EAPI | ||
323 | # endif /* ! DLL_EXPORT */ | ||
324 | # else | ||
325 | # define EAPI __declspec(dllimport) | ||
326 | # endif /* ! EFL_EMBRYO_BUILD */ | ||
327 | #else | ||
328 | # ifdef __GNUC__ | ||
329 | # if __GNUC__ >= 4 | ||
330 | # define EAPI __attribute__ ((visibility("default"))) | ||
331 | # else | ||
332 | # define EAPI | ||
333 | # endif | ||
334 | # else | ||
335 | # define EAPI | ||
336 | # endif | ||
337 | #endif /* ! _WIN32 */ | ||
338 | |||
339 | #ifdef __cplusplus | ||
340 | extern "C" { | ||
341 | #endif | ||
342 | |||
343 | #define EMBRYO_VERSION_MAJOR 1 | ||
344 | #define EMBRYO_VERSION_MINOR 2 | ||
345 | |||
346 | typedef struct _Embryo_Version | ||
347 | { | ||
348 | int major; | ||
349 | int minor; | ||
350 | int micro; | ||
351 | int revision; | ||
352 | } Embryo_Version; | ||
353 | |||
354 | EAPI extern Embryo_Version *embryo_version; | ||
355 | |||
356 | /* potential error values */ | ||
357 | typedef enum _Embryo_Error | ||
358 | { | ||
359 | EMBRYO_ERROR_NONE, | ||
360 | /* reserve the first 15 error codes for exit codes of the abstract machine */ | ||
361 | EMBRYO_ERROR_EXIT, /** Forced exit */ | ||
362 | EMBRYO_ERROR_ASSERT, /** Assertion failed */ | ||
363 | EMBRYO_ERROR_STACKERR, /** Stack/heap collision */ | ||
364 | EMBRYO_ERROR_BOUNDS, /** Index out of bounds */ | ||
365 | EMBRYO_ERROR_MEMACCESS, /** Invalid memory access */ | ||
366 | EMBRYO_ERROR_INVINSTR, /** Invalid instruction */ | ||
367 | EMBRYO_ERROR_STACKLOW, /** Stack underflow */ | ||
368 | EMBRYO_ERROR_HEAPLOW, /** Heap underflow */ | ||
369 | EMBRYO_ERROR_CALLBACK, /** No callback, or invalid callback */ | ||
370 | EMBRYO_ERROR_NATIVE, /** Native function failed */ | ||
371 | EMBRYO_ERROR_DIVIDE, /** Divide by zero */ | ||
372 | EMBRYO_ERROR_SLEEP, /** Go into sleepmode - code can be restarted */ | ||
373 | |||
374 | EMBRYO_ERROR_MEMORY = 16, /** Out of memory */ | ||
375 | EMBRYO_ERROR_FORMAT, /** Invalid file format */ | ||
376 | EMBRYO_ERROR_VERSION, /** File is for a newer version of the Embryo_Program */ | ||
377 | EMBRYO_ERROR_NOTFOUND, /** Function not found */ | ||
378 | EMBRYO_ERROR_INDEX, /** Invalid index parameter (bad entry point) */ | ||
379 | EMBRYO_ERROR_DEBUG, /** Debugger cannot run */ | ||
380 | EMBRYO_ERROR_INIT, /** Embryo_Program not initialized (or doubly initialized) */ | ||
381 | EMBRYO_ERROR_USERDATA, /** Unable to set user data field (table full) */ | ||
382 | EMBRYO_ERROR_INIT_JIT, /** Cannot initialize the JIT */ | ||
383 | EMBRYO_ERROR_PARAMS, /** Parameter error */ | ||
384 | EMBRYO_ERROR_DOMAIN, /** Domain error, expression result does not fit in range */ | ||
385 | } Embryo_Error; | ||
386 | |||
387 | /* program run return values */ | ||
388 | typedef enum _Embryo_Status | ||
389 | { | ||
390 | EMBRYO_PROGRAM_FAIL = 0, | ||
391 | EMBRYO_PROGRAM_OK = 1, | ||
392 | EMBRYO_PROGRAM_SLEEP = 2, | ||
393 | EMBRYO_PROGRAM_BUSY = 3, | ||
394 | EMBRYO_PROGRAM_TOOLONG = 4 | ||
395 | } Embryo_Status; | ||
396 | |||
397 | typedef unsigned int Embryo_UCell; | ||
398 | typedef int Embryo_Cell; | ||
399 | /** An invalid cell reference */ | ||
400 | #define EMBRYO_CELL_NONE 0x7fffffff | ||
401 | |||
402 | typedef struct _Embryo_Program Embryo_Program; | ||
403 | typedef int Embryo_Function; | ||
404 | /* possible function type values that are enumerated */ | ||
405 | #define EMBRYO_FUNCTION_NONE 0x7fffffff /* An invalid/non existent function */ | ||
406 | #define EMBRYO_FUNCTION_MAIN -1 /* Start at program entry point */ | ||
407 | #define EMBRYO_FUNCTION_CONT -2 /* Continue from last address */ | ||
408 | |||
409 | typedef union | ||
410 | { | ||
411 | float f; | ||
412 | Embryo_Cell c; | ||
413 | } Embryo_Float_Cell; | ||
414 | |||
415 | #if defined _MSC_VER || defined __SUNPRO_C | ||
416 | /** Float to Embryo_Cell */ | ||
417 | # define EMBRYO_FLOAT_TO_CELL(f) (((Embryo_Float_Cell *)&(f))->c) | ||
418 | /** Embryo_Cell to float */ | ||
419 | # define EMBRYO_CELL_TO_FLOAT(c) (((Embryo_Float_Cell *)&(c))->f) | ||
420 | #else | ||
421 | /** Float to Embryo_Cell */ | ||
422 | # define EMBRYO_FLOAT_TO_CELL(f) ((Embryo_Float_Cell) f).c | ||
423 | /** Embryo_Cell to float */ | ||
424 | # define EMBRYO_CELL_TO_FLOAT(c) ((Embryo_Float_Cell) c).f | ||
425 | #endif | ||
426 | |||
427 | /** | ||
428 | * @defgroup Embryo_Library_Group Library Maintenance Functions | ||
429 | * | ||
430 | * Functions that start up and shutdown the Embryo library. | ||
431 | */ | ||
432 | |||
433 | |||
434 | /** | ||
435 | * Initialises the Embryo library. | ||
436 | * @return The number of times the library has been initialised without being | ||
437 | * shut down. | ||
438 | * @ingroup Embryo_Library_Group | ||
439 | */ | ||
440 | EAPI int embryo_init(void); | ||
441 | |||
442 | /** | ||
443 | * Shuts down the Embryo library. | ||
444 | * @return The number of times the library has been initialised without being | ||
445 | * shutdown. | ||
446 | * @ingroup Embryo_Library_Group | ||
447 | */ | ||
448 | EAPI int embryo_shutdown(void); | ||
449 | |||
450 | /** | ||
451 | * @defgroup Embryo_Program_Creation_Group Program Creation and Destruction Functions | ||
452 | * | ||
453 | * Functions that set up programs, and destroy them. | ||
454 | */ | ||
455 | |||
456 | /** | ||
457 | * Creates a new Embryo program, with bytecode data that can be freed. | ||
458 | * @param data Pointer to the bytecode of the program. | ||
459 | * @param size Number of bytes of bytecode. | ||
460 | * @return A new Embryo program. | ||
461 | * @ingroup Embryo_Program_Creation_Group | ||
462 | */ | ||
463 | EAPI Embryo_Program *embryo_program_new(void *data, int size); | ||
464 | |||
465 | /** | ||
466 | * Creates a new Embryo program, with bytecode data that cannot be | ||
467 | * freed. | ||
468 | * @param data Pointer to the bytecode of the program. | ||
469 | * @param size Number of bytes of bytecode. | ||
470 | * @return A new Embryo program. | ||
471 | * @ingroup Embryo_Program_Creation_Group | ||
472 | */ | ||
473 | EAPI Embryo_Program *embryo_program_const_new(void *data, int size); | ||
474 | |||
475 | /** | ||
476 | * Creates a new Embryo program based on the bytecode data stored in the | ||
477 | * given file. | ||
478 | * @param file Filename of the given file. | ||
479 | * @return A new Embryo program. | ||
480 | * @ingroup Embryo_Program_Creation_Group | ||
481 | */ | ||
482 | EAPI Embryo_Program *embryo_program_load(const char *file); | ||
483 | |||
484 | /** | ||
485 | * Frees the given Embryo program. | ||
486 | * @param ep The given program. | ||
487 | * @ingroup Embryo_Program_Creation_Group | ||
488 | */ | ||
489 | EAPI void embryo_program_free(Embryo_Program *ep); | ||
490 | |||
491 | /** | ||
492 | * Adds a native program call to the given Embryo program. | ||
493 | * @param ep The given Embryo program. | ||
494 | * @param name The name for the call used in the script. | ||
495 | * @param func The function to use when the call is made. | ||
496 | * @ingroup Embryo_Func_Group | ||
497 | */ | ||
498 | |||
499 | /** | ||
500 | * @defgroup Embryo_Func_Group Function Functions | ||
501 | * | ||
502 | * Functions that deal with Embryo program functions. | ||
503 | */ | ||
504 | EAPI void embryo_program_native_call_add(Embryo_Program *ep, const char *name, Embryo_Cell (*func) (Embryo_Program *ep, Embryo_Cell *params)); | ||
505 | |||
506 | /** | ||
507 | * Resets the current virtual machine session of the given program. | ||
508 | * @param ep The given program. | ||
509 | * @ingroup Embryo_Program_VM_Group | ||
510 | */ | ||
511 | |||
512 | /** | ||
513 | * @defgroup Embryo_Program_VM_Group Virtual Machine Functions | ||
514 | * | ||
515 | * Functions that deal with creating and destroying virtual machine sessions | ||
516 | * for a given program. | ||
517 | * | ||
518 | * A given embryo program can have multiple virtual machine sessions running. | ||
519 | * This is useful when you have a native call that in turn calls a function in | ||
520 | * the embryo program. The native call can start a new virtual machine | ||
521 | * session to run the function it needs. Once completed, the session can be | ||
522 | * popped off the program's stack, and the native call can return its value | ||
523 | * to the old session. | ||
524 | * | ||
525 | * A new virtual machine session is created by pushing a new virtual machine | ||
526 | * onto the session stack of a program using @ref embryo_program_vm_push. | ||
527 | * The current virtual machine session can be destroyed by calling | ||
528 | * @ref embryo_program_vm_pop. | ||
529 | */ | ||
530 | EAPI void embryo_program_vm_reset(Embryo_Program *ep); | ||
531 | |||
532 | /** | ||
533 | * Starts a new virtual machine session for the given program. | ||
534 | * | ||
535 | * See @ref Embryo_Program_VM_Group for more information about how this works. | ||
536 | * | ||
537 | * @param ep The given program. | ||
538 | * @ingroup Embryo_Program_VM_Group | ||
539 | */ | ||
540 | EAPI void embryo_program_vm_push(Embryo_Program *ep); | ||
541 | |||
542 | /** | ||
543 | * Frees the current virtual machine session associated with the given program. | ||
544 | * | ||
545 | * See @ref Embryo_Program_VM_Group for more information about how this works. | ||
546 | * Note that you will need to retrieve any return data or data on the stack | ||
547 | * before you pop. | ||
548 | * | ||
549 | * @param ep The given program. | ||
550 | * @ingroup Embryo_Program_VM_Group | ||
551 | */ | ||
552 | EAPI void embryo_program_vm_pop(Embryo_Program *ep); | ||
553 | |||
554 | /** | ||
555 | * Ensures that the given unsigned short integer is in the small | ||
556 | * endian format. | ||
557 | * @param v Pointer to the given integer. | ||
558 | * @ingroup Embryo_Swap_Group | ||
559 | */ | ||
560 | |||
561 | /** | ||
562 | * @defgroup Embryo_Swap_Group Byte Swapping Functions | ||
563 | * | ||
564 | * Functions that are used to ensure that integers passed to the | ||
565 | * virtual machine are in small endian format. These functions are | ||
566 | * used to ensure that the virtual machine operates correctly on big | ||
567 | * endian machines. | ||
568 | */ | ||
569 | EAPI void embryo_swap_16(unsigned short *v); | ||
570 | |||
571 | /** | ||
572 | * Ensures that the given unsigned integer is in the small endian | ||
573 | * format. | ||
574 | * @param v Pointer to the given integer. | ||
575 | * @ingroup Embryo_Swap_Group | ||
576 | */ | ||
577 | EAPI void embryo_swap_32(unsigned int *v); | ||
578 | |||
579 | /** | ||
580 | * Returns the function in the given program with the given name. | ||
581 | * @param ep The given program. | ||
582 | * @param name The given function name. | ||
583 | * @return The function if successful. Otherwise, @c EMBRYO_FUNCTION_NONE. | ||
584 | * @ingroup Embryo_Func_Group | ||
585 | */ | ||
586 | EAPI Embryo_Function embryo_program_function_find(Embryo_Program *ep, const char *name); | ||
587 | |||
588 | /** | ||
589 | * Retrieves the location of the public variable in the given program | ||
590 | * with the given name. | ||
591 | * @param ep The given program. | ||
592 | * @param name The given name. | ||
593 | * @return The address of the variable if found. @c EMBRYO_CELL_NONE | ||
594 | * otherwise. | ||
595 | * @ingroup Embryo_Public_Variable_Group | ||
596 | */ | ||
597 | |||
598 | /** | ||
599 | * @defgroup Embryo_Public_Variable_Group Public Variable Access Functions | ||
600 | * | ||
601 | * In an Embryo program, a global variable can be declared public, as | ||
602 | * described in @ref Small_Scope_Subsection. The functions here allow | ||
603 | * the host program to access these public variables. | ||
604 | */ | ||
605 | EAPI Embryo_Cell embryo_program_variable_find(Embryo_Program *ep, const char *name); | ||
606 | |||
607 | /** | ||
608 | * Retrieves the number of public variables in the given program. | ||
609 | * @param ep The given program. | ||
610 | * @return The number of public variables. | ||
611 | * @ingroup Embryo_Public_Variable_Group | ||
612 | */ | ||
613 | EAPI int embryo_program_variable_count_get(Embryo_Program *ep); | ||
614 | |||
615 | /** | ||
616 | * Retrieves the location of the public variable in the given program | ||
617 | * with the given identifier. | ||
618 | * @param ep The given program. | ||
619 | * @param num The identifier of the public variable. | ||
620 | * @return The virtual machine address of the variable if found. | ||
621 | * @c EMBRYO_CELL_NONE otherwise. | ||
622 | * @ingroup Embryo_Public_Variable_Group | ||
623 | */ | ||
624 | EAPI Embryo_Cell embryo_program_variable_get(Embryo_Program *ep, int num); | ||
625 | |||
626 | /** | ||
627 | * Sets the error code for the given program to the given code. | ||
628 | * @param ep The given program. | ||
629 | * @param error The given error code. | ||
630 | * @ingroup Embryo_Error_Group | ||
631 | */ | ||
632 | |||
633 | /** | ||
634 | * @defgroup Embryo_Error_Group Error Functions | ||
635 | * | ||
636 | * Functions that set and retrieve error codes in Embryo programs. | ||
637 | */ | ||
638 | EAPI void embryo_program_error_set(Embryo_Program *ep, Embryo_Error error); | ||
639 | |||
640 | /** | ||
641 | * Retrieves the current error code for the given program. | ||
642 | * @param ep The given program. | ||
643 | * @return The current error code. | ||
644 | * @ingroup Embryo_Error_Group | ||
645 | */ | ||
646 | EAPI Embryo_Error embryo_program_error_get(Embryo_Program *ep); | ||
647 | |||
648 | /** | ||
649 | * Sets the data associated to the given program. | ||
650 | * @param ep The given program. | ||
651 | * @param data New bytecode data. | ||
652 | * @ingroup Embryo_Program_Data_Group | ||
653 | */ | ||
654 | |||
655 | /** | ||
656 | * @defgroup Embryo_Program_Data_Group Program Data Functions | ||
657 | * | ||
658 | * Functions that set and retrieve data associated with the given | ||
659 | * program. | ||
660 | */ | ||
661 | EAPI void embryo_program_data_set(Embryo_Program *ep, void *data); | ||
662 | |||
663 | /** | ||
664 | * Retrieves the data associated to the given program. | ||
665 | * @param ep The given program. | ||
666 | * @ingroup Embryo_Program_Data_Group | ||
667 | */ | ||
668 | EAPI void *embryo_program_data_get(Embryo_Program *ep); | ||
669 | |||
670 | /** | ||
671 | * Retrieves a string describing the given error code. | ||
672 | * @param error The given error code. | ||
673 | * @return String describing the given error code. If the given code is not | ||
674 | * known, the string "(unknown)" is returned. | ||
675 | * @ingroup Embryo_Error_Group | ||
676 | */ | ||
677 | EAPI const char *embryo_error_string_get(Embryo_Error error); | ||
678 | |||
679 | /** | ||
680 | * Retrieves the length of the string starting at the given cell. | ||
681 | * @param ep The program the cell is part of. | ||
682 | * @param str_cell Pointer to the first cell of the string. | ||
683 | * @return The length of the string. @c 0 is returned if there is an error. | ||
684 | * @ingroup Embryo_Data_String_Group | ||
685 | */ | ||
686 | |||
687 | /** | ||
688 | * @defgroup Embryo_Data_String_Group Embryo Data String Functions | ||
689 | * | ||
690 | * Functions that operate on strings in the memory of a virtual machine. | ||
691 | */ | ||
692 | EAPI int embryo_data_string_length_get(Embryo_Program *ep, Embryo_Cell *str_cell); | ||
693 | |||
694 | /** | ||
695 | * Copies the string starting at the given cell to the given buffer. | ||
696 | * @param ep The program the cell is part of. | ||
697 | * @param str_cell Pointer to the first cell of the string. | ||
698 | * @param dst The given buffer. | ||
699 | * @ingroup Embryo_Data_String_Group | ||
700 | */ | ||
701 | EAPI void embryo_data_string_get(Embryo_Program *ep, Embryo_Cell *str_cell, char *dst); | ||
702 | |||
703 | /** | ||
704 | * Copies string in the given buffer into the virtual machine memory | ||
705 | * starting at the given cell. | ||
706 | * @param ep The program the cell is part of. | ||
707 | * @param src The given buffer. | ||
708 | * @param str_cell Pointer to the first cell to copy the string to. | ||
709 | * @ingroup Embryo_Data_String_Group | ||
710 | */ | ||
711 | EAPI void embryo_data_string_set(Embryo_Program *ep, const char *src, Embryo_Cell *str_cell); | ||
712 | |||
713 | /** | ||
714 | * Retreives a pointer to the address in the virtual machine given by the | ||
715 | * given cell. | ||
716 | * @param ep The program whose virtual machine address is being queried. | ||
717 | * @param addr The given cell. | ||
718 | * @return A pointer to the cell at the given address. | ||
719 | * @ingroup Embryo_Data_String_Group | ||
720 | */ | ||
721 | EAPI Embryo_Cell *embryo_data_address_get(Embryo_Program *ep, Embryo_Cell addr); | ||
722 | |||
723 | /** | ||
724 | * Increases the size of the heap of the given virtual machine by the given | ||
725 | * number of Embryo_Cells. | ||
726 | * @param ep The program with the given virtual machine. | ||
727 | * @param cells The given number of Embryo_Cells. | ||
728 | * @return The address of the new memory region on success. | ||
729 | * @c EMBRYO_CELL_NONE otherwise. | ||
730 | * @ingroup Embryo_Heap_Group | ||
731 | */ | ||
732 | |||
733 | /** | ||
734 | * @defgroup Embryo_Heap_Group Heap Functions | ||
735 | * | ||
736 | * The heap is an area of memory that can be allocated for program | ||
737 | * use at runtime. The heap functions here change the amount of heap | ||
738 | * memory available. | ||
739 | */ | ||
740 | EAPI Embryo_Cell embryo_data_heap_push(Embryo_Program *ep, int cells); | ||
741 | |||
742 | /** | ||
743 | * Decreases the size of the heap of the given virtual machine down to the | ||
744 | * given size. | ||
745 | * @param ep The program with the given virtual machine. | ||
746 | * @param down_to The given size. | ||
747 | * @ingroup Embryo_Heap_Group | ||
748 | */ | ||
749 | EAPI void embryo_data_heap_pop(Embryo_Program *ep, Embryo_Cell down_to); | ||
750 | |||
751 | /** | ||
752 | * Returns the number of virtual machines are running for the given program. | ||
753 | * @param ep The given program. | ||
754 | * @return The number of virtual machines running. | ||
755 | * @ingroup Embryo_Run_Group | ||
756 | */ | ||
757 | |||
758 | /** | ||
759 | * @defgroup Embryo_Run_Group Program Run Functions | ||
760 | * | ||
761 | * Functions that are involved in actually running functions in an | ||
762 | * Embryo program. | ||
763 | */ | ||
764 | EAPI int embryo_program_recursion_get(Embryo_Program *ep); | ||
765 | |||
766 | /** | ||
767 | * Runs the given function of the given Embryo program in the current | ||
768 | * virtual machine. The parameter @p fn can be found using | ||
769 | * @ref embryo_program_function_find. | ||
770 | * | ||
771 | * @note For Embryo to be able to run a function, it must have been | ||
772 | * declared @c public in the Small source code. | ||
773 | * | ||
774 | * @param ep The given program. | ||
775 | * @param fn The given function. Normally "main", in which case the | ||
776 | * constant @c EMBRYO_FUNCTION_MAIN can be used. | ||
777 | * @return @c EMBRYO_PROGRAM_OK on success. @c EMBRYO_PROGRAM_SLEEP if the | ||
778 | * program is halted by the Small @c sleep call. | ||
779 | * @c EMBRYO_PROGRAM_FAIL if there is an error. | ||
780 | * @c EMBRYO_PROGRAM_TOOLONG if the program executes for longer than | ||
781 | * it is allowed to in abstract machine instruction count. | ||
782 | * @ingroup Embryo_Run_Group | ||
783 | */ | ||
784 | EAPI Embryo_Status embryo_program_run(Embryo_Program *ep, Embryo_Function func); | ||
785 | |||
786 | /** | ||
787 | * Retreives the return value of the last called function of the given | ||
788 | * program. | ||
789 | * @param ep The given program. | ||
790 | * @return An Embryo_Cell representing the return value of the function | ||
791 | * that was last called. | ||
792 | * @ingroup Embryo_Run_Group | ||
793 | */ | ||
794 | EAPI Embryo_Cell embryo_program_return_value_get(Embryo_Program *ep); | ||
795 | |||
796 | /** | ||
797 | * Sets the maximum number of abstract machine cycles any given program run | ||
798 | * can execute before being put to sleep and returning. | ||
799 | * | ||
800 | * @param ep The given program. | ||
801 | * @param max The number of machine cycles as a limit. | ||
802 | * | ||
803 | * This sets the maximum number of abstract machine (virtual machine) | ||
804 | * instructions that a single run of an embryo function (even if its main) | ||
805 | * can use before embryo embryo_program_run() reutrns with the value | ||
806 | * EMBRYO_PROGRAM_TOOLONG. If the function fully executes within this number | ||
807 | * of cycles, embryo_program_run() will return as normal with either | ||
808 | * EMBRYO_PROGRAM_OK, EMBRYO_PROGRAM_FAIL or EMBRYO_PROGRAM_SLEEP. If the | ||
809 | * run exceeds this instruction count, then EMBRYO_PROGRAM_TOOLONG will be | ||
810 | * returned indicating the program exceeded its run count. If the app wishes | ||
811 | * to continue running this anyway - it is free to process its own events or | ||
812 | * whatever it wants and continue the function by calling | ||
813 | * embryo_program_run(program, EMBRYO_FUNCTION_CONT); which will start the | ||
814 | * run again until the instruction count is reached. This can keep being done | ||
815 | * to allow the calling program to still be able to control things outside the | ||
816 | * embryo function being called. If the maximum run cycle count is 0 then the | ||
817 | * program is allowed to run forever only returning when it is done. | ||
818 | * | ||
819 | * It is important to note that abstract machine cycles are NOT the same as | ||
820 | * the host machine cpu cycles. They are not fixed in runtime per cycle, so | ||
821 | * this is more of a helper tool than a way to HARD-FORCE a script to only | ||
822 | * run for a specific period of time. If the cycle count is set to something | ||
823 | * low like 5000 or 1000, then every 1000 (or 5000) cycles control will be | ||
824 | * returned to the calling process where it can check a timer to see if a | ||
825 | * physical runtime limit has been elapsed and then abort running further | ||
826 | * assuming a "runaway script" or keep continuing the script run. This | ||
827 | * limits resolution to only that many cycles which do not take a determined | ||
828 | * amount of time to execute, as this varies from cpu to cpu and also depends | ||
829 | * on how loaded the system is. Making the max cycle run too low will | ||
830 | * impact performance requiring the abstract machine to do setup and teardown | ||
831 | * cycles too often comapred to cycles actually executed. | ||
832 | * | ||
833 | * Also note it does NOT include nested abstract machines. IF this abstract | ||
834 | * machine run calls embryo script that calls a native function that in turn | ||
835 | * calls more embryo script, then the 2nd (and so on) levels are not included | ||
836 | * in this run count. They can set their own max instruction count values | ||
837 | * separately. | ||
838 | * | ||
839 | * The default max cycle run value is 0 in any program until set with this | ||
840 | * function. | ||
841 | * | ||
842 | * @ingroup Embryo_Run_Group | ||
843 | */ | ||
844 | EAPI void embryo_program_max_cycle_run_set(Embryo_Program *ep, int max); | ||
845 | |||
846 | /** | ||
847 | * Retreives the maximum number of abstract machine cycles a program is allowed | ||
848 | * to run. | ||
849 | * @param ep The given program. | ||
850 | * @return The number of cycles a run cycle is allowed to run for this | ||
851 | * program. | ||
852 | * | ||
853 | * This returns the value set by embryo_program_max_cycle_run_set(). See | ||
854 | * embryo_program_max_cycle_run_set() for more information. | ||
855 | * | ||
856 | * @ingroup Embryo_Run_Group | ||
857 | */ | ||
858 | EAPI int embryo_program_max_cycle_run_get(Embryo_Program *ep); | ||
859 | |||
860 | /** | ||
861 | * Pushes an Embryo_Cell onto the function stack to use as a parameter for | ||
862 | * the next function that is called in the given program. | ||
863 | * @param ep The given program. | ||
864 | * @param cell The Embryo_Cell to push onto the stack. | ||
865 | * @return @c 1 if successful. @c 0 otherwise. | ||
866 | * @ingroup Embryo_Parameter_Group | ||
867 | */ | ||
868 | |||
869 | /** | ||
870 | * @defgroup Embryo_Parameter_Group Function Parameter Functions | ||
871 | * | ||
872 | * Functions that set parameters for the next function that is called. | ||
873 | */ | ||
874 | EAPI int embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell); | ||
875 | |||
876 | /** | ||
877 | * Pushes a string onto the function stack to use as a parameter for the | ||
878 | * next function that is called in the given program. | ||
879 | * @param ep The given program. | ||
880 | * @param str The string to push onto the stack. | ||
881 | * @return @c 1 if successful. @c 0 otherwise. | ||
882 | * @ingroup Embryo_Parameter_Group | ||
883 | */ | ||
884 | EAPI int embryo_parameter_string_push(Embryo_Program *ep, const char *str); | ||
885 | |||
886 | /** | ||
887 | * Pushes an array of Embryo_Cells onto the function stack to be used as | ||
888 | * parameters for the next function that is called in the given program. | ||
889 | * @param ep The given program. | ||
890 | * @param cells The array of Embryo_Cells. | ||
891 | * @param num The number of cells in @p cells. | ||
892 | * @return @c 1 if successful. @c 0 otherwise. | ||
893 | * @ingroup Embryo_Parameter_Group | ||
894 | */ | ||
895 | EAPI int embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num); | ||
896 | |||
897 | #ifdef __cplusplus | ||
898 | } | ||
899 | #endif | ||
900 | |||
901 | #endif | ||
diff --git a/libraries/embryo/src/lib/Makefile.am b/libraries/embryo/src/lib/Makefile.am deleted file mode 100644 index d2ccb55..0000000 --- a/libraries/embryo/src/lib/Makefile.am +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | |||
2 | MAINTAINERCLEANFILES = Makefile.in | ||
3 | |||
4 | AM_CPPFLAGS = \ | ||
5 | -I. \ | ||
6 | -I$(top_srcdir)/src/lib \ | ||
7 | -I$(top_builddir) \ | ||
8 | -I$(top_srcdir)/src/lib \ | ||
9 | -I$(top_srcdir)/src/lib/include \ | ||
10 | -DPACKAGE_BIN_DIR=\"$(bindir)\" \ | ||
11 | -DPACKAGE_LIB_DIR=\"$(libdir)\" \ | ||
12 | -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ | ||
13 | @EVIL_CFLAGS@ \ | ||
14 | @EXOTIC_CFLAGS@ \ | ||
15 | @EMBRYO_CPPFLAGS@ \ | ||
16 | @EFL_EMBRYO_BUILD@ | ||
17 | |||
18 | includes_HEADERS = Embryo.h | ||
19 | includesdir = $(includedir)/embryo-@VMAJ@ | ||
20 | |||
21 | lib_LTLIBRARIES = libembryo.la | ||
22 | |||
23 | libembryo_la_SOURCES = \ | ||
24 | embryo_amx.c \ | ||
25 | embryo_args.c \ | ||
26 | embryo_float.c \ | ||
27 | embryo_main.c \ | ||
28 | embryo_rand.c \ | ||
29 | embryo_str.c \ | ||
30 | embryo_time.c | ||
31 | |||
32 | libembryo_la_CFLAGS = @EMBRYO_CFLAGS@ | ||
33 | libembryo_la_LIBADD = @EXOTIC_LIBS@ @EVIL_LIBS@ -lm | ||
34 | libembryo_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@ | ||
35 | |||
36 | EXTRA_DIST = embryo_private.h | ||
diff --git a/libraries/embryo/src/lib/Makefile.in b/libraries/embryo/src/lib/Makefile.in deleted file mode 100644 index c46a03e..0000000 --- a/libraries/embryo/src/lib/Makefile.in +++ /dev/null | |||
@@ -1,686 +0,0 @@ | |||
1 | # Makefile.in generated by automake 1.11.1 from Makefile.am. | ||
2 | # @configure_input@ | ||
3 | |||
4 | # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, | ||
5 | # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, | ||
6 | # Inc. | ||
7 | # This Makefile.in is free software; the Free Software Foundation | ||
8 | # gives unlimited permission to copy and/or distribute it, | ||
9 | # with or without modifications, as long as this notice is preserved. | ||
10 | |||
11 | # This program is distributed in the hope that it will be useful, | ||
12 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without | ||
13 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
14 | # PARTICULAR PURPOSE. | ||
15 | |||
16 | @SET_MAKE@ | ||
17 | |||
18 | |||
19 | VPATH = @srcdir@ | ||
20 | pkgdatadir = $(datadir)/@PACKAGE@ | ||
21 | pkgincludedir = $(includedir)/@PACKAGE@ | ||
22 | pkglibdir = $(libdir)/@PACKAGE@ | ||
23 | pkglibexecdir = $(libexecdir)/@PACKAGE@ | ||
24 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd | ||
25 | install_sh_DATA = $(install_sh) -c -m 644 | ||
26 | install_sh_PROGRAM = $(install_sh) -c | ||
27 | install_sh_SCRIPT = $(install_sh) -c | ||
28 | INSTALL_HEADER = $(INSTALL_DATA) | ||
29 | transform = $(program_transform_name) | ||
30 | NORMAL_INSTALL = : | ||
31 | PRE_INSTALL = : | ||
32 | POST_INSTALL = : | ||
33 | NORMAL_UNINSTALL = : | ||
34 | PRE_UNINSTALL = : | ||
35 | POST_UNINSTALL = : | ||
36 | build_triplet = @build@ | ||
37 | host_triplet = @host@ | ||
38 | subdir = src/lib | ||
39 | DIST_COMMON = $(includes_HEADERS) $(srcdir)/Makefile.am \ | ||
40 | $(srcdir)/Makefile.in | ||
41 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 | ||
42 | am__aclocal_m4_deps = $(top_srcdir)/m4/ac_attribute.m4 \ | ||
43 | $(top_srcdir)/m4/efl_binary.m4 $(top_srcdir)/m4/efl_doxygen.m4 \ | ||
44 | $(top_srcdir)/m4/efl_fnmatch.m4 \ | ||
45 | $(top_srcdir)/m4/efl_gettimeofday.m4 \ | ||
46 | $(top_srcdir)/m4/efl_path_max.m4 $(top_srcdir)/m4/libtool.m4 \ | ||
47 | $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ | ||
48 | $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ | ||
49 | $(top_srcdir)/configure.ac | ||
50 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ | ||
51 | $(ACLOCAL_M4) | ||
52 | mkinstalldirs = $(install_sh) -d | ||
53 | CONFIG_HEADER = $(top_builddir)/config.h | ||
54 | CONFIG_CLEAN_FILES = | ||
55 | CONFIG_CLEAN_VPATH_FILES = | ||
56 | am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; | ||
57 | am__vpath_adj = case $$p in \ | ||
58 | $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ | ||
59 | *) f=$$p;; \ | ||
60 | esac; | ||
61 | am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; | ||
62 | am__install_max = 40 | ||
63 | am__nobase_strip_setup = \ | ||
64 | srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` | ||
65 | am__nobase_strip = \ | ||
66 | for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" | ||
67 | am__nobase_list = $(am__nobase_strip_setup); \ | ||
68 | for p in $$list; do echo "$$p $$p"; done | \ | ||
69 | sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ | ||
70 | $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ | ||
71 | if (++n[$$2] == $(am__install_max)) \ | ||
72 | { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ | ||
73 | END { for (dir in files) print dir, files[dir] }' | ||
74 | am__base_list = \ | ||
75 | sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ | ||
76 | sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | ||
77 | am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includesdir)" | ||
78 | LTLIBRARIES = $(lib_LTLIBRARIES) | ||
79 | libembryo_la_DEPENDENCIES = | ||
80 | am_libembryo_la_OBJECTS = libembryo_la-embryo_amx.lo \ | ||
81 | libembryo_la-embryo_args.lo libembryo_la-embryo_float.lo \ | ||
82 | libembryo_la-embryo_main.lo libembryo_la-embryo_rand.lo \ | ||
83 | libembryo_la-embryo_str.lo libembryo_la-embryo_time.lo | ||
84 | libembryo_la_OBJECTS = $(am_libembryo_la_OBJECTS) | ||
85 | AM_V_lt = $(am__v_lt_$(V)) | ||
86 | am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) | ||
87 | am__v_lt_0 = --silent | ||
88 | libembryo_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ | ||
89 | $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libembryo_la_CFLAGS) \ | ||
90 | $(CFLAGS) $(libembryo_la_LDFLAGS) $(LDFLAGS) -o $@ | ||
91 | DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) | ||
92 | depcomp = $(SHELL) $(top_srcdir)/depcomp | ||
93 | am__depfiles_maybe = depfiles | ||
94 | am__mv = mv -f | ||
95 | COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ | ||
96 | $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) | ||
97 | LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ | ||
98 | $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ | ||
99 | $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ | ||
100 | $(AM_CFLAGS) $(CFLAGS) | ||
101 | AM_V_CC = $(am__v_CC_$(V)) | ||
102 | am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) | ||
103 | am__v_CC_0 = @echo " CC " $@; | ||
104 | AM_V_at = $(am__v_at_$(V)) | ||
105 | am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) | ||
106 | am__v_at_0 = @ | ||
107 | CCLD = $(CC) | ||
108 | LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ | ||
109 | $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ | ||
110 | $(AM_LDFLAGS) $(LDFLAGS) -o $@ | ||
111 | AM_V_CCLD = $(am__v_CCLD_$(V)) | ||
112 | am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) | ||
113 | am__v_CCLD_0 = @echo " CCLD " $@; | ||
114 | AM_V_GEN = $(am__v_GEN_$(V)) | ||
115 | am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) | ||
116 | am__v_GEN_0 = @echo " GEN " $@; | ||
117 | SOURCES = $(libembryo_la_SOURCES) | ||
118 | DIST_SOURCES = $(libembryo_la_SOURCES) | ||
119 | HEADERS = $(includes_HEADERS) | ||
120 | ETAGS = etags | ||
121 | CTAGS = ctags | ||
122 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) | ||
123 | ACLOCAL = @ACLOCAL@ | ||
124 | ALLOCA = @ALLOCA@ | ||
125 | AMTAR = @AMTAR@ | ||
126 | AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ | ||
127 | AR = @AR@ | ||
128 | AS = @AS@ | ||
129 | AUTOCONF = @AUTOCONF@ | ||
130 | AUTOHEADER = @AUTOHEADER@ | ||
131 | AUTOMAKE = @AUTOMAKE@ | ||
132 | AWK = @AWK@ | ||
133 | CC = @CC@ | ||
134 | CCDEPMODE = @CCDEPMODE@ | ||
135 | CFLAGS = @CFLAGS@ | ||
136 | CPP = @CPP@ | ||
137 | CPPFLAGS = @CPPFLAGS@ | ||
138 | CYGPATH_W = @CYGPATH_W@ | ||
139 | DEFS = @DEFS@ | ||
140 | DEPDIR = @DEPDIR@ | ||
141 | DLLTOOL = @DLLTOOL@ | ||
142 | DSYMUTIL = @DSYMUTIL@ | ||
143 | DUMPBIN = @DUMPBIN@ | ||
144 | ECHO_C = @ECHO_C@ | ||
145 | ECHO_N = @ECHO_N@ | ||
146 | ECHO_T = @ECHO_T@ | ||
147 | EFL_EMBRYO_BUILD = @EFL_EMBRYO_BUILD@ | ||
148 | EFL_FNMATCH_LIBS = @EFL_FNMATCH_LIBS@ | ||
149 | EGREP = @EGREP@ | ||
150 | EINA_CFLAGS = @EINA_CFLAGS@ | ||
151 | EINA_LIBS = @EINA_LIBS@ | ||
152 | EMBRYO_CC_PRG = @EMBRYO_CC_PRG@ | ||
153 | EMBRYO_CFLAGS = @EMBRYO_CFLAGS@ | ||
154 | EMBRYO_CPPFLAGS = @EMBRYO_CPPFLAGS@ | ||
155 | EVIL_CFLAGS = @EVIL_CFLAGS@ | ||
156 | EVIL_LIBS = @EVIL_LIBS@ | ||
157 | EXEEXT = @EXEEXT@ | ||
158 | EXOTIC_CFLAGS = @EXOTIC_CFLAGS@ | ||
159 | EXOTIC_LIBS = @EXOTIC_LIBS@ | ||
160 | FGREP = @FGREP@ | ||
161 | GREP = @GREP@ | ||
162 | INSTALL = @INSTALL@ | ||
163 | INSTALL_DATA = @INSTALL_DATA@ | ||
164 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ | ||
165 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ | ||
166 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ | ||
167 | LD = @LD@ | ||
168 | LDFLAGS = @LDFLAGS@ | ||
169 | LIBOBJS = @LIBOBJS@ | ||
170 | LIBS = @LIBS@ | ||
171 | LIBTOOL = @LIBTOOL@ | ||
172 | LIPO = @LIPO@ | ||
173 | LN_S = @LN_S@ | ||
174 | LTLIBOBJS = @LTLIBOBJS@ | ||
175 | MAKEINFO = @MAKEINFO@ | ||
176 | MKDIR_P = @MKDIR_P@ | ||
177 | NM = @NM@ | ||
178 | NMEDIT = @NMEDIT@ | ||
179 | OBJDUMP = @OBJDUMP@ | ||
180 | OBJEXT = @OBJEXT@ | ||
181 | OTOOL = @OTOOL@ | ||
182 | OTOOL64 = @OTOOL64@ | ||
183 | PACKAGE = @PACKAGE@ | ||
184 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ | ||
185 | PACKAGE_NAME = @PACKAGE_NAME@ | ||
186 | PACKAGE_STRING = @PACKAGE_STRING@ | ||
187 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ | ||
188 | PACKAGE_URL = @PACKAGE_URL@ | ||
189 | PACKAGE_VERSION = @PACKAGE_VERSION@ | ||
190 | PATH_SEPARATOR = @PATH_SEPARATOR@ | ||
191 | PKG_CONFIG = @PKG_CONFIG@ | ||
192 | PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ | ||
193 | PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ | ||
194 | RANLIB = @RANLIB@ | ||
195 | SED = @SED@ | ||
196 | SET_MAKE = @SET_MAKE@ | ||
197 | SHELL = @SHELL@ | ||
198 | STRIP = @STRIP@ | ||
199 | VERSION = @VERSION@ | ||
200 | VMAJ = @VMAJ@ | ||
201 | abs_builddir = @abs_builddir@ | ||
202 | abs_srcdir = @abs_srcdir@ | ||
203 | abs_top_builddir = @abs_top_builddir@ | ||
204 | abs_top_srcdir = @abs_top_srcdir@ | ||
205 | ac_ct_CC = @ac_ct_CC@ | ||
206 | ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ | ||
207 | am__include = @am__include@ | ||
208 | am__leading_dot = @am__leading_dot@ | ||
209 | am__quote = @am__quote@ | ||
210 | am__tar = @am__tar@ | ||
211 | am__untar = @am__untar@ | ||
212 | bindir = @bindir@ | ||
213 | build = @build@ | ||
214 | build_alias = @build_alias@ | ||
215 | build_cpu = @build_cpu@ | ||
216 | build_os = @build_os@ | ||
217 | build_vendor = @build_vendor@ | ||
218 | builddir = @builddir@ | ||
219 | datadir = @datadir@ | ||
220 | datarootdir = @datarootdir@ | ||
221 | docdir = @docdir@ | ||
222 | dvidir = @dvidir@ | ||
223 | efl_doxygen = @efl_doxygen@ | ||
224 | efl_have_doxygen = @efl_have_doxygen@ | ||
225 | embryoincludedir = @embryoincludedir@ | ||
226 | exec_prefix = @exec_prefix@ | ||
227 | host = @host@ | ||
228 | host_alias = @host_alias@ | ||
229 | host_cpu = @host_cpu@ | ||
230 | host_os = @host_os@ | ||
231 | host_vendor = @host_vendor@ | ||
232 | htmldir = @htmldir@ | ||
233 | includedir = @includedir@ | ||
234 | infodir = @infodir@ | ||
235 | install_sh = @install_sh@ | ||
236 | libdir = @libdir@ | ||
237 | libexecdir = @libexecdir@ | ||
238 | localedir = @localedir@ | ||
239 | localstatedir = @localstatedir@ | ||
240 | lt_ECHO = @lt_ECHO@ | ||
241 | lt_enable_auto_import = @lt_enable_auto_import@ | ||
242 | mandir = @mandir@ | ||
243 | mkdir_p = @mkdir_p@ | ||
244 | oldincludedir = @oldincludedir@ | ||
245 | pdfdir = @pdfdir@ | ||
246 | pkgconfig_requires_private = @pkgconfig_requires_private@ | ||
247 | prefix = @prefix@ | ||
248 | program_transform_name = @program_transform_name@ | ||
249 | psdir = @psdir@ | ||
250 | release_info = @release_info@ | ||
251 | requirement_embryo = @requirement_embryo@ | ||
252 | sbindir = @sbindir@ | ||
253 | sharedstatedir = @sharedstatedir@ | ||
254 | srcdir = @srcdir@ | ||
255 | sysconfdir = @sysconfdir@ | ||
256 | target_alias = @target_alias@ | ||
257 | top_build_prefix = @top_build_prefix@ | ||
258 | top_builddir = @top_builddir@ | ||
259 | top_srcdir = @top_srcdir@ | ||
260 | version_info = @version_info@ | ||
261 | MAINTAINERCLEANFILES = Makefile.in | ||
262 | AM_CPPFLAGS = \ | ||
263 | -I. \ | ||
264 | -I$(top_srcdir)/src/lib \ | ||
265 | -I$(top_builddir) \ | ||
266 | -I$(top_srcdir)/src/lib \ | ||
267 | -I$(top_srcdir)/src/lib/include \ | ||
268 | -DPACKAGE_BIN_DIR=\"$(bindir)\" \ | ||
269 | -DPACKAGE_LIB_DIR=\"$(libdir)\" \ | ||
270 | -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \ | ||
271 | @EVIL_CFLAGS@ \ | ||
272 | @EXOTIC_CFLAGS@ \ | ||
273 | @EMBRYO_CPPFLAGS@ \ | ||
274 | @EFL_EMBRYO_BUILD@ | ||
275 | |||
276 | includes_HEADERS = Embryo.h | ||
277 | includesdir = $(includedir)/embryo-@VMAJ@ | ||
278 | lib_LTLIBRARIES = libembryo.la | ||
279 | libembryo_la_SOURCES = \ | ||
280 | embryo_amx.c \ | ||
281 | embryo_args.c \ | ||
282 | embryo_float.c \ | ||
283 | embryo_main.c \ | ||
284 | embryo_rand.c \ | ||
285 | embryo_str.c \ | ||
286 | embryo_time.c | ||
287 | |||
288 | libembryo_la_CFLAGS = @EMBRYO_CFLAGS@ | ||
289 | libembryo_la_LIBADD = @EXOTIC_LIBS@ @EVIL_LIBS@ -lm | ||
290 | libembryo_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @release_info@ | ||
291 | EXTRA_DIST = embryo_private.h | ||
292 | all: all-am | ||
293 | |||
294 | .SUFFIXES: | ||
295 | .SUFFIXES: .c .lo .o .obj | ||
296 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) | ||
297 | @for dep in $?; do \ | ||
298 | case '$(am__configure_deps)' in \ | ||
299 | *$$dep*) \ | ||
300 | ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ | ||
301 | && { if test -f $@; then exit 0; else break; fi; }; \ | ||
302 | exit 1;; \ | ||
303 | esac; \ | ||
304 | done; \ | ||
305 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/lib/Makefile'; \ | ||
306 | $(am__cd) $(top_srcdir) && \ | ||
307 | $(AUTOMAKE) --gnu src/lib/Makefile | ||
308 | .PRECIOUS: Makefile | ||
309 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status | ||
310 | @case '$?' in \ | ||
311 | *config.status*) \ | ||
312 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ | ||
313 | *) \ | ||
314 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ | ||
315 | cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ | ||
316 | esac; | ||
317 | |||
318 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) | ||
319 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | ||
320 | |||
321 | $(top_srcdir)/configure: $(am__configure_deps) | ||
322 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | ||
323 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) | ||
324 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | ||
325 | $(am__aclocal_m4_deps): | ||
326 | install-libLTLIBRARIES: $(lib_LTLIBRARIES) | ||
327 | @$(NORMAL_INSTALL) | ||
328 | test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" | ||
329 | @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ | ||
330 | list2=; for p in $$list; do \ | ||
331 | if test -f $$p; then \ | ||
332 | list2="$$list2 $$p"; \ | ||
333 | else :; fi; \ | ||
334 | done; \ | ||
335 | test -z "$$list2" || { \ | ||
336 | echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ | ||
337 | $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ | ||
338 | } | ||
339 | |||
340 | uninstall-libLTLIBRARIES: | ||
341 | @$(NORMAL_UNINSTALL) | ||
342 | @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ | ||
343 | for p in $$list; do \ | ||
344 | $(am__strip_dir) \ | ||
345 | echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ | ||
346 | $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ | ||
347 | done | ||
348 | |||
349 | clean-libLTLIBRARIES: | ||
350 | -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) | ||
351 | @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ | ||
352 | dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ | ||
353 | test "$$dir" != "$$p" || dir=.; \ | ||
354 | echo "rm -f \"$${dir}/so_locations\""; \ | ||
355 | rm -f "$${dir}/so_locations"; \ | ||
356 | done | ||
357 | libembryo.la: $(libembryo_la_OBJECTS) $(libembryo_la_DEPENDENCIES) | ||
358 | $(AM_V_CCLD)$(libembryo_la_LINK) -rpath $(libdir) $(libembryo_la_OBJECTS) $(libembryo_la_LIBADD) $(LIBS) | ||
359 | |||
360 | mostlyclean-compile: | ||
361 | -rm -f *.$(OBJEXT) | ||
362 | |||
363 | distclean-compile: | ||
364 | -rm -f *.tab.c | ||
365 | |||
366 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libembryo_la-embryo_amx.Plo@am__quote@ | ||
367 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libembryo_la-embryo_args.Plo@am__quote@ | ||
368 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libembryo_la-embryo_float.Plo@am__quote@ | ||
369 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libembryo_la-embryo_main.Plo@am__quote@ | ||
370 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libembryo_la-embryo_rand.Plo@am__quote@ | ||
371 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libembryo_la-embryo_str.Plo@am__quote@ | ||
372 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libembryo_la-embryo_time.Plo@am__quote@ | ||
373 | |||
374 | .c.o: | ||
375 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< | ||
376 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po | ||
377 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
378 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ | ||
379 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
380 | @am__fastdepCC_FALSE@ $(COMPILE) -c $< | ||
381 | |||
382 | .c.obj: | ||
383 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` | ||
384 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po | ||
385 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
386 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ | ||
387 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
388 | @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` | ||
389 | |||
390 | .c.lo: | ||
391 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< | ||
392 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo | ||
393 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
394 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ | ||
395 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
396 | @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< | ||
397 | |||
398 | libembryo_la-embryo_amx.lo: embryo_amx.c | ||
399 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -MT libembryo_la-embryo_amx.lo -MD -MP -MF $(DEPDIR)/libembryo_la-embryo_amx.Tpo -c -o libembryo_la-embryo_amx.lo `test -f 'embryo_amx.c' || echo '$(srcdir)/'`embryo_amx.c | ||
400 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libembryo_la-embryo_amx.Tpo $(DEPDIR)/libembryo_la-embryo_amx.Plo | ||
401 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
402 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='embryo_amx.c' object='libembryo_la-embryo_amx.lo' libtool=yes @AMDEPBACKSLASH@ | ||
403 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
404 | @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -c -o libembryo_la-embryo_amx.lo `test -f 'embryo_amx.c' || echo '$(srcdir)/'`embryo_amx.c | ||
405 | |||
406 | libembryo_la-embryo_args.lo: embryo_args.c | ||
407 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -MT libembryo_la-embryo_args.lo -MD -MP -MF $(DEPDIR)/libembryo_la-embryo_args.Tpo -c -o libembryo_la-embryo_args.lo `test -f 'embryo_args.c' || echo '$(srcdir)/'`embryo_args.c | ||
408 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libembryo_la-embryo_args.Tpo $(DEPDIR)/libembryo_la-embryo_args.Plo | ||
409 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
410 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='embryo_args.c' object='libembryo_la-embryo_args.lo' libtool=yes @AMDEPBACKSLASH@ | ||
411 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
412 | @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -c -o libembryo_la-embryo_args.lo `test -f 'embryo_args.c' || echo '$(srcdir)/'`embryo_args.c | ||
413 | |||
414 | libembryo_la-embryo_float.lo: embryo_float.c | ||
415 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -MT libembryo_la-embryo_float.lo -MD -MP -MF $(DEPDIR)/libembryo_la-embryo_float.Tpo -c -o libembryo_la-embryo_float.lo `test -f 'embryo_float.c' || echo '$(srcdir)/'`embryo_float.c | ||
416 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libembryo_la-embryo_float.Tpo $(DEPDIR)/libembryo_la-embryo_float.Plo | ||
417 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
418 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='embryo_float.c' object='libembryo_la-embryo_float.lo' libtool=yes @AMDEPBACKSLASH@ | ||
419 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
420 | @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -c -o libembryo_la-embryo_float.lo `test -f 'embryo_float.c' || echo '$(srcdir)/'`embryo_float.c | ||
421 | |||
422 | libembryo_la-embryo_main.lo: embryo_main.c | ||
423 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -MT libembryo_la-embryo_main.lo -MD -MP -MF $(DEPDIR)/libembryo_la-embryo_main.Tpo -c -o libembryo_la-embryo_main.lo `test -f 'embryo_main.c' || echo '$(srcdir)/'`embryo_main.c | ||
424 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libembryo_la-embryo_main.Tpo $(DEPDIR)/libembryo_la-embryo_main.Plo | ||
425 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
426 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='embryo_main.c' object='libembryo_la-embryo_main.lo' libtool=yes @AMDEPBACKSLASH@ | ||
427 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
428 | @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -c -o libembryo_la-embryo_main.lo `test -f 'embryo_main.c' || echo '$(srcdir)/'`embryo_main.c | ||
429 | |||
430 | libembryo_la-embryo_rand.lo: embryo_rand.c | ||
431 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -MT libembryo_la-embryo_rand.lo -MD -MP -MF $(DEPDIR)/libembryo_la-embryo_rand.Tpo -c -o libembryo_la-embryo_rand.lo `test -f 'embryo_rand.c' || echo '$(srcdir)/'`embryo_rand.c | ||
432 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libembryo_la-embryo_rand.Tpo $(DEPDIR)/libembryo_la-embryo_rand.Plo | ||
433 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
434 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='embryo_rand.c' object='libembryo_la-embryo_rand.lo' libtool=yes @AMDEPBACKSLASH@ | ||
435 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
436 | @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -c -o libembryo_la-embryo_rand.lo `test -f 'embryo_rand.c' || echo '$(srcdir)/'`embryo_rand.c | ||
437 | |||
438 | libembryo_la-embryo_str.lo: embryo_str.c | ||
439 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -MT libembryo_la-embryo_str.lo -MD -MP -MF $(DEPDIR)/libembryo_la-embryo_str.Tpo -c -o libembryo_la-embryo_str.lo `test -f 'embryo_str.c' || echo '$(srcdir)/'`embryo_str.c | ||
440 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libembryo_la-embryo_str.Tpo $(DEPDIR)/libembryo_la-embryo_str.Plo | ||
441 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
442 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='embryo_str.c' object='libembryo_la-embryo_str.lo' libtool=yes @AMDEPBACKSLASH@ | ||
443 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
444 | @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -c -o libembryo_la-embryo_str.lo `test -f 'embryo_str.c' || echo '$(srcdir)/'`embryo_str.c | ||
445 | |||
446 | libembryo_la-embryo_time.lo: embryo_time.c | ||
447 | @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -MT libembryo_la-embryo_time.lo -MD -MP -MF $(DEPDIR)/libembryo_la-embryo_time.Tpo -c -o libembryo_la-embryo_time.lo `test -f 'embryo_time.c' || echo '$(srcdir)/'`embryo_time.c | ||
448 | @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libembryo_la-embryo_time.Tpo $(DEPDIR)/libembryo_la-embryo_time.Plo | ||
449 | @am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ | ||
450 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='embryo_time.c' object='libembryo_la-embryo_time.lo' libtool=yes @AMDEPBACKSLASH@ | ||
451 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
452 | @am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libembryo_la_CFLAGS) $(CFLAGS) -c -o libembryo_la-embryo_time.lo `test -f 'embryo_time.c' || echo '$(srcdir)/'`embryo_time.c | ||
453 | |||
454 | mostlyclean-libtool: | ||
455 | -rm -f *.lo | ||
456 | |||
457 | clean-libtool: | ||
458 | -rm -rf .libs _libs | ||
459 | install-includesHEADERS: $(includes_HEADERS) | ||
460 | @$(NORMAL_INSTALL) | ||
461 | test -z "$(includesdir)" || $(MKDIR_P) "$(DESTDIR)$(includesdir)" | ||
462 | @list='$(includes_HEADERS)'; test -n "$(includesdir)" || list=; \ | ||
463 | for p in $$list; do \ | ||
464 | if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ | ||
465 | echo "$$d$$p"; \ | ||
466 | done | $(am__base_list) | \ | ||
467 | while read files; do \ | ||
468 | echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includesdir)'"; \ | ||
469 | $(INSTALL_HEADER) $$files "$(DESTDIR)$(includesdir)" || exit $$?; \ | ||
470 | done | ||
471 | |||
472 | uninstall-includesHEADERS: | ||
473 | @$(NORMAL_UNINSTALL) | ||
474 | @list='$(includes_HEADERS)'; test -n "$(includesdir)" || list=; \ | ||
475 | files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ | ||
476 | test -n "$$files" || exit 0; \ | ||
477 | echo " ( cd '$(DESTDIR)$(includesdir)' && rm -f" $$files ")"; \ | ||
478 | cd "$(DESTDIR)$(includesdir)" && rm -f $$files | ||
479 | |||
480 | ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) | ||
481 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ | ||
482 | unique=`for i in $$list; do \ | ||
483 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ | ||
484 | done | \ | ||
485 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ | ||
486 | END { if (nonempty) { for (i in files) print i; }; }'`; \ | ||
487 | mkid -fID $$unique | ||
488 | tags: TAGS | ||
489 | |||
490 | TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ | ||
491 | $(TAGS_FILES) $(LISP) | ||
492 | set x; \ | ||
493 | here=`pwd`; \ | ||
494 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ | ||
495 | unique=`for i in $$list; do \ | ||
496 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ | ||
497 | done | \ | ||
498 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ | ||
499 | END { if (nonempty) { for (i in files) print i; }; }'`; \ | ||
500 | shift; \ | ||
501 | if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ | ||
502 | test -n "$$unique" || unique=$$empty_fix; \ | ||
503 | if test $$# -gt 0; then \ | ||
504 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ | ||
505 | "$$@" $$unique; \ | ||
506 | else \ | ||
507 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ | ||
508 | $$unique; \ | ||
509 | fi; \ | ||
510 | fi | ||
511 | ctags: CTAGS | ||
512 | CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ | ||
513 | $(TAGS_FILES) $(LISP) | ||
514 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ | ||
515 | unique=`for i in $$list; do \ | ||
516 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ | ||
517 | done | \ | ||
518 | $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ | ||
519 | END { if (nonempty) { for (i in files) print i; }; }'`; \ | ||
520 | test -z "$(CTAGS_ARGS)$$unique" \ | ||
521 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ | ||
522 | $$unique | ||
523 | |||
524 | GTAGS: | ||
525 | here=`$(am__cd) $(top_builddir) && pwd` \ | ||
526 | && $(am__cd) $(top_srcdir) \ | ||
527 | && gtags -i $(GTAGS_ARGS) "$$here" | ||
528 | |||
529 | distclean-tags: | ||
530 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags | ||
531 | |||
532 | distdir: $(DISTFILES) | ||
533 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ | ||
534 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ | ||
535 | list='$(DISTFILES)'; \ | ||
536 | dist_files=`for file in $$list; do echo $$file; done | \ | ||
537 | sed -e "s|^$$srcdirstrip/||;t" \ | ||
538 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ | ||
539 | case $$dist_files in \ | ||
540 | */*) $(MKDIR_P) `echo "$$dist_files" | \ | ||
541 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ | ||
542 | sort -u` ;; \ | ||
543 | esac; \ | ||
544 | for file in $$dist_files; do \ | ||
545 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ | ||
546 | if test -d $$d/$$file; then \ | ||
547 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ | ||
548 | if test -d "$(distdir)/$$file"; then \ | ||
549 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ | ||
550 | fi; \ | ||
551 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ | ||
552 | cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ | ||
553 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ | ||
554 | fi; \ | ||
555 | cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ | ||
556 | else \ | ||
557 | test -f "$(distdir)/$$file" \ | ||
558 | || cp -p $$d/$$file "$(distdir)/$$file" \ | ||
559 | || exit 1; \ | ||
560 | fi; \ | ||
561 | done | ||
562 | check-am: all-am | ||
563 | check: check-am | ||
564 | all-am: Makefile $(LTLIBRARIES) $(HEADERS) | ||
565 | installdirs: | ||
566 | for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includesdir)"; do \ | ||
567 | test -z "$$dir" || $(MKDIR_P) "$$dir"; \ | ||
568 | done | ||
569 | install: install-am | ||
570 | install-exec: install-exec-am | ||
571 | install-data: install-data-am | ||
572 | uninstall: uninstall-am | ||
573 | |||
574 | install-am: all-am | ||
575 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am | ||
576 | |||
577 | installcheck: installcheck-am | ||
578 | install-strip: | ||
579 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ | ||
580 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ | ||
581 | `test -z '$(STRIP)' || \ | ||
582 | echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install | ||
583 | mostlyclean-generic: | ||
584 | |||
585 | clean-generic: | ||
586 | |||
587 | distclean-generic: | ||
588 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) | ||
589 | -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) | ||
590 | |||
591 | maintainer-clean-generic: | ||
592 | @echo "This command is intended for maintainers to use" | ||
593 | @echo "it deletes files that may require special tools to rebuild." | ||
594 | -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) | ||
595 | clean: clean-am | ||
596 | |||
597 | clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ | ||
598 | mostlyclean-am | ||
599 | |||
600 | distclean: distclean-am | ||
601 | -rm -rf ./$(DEPDIR) | ||
602 | -rm -f Makefile | ||
603 | distclean-am: clean-am distclean-compile distclean-generic \ | ||
604 | distclean-tags | ||
605 | |||
606 | dvi: dvi-am | ||
607 | |||
608 | dvi-am: | ||
609 | |||
610 | html: html-am | ||
611 | |||
612 | html-am: | ||
613 | |||
614 | info: info-am | ||
615 | |||
616 | info-am: | ||
617 | |||
618 | install-data-am: install-includesHEADERS | ||
619 | |||
620 | install-dvi: install-dvi-am | ||
621 | |||
622 | install-dvi-am: | ||
623 | |||
624 | install-exec-am: install-libLTLIBRARIES | ||
625 | |||
626 | install-html: install-html-am | ||
627 | |||
628 | install-html-am: | ||
629 | |||
630 | install-info: install-info-am | ||
631 | |||
632 | install-info-am: | ||
633 | |||
634 | install-man: | ||
635 | |||
636 | install-pdf: install-pdf-am | ||
637 | |||
638 | install-pdf-am: | ||
639 | |||
640 | install-ps: install-ps-am | ||
641 | |||
642 | install-ps-am: | ||
643 | |||
644 | installcheck-am: | ||
645 | |||
646 | maintainer-clean: maintainer-clean-am | ||
647 | -rm -rf ./$(DEPDIR) | ||
648 | -rm -f Makefile | ||
649 | maintainer-clean-am: distclean-am maintainer-clean-generic | ||
650 | |||
651 | mostlyclean: mostlyclean-am | ||
652 | |||
653 | mostlyclean-am: mostlyclean-compile mostlyclean-generic \ | ||
654 | mostlyclean-libtool | ||
655 | |||
656 | pdf: pdf-am | ||
657 | |||
658 | pdf-am: | ||
659 | |||
660 | ps: ps-am | ||
661 | |||
662 | ps-am: | ||
663 | |||
664 | uninstall-am: uninstall-includesHEADERS uninstall-libLTLIBRARIES | ||
665 | |||
666 | .MAKE: install-am install-strip | ||
667 | |||
668 | .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ | ||
669 | clean-libLTLIBRARIES clean-libtool ctags distclean \ | ||
670 | distclean-compile distclean-generic distclean-libtool \ | ||
671 | distclean-tags distdir dvi dvi-am html html-am info info-am \ | ||
672 | install install-am install-data install-data-am install-dvi \ | ||
673 | install-dvi-am install-exec install-exec-am install-html \ | ||
674 | install-html-am install-includesHEADERS install-info \ | ||
675 | install-info-am install-libLTLIBRARIES install-man install-pdf \ | ||
676 | install-pdf-am install-ps install-ps-am install-strip \ | ||
677 | installcheck installcheck-am installdirs maintainer-clean \ | ||
678 | maintainer-clean-generic mostlyclean mostlyclean-compile \ | ||
679 | mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ | ||
680 | tags uninstall uninstall-am uninstall-includesHEADERS \ | ||
681 | uninstall-libLTLIBRARIES | ||
682 | |||
683 | |||
684 | # Tell versions [3.59,3.63) of GNU make to not export all variables. | ||
685 | # Otherwise a system limit (for SysV at least) may be exceeded. | ||
686 | .NOEXPORT: | ||
diff --git a/libraries/embryo/src/lib/embryo_amx.c b/libraries/embryo/src/lib/embryo_amx.c deleted file mode 100644 index 7a41111..0000000 --- a/libraries/embryo/src/lib/embryo_amx.c +++ /dev/null | |||
@@ -1,1995 +0,0 @@ | |||
1 | /* Abstract Machine for the Small compiler | ||
2 | * | ||
3 | * Copyright (c) ITB CompuPhase, 1997-2003 | ||
4 | * Portions Copyright (c) Carsten Haitzler, 2004-2010 <raster@rasterman.com> | ||
5 | * | ||
6 | * This software is provided "as-is", without any express or implied warranty. | ||
7 | * In no event will the authors be held liable for any damages arising from | ||
8 | * the use of this software. | ||
9 | * | ||
10 | * Permission is granted to anyone to use this software for any purpose, | ||
11 | * including commercial applications, and to alter it and redistribute it | ||
12 | * freely, subject to the following restrictions: | ||
13 | * | ||
14 | * 1. The origin of this software must not be misrepresented; you must not | ||
15 | * claim that you wrote the original software. If you use this software in | ||
16 | * a product, an acknowledgment in the product documentation would be | ||
17 | * appreciated but is not required. | ||
18 | * 2. Altered source versions must be plainly marked as such, and must not be | ||
19 | * misrepresented as being the original software. | ||
20 | * 3. This notice may not be removed or altered from any source distribution. | ||
21 | */ | ||
22 | |||
23 | |||
24 | #ifdef HAVE_CONFIG_H | ||
25 | # include "config.h" | ||
26 | #endif | ||
27 | |||
28 | #include <stdlib.h> | ||
29 | #include <stdio.h> | ||
30 | #include <string.h> | ||
31 | |||
32 | #ifdef HAVE_EXOTIC | ||
33 | # include <Exotic.h> | ||
34 | #endif | ||
35 | |||
36 | #include "Embryo.h" | ||
37 | #include "embryo_private.h" | ||
38 | |||
39 | |||
40 | #define JUMPABS(base, ip) ((Embryo_Cell *)(code + (*ip))) | ||
41 | |||
42 | #ifdef WORDS_BIGENDIAN | ||
43 | static void _embryo_byte_swap_16 (unsigned short *v); | ||
44 | static void _embryo_byte_swap_32 (unsigned int *v); | ||
45 | #endif | ||
46 | static int _embryo_native_call (Embryo_Program *ep, Embryo_Cell index, Embryo_Cell *result, Embryo_Cell *params); | ||
47 | static int _embryo_func_get (Embryo_Program *ep, int index, char *funcname); | ||
48 | static int _embryo_var_get (Embryo_Program *ep, int index, char *varname, Embryo_Cell *ep_addr); | ||
49 | static int _embryo_program_init (Embryo_Program *ep, void *code); | ||
50 | |||
51 | #ifdef WORDS_BIGENDIAN | ||
52 | static void | ||
53 | _embryo_byte_swap_16(unsigned short *v) | ||
54 | { | ||
55 | unsigned char *s, t; | ||
56 | |||
57 | s = (unsigned char *)v; | ||
58 | t = s[0]; s[0] = s[1]; s[1] = t; | ||
59 | } | ||
60 | |||
61 | static void | ||
62 | _embryo_byte_swap_32(unsigned int *v) | ||
63 | { | ||
64 | unsigned char *s, t; | ||
65 | |||
66 | s = (unsigned char *)v; | ||
67 | t = s[0]; s[0] = s[3]; s[3] = t; | ||
68 | t = s[1]; s[1] = s[2]; s[2] = t; | ||
69 | } | ||
70 | #endif | ||
71 | |||
72 | static int | ||
73 | _embryo_native_call(Embryo_Program *ep, Embryo_Cell index, Embryo_Cell *result, Embryo_Cell *params) | ||
74 | { | ||
75 | Embryo_Header *hdr; | ||
76 | Embryo_Func_Stub *func_entry; | ||
77 | Embryo_Native f; | ||
78 | |||
79 | hdr = (Embryo_Header *)ep->base; | ||
80 | func_entry = GETENTRY(hdr, natives, index); | ||
81 | if ((func_entry->address <= 0) || | ||
82 | (func_entry->address > ep->native_calls_size)) | ||
83 | { | ||
84 | ep->error = EMBRYO_ERROR_CALLBACK; | ||
85 | return ep->error; | ||
86 | } | ||
87 | f = ep->native_calls[func_entry->address - 1]; | ||
88 | if (!f) | ||
89 | { | ||
90 | ep->error = EMBRYO_ERROR_CALLBACK; | ||
91 | return ep->error; | ||
92 | } | ||
93 | ep->error = EMBRYO_ERROR_NONE; | ||
94 | *result = f(ep, params); | ||
95 | return ep->error; | ||
96 | } | ||
97 | |||
98 | static int | ||
99 | _embryo_func_get(Embryo_Program *ep, int index, char *funcname) | ||
100 | { | ||
101 | Embryo_Header *hdr; | ||
102 | Embryo_Func_Stub *func; | ||
103 | |||
104 | hdr = (Embryo_Header *)ep->code; | ||
105 | if (index >= (Embryo_Cell)NUMENTRIES(hdr, publics, natives)) | ||
106 | return EMBRYO_ERROR_INDEX; | ||
107 | |||
108 | func = GETENTRY(hdr, publics, index); | ||
109 | strcpy(funcname, GETENTRYNAME(hdr, func)); | ||
110 | return EMBRYO_ERROR_NONE; | ||
111 | } | ||
112 | |||
113 | static int | ||
114 | _embryo_var_get(Embryo_Program *ep, int index, char *varname, Embryo_Cell *ep_addr) | ||
115 | { | ||
116 | |||
117 | Embryo_Header *hdr; | ||
118 | Embryo_Func_Stub *var; | ||
119 | |||
120 | hdr=(Embryo_Header *)ep->base; | ||
121 | if (index >= (Embryo_Cell)NUMENTRIES(hdr, pubvars, tags)) | ||
122 | return EMBRYO_ERROR_INDEX; | ||
123 | |||
124 | var = GETENTRY(hdr, pubvars, index); | ||
125 | strcpy(varname, GETENTRYNAME(hdr, var)); | ||
126 | *ep_addr = var->address; | ||
127 | return EMBRYO_ERROR_NONE; | ||
128 | } | ||
129 | |||
130 | static int | ||
131 | _embryo_program_init(Embryo_Program *ep, void *code) | ||
132 | { | ||
133 | Embryo_Header *hdr; | ||
134 | |||
135 | if ((ep->flags & EMBRYO_FLAG_RELOC)) return 1; | ||
136 | ep->code = (unsigned char *)code; | ||
137 | hdr = (Embryo_Header *)ep->code; | ||
138 | #ifdef WORDS_BIGENDIAN | ||
139 | embryo_swap_32((unsigned int *)&hdr->size); | ||
140 | embryo_swap_16((unsigned short *)&hdr->magic); | ||
141 | embryo_swap_16((unsigned short *)&hdr->flags); | ||
142 | embryo_swap_16((unsigned short *)&hdr->defsize); | ||
143 | embryo_swap_32((unsigned int *)&hdr->cod); | ||
144 | embryo_swap_32((unsigned int *)&hdr->dat); | ||
145 | embryo_swap_32((unsigned int *)&hdr->hea); | ||
146 | embryo_swap_32((unsigned int *)&hdr->stp); | ||
147 | embryo_swap_32((unsigned int *)&hdr->cip); | ||
148 | embryo_swap_32((unsigned int *)&hdr->publics); | ||
149 | embryo_swap_32((unsigned int *)&hdr->natives); | ||
150 | embryo_swap_32((unsigned int *)&hdr->libraries); | ||
151 | embryo_swap_32((unsigned int *)&hdr->pubvars); | ||
152 | embryo_swap_32((unsigned int *)&hdr->tags); | ||
153 | embryo_swap_32((unsigned int *)&hdr->nametable); | ||
154 | #endif | ||
155 | |||
156 | if (hdr->magic != EMBRYO_MAGIC) return 0; | ||
157 | if ((hdr->file_version < MIN_FILE_VERSION) || | ||
158 | (hdr->ep_version > CUR_FILE_VERSION)) return 0; | ||
159 | if ((hdr->defsize != sizeof(Embryo_Func_Stub)) && | ||
160 | (hdr->defsize != (2 * sizeof(unsigned int)))) return 0; | ||
161 | if (hdr->defsize == (2 * sizeof(unsigned int))) | ||
162 | { | ||
163 | unsigned short *len; | ||
164 | |||
165 | len = (unsigned short*)((unsigned char*)ep->code + hdr->nametable); | ||
166 | #ifdef WORDS_BIGENDIAN | ||
167 | embryo_swap_16((unsigned short *)len); | ||
168 | #endif | ||
169 | if (*len > sNAMEMAX) return 0; | ||
170 | } | ||
171 | if (hdr->stp <= 0) return 0; | ||
172 | if ((hdr->flags & EMBRYO_FLAG_COMPACT)) return 0; | ||
173 | |||
174 | #ifdef WORDS_BIGENDIAN | ||
175 | { | ||
176 | Embryo_Func_Stub *fs; | ||
177 | int i, num; | ||
178 | |||
179 | /* also align all addresses in the public function, public variable and */ | ||
180 | /* public tag tables */ | ||
181 | fs = GETENTRY(hdr, publics, 0); | ||
182 | num = NUMENTRIES(hdr, publics, natives); | ||
183 | for (i = 0; i < num; i++) | ||
184 | { | ||
185 | embryo_swap_32(&(fs->address)); | ||
186 | fs = (Embryo_Func_Stub *)((unsigned char *)fs + hdr->defsize); | ||
187 | } | ||
188 | |||
189 | fs = GETENTRY(hdr, pubvars, 0); | ||
190 | num = NUMENTRIES(hdr, pubvars, tags); | ||
191 | for (i = 0; i < num; i++) | ||
192 | { | ||
193 | embryo_swap_32(&(fs->address)); | ||
194 | fs = (Embryo_Func_Stub *)((unsigned char *)fs + hdr->defsize); | ||
195 | } | ||
196 | |||
197 | fs = GETENTRY(hdr, tags, 0); | ||
198 | num = NUMENTRIES(hdr, tags, nametable); | ||
199 | for (i = 0; i < num; i++) | ||
200 | { | ||
201 | embryo_swap_32(&(fs->address)); | ||
202 | fs = (Embryo_Func_Stub *)((unsigned char *)fs + hdr->defsize); | ||
203 | } | ||
204 | } | ||
205 | #endif | ||
206 | ep->flags = EMBRYO_FLAG_RELOC; | ||
207 | |||
208 | { | ||
209 | Embryo_Cell cip, code_size, cip_end; | ||
210 | Embryo_Cell *code; | ||
211 | |||
212 | code_size = hdr->dat - hdr->cod; | ||
213 | code = (Embryo_Cell *)((unsigned char *)ep->code + (int)hdr->cod); | ||
214 | cip_end = code_size / sizeof(Embryo_Cell); | ||
215 | for (cip = 0; cip < cip_end; cip++) | ||
216 | { | ||
217 | /* move this here - later we probably want something that verifies opcodes | ||
218 | * are valid and ok... | ||
219 | */ | ||
220 | #ifdef WORDS_BIGENDIAN | ||
221 | embryo_swap_32(&(code[cip])); | ||
222 | #endif | ||
223 | |||
224 | } | ||
225 | } | ||
226 | /* init native api for handling floating point - default in embryo */ | ||
227 | _embryo_args_init(ep); | ||
228 | _embryo_fp_init(ep); | ||
229 | _embryo_rand_init(ep); | ||
230 | _embryo_str_init(ep); | ||
231 | _embryo_time_init(ep); | ||
232 | return 1; | ||
233 | } | ||
234 | |||
235 | /*** EXPORTED CALLS ***/ | ||
236 | |||
237 | EAPI Embryo_Program * | ||
238 | embryo_program_new(void *data, int size) | ||
239 | { | ||
240 | Embryo_Program *ep; | ||
241 | void *code_data; | ||
242 | |||
243 | if (size < (int)sizeof(Embryo_Header)) return NULL; | ||
244 | |||
245 | ep = calloc(1, sizeof(Embryo_Program)); | ||
246 | if (!ep) return NULL; | ||
247 | |||
248 | code_data = malloc(size); | ||
249 | if (!code_data) | ||
250 | { | ||
251 | free(ep); | ||
252 | return NULL; | ||
253 | } | ||
254 | memcpy(code_data, data, size); | ||
255 | if (_embryo_program_init(ep, code_data)) return ep; | ||
256 | free(code_data); | ||
257 | free(ep); | ||
258 | return NULL; | ||
259 | } | ||
260 | |||
261 | EAPI Embryo_Program * | ||
262 | embryo_program_const_new(void *data, int size) | ||
263 | { | ||
264 | Embryo_Program *ep; | ||
265 | |||
266 | if (size < (int)sizeof(Embryo_Header)) return NULL; | ||
267 | |||
268 | ep = calloc(1, sizeof(Embryo_Program)); | ||
269 | if (!ep) return NULL; | ||
270 | |||
271 | if (_embryo_program_init(ep, data)) | ||
272 | { | ||
273 | ep->dont_free_code = 1; | ||
274 | return ep; | ||
275 | } | ||
276 | free(ep); | ||
277 | return NULL; | ||
278 | } | ||
279 | |||
280 | EAPI Embryo_Program * | ||
281 | embryo_program_load(const char *file) | ||
282 | { | ||
283 | Embryo_Program *ep; | ||
284 | Embryo_Header hdr; | ||
285 | FILE *f; | ||
286 | void *program = NULL; | ||
287 | int program_size = 0; | ||
288 | |||
289 | f = fopen(file, "rb"); | ||
290 | if (!f) return NULL; | ||
291 | fseek(f, 0, SEEK_END); | ||
292 | program_size = ftell(f); | ||
293 | fseek(f, 0L, SEEK_SET); | ||
294 | if (program_size < (int)sizeof(Embryo_Header)) | ||
295 | { | ||
296 | fclose(f); | ||
297 | return NULL; | ||
298 | } | ||
299 | if (fread(&hdr, sizeof(Embryo_Header), 1, f) != 1) | ||
300 | { | ||
301 | fclose(f); | ||
302 | return NULL; | ||
303 | } | ||
304 | fseek(f, 0L, SEEK_SET); | ||
305 | #ifdef WORDS_BIGENDIAN | ||
306 | embryo_swap_32((unsigned int *)(&hdr.size)); | ||
307 | #endif | ||
308 | if ((int)hdr.size < program_size) program_size = hdr.size; | ||
309 | program = malloc(program_size); | ||
310 | if (!program) | ||
311 | { | ||
312 | fclose(f); | ||
313 | return NULL; | ||
314 | } | ||
315 | if (fread(program, program_size, 1, f) != 1) | ||
316 | { | ||
317 | free(program); | ||
318 | fclose(f); | ||
319 | return NULL; | ||
320 | } | ||
321 | ep = embryo_program_new(program, program_size); | ||
322 | free(program); | ||
323 | fclose(f); | ||
324 | return ep; | ||
325 | } | ||
326 | |||
327 | EAPI void | ||
328 | embryo_program_free(Embryo_Program *ep) | ||
329 | { | ||
330 | int i; | ||
331 | |||
332 | if (ep->base) free(ep->base); | ||
333 | if ((!ep->dont_free_code) && (ep->code)) free(ep->code); | ||
334 | if (ep->native_calls) free(ep->native_calls); | ||
335 | for (i = 0; i < ep->params_size; i++) | ||
336 | { | ||
337 | if (ep->params[i].string) free(ep->params[i].string); | ||
338 | if (ep->params[i].cell_array) free(ep->params[i].cell_array); | ||
339 | } | ||
340 | if (ep->params) free(ep->params); | ||
341 | free(ep); | ||
342 | } | ||
343 | |||
344 | |||
345 | EAPI void | ||
346 | embryo_program_native_call_add(Embryo_Program *ep, const char *name, Embryo_Cell (*func) (Embryo_Program *ep, Embryo_Cell *params)) | ||
347 | { | ||
348 | Embryo_Func_Stub *func_entry; | ||
349 | Embryo_Header *hdr; | ||
350 | int i, num; | ||
351 | |||
352 | if ((!ep ) || (!name) || (!func)) return; | ||
353 | if (strlen(name) > sNAMEMAX) return; | ||
354 | |||
355 | hdr = (Embryo_Header *)ep->code; | ||
356 | if (hdr->defsize < 1) return; | ||
357 | num = NUMENTRIES(hdr, natives, libraries); | ||
358 | if (num <= 0) return; | ||
359 | |||
360 | ep->native_calls_size++; | ||
361 | if (ep->native_calls_size > ep->native_calls_alloc) | ||
362 | { | ||
363 | Embryo_Native *calls; | ||
364 | |||
365 | ep->native_calls_alloc += 32; | ||
366 | calls = realloc(ep->native_calls, | ||
367 | ep->native_calls_alloc * sizeof(Embryo_Native)); | ||
368 | if (!calls) | ||
369 | { | ||
370 | ep->native_calls_size--; | ||
371 | ep->native_calls_alloc -= 32; | ||
372 | return; | ||
373 | } | ||
374 | ep->native_calls = calls; | ||
375 | } | ||
376 | ep->native_calls[ep->native_calls_size - 1] = func; | ||
377 | |||
378 | func_entry = GETENTRY(hdr, natives, 0); | ||
379 | for (i = 0; i < num; i++) | ||
380 | { | ||
381 | if (func_entry->address == 0) | ||
382 | { | ||
383 | char *entry_name; | ||
384 | |||
385 | entry_name = GETENTRYNAME(hdr, func_entry); | ||
386 | if ((entry_name) && (!strcmp(entry_name, name))) | ||
387 | { | ||
388 | func_entry->address = ep->native_calls_size; | ||
389 | /* FIXME: embryo_cc is putting in multiple native */ | ||
390 | /* function call entries - so we need to fill in all */ | ||
391 | /* of them!!! */ | ||
392 | /* return; */ | ||
393 | } | ||
394 | } | ||
395 | func_entry = | ||
396 | (Embryo_Func_Stub *)((unsigned char *)func_entry + hdr->defsize); | ||
397 | } | ||
398 | } | ||
399 | |||
400 | |||
401 | EAPI void | ||
402 | embryo_program_vm_reset(Embryo_Program *ep) | ||
403 | { | ||
404 | Embryo_Header *hdr; | ||
405 | |||
406 | if ((!ep) || (!ep->base)) return; | ||
407 | hdr = (Embryo_Header *)ep->code; | ||
408 | memcpy(ep->base, hdr, hdr->size); | ||
409 | *(Embryo_Cell *)(ep->base + (int)hdr->stp - sizeof(Embryo_Cell)) = 0; | ||
410 | |||
411 | ep->hlw = hdr->hea - hdr->dat; /* stack and heap relative to data segment */ | ||
412 | ep->stp = hdr->stp - hdr->dat - sizeof(Embryo_Cell); | ||
413 | ep->hea = ep->hlw; | ||
414 | ep->stk = ep->stp; | ||
415 | } | ||
416 | |||
417 | EAPI void | ||
418 | embryo_program_vm_push(Embryo_Program *ep) | ||
419 | { | ||
420 | Embryo_Header *hdr; | ||
421 | |||
422 | if (!ep) return; | ||
423 | ep->pushes++; | ||
424 | if (ep->pushes > 1) | ||
425 | { | ||
426 | embryo_program_vm_reset(ep); | ||
427 | return; | ||
428 | } | ||
429 | hdr = (Embryo_Header *)ep->code; | ||
430 | ep->base = malloc(hdr->stp); | ||
431 | if (!ep->base) | ||
432 | { | ||
433 | ep->pushes = 0; | ||
434 | return; | ||
435 | } | ||
436 | embryo_program_vm_reset(ep); | ||
437 | } | ||
438 | |||
439 | EAPI void | ||
440 | embryo_program_vm_pop(Embryo_Program *ep) | ||
441 | { | ||
442 | if ((!ep) || (!ep->base)) return; | ||
443 | ep->pushes--; | ||
444 | if (ep->pushes >= 1) return; | ||
445 | free(ep->base); | ||
446 | ep->base = NULL; | ||
447 | } | ||
448 | |||
449 | |||
450 | EAPI void | ||
451 | embryo_swap_16(unsigned short *v | ||
452 | #ifndef WORDS_BIGENDIAN | ||
453 | __UNUSED__ | ||
454 | #endif | ||
455 | ) | ||
456 | { | ||
457 | #ifdef WORDS_BIGENDIAN | ||
458 | _embryo_byte_swap_16(v); | ||
459 | #endif | ||
460 | } | ||
461 | |||
462 | EAPI void | ||
463 | embryo_swap_32(unsigned int *v | ||
464 | #ifndef WORDS_BIGENDIAN | ||
465 | __UNUSED__ | ||
466 | #endif | ||
467 | ) | ||
468 | { | ||
469 | #ifdef WORDS_BIGENDIAN | ||
470 | _embryo_byte_swap_32(v); | ||
471 | #endif | ||
472 | } | ||
473 | |||
474 | EAPI Embryo_Function | ||
475 | embryo_program_function_find(Embryo_Program *ep, const char *name) | ||
476 | { | ||
477 | int first, last, mid, result; | ||
478 | char pname[sNAMEMAX + 1]; | ||
479 | Embryo_Header *hdr; | ||
480 | |||
481 | if (!ep) return EMBRYO_FUNCTION_NONE; | ||
482 | hdr = (Embryo_Header *)ep->code; | ||
483 | last = NUMENTRIES(hdr, publics, natives) - 1; | ||
484 | first = 0; | ||
485 | /* binary search */ | ||
486 | while (first <= last) | ||
487 | { | ||
488 | mid = (first + last) / 2; | ||
489 | if (_embryo_func_get(ep, mid, pname) == EMBRYO_ERROR_NONE) | ||
490 | result = strcmp(pname, name); | ||
491 | else | ||
492 | return EMBRYO_FUNCTION_NONE; | ||
493 | /* result = -1;*/ | ||
494 | if (result > 0) last = mid - 1; | ||
495 | else if (result < 0) first = mid + 1; | ||
496 | else return mid; | ||
497 | } | ||
498 | return EMBRYO_FUNCTION_NONE; | ||
499 | } | ||
500 | |||
501 | |||
502 | EAPI Embryo_Cell | ||
503 | embryo_program_variable_find(Embryo_Program *ep, const char *name) | ||
504 | { | ||
505 | int first, last, mid, result; | ||
506 | char pname[sNAMEMAX + 1]; | ||
507 | Embryo_Cell paddr; | ||
508 | Embryo_Header *hdr; | ||
509 | |||
510 | if (!ep) return EMBRYO_CELL_NONE; | ||
511 | if (!ep->base) return EMBRYO_CELL_NONE; | ||
512 | hdr = (Embryo_Header *)ep->base; | ||
513 | last = NUMENTRIES(hdr, pubvars, tags) - 1; | ||
514 | first = 0; | ||
515 | /* binary search */ | ||
516 | while (first <= last) | ||
517 | { | ||
518 | mid = (first + last) / 2; | ||
519 | if (_embryo_var_get(ep, mid, pname, &paddr) == EMBRYO_ERROR_NONE) | ||
520 | result = strcmp(pname, name); | ||
521 | else | ||
522 | return EMBRYO_CELL_NONE; | ||
523 | /* result = -1;*/ | ||
524 | if (result > 0) last = mid - 1; | ||
525 | else if (result < 0) first = mid + 1; | ||
526 | else return paddr; | ||
527 | } | ||
528 | return EMBRYO_CELL_NONE; | ||
529 | } | ||
530 | |||
531 | EAPI int | ||
532 | embryo_program_variable_count_get(Embryo_Program *ep) | ||
533 | { | ||
534 | Embryo_Header *hdr; | ||
535 | |||
536 | if (!ep) return 0; | ||
537 | if (!ep->base) return 0; | ||
538 | hdr = (Embryo_Header *)ep->base; | ||
539 | return NUMENTRIES(hdr, pubvars, tags); | ||
540 | } | ||
541 | |||
542 | EAPI Embryo_Cell | ||
543 | embryo_program_variable_get(Embryo_Program *ep, int num) | ||
544 | { | ||
545 | Embryo_Cell paddr; | ||
546 | char pname[sNAMEMAX + 1]; | ||
547 | |||
548 | if (!ep) return EMBRYO_CELL_NONE; | ||
549 | if (!ep->base) return EMBRYO_CELL_NONE; | ||
550 | if (_embryo_var_get(ep, num, pname, &paddr) == EMBRYO_ERROR_NONE) | ||
551 | return paddr; | ||
552 | return EMBRYO_CELL_NONE; | ||
553 | } | ||
554 | |||
555 | |||
556 | EAPI void | ||
557 | embryo_program_error_set(Embryo_Program *ep, Embryo_Error error) | ||
558 | { | ||
559 | if (!ep) return; | ||
560 | ep->error = error; | ||
561 | } | ||
562 | |||
563 | EAPI Embryo_Error | ||
564 | embryo_program_error_get(Embryo_Program *ep) | ||
565 | { | ||
566 | if (!ep) return EMBRYO_ERROR_NONE; | ||
567 | return ep->error; | ||
568 | } | ||
569 | |||
570 | |||
571 | EAPI void | ||
572 | embryo_program_data_set(Embryo_Program *ep, void *data) | ||
573 | { | ||
574 | if (!ep) return; | ||
575 | ep->data = data; | ||
576 | } | ||
577 | |||
578 | EAPI void * | ||
579 | embryo_program_data_get(Embryo_Program *ep) | ||
580 | { | ||
581 | if (!ep) return NULL; | ||
582 | return ep->data; | ||
583 | } | ||
584 | |||
585 | EAPI const char * | ||
586 | embryo_error_string_get(Embryo_Error error) | ||
587 | { | ||
588 | const char *messages[] = | ||
589 | { | ||
590 | /* EMBRYO_ERROR_NONE */ "(none)", | ||
591 | /* EMBRYO_ERROR_EXIT */ "Forced exit", | ||
592 | /* EMBRYO_ERROR_ASSERT */ "Assertion failed", | ||
593 | /* EMBRYO_ERROR_STACKERR */ "Stack/heap collision (insufficient stack size)", | ||
594 | /* EMBRYO_ERROR_BOUNDS */ "Array index out of bounds", | ||
595 | /* EMBRYO_ERROR_MEMACCESS */ "Invalid memory access", | ||
596 | /* EMBRYO_ERROR_INVINSTR */ "Invalid instruction", | ||
597 | /* EMBRYO_ERROR_STACKLOW */ "Stack underflow", | ||
598 | /* EMBRYO_ERROR_HEAPLOW */ "Heap underflow", | ||
599 | /* EMBRYO_ERROR_CALLBACK */ "No (valid) native function callback", | ||
600 | /* EMBRYO_ERROR_NATIVE */ "Native function failed", | ||
601 | /* EMBRYO_ERROR_DIVIDE */ "Divide by zero", | ||
602 | /* EMBRYO_ERROR_SLEEP */ "(sleep mode)", | ||
603 | /* 13 */ "(reserved)", | ||
604 | /* 14 */ "(reserved)", | ||
605 | /* 15 */ "(reserved)", | ||
606 | /* EMBRYO_ERROR_MEMORY */ "Out of memory", | ||
607 | /* EMBRYO_ERROR_FORMAT */ "Invalid/unsupported P-code file format", | ||
608 | /* EMBRYO_ERROR_VERSION */ "File is for a newer version of the Embryo_Program", | ||
609 | /* EMBRYO_ERROR_NOTFOUND */ "Native/Public function is not found", | ||
610 | /* EMBRYO_ERROR_INDEX */ "Invalid index parameter (bad entry point)", | ||
611 | /* EMBRYO_ERROR_DEBUG */ "Debugger cannot run", | ||
612 | /* EMBRYO_ERROR_INIT */ "Embryo_Program not initialized (or doubly initialized)", | ||
613 | /* EMBRYO_ERROR_USERDATA */ "Unable to set user data field (table full)", | ||
614 | /* EMBRYO_ERROR_INIT_JIT */ "Cannot initialize the JIT", | ||
615 | /* EMBRYO_ERROR_PARAMS */ "Parameter error", | ||
616 | }; | ||
617 | if (((int)error < 0) || | ||
618 | ((int)error >= (int)(sizeof(messages) / sizeof(messages[0])))) | ||
619 | return (const char *)"(unknown)"; | ||
620 | return messages[error]; | ||
621 | } | ||
622 | |||
623 | |||
624 | EAPI int | ||
625 | embryo_data_string_length_get(Embryo_Program *ep, Embryo_Cell *str_cell) | ||
626 | { | ||
627 | int len; | ||
628 | Embryo_Header *hdr; | ||
629 | |||
630 | if ((!ep) || (!ep->base)) return 0; | ||
631 | hdr = (Embryo_Header *)ep->base; | ||
632 | if ((!str_cell) || | ||
633 | ((void *)str_cell >= (void *)(ep->base + hdr->stp)) || | ||
634 | ((void *)str_cell < (void *)ep->base)) | ||
635 | return 0; | ||
636 | for (len = 0; str_cell[len] != 0; len++); | ||
637 | return len; | ||
638 | } | ||
639 | |||
640 | EAPI void | ||
641 | embryo_data_string_get(Embryo_Program *ep, Embryo_Cell *str_cell, char *dst) | ||
642 | { | ||
643 | int i; | ||
644 | Embryo_Header *hdr; | ||
645 | |||
646 | if (!dst) return; | ||
647 | if ((!ep) || (!ep->base)) | ||
648 | { | ||
649 | dst[0] = 0; | ||
650 | return; | ||
651 | } | ||
652 | hdr = (Embryo_Header *)ep->base; | ||
653 | if ((!str_cell) || | ||
654 | ((void *)str_cell >= (void *)(ep->base + hdr->stp)) || | ||
655 | ((void *)str_cell < (void *)ep->base)) | ||
656 | { | ||
657 | dst[0] = 0; | ||
658 | return; | ||
659 | } | ||
660 | for (i = 0; str_cell[i] != 0; i++) | ||
661 | { | ||
662 | #ifdef WORDS_BIGENDIAN | ||
663 | { | ||
664 | Embryo_Cell tmp; | ||
665 | |||
666 | tmp = str_cell[i]; | ||
667 | _embryo_byte_swap_32(&tmp); | ||
668 | dst[i] = tmp; | ||
669 | } | ||
670 | #else | ||
671 | dst[i] = str_cell[i]; | ||
672 | #endif | ||
673 | } | ||
674 | dst[i] = 0; | ||
675 | } | ||
676 | |||
677 | EAPI void | ||
678 | embryo_data_string_set(Embryo_Program *ep, const char *src, Embryo_Cell *str_cell) | ||
679 | { | ||
680 | int i; | ||
681 | Embryo_Header *hdr; | ||
682 | |||
683 | if (!ep) return; | ||
684 | if (!ep->base) return; | ||
685 | hdr = (Embryo_Header *)ep->base; | ||
686 | if ((!str_cell) || | ||
687 | ((void *)str_cell >= (void *)(ep->base + hdr->stp)) || | ||
688 | ((void *)str_cell < (void *)ep->base)) | ||
689 | return; | ||
690 | if (!src) | ||
691 | { | ||
692 | str_cell[0] = 0; | ||
693 | return; | ||
694 | } | ||
695 | for (i = 0; src[i] != 0; i++) | ||
696 | { | ||
697 | if ((void *)(&(str_cell[i])) >= (void *)(ep->base + hdr->stp)) return; | ||
698 | else if ((void *)(&(str_cell[i])) == (void *)(ep->base + hdr->stp - 1)) | ||
699 | { | ||
700 | str_cell[i] = 0; | ||
701 | return; | ||
702 | } | ||
703 | #ifdef WORDS_BIGENDIAN | ||
704 | { | ||
705 | Embryo_Cell tmp; | ||
706 | |||
707 | tmp = src[i]; | ||
708 | _embryo_byte_swap_32(&tmp); | ||
709 | str_cell[i] = tmp; | ||
710 | } | ||
711 | #else | ||
712 | str_cell[i] = src[i]; | ||
713 | #endif | ||
714 | } | ||
715 | str_cell[i] = 0; | ||
716 | } | ||
717 | |||
718 | EAPI Embryo_Cell * | ||
719 | embryo_data_address_get(Embryo_Program *ep, Embryo_Cell addr) | ||
720 | { | ||
721 | Embryo_Header *hdr; | ||
722 | unsigned char *data; | ||
723 | |||
724 | if ((!ep) || (!ep->base)) return NULL; | ||
725 | hdr = (Embryo_Header *)ep->base; | ||
726 | data = ep->base + (int)hdr->dat; | ||
727 | if ((addr < 0) || (addr >= hdr->stp)) return NULL; | ||
728 | return (Embryo_Cell *)(data + (int)addr); | ||
729 | } | ||
730 | |||
731 | |||
732 | EAPI Embryo_Cell | ||
733 | embryo_data_heap_push(Embryo_Program *ep, int cells) | ||
734 | { | ||
735 | Embryo_Header *hdr; | ||
736 | Embryo_Cell addr; | ||
737 | |||
738 | if ((!ep) || (!ep->base)) return EMBRYO_CELL_NONE; | ||
739 | hdr = (Embryo_Header *)ep->base; | ||
740 | if (ep->stk - ep->hea - (cells * sizeof(Embryo_Cell)) < STKMARGIN) | ||
741 | return EMBRYO_CELL_NONE; | ||
742 | addr = ep->hea; | ||
743 | ep->hea += (cells * sizeof(Embryo_Cell)); | ||
744 | return addr; | ||
745 | } | ||
746 | |||
747 | EAPI void | ||
748 | embryo_data_heap_pop(Embryo_Program *ep, Embryo_Cell down_to) | ||
749 | { | ||
750 | if (!ep) return; | ||
751 | if (down_to < 0) down_to = 0; | ||
752 | if (ep->hea > down_to) ep->hea = down_to; | ||
753 | } | ||
754 | |||
755 | |||
756 | EAPI int | ||
757 | embryo_program_recursion_get(Embryo_Program *ep) | ||
758 | { | ||
759 | return ep->run_count; | ||
760 | } | ||
761 | |||
762 | #ifdef __GNUC__ | ||
763 | #if 1 | ||
764 | #define EMBRYO_EXEC_JUMPTABLE | ||
765 | #endif | ||
766 | #endif | ||
767 | |||
768 | /* jump table optimization - only works for gcc though */ | ||
769 | #ifdef EMBRYO_EXEC_JUMPTABLE | ||
770 | #define SWITCH(x) while (1) { goto *switchtable[x]; | ||
771 | #define SWITCHEND break; } | ||
772 | #define CASE(x) SWITCHTABLE_##x: | ||
773 | #define BREAK break; | ||
774 | #else | ||
775 | #define SWITCH(x) switch (x) { | ||
776 | #define SWITCHEND } | ||
777 | #define CASE(x) case x: | ||
778 | #define BREAK break | ||
779 | #endif | ||
780 | |||
781 | EAPI Embryo_Status | ||
782 | embryo_program_run(Embryo_Program *ep, Embryo_Function fn) | ||
783 | { | ||
784 | Embryo_Header *hdr; | ||
785 | Embryo_Func_Stub *func; | ||
786 | unsigned char *code, *data; | ||
787 | Embryo_Cell pri, alt, stk, frm, hea, hea_start; | ||
788 | Embryo_Cell reset_stk, reset_hea, *cip; | ||
789 | Embryo_UCell codesize; | ||
790 | int i; | ||
791 | unsigned char op; | ||
792 | Embryo_Cell offs; | ||
793 | int num; | ||
794 | int max_run_cycles; | ||
795 | int cycle_count; | ||
796 | #ifdef EMBRYO_EXEC_JUMPTABLE | ||
797 | /* we limit the jumptable to 256 elements. why? above we forced "op" to be | ||
798 | * a unsigned char - that means 256 max values. we limit opcode overflow | ||
799 | * here, so eliminating crashes on table lookups with bad/corrupt bytecode. | ||
800 | * no need to atuall do compares, branches etc. the datatype does the work | ||
801 | * for us. so that means EXCESS elements are all declared as OP_NONE to | ||
802 | * keep them innocuous. | ||
803 | */ | ||
804 | static const void *switchtable[256] = | ||
805 | { | ||
806 | &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
807 | &&SWITCHTABLE_EMBRYO_OP_LOAD_PRI, | ||
808 | &&SWITCHTABLE_EMBRYO_OP_LOAD_ALT, | ||
809 | &&SWITCHTABLE_EMBRYO_OP_LOAD_S_PRI, | ||
810 | &&SWITCHTABLE_EMBRYO_OP_LOAD_S_ALT, | ||
811 | &&SWITCHTABLE_EMBRYO_OP_LREF_PRI, | ||
812 | &&SWITCHTABLE_EMBRYO_OP_LREF_ALT, | ||
813 | &&SWITCHTABLE_EMBRYO_OP_LREF_S_PRI, | ||
814 | &&SWITCHTABLE_EMBRYO_OP_LREF_S_ALT, | ||
815 | &&SWITCHTABLE_EMBRYO_OP_LOAD_I, | ||
816 | &&SWITCHTABLE_EMBRYO_OP_LODB_I, | ||
817 | &&SWITCHTABLE_EMBRYO_OP_CONST_PRI, | ||
818 | &&SWITCHTABLE_EMBRYO_OP_CONST_ALT, | ||
819 | &&SWITCHTABLE_EMBRYO_OP_ADDR_PRI, | ||
820 | &&SWITCHTABLE_EMBRYO_OP_ADDR_ALT, | ||
821 | &&SWITCHTABLE_EMBRYO_OP_STOR_PRI, | ||
822 | &&SWITCHTABLE_EMBRYO_OP_STOR_ALT, | ||
823 | &&SWITCHTABLE_EMBRYO_OP_STOR_S_PRI, | ||
824 | &&SWITCHTABLE_EMBRYO_OP_STOR_S_ALT, | ||
825 | &&SWITCHTABLE_EMBRYO_OP_SREF_PRI, | ||
826 | &&SWITCHTABLE_EMBRYO_OP_SREF_ALT, | ||
827 | &&SWITCHTABLE_EMBRYO_OP_SREF_S_PRI, | ||
828 | &&SWITCHTABLE_EMBRYO_OP_SREF_S_ALT, | ||
829 | &&SWITCHTABLE_EMBRYO_OP_STOR_I, | ||
830 | &&SWITCHTABLE_EMBRYO_OP_STRB_I, | ||
831 | &&SWITCHTABLE_EMBRYO_OP_LIDX, | ||
832 | &&SWITCHTABLE_EMBRYO_OP_LIDX_B, | ||
833 | &&SWITCHTABLE_EMBRYO_OP_IDXADDR, | ||
834 | &&SWITCHTABLE_EMBRYO_OP_IDXADDR_B, | ||
835 | &&SWITCHTABLE_EMBRYO_OP_ALIGN_PRI, | ||
836 | &&SWITCHTABLE_EMBRYO_OP_ALIGN_ALT, | ||
837 | &&SWITCHTABLE_EMBRYO_OP_LCTRL, | ||
838 | &&SWITCHTABLE_EMBRYO_OP_SCTRL, | ||
839 | &&SWITCHTABLE_EMBRYO_OP_MOVE_PRI, | ||
840 | &&SWITCHTABLE_EMBRYO_OP_MOVE_ALT, | ||
841 | &&SWITCHTABLE_EMBRYO_OP_XCHG, | ||
842 | &&SWITCHTABLE_EMBRYO_OP_PUSH_PRI, | ||
843 | &&SWITCHTABLE_EMBRYO_OP_PUSH_ALT, | ||
844 | &&SWITCHTABLE_EMBRYO_OP_PUSH_R, | ||
845 | &&SWITCHTABLE_EMBRYO_OP_PUSH_C, | ||
846 | &&SWITCHTABLE_EMBRYO_OP_PUSH, | ||
847 | &&SWITCHTABLE_EMBRYO_OP_PUSH_S, | ||
848 | &&SWITCHTABLE_EMBRYO_OP_POP_PRI, | ||
849 | &&SWITCHTABLE_EMBRYO_OP_POP_ALT, | ||
850 | &&SWITCHTABLE_EMBRYO_OP_STACK, | ||
851 | &&SWITCHTABLE_EMBRYO_OP_HEAP, | ||
852 | &&SWITCHTABLE_EMBRYO_OP_PROC, | ||
853 | &&SWITCHTABLE_EMBRYO_OP_RET, | ||
854 | &&SWITCHTABLE_EMBRYO_OP_RETN, | ||
855 | &&SWITCHTABLE_EMBRYO_OP_CALL, | ||
856 | &&SWITCHTABLE_EMBRYO_OP_CALL_PRI, | ||
857 | &&SWITCHTABLE_EMBRYO_OP_JUMP, | ||
858 | &&SWITCHTABLE_EMBRYO_OP_JREL, | ||
859 | &&SWITCHTABLE_EMBRYO_OP_JZER, | ||
860 | &&SWITCHTABLE_EMBRYO_OP_JNZ, | ||
861 | &&SWITCHTABLE_EMBRYO_OP_JEQ, | ||
862 | &&SWITCHTABLE_EMBRYO_OP_JNEQ, | ||
863 | &&SWITCHTABLE_EMBRYO_OP_JLESS, | ||
864 | &&SWITCHTABLE_EMBRYO_OP_JLEQ, | ||
865 | &&SWITCHTABLE_EMBRYO_OP_JGRTR, | ||
866 | &&SWITCHTABLE_EMBRYO_OP_JGEQ, | ||
867 | &&SWITCHTABLE_EMBRYO_OP_JSLESS, | ||
868 | &&SWITCHTABLE_EMBRYO_OP_JSLEQ, | ||
869 | &&SWITCHTABLE_EMBRYO_OP_JSGRTR, | ||
870 | &&SWITCHTABLE_EMBRYO_OP_JSGEQ, | ||
871 | &&SWITCHTABLE_EMBRYO_OP_SHL, | ||
872 | &&SWITCHTABLE_EMBRYO_OP_SHR, | ||
873 | &&SWITCHTABLE_EMBRYO_OP_SSHR, | ||
874 | &&SWITCHTABLE_EMBRYO_OP_SHL_C_PRI, | ||
875 | &&SWITCHTABLE_EMBRYO_OP_SHL_C_ALT, | ||
876 | &&SWITCHTABLE_EMBRYO_OP_SHR_C_PRI, | ||
877 | &&SWITCHTABLE_EMBRYO_OP_SHR_C_ALT, | ||
878 | &&SWITCHTABLE_EMBRYO_OP_SMUL, | ||
879 | &&SWITCHTABLE_EMBRYO_OP_SDIV, | ||
880 | &&SWITCHTABLE_EMBRYO_OP_SDIV_ALT, | ||
881 | &&SWITCHTABLE_EMBRYO_OP_UMUL, | ||
882 | &&SWITCHTABLE_EMBRYO_OP_UDIV, | ||
883 | &&SWITCHTABLE_EMBRYO_OP_UDIV_ALT, | ||
884 | &&SWITCHTABLE_EMBRYO_OP_ADD, | ||
885 | &&SWITCHTABLE_EMBRYO_OP_SUB, | ||
886 | &&SWITCHTABLE_EMBRYO_OP_SUB_ALT, | ||
887 | &&SWITCHTABLE_EMBRYO_OP_AND, | ||
888 | &&SWITCHTABLE_EMBRYO_OP_OR, | ||
889 | &&SWITCHTABLE_EMBRYO_OP_XOR, | ||
890 | &&SWITCHTABLE_EMBRYO_OP_NOT, | ||
891 | &&SWITCHTABLE_EMBRYO_OP_NEG, | ||
892 | &&SWITCHTABLE_EMBRYO_OP_INVERT, | ||
893 | &&SWITCHTABLE_EMBRYO_OP_ADD_C, | ||
894 | &&SWITCHTABLE_EMBRYO_OP_SMUL_C, | ||
895 | &&SWITCHTABLE_EMBRYO_OP_ZERO_PRI, | ||
896 | &&SWITCHTABLE_EMBRYO_OP_ZERO_ALT, | ||
897 | &&SWITCHTABLE_EMBRYO_OP_ZERO, | ||
898 | &&SWITCHTABLE_EMBRYO_OP_ZERO_S, | ||
899 | &&SWITCHTABLE_EMBRYO_OP_SIGN_PRI, | ||
900 | &&SWITCHTABLE_EMBRYO_OP_SIGN_ALT, | ||
901 | &&SWITCHTABLE_EMBRYO_OP_EQ, | ||
902 | &&SWITCHTABLE_EMBRYO_OP_NEQ, | ||
903 | &&SWITCHTABLE_EMBRYO_OP_LESS, | ||
904 | &&SWITCHTABLE_EMBRYO_OP_LEQ, | ||
905 | &&SWITCHTABLE_EMBRYO_OP_GRTR, | ||
906 | &&SWITCHTABLE_EMBRYO_OP_GEQ, | ||
907 | &&SWITCHTABLE_EMBRYO_OP_SLESS, | ||
908 | &&SWITCHTABLE_EMBRYO_OP_SLEQ, | ||
909 | &&SWITCHTABLE_EMBRYO_OP_SGRTR, | ||
910 | &&SWITCHTABLE_EMBRYO_OP_SGEQ, | ||
911 | &&SWITCHTABLE_EMBRYO_OP_EQ_C_PRI, | ||
912 | &&SWITCHTABLE_EMBRYO_OP_EQ_C_ALT, | ||
913 | &&SWITCHTABLE_EMBRYO_OP_INC_PRI, | ||
914 | &&SWITCHTABLE_EMBRYO_OP_INC_ALT, | ||
915 | &&SWITCHTABLE_EMBRYO_OP_INC, | ||
916 | &&SWITCHTABLE_EMBRYO_OP_INC_S, | ||
917 | &&SWITCHTABLE_EMBRYO_OP_INC_I, | ||
918 | &&SWITCHTABLE_EMBRYO_OP_DEC_PRI, | ||
919 | &&SWITCHTABLE_EMBRYO_OP_DEC_ALT, | ||
920 | &&SWITCHTABLE_EMBRYO_OP_DEC, | ||
921 | &&SWITCHTABLE_EMBRYO_OP_DEC_S, | ||
922 | &&SWITCHTABLE_EMBRYO_OP_DEC_I, | ||
923 | &&SWITCHTABLE_EMBRYO_OP_MOVS, | ||
924 | &&SWITCHTABLE_EMBRYO_OP_CMPS, | ||
925 | &&SWITCHTABLE_EMBRYO_OP_FILL, | ||
926 | &&SWITCHTABLE_EMBRYO_OP_HALT, | ||
927 | &&SWITCHTABLE_EMBRYO_OP_BOUNDS, | ||
928 | &&SWITCHTABLE_EMBRYO_OP_SYSREQ_PRI, | ||
929 | &&SWITCHTABLE_EMBRYO_OP_SYSREQ_C, | ||
930 | &&SWITCHTABLE_EMBRYO_OP_FILE, | ||
931 | &&SWITCHTABLE_EMBRYO_OP_LINE, | ||
932 | &&SWITCHTABLE_EMBRYO_OP_SYMBOL, | ||
933 | &&SWITCHTABLE_EMBRYO_OP_SRANGE, | ||
934 | &&SWITCHTABLE_EMBRYO_OP_JUMP_PRI, | ||
935 | &&SWITCHTABLE_EMBRYO_OP_SWITCH, | ||
936 | &&SWITCHTABLE_EMBRYO_OP_CASETBL, | ||
937 | &&SWITCHTABLE_EMBRYO_OP_SWAP_PRI, | ||
938 | &&SWITCHTABLE_EMBRYO_OP_SWAP_ALT, | ||
939 | &&SWITCHTABLE_EMBRYO_OP_PUSHADDR, | ||
940 | &&SWITCHTABLE_EMBRYO_OP_NOP, | ||
941 | &&SWITCHTABLE_EMBRYO_OP_SYSREQ_D, | ||
942 | &&SWITCHTABLE_EMBRYO_OP_SYMTAG, | ||
943 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
944 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
945 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
946 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
947 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
948 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
949 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
950 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
951 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
952 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
953 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
954 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
955 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
956 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
957 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
958 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
959 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
960 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
961 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
962 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
963 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
964 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
965 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, | ||
966 | &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE | ||
967 | }; | ||
968 | #endif | ||
969 | if (!ep) return EMBRYO_PROGRAM_FAIL; | ||
970 | if (!(ep->flags & EMBRYO_FLAG_RELOC)) | ||
971 | { | ||
972 | ep->error = EMBRYO_ERROR_INIT; | ||
973 | return EMBRYO_PROGRAM_FAIL; | ||
974 | } | ||
975 | if (!ep->base) | ||
976 | { | ||
977 | ep->error = EMBRYO_ERROR_INIT; | ||
978 | return EMBRYO_PROGRAM_FAIL; | ||
979 | } | ||
980 | if (ep->run_count > 0) | ||
981 | { | ||
982 | /* return EMBRYO_PROGRAM_BUSY; */ | ||
983 | /* FIXME: test C->vm->C->vm recursion more fully */ | ||
984 | /* it seems to work... just fine!!! - strange! */ | ||
985 | } | ||
986 | |||
987 | /* set up the registers */ | ||
988 | hdr = (Embryo_Header *)ep->base; | ||
989 | codesize = (Embryo_UCell)(hdr->dat - hdr->cod); | ||
990 | code = ep->base + (int)hdr->cod; | ||
991 | data = ep->base + (int)hdr->dat; | ||
992 | hea_start = hea = ep->hea; | ||
993 | stk = ep->stk; | ||
994 | reset_stk = stk; | ||
995 | reset_hea = hea; | ||
996 | frm = alt = pri = 0; | ||
997 | |||
998 | /* get the start address */ | ||
999 | if (fn == EMBRYO_FUNCTION_MAIN) | ||
1000 | { | ||
1001 | if (hdr->cip < 0) | ||
1002 | { | ||
1003 | ep->error = EMBRYO_ERROR_INDEX; | ||
1004 | return EMBRYO_PROGRAM_FAIL; | ||
1005 | } | ||
1006 | cip = (Embryo_Cell *)(code + (int)hdr->cip); | ||
1007 | } | ||
1008 | else if (fn == EMBRYO_FUNCTION_CONT) | ||
1009 | { | ||
1010 | /* all registers: pri, alt, frm, cip, hea, stk, reset_stk, reset_hea */ | ||
1011 | frm = ep->frm; | ||
1012 | stk = ep->stk; | ||
1013 | hea = ep->hea; | ||
1014 | pri = ep->pri; | ||
1015 | alt = ep->alt; | ||
1016 | reset_stk = ep->reset_stk; | ||
1017 | reset_hea = ep->reset_hea; | ||
1018 | cip = (Embryo_Cell *)(code + (int)ep->cip); | ||
1019 | } | ||
1020 | else if (fn < 0) | ||
1021 | { | ||
1022 | ep->error = EMBRYO_ERROR_INDEX; | ||
1023 | return EMBRYO_PROGRAM_FAIL; | ||
1024 | } | ||
1025 | else | ||
1026 | { | ||
1027 | if (fn >= (Embryo_Cell)NUMENTRIES(hdr, publics, natives)) | ||
1028 | { | ||
1029 | ep->error = EMBRYO_ERROR_INDEX; | ||
1030 | return EMBRYO_PROGRAM_FAIL; | ||
1031 | } | ||
1032 | func = GETENTRY(hdr, publics, fn); | ||
1033 | cip = (Embryo_Cell *)(code + (int)func->address); | ||
1034 | } | ||
1035 | /* check values just copied */ | ||
1036 | CHKSTACK(); | ||
1037 | CHKHEAP(); | ||
1038 | |||
1039 | if (fn != EMBRYO_FUNCTION_CONT) | ||
1040 | { | ||
1041 | int i; | ||
1042 | |||
1043 | for (i = ep->params_size - 1; i >= 0; i--) | ||
1044 | { | ||
1045 | Embryo_Param *pr; | ||
1046 | |||
1047 | pr = &(ep->params[i]); | ||
1048 | if (pr->string) | ||
1049 | { | ||
1050 | int len; | ||
1051 | Embryo_Cell ep_addr, *addr; | ||
1052 | |||
1053 | len = strlen(pr->string); | ||
1054 | ep_addr = embryo_data_heap_push(ep, len + 1); | ||
1055 | if (ep_addr == EMBRYO_CELL_NONE) | ||
1056 | { | ||
1057 | ep->error = EMBRYO_ERROR_HEAPLOW; | ||
1058 | return EMBRYO_PROGRAM_FAIL; | ||
1059 | } | ||
1060 | addr = embryo_data_address_get(ep, ep_addr); | ||
1061 | if (addr) | ||
1062 | embryo_data_string_set(ep, pr->string, addr); | ||
1063 | else | ||
1064 | { | ||
1065 | ep->error = EMBRYO_ERROR_HEAPLOW; | ||
1066 | return EMBRYO_PROGRAM_FAIL; | ||
1067 | } | ||
1068 | PUSH(ep_addr); | ||
1069 | free(pr->string); | ||
1070 | } | ||
1071 | else if (pr->cell_array) | ||
1072 | { | ||
1073 | int len; | ||
1074 | Embryo_Cell ep_addr, *addr; | ||
1075 | |||
1076 | len = pr->cell_array_size; | ||
1077 | ep_addr = embryo_data_heap_push(ep, len + 1); | ||
1078 | if (ep_addr == EMBRYO_CELL_NONE) | ||
1079 | { | ||
1080 | ep->error = EMBRYO_ERROR_HEAPLOW; | ||
1081 | return EMBRYO_PROGRAM_FAIL; | ||
1082 | } | ||
1083 | addr = embryo_data_address_get(ep, ep_addr); | ||
1084 | if (addr) | ||
1085 | memcpy(addr, pr->cell_array, | ||
1086 | pr->cell_array_size * sizeof(Embryo_Cell)); | ||
1087 | else | ||
1088 | { | ||
1089 | ep->error = EMBRYO_ERROR_HEAPLOW; | ||
1090 | return EMBRYO_PROGRAM_FAIL; | ||
1091 | } | ||
1092 | PUSH(ep_addr); | ||
1093 | free(pr->cell_array); | ||
1094 | } | ||
1095 | else | ||
1096 | { | ||
1097 | PUSH(pr->cell); | ||
1098 | } | ||
1099 | } | ||
1100 | PUSH(ep->params_size * sizeof(Embryo_Cell)); | ||
1101 | PUSH(0); | ||
1102 | if (ep->params) | ||
1103 | { | ||
1104 | free(ep->params); | ||
1105 | ep->params = NULL; | ||
1106 | } | ||
1107 | ep->params_size = ep->params_alloc = 0; | ||
1108 | } | ||
1109 | /* check stack/heap before starting to run */ | ||
1110 | CHKMARGIN(); | ||
1111 | |||
1112 | /* track recursion depth */ | ||
1113 | ep->run_count++; | ||
1114 | |||
1115 | max_run_cycles = ep->max_run_cycles; | ||
1116 | /* start running */ | ||
1117 | for (cycle_count = 0;;) | ||
1118 | { | ||
1119 | if (max_run_cycles > 0) | ||
1120 | { | ||
1121 | if (cycle_count >= max_run_cycles) | ||
1122 | { | ||
1123 | TOOLONG(ep); | ||
1124 | } | ||
1125 | cycle_count++; | ||
1126 | } | ||
1127 | op = (Embryo_Opcode)*cip++; | ||
1128 | SWITCH(op); | ||
1129 | CASE(EMBRYO_OP_LOAD_PRI); | ||
1130 | GETPARAM(offs); | ||
1131 | pri = *(Embryo_Cell *)(data + (int)offs); | ||
1132 | BREAK; | ||
1133 | CASE(EMBRYO_OP_LOAD_ALT); | ||
1134 | GETPARAM(offs); | ||
1135 | alt = *(Embryo_Cell *)(data + (int)offs); | ||
1136 | BREAK; | ||
1137 | CASE(EMBRYO_OP_LOAD_S_PRI); | ||
1138 | GETPARAM(offs); | ||
1139 | pri = *(Embryo_Cell *)(data + (int)frm + (int)offs); | ||
1140 | BREAK; | ||
1141 | CASE(EMBRYO_OP_LOAD_S_ALT); | ||
1142 | GETPARAM(offs); | ||
1143 | alt = *(Embryo_Cell *)(data + (int)frm + (int)offs); | ||
1144 | BREAK; | ||
1145 | CASE(EMBRYO_OP_LREF_PRI); | ||
1146 | GETPARAM(offs); | ||
1147 | offs = *(Embryo_Cell *)(data + (int)offs); | ||
1148 | pri = *(Embryo_Cell *)(data + (int)offs); | ||
1149 | BREAK; | ||
1150 | CASE(EMBRYO_OP_LREF_ALT); | ||
1151 | GETPARAM(offs); | ||
1152 | offs = *(Embryo_Cell *)(data + (int)offs); | ||
1153 | alt = *(Embryo_Cell *)(data + (int)offs); | ||
1154 | BREAK; | ||
1155 | CASE(EMBRYO_OP_LREF_S_PRI); | ||
1156 | GETPARAM(offs); | ||
1157 | offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); | ||
1158 | pri = *(Embryo_Cell *)(data + (int)offs); | ||
1159 | BREAK; | ||
1160 | CASE(EMBRYO_OP_LREF_S_ALT); | ||
1161 | GETPARAM(offs); | ||
1162 | offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); | ||
1163 | alt = *(Embryo_Cell *)(data + (int)offs); | ||
1164 | BREAK; | ||
1165 | CASE(EMBRYO_OP_LOAD_I); | ||
1166 | CHKMEM(pri); | ||
1167 | pri = *(Embryo_Cell *)(data + (int)pri); | ||
1168 | BREAK; | ||
1169 | CASE(EMBRYO_OP_LODB_I); | ||
1170 | GETPARAM(offs); | ||
1171 | CHKMEM(pri); | ||
1172 | switch (offs) | ||
1173 | { | ||
1174 | case 1: | ||
1175 | pri = *(data + (int)pri); | ||
1176 | break; | ||
1177 | case 2: | ||
1178 | pri = *(unsigned short *)(data + (int)pri); | ||
1179 | break; | ||
1180 | case 4: | ||
1181 | pri = *(unsigned int *)(data + (int)pri); | ||
1182 | break; | ||
1183 | default: | ||
1184 | ABORT(ep, EMBRYO_ERROR_INVINSTR); | ||
1185 | break; | ||
1186 | } | ||
1187 | BREAK; | ||
1188 | CASE(EMBRYO_OP_CONST_PRI); | ||
1189 | GETPARAM(pri); | ||
1190 | BREAK; | ||
1191 | CASE(EMBRYO_OP_CONST_ALT); | ||
1192 | GETPARAM(alt); | ||
1193 | BREAK; | ||
1194 | CASE(EMBRYO_OP_ADDR_PRI); | ||
1195 | GETPARAM(pri); | ||
1196 | pri += frm; | ||
1197 | BREAK; | ||
1198 | CASE(EMBRYO_OP_ADDR_ALT); | ||
1199 | GETPARAM(alt); | ||
1200 | alt += frm; | ||
1201 | BREAK; | ||
1202 | CASE(EMBRYO_OP_STOR_PRI); | ||
1203 | GETPARAM(offs); | ||
1204 | *(Embryo_Cell *)(data + (int)offs) = pri; | ||
1205 | BREAK; | ||
1206 | CASE(EMBRYO_OP_STOR_ALT); | ||
1207 | GETPARAM(offs); | ||
1208 | *(Embryo_Cell *)(data + (int)offs) = alt; | ||
1209 | BREAK; | ||
1210 | CASE(EMBRYO_OP_STOR_S_PRI); | ||
1211 | GETPARAM(offs); | ||
1212 | *(Embryo_Cell *)(data + (int)frm + (int)offs) = pri; | ||
1213 | BREAK; | ||
1214 | CASE(EMBRYO_OP_STOR_S_ALT); | ||
1215 | GETPARAM(offs); | ||
1216 | *(Embryo_Cell *)(data + (int)frm + (int)offs) = alt; | ||
1217 | BREAK; | ||
1218 | CASE(EMBRYO_OP_SREF_PRI); | ||
1219 | GETPARAM(offs); | ||
1220 | offs = *(Embryo_Cell *)(data + (int)offs); | ||
1221 | *(Embryo_Cell *)(data + (int)offs) = pri; | ||
1222 | BREAK; | ||
1223 | CASE(EMBRYO_OP_SREF_ALT); | ||
1224 | GETPARAM(offs); | ||
1225 | offs = *(Embryo_Cell *)(data + (int)offs); | ||
1226 | *(Embryo_Cell *)(data + (int)offs) = alt; | ||
1227 | BREAK; | ||
1228 | CASE(EMBRYO_OP_SREF_S_PRI); | ||
1229 | GETPARAM(offs); | ||
1230 | offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); | ||
1231 | *(Embryo_Cell *)(data + (int)offs) = pri; | ||
1232 | BREAK; | ||
1233 | CASE(EMBRYO_OP_SREF_S_ALT); | ||
1234 | GETPARAM(offs); | ||
1235 | offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); | ||
1236 | *(Embryo_Cell *)(data + (int)offs) = alt; | ||
1237 | BREAK; | ||
1238 | CASE(EMBRYO_OP_STOR_I); | ||
1239 | CHKMEM(alt); | ||
1240 | *(Embryo_Cell *)(data + (int)alt) = pri; | ||
1241 | BREAK; | ||
1242 | CASE(EMBRYO_OP_STRB_I); | ||
1243 | GETPARAM(offs); | ||
1244 | CHKMEM(alt); | ||
1245 | switch (offs) | ||
1246 | { | ||
1247 | case 1: | ||
1248 | *(data + (int)alt) = (unsigned char)pri; | ||
1249 | break; | ||
1250 | case 2: | ||
1251 | *(unsigned short *)(data + (int)alt) = (unsigned short)pri; | ||
1252 | break; | ||
1253 | case 4: | ||
1254 | *(unsigned int *)(data + (int)alt) = (unsigned int)pri; | ||
1255 | break; | ||
1256 | default: | ||
1257 | ABORT(ep, EMBRYO_ERROR_INVINSTR); | ||
1258 | break; | ||
1259 | } | ||
1260 | BREAK; | ||
1261 | CASE(EMBRYO_OP_LIDX); | ||
1262 | offs = (pri * sizeof(Embryo_Cell)) + alt; | ||
1263 | CHKMEM(offs); | ||
1264 | pri = *(Embryo_Cell *)(data + (int)offs); | ||
1265 | BREAK; | ||
1266 | CASE(EMBRYO_OP_LIDX_B); | ||
1267 | GETPARAM(offs); | ||
1268 | offs = (pri << (int)offs) + alt; | ||
1269 | CHKMEM(offs); | ||
1270 | pri = *(Embryo_Cell *)(data + (int)offs); | ||
1271 | BREAK; | ||
1272 | CASE(EMBRYO_OP_IDXADDR); | ||
1273 | pri = (pri * sizeof(Embryo_Cell)) + alt; | ||
1274 | BREAK; | ||
1275 | CASE(EMBRYO_OP_IDXADDR_B); | ||
1276 | GETPARAM(offs); | ||
1277 | pri = (pri << (int)offs) + alt; | ||
1278 | BREAK; | ||
1279 | CASE(EMBRYO_OP_ALIGN_PRI); | ||
1280 | GETPARAM(offs); | ||
1281 | #ifdef WORDS_BIGENDIAN | ||
1282 | if ((size_t)offs < sizeof(Embryo_Cell)) | ||
1283 | pri ^= sizeof(Embryo_Cell) - offs; | ||
1284 | #endif | ||
1285 | BREAK; | ||
1286 | CASE(EMBRYO_OP_ALIGN_ALT); | ||
1287 | GETPARAM(offs); | ||
1288 | #ifdef WORDS_BIGENDIAN | ||
1289 | if ((size_t)offs < sizeof(Embryo_Cell)) | ||
1290 | alt ^= sizeof(Embryo_Cell) - offs; | ||
1291 | #endif | ||
1292 | BREAK; | ||
1293 | CASE(EMBRYO_OP_LCTRL); | ||
1294 | GETPARAM(offs); | ||
1295 | switch (offs) | ||
1296 | { | ||
1297 | case 0: | ||
1298 | pri = hdr->cod; | ||
1299 | break; | ||
1300 | case 1: | ||
1301 | pri = hdr->dat; | ||
1302 | break; | ||
1303 | case 2: | ||
1304 | pri = hea; | ||
1305 | break; | ||
1306 | case 3: | ||
1307 | pri = ep->stp; | ||
1308 | break; | ||
1309 | case 4: | ||
1310 | pri = stk; | ||
1311 | break; | ||
1312 | case 5: | ||
1313 | pri = frm; | ||
1314 | break; | ||
1315 | case 6: | ||
1316 | pri = (Embryo_Cell)((unsigned char *)cip - code); | ||
1317 | break; | ||
1318 | default: | ||
1319 | ABORT(ep, EMBRYO_ERROR_INVINSTR); | ||
1320 | break; | ||
1321 | } | ||
1322 | BREAK; | ||
1323 | CASE(EMBRYO_OP_SCTRL); | ||
1324 | GETPARAM(offs); | ||
1325 | switch (offs) | ||
1326 | { | ||
1327 | case 0: | ||
1328 | case 1: | ||
1329 | case 2: | ||
1330 | hea = pri; | ||
1331 | break; | ||
1332 | case 3: | ||
1333 | /* cannot change these parameters */ | ||
1334 | break; | ||
1335 | case 4: | ||
1336 | stk = pri; | ||
1337 | break; | ||
1338 | case 5: | ||
1339 | frm = pri; | ||
1340 | break; | ||
1341 | case 6: | ||
1342 | cip = (Embryo_Cell *)(code + (int)pri); | ||
1343 | break; | ||
1344 | default: | ||
1345 | ABORT(ep, EMBRYO_ERROR_INVINSTR); | ||
1346 | break; | ||
1347 | } | ||
1348 | BREAK; | ||
1349 | CASE(EMBRYO_OP_MOVE_PRI); | ||
1350 | pri = alt; | ||
1351 | BREAK; | ||
1352 | CASE(EMBRYO_OP_MOVE_ALT); | ||
1353 | alt = pri; | ||
1354 | BREAK; | ||
1355 | CASE(EMBRYO_OP_XCHG); | ||
1356 | offs = pri; /* offs is a temporary variable */ | ||
1357 | pri = alt; | ||
1358 | alt = offs; | ||
1359 | BREAK; | ||
1360 | CASE(EMBRYO_OP_PUSH_PRI); | ||
1361 | PUSH(pri); | ||
1362 | BREAK; | ||
1363 | CASE(EMBRYO_OP_PUSH_ALT); | ||
1364 | PUSH(alt); | ||
1365 | BREAK; | ||
1366 | CASE(EMBRYO_OP_PUSH_C); | ||
1367 | GETPARAM(offs); | ||
1368 | PUSH(offs); | ||
1369 | BREAK; | ||
1370 | CASE(EMBRYO_OP_PUSH_R); | ||
1371 | GETPARAM(offs); | ||
1372 | while (offs--) PUSH(pri); | ||
1373 | BREAK; | ||
1374 | CASE(EMBRYO_OP_PUSH); | ||
1375 | GETPARAM(offs); | ||
1376 | PUSH(*(Embryo_Cell *)(data + (int)offs)); | ||
1377 | BREAK; | ||
1378 | CASE(EMBRYO_OP_PUSH_S); | ||
1379 | GETPARAM(offs); | ||
1380 | PUSH(*(Embryo_Cell *)(data + (int)frm + (int)offs)); | ||
1381 | BREAK; | ||
1382 | CASE(EMBRYO_OP_POP_PRI); | ||
1383 | POP(pri); | ||
1384 | BREAK; | ||
1385 | CASE(EMBRYO_OP_POP_ALT); | ||
1386 | POP(alt); | ||
1387 | BREAK; | ||
1388 | CASE(EMBRYO_OP_STACK); | ||
1389 | GETPARAM(offs); | ||
1390 | alt = stk; | ||
1391 | stk += offs; | ||
1392 | CHKMARGIN(); | ||
1393 | CHKSTACK(); | ||
1394 | BREAK; | ||
1395 | CASE(EMBRYO_OP_HEAP); | ||
1396 | GETPARAM(offs); | ||
1397 | alt = hea; | ||
1398 | hea += offs; | ||
1399 | CHKMARGIN(); | ||
1400 | CHKHEAP(); | ||
1401 | BREAK; | ||
1402 | CASE(EMBRYO_OP_PROC); | ||
1403 | PUSH(frm); | ||
1404 | frm = stk; | ||
1405 | CHKMARGIN(); | ||
1406 | BREAK; | ||
1407 | CASE(EMBRYO_OP_RET); | ||
1408 | POP(frm); | ||
1409 | POP(offs); | ||
1410 | if ((Embryo_UCell)offs >= codesize) | ||
1411 | ABORT(ep, EMBRYO_ERROR_MEMACCESS); | ||
1412 | cip = (Embryo_Cell *)(code + (int)offs); | ||
1413 | BREAK; | ||
1414 | CASE(EMBRYO_OP_RETN); | ||
1415 | POP(frm); | ||
1416 | POP(offs); | ||
1417 | if ((Embryo_UCell)offs >= codesize) | ||
1418 | ABORT(ep, EMBRYO_ERROR_MEMACCESS); | ||
1419 | cip = (Embryo_Cell *)(code + (int)offs); | ||
1420 | stk += *(Embryo_Cell *)(data + (int)stk) + sizeof(Embryo_Cell); /* remove parameters from the stack */ | ||
1421 | ep->stk = stk; | ||
1422 | BREAK; | ||
1423 | CASE(EMBRYO_OP_CALL); | ||
1424 | PUSH(((unsigned char *)cip - code) + sizeof(Embryo_Cell));/* skip address */ | ||
1425 | cip = JUMPABS(code, cip); /* jump to the address */ | ||
1426 | BREAK; | ||
1427 | CASE(EMBRYO_OP_CALL_PRI); | ||
1428 | PUSH((unsigned char *)cip - code); | ||
1429 | cip = (Embryo_Cell *)(code + (int)pri); | ||
1430 | BREAK; | ||
1431 | CASE(EMBRYO_OP_JUMP); | ||
1432 | /* since the GETPARAM() macro modifies cip, you cannot | ||
1433 | * do GETPARAM(cip) directly */ | ||
1434 | cip = JUMPABS(code, cip); | ||
1435 | BREAK; | ||
1436 | CASE(EMBRYO_OP_JREL); | ||
1437 | offs = *cip; | ||
1438 | cip = (Embryo_Cell *)((unsigned char *)cip + (int)offs + sizeof(Embryo_Cell)); | ||
1439 | BREAK; | ||
1440 | CASE(EMBRYO_OP_JZER); | ||
1441 | if (pri == 0) | ||
1442 | cip = JUMPABS(code, cip); | ||
1443 | else | ||
1444 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1445 | BREAK; | ||
1446 | CASE(EMBRYO_OP_JNZ); | ||
1447 | if (pri != 0) | ||
1448 | cip = JUMPABS(code, cip); | ||
1449 | else | ||
1450 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1451 | BREAK; | ||
1452 | CASE(EMBRYO_OP_JEQ); | ||
1453 | if (pri==alt) | ||
1454 | cip = JUMPABS(code, cip); | ||
1455 | else | ||
1456 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1457 | BREAK; | ||
1458 | CASE(EMBRYO_OP_JNEQ); | ||
1459 | if (pri != alt) | ||
1460 | cip = JUMPABS(code, cip); | ||
1461 | else | ||
1462 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1463 | BREAK; | ||
1464 | CASE(EMBRYO_OP_JLESS); | ||
1465 | if ((Embryo_UCell)pri < (Embryo_UCell)alt) | ||
1466 | cip = JUMPABS(code, cip); | ||
1467 | else | ||
1468 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1469 | BREAK; | ||
1470 | CASE(EMBRYO_OP_JLEQ); | ||
1471 | if ((Embryo_UCell)pri <= (Embryo_UCell)alt) | ||
1472 | cip = JUMPABS(code, cip); | ||
1473 | else | ||
1474 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1475 | BREAK; | ||
1476 | CASE(EMBRYO_OP_JGRTR); | ||
1477 | if ((Embryo_UCell)pri > (Embryo_UCell)alt) | ||
1478 | cip = JUMPABS(code, cip); | ||
1479 | else | ||
1480 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1481 | BREAK; | ||
1482 | CASE(EMBRYO_OP_JGEQ); | ||
1483 | if ((Embryo_UCell)pri >= (Embryo_UCell)alt) | ||
1484 | cip = JUMPABS(code, cip); | ||
1485 | else | ||
1486 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1487 | BREAK; | ||
1488 | CASE(EMBRYO_OP_JSLESS); | ||
1489 | if (pri < alt) | ||
1490 | cip = JUMPABS(code, cip); | ||
1491 | else | ||
1492 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1493 | BREAK; | ||
1494 | CASE(EMBRYO_OP_JSLEQ); | ||
1495 | if (pri <= alt) | ||
1496 | cip = JUMPABS(code, cip); | ||
1497 | else | ||
1498 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1499 | BREAK; | ||
1500 | CASE(EMBRYO_OP_JSGRTR); | ||
1501 | if (pri > alt) | ||
1502 | cip = JUMPABS(code, cip); | ||
1503 | else | ||
1504 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1505 | BREAK; | ||
1506 | CASE(EMBRYO_OP_JSGEQ); | ||
1507 | if (pri >= alt) | ||
1508 | cip = JUMPABS(code, cip); | ||
1509 | else | ||
1510 | cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); | ||
1511 | BREAK; | ||
1512 | CASE(EMBRYO_OP_SHL); | ||
1513 | pri <<= alt; | ||
1514 | BREAK; | ||
1515 | CASE(EMBRYO_OP_SHR); | ||
1516 | pri = (Embryo_UCell)pri >> (int)alt; | ||
1517 | BREAK; | ||
1518 | CASE(EMBRYO_OP_SSHR); | ||
1519 | pri >>= alt; | ||
1520 | BREAK; | ||
1521 | CASE(EMBRYO_OP_SHL_C_PRI); | ||
1522 | GETPARAM(offs); | ||
1523 | pri <<= offs; | ||
1524 | BREAK; | ||
1525 | CASE(EMBRYO_OP_SHL_C_ALT); | ||
1526 | GETPARAM(offs); | ||
1527 | alt <<= offs; | ||
1528 | BREAK; | ||
1529 | CASE(EMBRYO_OP_SHR_C_PRI); | ||
1530 | GETPARAM(offs); | ||
1531 | pri = (Embryo_UCell)pri >> (int)offs; | ||
1532 | BREAK; | ||
1533 | CASE(EMBRYO_OP_SHR_C_ALT); | ||
1534 | GETPARAM(offs); | ||
1535 | alt = (Embryo_UCell)alt >> (int)offs; | ||
1536 | BREAK; | ||
1537 | CASE(EMBRYO_OP_SMUL); | ||
1538 | pri *= alt; | ||
1539 | BREAK; | ||
1540 | CASE(EMBRYO_OP_SDIV); | ||
1541 | if (alt == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); | ||
1542 | /* divide must always round down; this is a bit | ||
1543 | * involved to do in a machine-independent way. | ||
1544 | */ | ||
1545 | offs = ((pri % alt) + alt) % alt; /* true modulus */ | ||
1546 | pri = (pri - offs) / alt; /* division result */ | ||
1547 | alt = offs; | ||
1548 | BREAK; | ||
1549 | CASE(EMBRYO_OP_SDIV_ALT); | ||
1550 | if (pri == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); | ||
1551 | /* divide must always round down; this is a bit | ||
1552 | * involved to do in a machine-independent way. | ||
1553 | */ | ||
1554 | offs = ((alt % pri) + pri) % pri; /* true modulus */ | ||
1555 | pri = (alt - offs) / pri; /* division result */ | ||
1556 | alt = offs; | ||
1557 | BREAK; | ||
1558 | CASE(EMBRYO_OP_UMUL); | ||
1559 | pri = (Embryo_UCell)pri * (Embryo_UCell)alt; | ||
1560 | BREAK; | ||
1561 | CASE(EMBRYO_OP_UDIV); | ||
1562 | if (alt == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); | ||
1563 | offs = (Embryo_UCell)pri % (Embryo_UCell)alt; /* temporary storage */ | ||
1564 | pri = (Embryo_UCell)pri / (Embryo_UCell)alt; | ||
1565 | alt = offs; | ||
1566 | BREAK; | ||
1567 | CASE(EMBRYO_OP_UDIV_ALT); | ||
1568 | if (pri == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); | ||
1569 | offs = (Embryo_UCell)alt % (Embryo_UCell)pri; /* temporary storage */ | ||
1570 | pri = (Embryo_UCell)alt / (Embryo_UCell)pri; | ||
1571 | alt = offs; | ||
1572 | BREAK; | ||
1573 | CASE(EMBRYO_OP_ADD); | ||
1574 | pri += alt; | ||
1575 | BREAK; | ||
1576 | CASE(EMBRYO_OP_SUB); | ||
1577 | pri -= alt; | ||
1578 | BREAK; | ||
1579 | CASE(EMBRYO_OP_SUB_ALT); | ||
1580 | pri = alt - pri; | ||
1581 | BREAK; | ||
1582 | CASE(EMBRYO_OP_AND); | ||
1583 | pri &= alt; | ||
1584 | BREAK; | ||
1585 | CASE(EMBRYO_OP_OR); | ||
1586 | pri |= alt; | ||
1587 | BREAK; | ||
1588 | CASE(EMBRYO_OP_XOR); | ||
1589 | pri ^= alt; | ||
1590 | BREAK; | ||
1591 | CASE(EMBRYO_OP_NOT); | ||
1592 | pri = !pri; | ||
1593 | BREAK; | ||
1594 | CASE(EMBRYO_OP_NEG); | ||
1595 | pri = -pri; | ||
1596 | BREAK; | ||
1597 | CASE(EMBRYO_OP_INVERT); | ||
1598 | pri = ~pri; | ||
1599 | BREAK; | ||
1600 | CASE(EMBRYO_OP_ADD_C); | ||
1601 | GETPARAM(offs); | ||
1602 | pri += offs; | ||
1603 | BREAK; | ||
1604 | CASE(EMBRYO_OP_SMUL_C); | ||
1605 | GETPARAM(offs); | ||
1606 | pri *= offs; | ||
1607 | BREAK; | ||
1608 | CASE(EMBRYO_OP_ZERO_PRI); | ||
1609 | pri = 0; | ||
1610 | BREAK; | ||
1611 | CASE(EMBRYO_OP_ZERO_ALT); | ||
1612 | alt = 0; | ||
1613 | BREAK; | ||
1614 | CASE(EMBRYO_OP_ZERO); | ||
1615 | GETPARAM(offs); | ||
1616 | *(Embryo_Cell *)(data + (int)offs) = 0; | ||
1617 | BREAK; | ||
1618 | CASE(EMBRYO_OP_ZERO_S); | ||
1619 | GETPARAM(offs); | ||
1620 | *(Embryo_Cell *)(data + (int)frm + (int)offs) = 0; | ||
1621 | BREAK; | ||
1622 | CASE(EMBRYO_OP_SIGN_PRI); | ||
1623 | if ((pri & 0xff) >= 0x80) pri |= ~(Embryo_UCell)0xff; | ||
1624 | BREAK; | ||
1625 | CASE(EMBRYO_OP_SIGN_ALT); | ||
1626 | if ((alt & 0xff) >= 0x80) alt |= ~(Embryo_UCell)0xff; | ||
1627 | BREAK; | ||
1628 | CASE(EMBRYO_OP_EQ); | ||
1629 | pri = (pri == alt) ? 1 : 0; | ||
1630 | BREAK; | ||
1631 | CASE(EMBRYO_OP_NEQ); | ||
1632 | pri = (pri != alt) ? 1 : 0; | ||
1633 | BREAK; | ||
1634 | CASE(EMBRYO_OP_LESS); | ||
1635 | pri = ((Embryo_UCell)pri < (Embryo_UCell)alt) ? 1 : 0; | ||
1636 | BREAK; | ||
1637 | CASE(EMBRYO_OP_LEQ); | ||
1638 | pri = ((Embryo_UCell)pri <= (Embryo_UCell)alt) ? 1 : 0; | ||
1639 | BREAK; | ||
1640 | CASE(EMBRYO_OP_GRTR); | ||
1641 | pri = ((Embryo_UCell)pri > (Embryo_UCell)alt) ? 1 : 0; | ||
1642 | BREAK; | ||
1643 | CASE(EMBRYO_OP_GEQ); | ||
1644 | pri = ((Embryo_UCell)pri >= (Embryo_UCell)alt) ? 1 : 0; | ||
1645 | BREAK; | ||
1646 | CASE(EMBRYO_OP_SLESS); | ||
1647 | pri = (pri < alt) ? 1 : 0; | ||
1648 | BREAK; | ||
1649 | CASE(EMBRYO_OP_SLEQ); | ||
1650 | pri = (pri <= alt) ? 1 : 0; | ||
1651 | BREAK; | ||
1652 | CASE(EMBRYO_OP_SGRTR); | ||
1653 | pri = (pri > alt) ? 1 : 0; | ||
1654 | BREAK; | ||
1655 | CASE(EMBRYO_OP_SGEQ); | ||
1656 | pri = (pri >= alt) ? 1 : 0; | ||
1657 | BREAK; | ||
1658 | CASE(EMBRYO_OP_EQ_C_PRI); | ||
1659 | GETPARAM(offs); | ||
1660 | pri = (pri == offs) ? 1 : 0; | ||
1661 | BREAK; | ||
1662 | CASE(EMBRYO_OP_EQ_C_ALT); | ||
1663 | GETPARAM(offs); | ||
1664 | pri = (alt == offs) ? 1 : 0; | ||
1665 | BREAK; | ||
1666 | CASE(EMBRYO_OP_INC_PRI); | ||
1667 | pri++; | ||
1668 | BREAK; | ||
1669 | CASE(EMBRYO_OP_INC_ALT); | ||
1670 | alt++; | ||
1671 | BREAK; | ||
1672 | CASE(EMBRYO_OP_INC); | ||
1673 | GETPARAM(offs); | ||
1674 | *(Embryo_Cell *)(data + (int)offs) += 1; | ||
1675 | BREAK; | ||
1676 | CASE(EMBRYO_OP_INC_S); | ||
1677 | GETPARAM(offs); | ||
1678 | *(Embryo_Cell *)(data + (int)frm + (int)offs) += 1; | ||
1679 | BREAK; | ||
1680 | CASE(EMBRYO_OP_INC_I); | ||
1681 | *(Embryo_Cell *)(data + (int)pri) += 1; | ||
1682 | BREAK; | ||
1683 | CASE(EMBRYO_OP_DEC_PRI); | ||
1684 | pri--; | ||
1685 | BREAK; | ||
1686 | CASE(EMBRYO_OP_DEC_ALT); | ||
1687 | alt--; | ||
1688 | BREAK; | ||
1689 | CASE(EMBRYO_OP_DEC); | ||
1690 | GETPARAM(offs); | ||
1691 | *(Embryo_Cell *)(data + (int)offs) -= 1; | ||
1692 | BREAK; | ||
1693 | CASE(EMBRYO_OP_DEC_S); | ||
1694 | GETPARAM(offs); | ||
1695 | *(Embryo_Cell *)(data + (int)frm + (int)offs) -= 1; | ||
1696 | BREAK; | ||
1697 | CASE(EMBRYO_OP_DEC_I); | ||
1698 | *(Embryo_Cell *)(data + (int)pri) -= 1; | ||
1699 | BREAK; | ||
1700 | CASE(EMBRYO_OP_MOVS); | ||
1701 | GETPARAM(offs); | ||
1702 | CHKMEM(pri); | ||
1703 | CHKMEM(pri + offs); | ||
1704 | CHKMEM(alt); | ||
1705 | CHKMEM(alt + offs); | ||
1706 | memcpy(data+(int)alt, data+(int)pri, (int)offs); | ||
1707 | BREAK; | ||
1708 | CASE(EMBRYO_OP_CMPS); | ||
1709 | GETPARAM(offs); | ||
1710 | CHKMEM(pri); | ||
1711 | CHKMEM(pri + offs); | ||
1712 | CHKMEM(alt); | ||
1713 | CHKMEM(alt + offs); | ||
1714 | pri = memcmp(data + (int)alt, data + (int)pri, (int)offs); | ||
1715 | BREAK; | ||
1716 | CASE(EMBRYO_OP_FILL); | ||
1717 | GETPARAM(offs); | ||
1718 | CHKMEM(alt); | ||
1719 | CHKMEM(alt + offs); | ||
1720 | for (i = (int)alt; | ||
1721 | (size_t)offs >= sizeof(Embryo_Cell); | ||
1722 | i += sizeof(Embryo_Cell), offs -= sizeof(Embryo_Cell)) | ||
1723 | *(Embryo_Cell *)(data + i) = pri; | ||
1724 | BREAK; | ||
1725 | CASE(EMBRYO_OP_HALT); | ||
1726 | GETPARAM(offs); | ||
1727 | ep->retval = pri; | ||
1728 | /* store complete status */ | ||
1729 | ep->frm = frm; | ||
1730 | ep->stk = stk; | ||
1731 | ep->hea = hea; | ||
1732 | ep->pri = pri; | ||
1733 | ep->alt = alt; | ||
1734 | ep->cip = (Embryo_Cell)((unsigned char*)cip - code); | ||
1735 | if (offs == EMBRYO_ERROR_SLEEP) | ||
1736 | { | ||
1737 | ep->reset_stk = reset_stk; | ||
1738 | ep->reset_hea = reset_hea; | ||
1739 | ep->run_count--; | ||
1740 | return EMBRYO_PROGRAM_SLEEP; | ||
1741 | } | ||
1742 | OK(ep, (int)offs); | ||
1743 | CASE(EMBRYO_OP_BOUNDS); | ||
1744 | GETPARAM(offs); | ||
1745 | if ((Embryo_UCell)pri > (Embryo_UCell)offs) | ||
1746 | ABORT(ep, EMBRYO_ERROR_BOUNDS); | ||
1747 | BREAK; | ||
1748 | CASE(EMBRYO_OP_SYSREQ_PRI); | ||
1749 | /* save a few registers */ | ||
1750 | ep->cip = (Embryo_Cell)((unsigned char *)cip - code); | ||
1751 | ep->hea = hea; | ||
1752 | ep->frm = frm; | ||
1753 | ep->stk = stk; | ||
1754 | num = _embryo_native_call(ep, pri, &pri, (Embryo_Cell *)(data + (int)stk)); | ||
1755 | if (num != EMBRYO_ERROR_NONE) | ||
1756 | { | ||
1757 | if (num == EMBRYO_ERROR_SLEEP) | ||
1758 | { | ||
1759 | ep->pri = pri; | ||
1760 | ep->alt = alt; | ||
1761 | ep->reset_stk = reset_stk; | ||
1762 | ep->reset_hea = reset_hea; | ||
1763 | ep->run_count--; | ||
1764 | return EMBRYO_PROGRAM_SLEEP; | ||
1765 | } | ||
1766 | ABORT(ep, num); | ||
1767 | } | ||
1768 | BREAK; | ||
1769 | CASE(EMBRYO_OP_SYSREQ_C); | ||
1770 | GETPARAM(offs); | ||
1771 | /* save a few registers */ | ||
1772 | ep->cip = (Embryo_Cell)((unsigned char *)cip - code); | ||
1773 | ep->hea = hea; | ||
1774 | ep->frm = frm; | ||
1775 | ep->stk = stk; | ||
1776 | num = _embryo_native_call(ep, offs, &pri, (Embryo_Cell *)(data + (int)stk)); | ||
1777 | if (num != EMBRYO_ERROR_NONE) | ||
1778 | { | ||
1779 | if (num == EMBRYO_ERROR_SLEEP) | ||
1780 | { | ||
1781 | ep->pri = pri; | ||
1782 | ep->alt = alt; | ||
1783 | ep->reset_stk = reset_stk; | ||
1784 | ep->reset_hea = reset_hea; | ||
1785 | ep->run_count--; | ||
1786 | return EMBRYO_PROGRAM_SLEEP; | ||
1787 | } | ||
1788 | { | ||
1789 | Embryo_Header *hdr; | ||
1790 | int i, num; | ||
1791 | Embryo_Func_Stub *func_entry; | ||
1792 | |||
1793 | hdr = (Embryo_Header *)ep->code; | ||
1794 | num = NUMENTRIES(hdr, natives, libraries); | ||
1795 | func_entry = GETENTRY(hdr, natives, 0); | ||
1796 | for (i = 0; i < num; i++) | ||
1797 | { | ||
1798 | char *entry_name; | ||
1799 | |||
1800 | entry_name = GETENTRYNAME(hdr, func_entry); | ||
1801 | if (i == offs) | ||
1802 | printf("EMBRYO: CALL [%i] %s() non-existent!\n", i, entry_name); | ||
1803 | func_entry = | ||
1804 | (Embryo_Func_Stub *)((unsigned char *)func_entry + hdr->defsize); | ||
1805 | } | ||
1806 | } | ||
1807 | ABORT(ep, num); | ||
1808 | } | ||
1809 | BREAK; | ||
1810 | CASE(EMBRYO_OP_SYSREQ_D); | ||
1811 | GETPARAM(offs); | ||
1812 | /* save a few registers */ | ||
1813 | ep->cip = (Embryo_Cell)((unsigned char *)cip - code); | ||
1814 | ep->hea = hea; | ||
1815 | ep->frm = frm; | ||
1816 | ep->stk = stk; | ||
1817 | num = _embryo_native_call(ep, offs, &pri, (Embryo_Cell *)(data + (int)stk)); | ||
1818 | if (num != EMBRYO_ERROR_NONE) | ||
1819 | { | ||
1820 | if (num == EMBRYO_ERROR_SLEEP) | ||
1821 | { | ||
1822 | ep->pri = pri; | ||
1823 | ep->alt = alt; | ||
1824 | ep->reset_stk = reset_stk; | ||
1825 | ep->reset_hea = reset_hea; | ||
1826 | ep->run_count--; | ||
1827 | return EMBRYO_PROGRAM_SLEEP; | ||
1828 | } | ||
1829 | ABORT(ep, ep->error); | ||
1830 | } | ||
1831 | BREAK; | ||
1832 | CASE(EMBRYO_OP_JUMP_PRI); | ||
1833 | cip = (Embryo_Cell *)(code + (int)pri); | ||
1834 | BREAK; | ||
1835 | CASE(EMBRYO_OP_SWITCH); | ||
1836 | { | ||
1837 | Embryo_Cell *cptr; | ||
1838 | |||
1839 | /* +1, to skip the "casetbl" opcode */ | ||
1840 | cptr = (Embryo_Cell *)(code + (*cip)) + 1; | ||
1841 | /* number of records in the case table */ | ||
1842 | num = (int)(*cptr); | ||
1843 | /* preset to "none-matched" case */ | ||
1844 | cip = (Embryo_Cell *)(code + *(cptr + 1)); | ||
1845 | for (cptr += 2; | ||
1846 | (num > 0) && (*cptr != pri); | ||
1847 | num--, cptr += 2); | ||
1848 | /* case found */ | ||
1849 | if (num > 0) | ||
1850 | cip = (Embryo_Cell *)(code + *(cptr + 1)); | ||
1851 | } | ||
1852 | BREAK; | ||
1853 | CASE(EMBRYO_OP_SWAP_PRI); | ||
1854 | offs = *(Embryo_Cell *)(data + (int)stk); | ||
1855 | *(Embryo_Cell *)(data + (int)stk) = pri; | ||
1856 | pri = offs; | ||
1857 | BREAK; | ||
1858 | CASE(EMBRYO_OP_SWAP_ALT); | ||
1859 | offs = *(Embryo_Cell *)(data + (int)stk); | ||
1860 | *(Embryo_Cell *)(data + (int)stk) = alt; | ||
1861 | alt = offs; | ||
1862 | BREAK; | ||
1863 | CASE(EMBRYO_OP_PUSHADDR); | ||
1864 | GETPARAM(offs); | ||
1865 | PUSH(frm + offs); | ||
1866 | BREAK; | ||
1867 | CASE(EMBRYO_OP_NOP); | ||
1868 | BREAK; | ||
1869 | CASE(EMBRYO_OP_NONE); | ||
1870 | CASE(EMBRYO_OP_FILE); | ||
1871 | CASE(EMBRYO_OP_LINE); | ||
1872 | CASE(EMBRYO_OP_SYMBOL); | ||
1873 | CASE(EMBRYO_OP_SRANGE); | ||
1874 | CASE(EMBRYO_OP_CASETBL); | ||
1875 | CASE(EMBRYO_OP_SYMTAG); | ||
1876 | BREAK; | ||
1877 | #ifndef EMBRYO_EXEC_JUMPTABLE | ||
1878 | default: | ||
1879 | ABORT(ep, EMBRYO_ERROR_INVINSTR); | ||
1880 | #endif | ||
1881 | SWITCHEND; | ||
1882 | } | ||
1883 | ep->max_run_cycles = max_run_cycles; | ||
1884 | ep->run_count--; | ||
1885 | ep->hea = hea_start; | ||
1886 | return EMBRYO_PROGRAM_OK; | ||
1887 | } | ||
1888 | |||
1889 | EAPI Embryo_Cell | ||
1890 | embryo_program_return_value_get(Embryo_Program *ep) | ||
1891 | { | ||
1892 | if (!ep) return 0; | ||
1893 | return ep->retval; | ||
1894 | } | ||
1895 | |||
1896 | EAPI void | ||
1897 | embryo_program_max_cycle_run_set(Embryo_Program *ep, int max) | ||
1898 | { | ||
1899 | if (!ep) return; | ||
1900 | if (max < 0) max = 0; | ||
1901 | ep->max_run_cycles = max; | ||
1902 | } | ||
1903 | |||
1904 | EAPI int | ||
1905 | embryo_program_max_cycle_run_get(Embryo_Program *ep) | ||
1906 | { | ||
1907 | if (!ep) return 0; | ||
1908 | return ep->max_run_cycles; | ||
1909 | } | ||
1910 | |||
1911 | |||
1912 | EAPI int | ||
1913 | embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell) | ||
1914 | { | ||
1915 | Embryo_Param *pr; | ||
1916 | |||
1917 | ep->params_size++; | ||
1918 | if (ep->params_size > ep->params_alloc) | ||
1919 | { | ||
1920 | ep->params_alloc += 8; | ||
1921 | pr = realloc(ep->params, ep->params_alloc * sizeof(Embryo_Param)); | ||
1922 | if (!pr) return 0; | ||
1923 | ep->params = pr; | ||
1924 | } | ||
1925 | pr = &(ep->params[ep->params_size - 1]); | ||
1926 | pr->string = NULL; | ||
1927 | pr->cell_array = NULL; | ||
1928 | pr->cell_array_size = 0; | ||
1929 | pr->cell = 0; | ||
1930 | pr->cell = cell; | ||
1931 | return 1; | ||
1932 | } | ||
1933 | |||
1934 | EAPI int | ||
1935 | embryo_parameter_string_push(Embryo_Program *ep, const char *str) | ||
1936 | { | ||
1937 | Embryo_Param *pr; | ||
1938 | char *str_dup; | ||
1939 | |||
1940 | if (!str) | ||
1941 | return embryo_parameter_string_push(ep, ""); | ||
1942 | str_dup = strdup(str); | ||
1943 | if (!str_dup) return 0; | ||
1944 | ep->params_size++; | ||
1945 | if (ep->params_size > ep->params_alloc) | ||
1946 | { | ||
1947 | ep->params_alloc += 8; | ||
1948 | pr = realloc(ep->params, ep->params_alloc * sizeof(Embryo_Param)); | ||
1949 | if (!pr) | ||
1950 | { | ||
1951 | free(str_dup); | ||
1952 | return 0; | ||
1953 | } | ||
1954 | ep->params = pr; | ||
1955 | } | ||
1956 | pr = &(ep->params[ep->params_size - 1]); | ||
1957 | pr->string = NULL; | ||
1958 | pr->cell_array = NULL; | ||
1959 | pr->cell_array_size = 0; | ||
1960 | pr->cell = 0; | ||
1961 | pr->string = str_dup; | ||
1962 | return 1; | ||
1963 | } | ||
1964 | |||
1965 | EAPI int | ||
1966 | embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num) | ||
1967 | { | ||
1968 | Embryo_Param *pr; | ||
1969 | Embryo_Cell *cell_array; | ||
1970 | |||
1971 | if ((!cells) || (num <= 0)) | ||
1972 | return embryo_parameter_cell_push(ep, 0); | ||
1973 | cell_array = malloc(num * sizeof(Embryo_Cell)); | ||
1974 | ep->params_size++; | ||
1975 | if (ep->params_size > ep->params_alloc) | ||
1976 | { | ||
1977 | ep->params_alloc += 8; | ||
1978 | pr = realloc(ep->params, ep->params_alloc * sizeof(Embryo_Param)); | ||
1979 | if (!pr) | ||
1980 | { | ||
1981 | free(cell_array); | ||
1982 | return 0; | ||
1983 | } | ||
1984 | ep->params = pr; | ||
1985 | } | ||
1986 | pr = &(ep->params[ep->params_size - 1]); | ||
1987 | pr->string = NULL; | ||
1988 | pr->cell_array = NULL; | ||
1989 | pr->cell_array_size = 0; | ||
1990 | pr->cell = 0; | ||
1991 | pr->cell_array = cell_array; | ||
1992 | pr->cell_array_size = num; | ||
1993 | memcpy(pr->cell_array, cells, num * sizeof(Embryo_Cell)); | ||
1994 | return 1; | ||
1995 | } | ||
diff --git a/libraries/embryo/src/lib/embryo_args.c b/libraries/embryo/src/lib/embryo_args.c deleted file mode 100644 index 0c0089e..0000000 --- a/libraries/embryo/src/lib/embryo_args.c +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #ifdef HAVE_ALLOCA_H | ||
6 | # include <alloca.h> | ||
7 | #elif defined __GNUC__ | ||
8 | # define alloca __builtin_alloca | ||
9 | #elif defined _AIX | ||
10 | # define alloca __alloca | ||
11 | #elif defined _MSC_VER | ||
12 | # include <malloc.h> | ||
13 | # define alloca _alloca | ||
14 | #else | ||
15 | # include <stddef.h> | ||
16 | # ifdef __cplusplus | ||
17 | extern "C" | ||
18 | # endif | ||
19 | void *alloca (size_t); | ||
20 | #endif | ||
21 | |||
22 | #include "Embryo.h" | ||
23 | #include "embryo_private.h" | ||
24 | |||
25 | #define STRSET(ep, par, str) { \ | ||
26 | Embryo_Cell *___cptr; \ | ||
27 | if ((___cptr = embryo_data_address_get(ep, par))) { \ | ||
28 | embryo_data_string_set(ep, str, ___cptr); \ | ||
29 | } } | ||
30 | |||
31 | /* exported args api */ | ||
32 | |||
33 | static Embryo_Cell | ||
34 | _embryo_args_numargs(Embryo_Program *ep, Embryo_Cell *params __UNUSED__) | ||
35 | { | ||
36 | Embryo_Header *hdr; | ||
37 | unsigned char *data; | ||
38 | Embryo_Cell bytes; | ||
39 | |||
40 | hdr = (Embryo_Header *)ep->base; | ||
41 | data = ep->base + (int)hdr->dat; | ||
42 | bytes = *(Embryo_Cell *)(data + (int)ep->frm + | ||
43 | (2 * sizeof(Embryo_Cell))); | ||
44 | return bytes / sizeof(Embryo_Cell); | ||
45 | } | ||
46 | |||
47 | static Embryo_Cell | ||
48 | _embryo_args_getarg(Embryo_Program *ep, Embryo_Cell *params) | ||
49 | { | ||
50 | Embryo_Header *hdr; | ||
51 | unsigned char *data; | ||
52 | Embryo_Cell val; | ||
53 | |||
54 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
55 | hdr = (Embryo_Header *)ep->base; | ||
56 | data = ep->base + (int)hdr->dat; | ||
57 | val = *(Embryo_Cell *)(data + (int)ep->frm + | ||
58 | (((int)params[1] + 3) * sizeof(Embryo_Cell))); | ||
59 | val += params[2] * sizeof(Embryo_Cell); | ||
60 | val = *(Embryo_Cell *)(data + (int)val); | ||
61 | return val; | ||
62 | } | ||
63 | |||
64 | static Embryo_Cell | ||
65 | _embryo_args_setarg(Embryo_Program *ep, Embryo_Cell *params) | ||
66 | { | ||
67 | Embryo_Header *hdr; | ||
68 | unsigned char *data; | ||
69 | Embryo_Cell val; | ||
70 | |||
71 | if (params[0] != (3 * sizeof(Embryo_Cell))) return 0; | ||
72 | hdr = (Embryo_Header *)ep->base; | ||
73 | data = ep->base + (int)hdr->dat; | ||
74 | val = *(Embryo_Cell *)(data + (int)ep->frm + | ||
75 | (((int)params[1] + 3) * sizeof(Embryo_Cell))); | ||
76 | val += params[2] * sizeof(Embryo_Cell); | ||
77 | if ((val < 0) || ((val >= ep->hea) && (val < ep->stk))) return 0; | ||
78 | *(Embryo_Cell *)(data + (int)val) = params[3]; | ||
79 | return 1; | ||
80 | } | ||
81 | |||
82 | static Embryo_Cell | ||
83 | _embryo_args_getsarg(Embryo_Program *ep, Embryo_Cell *params) | ||
84 | { | ||
85 | Embryo_Header *hdr; | ||
86 | unsigned char *data; | ||
87 | Embryo_Cell base_cell; | ||
88 | char *s; | ||
89 | int i = 0; | ||
90 | |||
91 | /* params[1] = arg_no */ | ||
92 | /* params[2] = buf */ | ||
93 | /* params[3] = buflen */ | ||
94 | if (params[0] != (3 * sizeof(Embryo_Cell))) return 0; | ||
95 | if (params[3] <= 0) return 0; /* buflen must be > 0 */ | ||
96 | hdr = (Embryo_Header *)ep->base; | ||
97 | data = ep->base + (int)hdr->dat; | ||
98 | base_cell = *(Embryo_Cell *)(data + (int)ep->frm + | ||
99 | (((int)params[1] + 3) * sizeof(Embryo_Cell))); | ||
100 | |||
101 | s = alloca(params[3]); | ||
102 | |||
103 | while (i < params[3]) | ||
104 | { | ||
105 | int offset = base_cell + (i * sizeof(Embryo_Cell)); | ||
106 | |||
107 | s[i] = *(Embryo_Cell *)(data + offset); | ||
108 | if (!s[i++]) break; | ||
109 | } | ||
110 | |||
111 | s[i - 1] = 0; | ||
112 | STRSET(ep, params[2], s); | ||
113 | |||
114 | return i - 1; /* characters written minus terminator */ | ||
115 | } | ||
116 | |||
117 | /* functions used by the rest of embryo */ | ||
118 | |||
119 | void | ||
120 | _embryo_args_init(Embryo_Program *ep) | ||
121 | { | ||
122 | embryo_program_native_call_add(ep, "numargs", _embryo_args_numargs); | ||
123 | embryo_program_native_call_add(ep, "getarg", _embryo_args_getarg); | ||
124 | embryo_program_native_call_add(ep, "setarg", _embryo_args_setarg); | ||
125 | embryo_program_native_call_add(ep, "getfarg", _embryo_args_getarg); | ||
126 | embryo_program_native_call_add(ep, "setfarg", _embryo_args_setarg); | ||
127 | embryo_program_native_call_add(ep, "getsarg", _embryo_args_getsarg); | ||
128 | } | ||
diff --git a/libraries/embryo/src/lib/embryo_float.c b/libraries/embryo/src/lib/embryo_float.c deleted file mode 100644 index 608be9d..0000000 --- a/libraries/embryo/src/lib/embryo_float.c +++ /dev/null | |||
@@ -1,331 +0,0 @@ | |||
1 | /* Float arithmetic for the Small AMX engine | ||
2 | * | ||
3 | * Copyright (c) Artran, Inc. 1999 | ||
4 | * Written by Greg Garner (gmg@artran.com) | ||
5 | * Portions Copyright (c) Carsten Haitzler, 2004 <raster@rasterman.com> | ||
6 | * | ||
7 | * This software is provided "as-is", without any express or implied warranty. | ||
8 | * In no event will the authors be held liable for any damages arising from | ||
9 | * the use of this software. | ||
10 | * | ||
11 | * Permission is granted to anyone to use this software for any purpose, | ||
12 | * including commercial applications, and to alter it and redistribute it | ||
13 | * freely, subject to the following restrictions: | ||
14 | * | ||
15 | * 1. The origin of this software must not be misrepresented; you must not | ||
16 | * claim that you wrote the original software. If you use this software in | ||
17 | * a product, an acknowledgment in the product documentation would be | ||
18 | * appreciated but is not required. | ||
19 | * 2. Altered source versions must be plainly marked as such, and must not be | ||
20 | * misrepresented as being the original software. | ||
21 | * 3. This notice may not be removed or altered from any source distribution. | ||
22 | */ | ||
23 | |||
24 | /* CHANGES - | ||
25 | * 2002-08-27: Basic conversion of source from C++ to C by Adam D. Moss | ||
26 | * <adam@gimp.org> <aspirin@icculus.org> | ||
27 | * 2003-08-29: Removal of the dynamic memory allocation and replacing two | ||
28 | * type conversion functions by macros, by Thiadmer Riemersma | ||
29 | * 2003-09-22: Moved the type conversion macros to AMX.H, and simplifications | ||
30 | * of some routines, by Thiadmer Riemersma | ||
31 | * 2003-11-24: A few more native functions (geometry), plus minor modifications, | ||
32 | * mostly to be compatible with dynamically loadable extension | ||
33 | * modules, by Thiadmer Riemersma | ||
34 | * 2004-03-20: Cleaned up and reduced size for Embryo, Modified to conform to | ||
35 | * E coding style. Added extra parameter checks. | ||
36 | * Carsten Haitzler, <raster@rasterman.com> | ||
37 | */ | ||
38 | |||
39 | |||
40 | #ifdef HAVE_CONFIG_H | ||
41 | # include "config.h" | ||
42 | #endif | ||
43 | |||
44 | #include <stdlib.h> | ||
45 | #include <math.h> | ||
46 | |||
47 | #include "Embryo.h" | ||
48 | #include "embryo_private.h" | ||
49 | |||
50 | #define PI 3.1415926535897932384626433832795f | ||
51 | |||
52 | /* internally useful calls */ | ||
53 | |||
54 | static float | ||
55 | _embryo_fp_degrees_to_radians(float angle, int radix) | ||
56 | { | ||
57 | switch (radix) | ||
58 | { | ||
59 | case 1: /* degrees, sexagesimal system (technically: degrees/minutes/seconds) */ | ||
60 | return (angle * PI / 180.0f); | ||
61 | case 2: /* grades, centesimal system */ | ||
62 | return (angle * PI / 200.0f); | ||
63 | default: /* assume already radian */ | ||
64 | break; | ||
65 | } | ||
66 | return angle; | ||
67 | } | ||
68 | |||
69 | /* exported float api */ | ||
70 | |||
71 | static Embryo_Cell | ||
72 | _embryo_fp(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
73 | { | ||
74 | /* params[1] = long value to convert to a float */ | ||
75 | float f; | ||
76 | |||
77 | if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; | ||
78 | f = (float)params[1]; | ||
79 | return EMBRYO_FLOAT_TO_CELL(f); | ||
80 | } | ||
81 | |||
82 | static Embryo_Cell | ||
83 | _embryo_fp_str(Embryo_Program *ep, Embryo_Cell *params) | ||
84 | { | ||
85 | /* params[1] = virtual string address to convert to a float */ | ||
86 | char buf[64]; | ||
87 | Embryo_Cell *str; | ||
88 | float f; | ||
89 | int len; | ||
90 | |||
91 | if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; | ||
92 | str = embryo_data_address_get(ep, params[1]); | ||
93 | len = embryo_data_string_length_get(ep, str); | ||
94 | if ((len == 0) || (len >= (int)sizeof(buf))) return 0; | ||
95 | embryo_data_string_get(ep, str, buf); | ||
96 | f = (float)atof(buf); | ||
97 | return EMBRYO_FLOAT_TO_CELL(f); | ||
98 | } | ||
99 | |||
100 | static Embryo_Cell | ||
101 | _embryo_fp_mul(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
102 | { | ||
103 | /* params[1] = float operand 1 */ | ||
104 | /* params[2] = float operand 2 */ | ||
105 | float f; | ||
106 | |||
107 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
108 | f = EMBRYO_CELL_TO_FLOAT(params[1]) * EMBRYO_CELL_TO_FLOAT(params[2]); | ||
109 | return EMBRYO_FLOAT_TO_CELL(f); | ||
110 | } | ||
111 | |||
112 | static Embryo_Cell | ||
113 | _embryo_fp_div(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
114 | { | ||
115 | /* params[1] = float dividend (top) */ | ||
116 | /* params[2] = float divisor (bottom) */ | ||
117 | float f; | ||
118 | |||
119 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
120 | f = EMBRYO_CELL_TO_FLOAT(params[1]) / EMBRYO_CELL_TO_FLOAT(params[2]); | ||
121 | return EMBRYO_FLOAT_TO_CELL(f); | ||
122 | } | ||
123 | |||
124 | static Embryo_Cell | ||
125 | _embryo_fp_add(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
126 | { | ||
127 | /* params[1] = float operand 1 */ | ||
128 | /* params[2] = float operand 2 */ | ||
129 | float f; | ||
130 | |||
131 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
132 | f = EMBRYO_CELL_TO_FLOAT(params[1]) + EMBRYO_CELL_TO_FLOAT(params[2]); | ||
133 | return EMBRYO_FLOAT_TO_CELL(f); | ||
134 | } | ||
135 | |||
136 | static Embryo_Cell | ||
137 | _embryo_fp_sub(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
138 | { | ||
139 | /* params[1] = float operand 1 */ | ||
140 | /* params[2] = float operand 2 */ | ||
141 | float f; | ||
142 | |||
143 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
144 | f = EMBRYO_CELL_TO_FLOAT(params[1]) - EMBRYO_CELL_TO_FLOAT(params[2]); | ||
145 | return EMBRYO_FLOAT_TO_CELL(f); | ||
146 | } | ||
147 | |||
148 | /* Return fractional part of float */ | ||
149 | static Embryo_Cell | ||
150 | _embryo_fp_fract(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
151 | { | ||
152 | /* params[1] = float operand */ | ||
153 | float f; | ||
154 | |||
155 | if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; | ||
156 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
157 | f -= (floorf(f)); | ||
158 | return EMBRYO_FLOAT_TO_CELL(f); | ||
159 | } | ||
160 | |||
161 | /* Return integer part of float, rounded */ | ||
162 | static Embryo_Cell | ||
163 | _embryo_fp_round(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
164 | { | ||
165 | /* params[1] = float operand */ | ||
166 | /* params[2] = Type of rounding (cell) */ | ||
167 | float f; | ||
168 | |||
169 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
170 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
171 | switch (params[2]) | ||
172 | { | ||
173 | case 1: /* round downwards (truncate) */ | ||
174 | f = (floorf(f)); | ||
175 | break; | ||
176 | case 2: /* round upwards */ | ||
177 | f = (ceilf(f)); | ||
178 | break; | ||
179 | case 3: /* round towards zero */ | ||
180 | if (f >= 0.0) f = (floorf(f)); | ||
181 | else f = (ceilf(f)); | ||
182 | break; | ||
183 | default: /* standard, round to nearest */ | ||
184 | f = (floorf(f + 0.5)); | ||
185 | break; | ||
186 | } | ||
187 | return (Embryo_Cell)f; | ||
188 | } | ||
189 | |||
190 | static Embryo_Cell | ||
191 | _embryo_fp_cmp(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
192 | { | ||
193 | /* params[1] = float operand 1 */ | ||
194 | /* params[2] = float operand 2 */ | ||
195 | float f, ff; | ||
196 | |||
197 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
198 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
199 | ff = EMBRYO_CELL_TO_FLOAT(params[2]); | ||
200 | if (f == ff) return 0; | ||
201 | else if (f > ff) return 1; | ||
202 | return -1; | ||
203 | } | ||
204 | |||
205 | static Embryo_Cell | ||
206 | _embryo_fp_sqroot(Embryo_Program *ep, Embryo_Cell *params) | ||
207 | { | ||
208 | /* params[1] = float operand */ | ||
209 | float f; | ||
210 | |||
211 | if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; | ||
212 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
213 | f = sqrtf(f); | ||
214 | if (f < 0) | ||
215 | { | ||
216 | embryo_program_error_set(ep, EMBRYO_ERROR_DOMAIN); | ||
217 | return 0; | ||
218 | } | ||
219 | return EMBRYO_FLOAT_TO_CELL(f); | ||
220 | } | ||
221 | |||
222 | static Embryo_Cell | ||
223 | _embryo_fp_power(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
224 | { | ||
225 | /* params[1] = float operand 1 */ | ||
226 | /* params[2] = float operand 2 */ | ||
227 | float f, ff; | ||
228 | |||
229 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
230 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
231 | ff = EMBRYO_CELL_TO_FLOAT(params[2]); | ||
232 | f = powf(f, ff); | ||
233 | return EMBRYO_FLOAT_TO_CELL(f); | ||
234 | } | ||
235 | |||
236 | static Embryo_Cell | ||
237 | _embryo_fp_log(Embryo_Program *ep, Embryo_Cell *params) | ||
238 | { | ||
239 | /* params[1] = float operand 1 (value) */ | ||
240 | /* params[2] = float operand 2 (base) */ | ||
241 | float f, ff; | ||
242 | |||
243 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
244 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
245 | ff = EMBRYO_CELL_TO_FLOAT(params[2]); | ||
246 | if ((f <= 0.0) || (ff <= 0.0)) | ||
247 | { | ||
248 | embryo_program_error_set(ep, EMBRYO_ERROR_DOMAIN); | ||
249 | return 0; | ||
250 | } | ||
251 | if (ff == 10.0) f = log10f(f); | ||
252 | else f = (logf(f) / logf(ff)); | ||
253 | return EMBRYO_FLOAT_TO_CELL(f); | ||
254 | } | ||
255 | |||
256 | static Embryo_Cell | ||
257 | _embryo_fp_sin(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
258 | { | ||
259 | /* params[1] = float operand 1 (angle) */ | ||
260 | /* params[2] = float operand 2 (radix) */ | ||
261 | float f; | ||
262 | |||
263 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
264 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
265 | f = _embryo_fp_degrees_to_radians(f, params[2]); | ||
266 | f = sinf(f); | ||
267 | return EMBRYO_FLOAT_TO_CELL(f); | ||
268 | } | ||
269 | |||
270 | static Embryo_Cell | ||
271 | _embryo_fp_cos(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
272 | { | ||
273 | /* params[1] = float operand 1 (angle) */ | ||
274 | /* params[2] = float operand 2 (radix) */ | ||
275 | float f; | ||
276 | |||
277 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
278 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
279 | f = _embryo_fp_degrees_to_radians(f, params[2]); | ||
280 | f = cosf(f); | ||
281 | return EMBRYO_FLOAT_TO_CELL(f); | ||
282 | } | ||
283 | |||
284 | static Embryo_Cell | ||
285 | _embryo_fp_tan(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
286 | { | ||
287 | /* params[1] = float operand 1 (angle) */ | ||
288 | /* params[2] = float operand 2 (radix) */ | ||
289 | float f; | ||
290 | |||
291 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
292 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
293 | f = _embryo_fp_degrees_to_radians(f, params[2]); | ||
294 | f = tanf(f); | ||
295 | return EMBRYO_FLOAT_TO_CELL(f); | ||
296 | } | ||
297 | |||
298 | static Embryo_Cell | ||
299 | _embryo_fp_abs(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) | ||
300 | { | ||
301 | /* params[1] = float operand */ | ||
302 | float f; | ||
303 | |||
304 | if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; | ||
305 | f = EMBRYO_CELL_TO_FLOAT(params[1]); | ||
306 | f = (f >= 0) ? f : -f; | ||
307 | return EMBRYO_FLOAT_TO_CELL(f); | ||
308 | } | ||
309 | |||
310 | /* functions used by the rest of embryo */ | ||
311 | |||
312 | void | ||
313 | _embryo_fp_init(Embryo_Program *ep) | ||
314 | { | ||
315 | embryo_program_native_call_add(ep, "float", _embryo_fp); | ||
316 | embryo_program_native_call_add(ep, "atof", _embryo_fp_str); | ||
317 | embryo_program_native_call_add(ep, "float_mul", _embryo_fp_mul); | ||
318 | embryo_program_native_call_add(ep, "float_div", _embryo_fp_div); | ||
319 | embryo_program_native_call_add(ep, "float_add", _embryo_fp_add); | ||
320 | embryo_program_native_call_add(ep, "float_sub", _embryo_fp_sub); | ||
321 | embryo_program_native_call_add(ep, "fract", _embryo_fp_fract); | ||
322 | embryo_program_native_call_add(ep, "round", _embryo_fp_round); | ||
323 | embryo_program_native_call_add(ep, "float_cmp", _embryo_fp_cmp); | ||
324 | embryo_program_native_call_add(ep, "sqrt", _embryo_fp_sqroot); | ||
325 | embryo_program_native_call_add(ep, "pow", _embryo_fp_power); | ||
326 | embryo_program_native_call_add(ep, "log", _embryo_fp_log); | ||
327 | embryo_program_native_call_add(ep, "sin", _embryo_fp_sin); | ||
328 | embryo_program_native_call_add(ep, "cos", _embryo_fp_cos); | ||
329 | embryo_program_native_call_add(ep, "tan", _embryo_fp_tan); | ||
330 | embryo_program_native_call_add(ep, "abs", _embryo_fp_abs); | ||
331 | } | ||
diff --git a/libraries/embryo/src/lib/embryo_main.c b/libraries/embryo/src/lib/embryo_main.c deleted file mode 100644 index 0b01b11..0000000 --- a/libraries/embryo/src/lib/embryo_main.c +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <stdlib.h> | ||
6 | #include <time.h> | ||
7 | |||
8 | #include "Embryo.h" | ||
9 | #include "embryo_private.h" | ||
10 | |||
11 | static Embryo_Version _version = { VMAJ, VMIN, VMIC, VREV }; | ||
12 | EAPI Embryo_Version *embryo_version = &_version; | ||
13 | |||
14 | static int _embryo_init_count = 0; | ||
15 | |||
16 | /*** EXPORTED CALLS ***/ | ||
17 | |||
18 | EAPI int | ||
19 | embryo_init(void) | ||
20 | { | ||
21 | if (++_embryo_init_count != 1) | ||
22 | return _embryo_init_count; | ||
23 | |||
24 | srand(time(NULL)); | ||
25 | |||
26 | return _embryo_init_count; | ||
27 | } | ||
28 | |||
29 | EAPI int | ||
30 | embryo_shutdown(void) | ||
31 | { | ||
32 | if (--_embryo_init_count != 0) | ||
33 | return _embryo_init_count; | ||
34 | |||
35 | return _embryo_init_count; | ||
36 | } | ||
diff --git a/libraries/embryo/src/lib/embryo_private.h b/libraries/embryo/src/lib/embryo_private.h deleted file mode 100644 index a4205e1..0000000 --- a/libraries/embryo/src/lib/embryo_private.h +++ /dev/null | |||
@@ -1,298 +0,0 @@ | |||
1 | #ifndef _EMBRYO_PRIVATE_H | ||
2 | #define _EMBRYO_PRIVATE_H | ||
3 | |||
4 | |||
5 | #ifdef __GNUC__ | ||
6 | # if __GNUC__ >= 4 | ||
7 | // BROKEN in gcc 4 on amd64 | ||
8 | //# pragma GCC visibility push(hidden) | ||
9 | # endif | ||
10 | #endif | ||
11 | |||
12 | typedef enum _Embryo_Opcode Embryo_Opcode; | ||
13 | |||
14 | enum _Embryo_Opcode | ||
15 | { | ||
16 | EMBRYO_OP_NONE, | ||
17 | EMBRYO_OP_LOAD_PRI, | ||
18 | EMBRYO_OP_LOAD_ALT, | ||
19 | EMBRYO_OP_LOAD_S_PRI, | ||
20 | EMBRYO_OP_LOAD_S_ALT, | ||
21 | EMBRYO_OP_LREF_PRI, | ||
22 | EMBRYO_OP_LREF_ALT, | ||
23 | EMBRYO_OP_LREF_S_PRI, | ||
24 | EMBRYO_OP_LREF_S_ALT, | ||
25 | EMBRYO_OP_LOAD_I, | ||
26 | EMBRYO_OP_LODB_I, | ||
27 | EMBRYO_OP_CONST_PRI, | ||
28 | EMBRYO_OP_CONST_ALT, | ||
29 | EMBRYO_OP_ADDR_PRI, | ||
30 | EMBRYO_OP_ADDR_ALT, | ||
31 | EMBRYO_OP_STOR_PRI, | ||
32 | EMBRYO_OP_STOR_ALT, | ||
33 | EMBRYO_OP_STOR_S_PRI, | ||
34 | EMBRYO_OP_STOR_S_ALT, | ||
35 | EMBRYO_OP_SREF_PRI, | ||
36 | EMBRYO_OP_SREF_ALT, | ||
37 | EMBRYO_OP_SREF_S_PRI, | ||
38 | EMBRYO_OP_SREF_S_ALT, | ||
39 | EMBRYO_OP_STOR_I, | ||
40 | EMBRYO_OP_STRB_I, | ||
41 | EMBRYO_OP_LIDX, | ||
42 | EMBRYO_OP_LIDX_B, | ||
43 | EMBRYO_OP_IDXADDR, | ||
44 | EMBRYO_OP_IDXADDR_B, | ||
45 | EMBRYO_OP_ALIGN_PRI, | ||
46 | EMBRYO_OP_ALIGN_ALT, | ||
47 | EMBRYO_OP_LCTRL, | ||
48 | EMBRYO_OP_SCTRL, | ||
49 | EMBRYO_OP_MOVE_PRI, | ||
50 | EMBRYO_OP_MOVE_ALT, | ||
51 | EMBRYO_OP_XCHG, | ||
52 | EMBRYO_OP_PUSH_PRI, | ||
53 | EMBRYO_OP_PUSH_ALT, | ||
54 | EMBRYO_OP_PUSH_R, | ||
55 | EMBRYO_OP_PUSH_C, | ||
56 | EMBRYO_OP_PUSH, | ||
57 | EMBRYO_OP_PUSH_S, | ||
58 | EMBRYO_OP_POP_PRI, | ||
59 | EMBRYO_OP_POP_ALT, | ||
60 | EMBRYO_OP_STACK, | ||
61 | EMBRYO_OP_HEAP, | ||
62 | EMBRYO_OP_PROC, | ||
63 | EMBRYO_OP_RET, | ||
64 | EMBRYO_OP_RETN, | ||
65 | EMBRYO_OP_CALL, | ||
66 | EMBRYO_OP_CALL_PRI, | ||
67 | EMBRYO_OP_JUMP, | ||
68 | EMBRYO_OP_JREL, | ||
69 | EMBRYO_OP_JZER, | ||
70 | EMBRYO_OP_JNZ, | ||
71 | EMBRYO_OP_JEQ, | ||
72 | EMBRYO_OP_JNEQ, | ||
73 | EMBRYO_OP_JLESS, | ||
74 | EMBRYO_OP_JLEQ, | ||
75 | EMBRYO_OP_JGRTR, | ||
76 | EMBRYO_OP_JGEQ, | ||
77 | EMBRYO_OP_JSLESS, | ||
78 | EMBRYO_OP_JSLEQ, | ||
79 | EMBRYO_OP_JSGRTR, | ||
80 | EMBRYO_OP_JSGEQ, | ||
81 | EMBRYO_OP_SHL, | ||
82 | EMBRYO_OP_SHR, | ||
83 | EMBRYO_OP_SSHR, | ||
84 | EMBRYO_OP_SHL_C_PRI, | ||
85 | EMBRYO_OP_SHL_C_ALT, | ||
86 | EMBRYO_OP_SHR_C_PRI, | ||
87 | EMBRYO_OP_SHR_C_ALT, | ||
88 | EMBRYO_OP_SMUL, | ||
89 | EMBRYO_OP_SDIV, | ||
90 | EMBRYO_OP_SDIV_ALT, | ||
91 | EMBRYO_OP_UMUL, | ||
92 | EMBRYO_OP_UDIV, | ||
93 | EMBRYO_OP_UDIV_ALT, | ||
94 | EMBRYO_OP_ADD, | ||
95 | EMBRYO_OP_SUB, | ||
96 | EMBRYO_OP_SUB_ALT, | ||
97 | EMBRYO_OP_AND, | ||
98 | EMBRYO_OP_OR, | ||
99 | EMBRYO_OP_XOR, | ||
100 | EMBRYO_OP_NOT, | ||
101 | EMBRYO_OP_NEG, | ||
102 | EMBRYO_OP_INVERT, | ||
103 | EMBRYO_OP_ADD_C, | ||
104 | EMBRYO_OP_SMUL_C, | ||
105 | EMBRYO_OP_ZERO_PRI, | ||
106 | EMBRYO_OP_ZERO_ALT, | ||
107 | EMBRYO_OP_ZERO, | ||
108 | EMBRYO_OP_ZERO_S, | ||
109 | EMBRYO_OP_SIGN_PRI, | ||
110 | EMBRYO_OP_SIGN_ALT, | ||
111 | EMBRYO_OP_EQ, | ||
112 | EMBRYO_OP_NEQ, | ||
113 | EMBRYO_OP_LESS, | ||
114 | EMBRYO_OP_LEQ, | ||
115 | EMBRYO_OP_GRTR, | ||
116 | EMBRYO_OP_GEQ, | ||
117 | EMBRYO_OP_SLESS, | ||
118 | EMBRYO_OP_SLEQ, | ||
119 | EMBRYO_OP_SGRTR, | ||
120 | EMBRYO_OP_SGEQ, | ||
121 | EMBRYO_OP_EQ_C_PRI, | ||
122 | EMBRYO_OP_EQ_C_ALT, | ||
123 | EMBRYO_OP_INC_PRI, | ||
124 | EMBRYO_OP_INC_ALT, | ||
125 | EMBRYO_OP_INC, | ||
126 | EMBRYO_OP_INC_S, | ||
127 | EMBRYO_OP_INC_I, | ||
128 | EMBRYO_OP_DEC_PRI, | ||
129 | EMBRYO_OP_DEC_ALT, | ||
130 | EMBRYO_OP_DEC, | ||
131 | EMBRYO_OP_DEC_S, | ||
132 | EMBRYO_OP_DEC_I, | ||
133 | EMBRYO_OP_MOVS, | ||
134 | EMBRYO_OP_CMPS, | ||
135 | EMBRYO_OP_FILL, | ||
136 | EMBRYO_OP_HALT, | ||
137 | EMBRYO_OP_BOUNDS, | ||
138 | EMBRYO_OP_SYSREQ_PRI, | ||
139 | EMBRYO_OP_SYSREQ_C, | ||
140 | EMBRYO_OP_FILE, | ||
141 | EMBRYO_OP_LINE, | ||
142 | EMBRYO_OP_SYMBOL, | ||
143 | EMBRYO_OP_SRANGE, | ||
144 | EMBRYO_OP_JUMP_PRI, | ||
145 | EMBRYO_OP_SWITCH, | ||
146 | EMBRYO_OP_CASETBL, | ||
147 | EMBRYO_OP_SWAP_PRI, | ||
148 | EMBRYO_OP_SWAP_ALT, | ||
149 | EMBRYO_OP_PUSHADDR, | ||
150 | EMBRYO_OP_NOP, | ||
151 | EMBRYO_OP_SYSREQ_D, | ||
152 | EMBRYO_OP_SYMTAG, | ||
153 | /* ----- */ | ||
154 | EMBRYO_OP_NUM_OPCODES | ||
155 | }; | ||
156 | |||
157 | #define NUMENTRIES(hdr, field, nextfield) \ | ||
158 | (int)(((hdr)->nextfield - (hdr)->field) / (hdr)->defsize) | ||
159 | #define GETENTRY(hdr, table, index) \ | ||
160 | (Embryo_Func_Stub *)((unsigned char*)(hdr) + \ | ||
161 | (int)(hdr)->table + index * (hdr)->defsize) | ||
162 | #ifdef WORDS_BIGENDIAN | ||
163 | static int __inline __entryswap32(int v) | ||
164 | {int vv; vv = v; embryo_swap_32((unsigned int *)&vv); return vv;} | ||
165 | # define GETENTRYNAME(hdr, entry) \ | ||
166 | (((hdr)->defsize == 2 * sizeof(unsigned int)) \ | ||
167 | ? (char *)((unsigned char*)(hdr) + \ | ||
168 | __entryswap32(*((unsigned int *)(entry) + 1))) \ | ||
169 | : (entry)->name) | ||
170 | #else | ||
171 | # define GETENTRYNAME(hdr, entry) \ | ||
172 | (((hdr)->defsize == 2 * sizeof(unsigned int)) \ | ||
173 | ? (char *)((unsigned char*)(hdr) + *((unsigned int *)(entry) + 1)) \ | ||
174 | : (entry)->name) | ||
175 | #endif | ||
176 | |||
177 | #define CUR_FILE_VERSION 7 /* current file version; also the current Embryo_Program version */ | ||
178 | #define MIN_FILE_VERSION 7 /* lowest supported file format version for the current Embryo_Program version */ | ||
179 | #define MIN_AMX_VERSION 7 /* minimum Embryo_Program version needed to support the current file format */ | ||
180 | #define sEXPMAX 19 /* maximum name length for file version <= 6 */ | ||
181 | #define sNAMEMAX 31 /* maximum name length of symbol name */ | ||
182 | #define EMBRYO_MAGIC 0xf1e0 /* magic byte pattern */ | ||
183 | #define EMBRYO_FLAG_COMPACT 0x04 /* compact encoding */ | ||
184 | #define EMBRYO_FLAG_RELOC 0x8000 /* jump/call addresses relocated */ | ||
185 | #define GETPARAM(v) (v = *(Embryo_Cell *)cip++) | ||
186 | #define PUSH(v) (stk -= sizeof(Embryo_Cell), *(Embryo_Cell *)(data + (int)stk) = v) | ||
187 | #define POP(v) (v = *(Embryo_Cell *)(data + (int)stk), stk += sizeof(Embryo_Cell)) | ||
188 | #define ABORT(ep,v) {(ep)->stk = reset_stk; (ep)->hea = reset_hea; (ep)->run_count--; ep->error = v; (ep)->max_run_cycles = max_run_cycles; return EMBRYO_PROGRAM_FAIL;} | ||
189 | #define OK(ep,v) {(ep)->stk = reset_stk; (ep)->hea = reset_hea; (ep)->run_count--; ep->error = v; (ep)->max_run_cycles = max_run_cycles; return EMBRYO_PROGRAM_OK;} | ||
190 | #define TOOLONG(ep) {(ep)->pri = pri; (ep)->cip = (Embryo_Cell)((unsigned char *)cip - code); (ep)->alt = alt; (ep)->frm = frm; (ep)->stk = stk; (ep)->hea = hea; (ep)->reset_stk = reset_stk; (ep)->reset_hea = reset_hea; (ep)->run_count--; (ep)->max_run_cycles = max_run_cycles; return EMBRYO_PROGRAM_TOOLONG;} | ||
191 | #define STKMARGIN ((Embryo_Cell)(16 * sizeof(Embryo_Cell))) | ||
192 | #define CHKMARGIN() if ((hea + STKMARGIN) > stk) {ep->error = EMBRYO_ERROR_STACKERR; return 0;} | ||
193 | #define CHKSTACK() if (stk > ep->stp) {ep->run_count--; ep->error = EMBRYO_ERROR_STACKLOW; return 0;} | ||
194 | #define CHKHEAP() if (hea < ep->hlw) {ep->run_count--; ep->error = EMBRYO_ERROR_HEAPLOW; return 0;} | ||
195 | #define CHKMEM(x) if ((((x) >= hea) && ((x) < stk)) || ((Embryo_UCell)(x) >= (Embryo_UCell)ep->stp)) ABORT(ep, EMBRYO_ERROR_MEMACCESS); | ||
196 | |||
197 | typedef struct _Embryo_Param Embryo_Param; | ||
198 | typedef struct _Embryo_Header Embryo_Header; | ||
199 | typedef struct _Embryo_Func_Stub Embryo_Func_Stub; | ||
200 | |||
201 | typedef Embryo_Cell (*Embryo_Native)(Embryo_Program *ep, Embryo_Cell *params); | ||
202 | |||
203 | struct _Embryo_Param | ||
204 | { | ||
205 | char *string; | ||
206 | Embryo_Cell *cell_array; | ||
207 | int cell_array_size; | ||
208 | Embryo_Cell cell; | ||
209 | }; | ||
210 | |||
211 | struct _Embryo_Program | ||
212 | { | ||
213 | unsigned char *base; /* points to the Embryo_Program header ("ephdr") plus the code, optionally also the data */ | ||
214 | int pushes; /* number of pushes - pops */ | ||
215 | /* for external functions a few registers must be accessible from the outside */ | ||
216 | Embryo_Cell cip; /* instruction pointer: relative to base + ephdr->cod */ | ||
217 | Embryo_Cell frm; /* stack frame base: relative to base + ephdr->dat */ | ||
218 | Embryo_Cell hea; /* top of the heap: relative to base + ephdr->dat */ | ||
219 | Embryo_Cell hlw; /* bottom of the heap: relative to base + ephdr->dat */ | ||
220 | Embryo_Cell stk; /* stack pointer: relative to base + ephdr->dat */ | ||
221 | Embryo_Cell stp; /* top of the stack: relative to base + ephdr->dat */ | ||
222 | int flags; /* current status */ | ||
223 | /* native functions can raise an error */ | ||
224 | int error; | ||
225 | /* the sleep opcode needs to store the full Embryo_Program status */ | ||
226 | Embryo_Cell pri; | ||
227 | Embryo_Cell alt; | ||
228 | Embryo_Cell reset_stk; | ||
229 | Embryo_Cell reset_hea; | ||
230 | Embryo_Cell *syscall_d; /* relocated value/address for the SYSCALL.D opcode */ | ||
231 | |||
232 | /* extended stuff */ | ||
233 | Embryo_Native *native_calls; | ||
234 | int native_calls_size; | ||
235 | int native_calls_alloc; | ||
236 | |||
237 | unsigned char *code; | ||
238 | unsigned char dont_free_code : 1; | ||
239 | Embryo_Cell retval; | ||
240 | |||
241 | Embryo_Param *params; | ||
242 | int params_size; | ||
243 | int params_alloc; | ||
244 | |||
245 | int run_count; | ||
246 | |||
247 | int max_run_cycles; | ||
248 | |||
249 | void *data; | ||
250 | }; | ||
251 | |||
252 | #if defined (_MSC_VER) || (defined (__SUNPRO_C) && __SUNPRO_C < 0x5100) | ||
253 | # pragma pack(1) | ||
254 | # define EMBRYO_STRUCT_PACKED | ||
255 | #elif defined (__GNUC__) || (defined (__SUNPRO_C) && __SUNPRO_C >= 0x5100) | ||
256 | # define EMBRYO_STRUCT_PACKED __attribute__((packed)) | ||
257 | #else | ||
258 | # define EMBRYO_STRUCT_PACKED | ||
259 | #endif | ||
260 | |||
261 | struct _Embryo_Func_Stub | ||
262 | { | ||
263 | int address; | ||
264 | char name[sEXPMAX+1]; | ||
265 | } EMBRYO_STRUCT_PACKED; | ||
266 | |||
267 | struct _Embryo_Header | ||
268 | { | ||
269 | unsigned int size; /* size of the "file" */ | ||
270 | unsigned short magic; /* signature */ | ||
271 | char file_version; /* file format version */ | ||
272 | char ep_version; /* required version of the Embryo_Program */ | ||
273 | short flags; | ||
274 | short defsize; /* size of a definition record */ | ||
275 | int cod; /* initial value of COD - code block */ | ||
276 | int dat; /* initial value of DAT - data block */ | ||
277 | int hea; /* initial value of HEA - start of the heap */ | ||
278 | int stp; /* initial value of STP - stack top */ | ||
279 | int cip; /* initial value of CIP - the instruction pointer */ | ||
280 | int publics; /* offset to the "public functions" table */ | ||
281 | int natives; /* offset to the "native functions" table */ | ||
282 | int libraries; /* offset to the table of libraries */ | ||
283 | int pubvars; /* the "public variables" table */ | ||
284 | int tags; /* the "public tagnames" table */ | ||
285 | int nametable; /* name table, file version 7 only */ | ||
286 | } EMBRYO_STRUCT_PACKED; | ||
287 | |||
288 | #if defined _MSC_VER || (defined (__SUNPRO_C) && __SUNPRO_C < 0x5100) | ||
289 | # pragma pack() | ||
290 | #endif | ||
291 | |||
292 | void _embryo_args_init(Embryo_Program *ep); | ||
293 | void _embryo_fp_init(Embryo_Program *ep); | ||
294 | void _embryo_rand_init(Embryo_Program *ep); | ||
295 | void _embryo_str_init(Embryo_Program *ep); | ||
296 | void _embryo_time_init(Embryo_Program *ep); | ||
297 | |||
298 | #endif | ||
diff --git a/libraries/embryo/src/lib/embryo_rand.c b/libraries/embryo/src/lib/embryo_rand.c deleted file mode 100644 index 627f7ed..0000000 --- a/libraries/embryo/src/lib/embryo_rand.c +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include <stdlib.h> | ||
6 | |||
7 | #include "Embryo.h" | ||
8 | #include "embryo_private.h" | ||
9 | |||
10 | /* exported random number api */ | ||
11 | |||
12 | static Embryo_Cell | ||
13 | _embryo_rand_rand(Embryo_Program *ep __UNUSED__, Embryo_Cell *params __UNUSED__) | ||
14 | { | ||
15 | return (Embryo_Cell)(rand() & 0xffff); | ||
16 | } | ||
17 | |||
18 | static Embryo_Cell | ||
19 | _embryo_rand_randf(Embryo_Program *ep __UNUSED__, Embryo_Cell *params __UNUSED__) | ||
20 | { | ||
21 | double r; | ||
22 | float f; | ||
23 | |||
24 | r = (double)(rand() & 0xffff) / 65535.0; | ||
25 | f = (float)r; | ||
26 | return EMBRYO_FLOAT_TO_CELL(f); | ||
27 | } | ||
28 | |||
29 | /* functions used by the rest of embryo */ | ||
30 | |||
31 | void | ||
32 | _embryo_rand_init(Embryo_Program *ep) | ||
33 | { | ||
34 | embryo_program_native_call_add(ep, "rand", _embryo_rand_rand); | ||
35 | embryo_program_native_call_add(ep, "randf", _embryo_rand_randf); | ||
36 | } | ||
diff --git a/libraries/embryo/src/lib/embryo_str.c b/libraries/embryo/src/lib/embryo_str.c deleted file mode 100644 index 0c2faa2..0000000 --- a/libraries/embryo/src/lib/embryo_str.c +++ /dev/null | |||
@@ -1,498 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #ifdef STDC_HEADERS | ||
6 | # include <stdlib.h> | ||
7 | # include <stddef.h> | ||
8 | #else | ||
9 | # ifdef HAVE_STDLIB_H | ||
10 | # include <stdlib.h> | ||
11 | # endif | ||
12 | #endif | ||
13 | #ifdef HAVE_ALLOCA_H | ||
14 | # include <alloca.h> | ||
15 | #elif !defined alloca | ||
16 | # ifdef __GNUC__ | ||
17 | # define alloca __builtin_alloca | ||
18 | # elif defined _AIX | ||
19 | # define alloca __alloca | ||
20 | # elif defined _MSC_VER | ||
21 | # include <malloc.h> | ||
22 | # define alloca _alloca | ||
23 | # elif !defined HAVE_ALLOCA | ||
24 | # ifdef __cplusplus | ||
25 | extern "C" | ||
26 | # endif | ||
27 | void *alloca (size_t); | ||
28 | # endif | ||
29 | #endif | ||
30 | |||
31 | #ifdef HAVE_EXOTIC | ||
32 | # include <Exotic.h> | ||
33 | #endif | ||
34 | |||
35 | #include <stdlib.h> | ||
36 | #include <stdio.h> | ||
37 | #include <string.h> | ||
38 | #include <fnmatch.h> | ||
39 | |||
40 | #include "Embryo.h" | ||
41 | #include "embryo_private.h" | ||
42 | |||
43 | #define STRGET(ep, str, par) { \ | ||
44 | Embryo_Cell *___cptr; \ | ||
45 | str = NULL; \ | ||
46 | if ((___cptr = embryo_data_address_get(ep, par))) { \ | ||
47 | int ___l; \ | ||
48 | ___l = embryo_data_string_length_get(ep, ___cptr); \ | ||
49 | (str) = alloca(___l + 1); \ | ||
50 | if (str) embryo_data_string_get(ep, ___cptr, str); \ | ||
51 | } } | ||
52 | #define STRSET(ep, par, str) { \ | ||
53 | Embryo_Cell *___cptr; \ | ||
54 | if ((___cptr = embryo_data_address_get(ep, par))) { \ | ||
55 | embryo_data_string_set(ep, str, ___cptr); \ | ||
56 | } } | ||
57 | |||
58 | /* exported string api */ | ||
59 | |||
60 | static Embryo_Cell | ||
61 | _embryo_str_atoi(Embryo_Program *ep, Embryo_Cell *params) | ||
62 | { | ||
63 | char *s1; | ||
64 | |||
65 | /* params[1] = str */ | ||
66 | if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; | ||
67 | STRGET(ep, s1, params[1]); | ||
68 | if (!s1) return 0; | ||
69 | return (Embryo_Cell)atoi(s1); | ||
70 | } | ||
71 | |||
72 | static Embryo_Cell | ||
73 | _embryo_str_fnmatch(Embryo_Program *ep, Embryo_Cell *params) | ||
74 | { | ||
75 | char *s1, *s2; | ||
76 | |||
77 | /* params[1] = glob */ | ||
78 | /* params[2] = str */ | ||
79 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
80 | STRGET(ep, s1, params[1]); | ||
81 | STRGET(ep, s2, params[2]); | ||
82 | if ((!s1) || (!s2)) return -1; | ||
83 | return (Embryo_Cell)fnmatch(s1, s2, 0); | ||
84 | } | ||
85 | |||
86 | static Embryo_Cell | ||
87 | _embryo_str_strcmp(Embryo_Program *ep, Embryo_Cell *params) | ||
88 | { | ||
89 | char *s1, *s2; | ||
90 | |||
91 | /* params[1] = str1 */ | ||
92 | /* params[2] = str2 */ | ||
93 | if (params[0] != (2 * sizeof(Embryo_Cell))) return -1; | ||
94 | STRGET(ep, s1, params[1]); | ||
95 | STRGET(ep, s2, params[2]); | ||
96 | if ((!s1) || (!s2)) return -1; | ||
97 | return (Embryo_Cell)strcmp(s1, s2); | ||
98 | } | ||
99 | |||
100 | static Embryo_Cell | ||
101 | _embryo_str_strncmp(Embryo_Program *ep, Embryo_Cell *params) | ||
102 | { | ||
103 | char *s1, *s2; | ||
104 | |||
105 | /* params[1] = str1 */ | ||
106 | /* params[2] = str2 */ | ||
107 | /* params[3] = n */ | ||
108 | if (params[0] != (3 * sizeof(Embryo_Cell))) return 0; | ||
109 | if (params[3] < 0) params[3] = 0; | ||
110 | STRGET(ep, s1, params[1]); | ||
111 | STRGET(ep, s2, params[2]); | ||
112 | if ((!s1) || (!s2)) return -1; | ||
113 | return (Embryo_Cell)strncmp(s1, s2, (size_t)params[3]); | ||
114 | } | ||
115 | |||
116 | static Embryo_Cell | ||
117 | _embryo_str_strcpy(Embryo_Program *ep, Embryo_Cell *params) | ||
118 | { | ||
119 | char *s1; | ||
120 | |||
121 | /* params[1] = dst */ | ||
122 | /* params[2] = str */ | ||
123 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
124 | STRGET(ep, s1, params[2]); | ||
125 | if (!s1) return 0; | ||
126 | STRSET(ep, params[1], s1); | ||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static Embryo_Cell | ||
131 | _embryo_str_strncpy(Embryo_Program *ep, Embryo_Cell *params) | ||
132 | { | ||
133 | char *s1; | ||
134 | int l; | ||
135 | |||
136 | /* params[1] = dst */ | ||
137 | /* params[2] = str */ | ||
138 | /* params[3] = n */ | ||
139 | if (params[0] != (3 * sizeof(Embryo_Cell))) return 0; | ||
140 | if (params[3] < 0) params[3] = 0; | ||
141 | STRGET(ep, s1, params[2]); | ||
142 | if (!s1) return 0; | ||
143 | l = strlen(s1); | ||
144 | if (l > params[3]) s1[params[3]] = 0; | ||
145 | STRSET(ep, params[1], s1); | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | static Embryo_Cell | ||
150 | _embryo_str_strlen(Embryo_Program *ep, Embryo_Cell *params) | ||
151 | { | ||
152 | char *s1; | ||
153 | |||
154 | /* params[1] = str */ | ||
155 | if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; | ||
156 | STRGET(ep, s1, params[1]); | ||
157 | if (!s1) return 0; | ||
158 | return (Embryo_Cell)strlen(s1); | ||
159 | } | ||
160 | |||
161 | static Embryo_Cell | ||
162 | _embryo_str_strcat(Embryo_Program *ep, Embryo_Cell *params) | ||
163 | { | ||
164 | char *s1, *s2, *s3; | ||
165 | |||
166 | /* params[1] = dsr */ | ||
167 | /* params[2] = str */ | ||
168 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
169 | STRGET(ep, s1, params[1]); | ||
170 | STRGET(ep, s2, params[2]); | ||
171 | if ((!s1) || (!s2)) return 0; | ||
172 | s3 = alloca(strlen(s1) + strlen(s2) + 1); | ||
173 | if (!s3) return 0; | ||
174 | strcpy(s3, s1); | ||
175 | strcat(s3, s2); | ||
176 | STRSET(ep, params[1], s3); | ||
177 | return 0; | ||
178 | } | ||
179 | |||
180 | static Embryo_Cell | ||
181 | _embryo_str_strncat(Embryo_Program *ep, Embryo_Cell *params) | ||
182 | { | ||
183 | char *s1, *s2, *s3; | ||
184 | int l1, l2; | ||
185 | |||
186 | /* params[1] = dst */ | ||
187 | /* params[2] = str */ | ||
188 | /* params[3] = n */ | ||
189 | if (params[0] != (3 * sizeof(Embryo_Cell))) return 0; | ||
190 | if (params[3] < 0) params[3] = 0; | ||
191 | STRGET(ep, s1, params[1]); | ||
192 | STRGET(ep, s2, params[2]); | ||
193 | if ((!s1) || (!s2)) return 0; | ||
194 | l1 = strlen(s1); | ||
195 | l2 = strlen(s2); | ||
196 | s3 = alloca(l1 + l2 + 1); | ||
197 | if (!s3) return 0; | ||
198 | strcpy(s3, s1); | ||
199 | strncat(s3, s2, params[3]); | ||
200 | if (l2 >= params[3]) s3[l1 + params[3]] = 0; | ||
201 | STRSET(ep, params[1], s3); | ||
202 | return 0; | ||
203 | } | ||
204 | |||
205 | static Embryo_Cell | ||
206 | _embryo_str_strprep(Embryo_Program *ep, Embryo_Cell *params) | ||
207 | { | ||
208 | char *s1, *s2, *s3; | ||
209 | |||
210 | /* params[1] = dst */ | ||
211 | /* params[2] = str */ | ||
212 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
213 | STRGET(ep, s1, params[1]); | ||
214 | STRGET(ep, s2, params[2]); | ||
215 | if ((!s1) || (!s2)) return 0; | ||
216 | s3 = alloca(strlen(s1) + strlen(s2) + 1); | ||
217 | if (!s3) return 0; | ||
218 | strcpy(s3, s2); | ||
219 | strcat(s3, s1); | ||
220 | STRSET(ep, params[1], s3); | ||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | static Embryo_Cell | ||
225 | _embryo_str_strnprep(Embryo_Program *ep, Embryo_Cell *params) | ||
226 | { | ||
227 | char *s1, *s2, *s3; | ||
228 | int l1, l2; | ||
229 | |||
230 | /* params[1] = dst */ | ||
231 | /* params[2] = str */ | ||
232 | /* params[3] = n */ | ||
233 | if (params[0] != (3 * sizeof(Embryo_Cell))) return 0; | ||
234 | if (params[3] < 0) params[3] = 0; | ||
235 | STRGET(ep, s1, params[1]); | ||
236 | STRGET(ep, s2, params[2]); | ||
237 | if ((!s1) || (!s2)) return 0; | ||
238 | l1 = strlen(s1); | ||
239 | l2 = strlen(s2); | ||
240 | s3 = alloca(l1 + l2 + 1); | ||
241 | if (!s3) return 0; | ||
242 | strncpy(s3, s2, params[3]); | ||
243 | if (params[3] <= l2) s3[params[3]] = 0; | ||
244 | strcat(s3, s1); | ||
245 | STRSET(ep, params[1], s3); | ||
246 | return 0; | ||
247 | } | ||
248 | |||
249 | static Embryo_Cell | ||
250 | _embryo_str_strcut(Embryo_Program *ep, Embryo_Cell *params) | ||
251 | { | ||
252 | char *s1, *s2; | ||
253 | int l1; | ||
254 | |||
255 | /* params[1] = dst */ | ||
256 | /* params[2] = str */ | ||
257 | /* params[3] = n */ | ||
258 | /* params[4] = n2 */ | ||
259 | if (params[0] != (4 * sizeof(Embryo_Cell))) return 0; | ||
260 | if (params[3] < 0) params[3] = 0; | ||
261 | if (params[4] < params[3]) params[4] = params[3]; | ||
262 | STRGET(ep, s1, params[2]); | ||
263 | if (!s1) return 0; | ||
264 | l1 = strlen(s1); | ||
265 | if (params[3] >= l1) params[3] = l1; | ||
266 | if (params[4] >= l1) params[4] = l1; | ||
267 | if (params[4] == params[3]) | ||
268 | { | ||
269 | STRSET(ep, params[1], ""); | ||
270 | return 0; | ||
271 | } | ||
272 | s2 = alloca(params[4] - params[3] + 1); | ||
273 | strncpy(s2, s1 + params[3], params[4] - params[3]); | ||
274 | s2[params[4] - params[3]] = 0; | ||
275 | STRSET(ep, params[1], s2); | ||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | static Embryo_Cell | ||
280 | _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params) | ||
281 | { | ||
282 | char *s1, *s2; | ||
283 | int i, o; | ||
284 | int inesc = 0; | ||
285 | int insub = 0; | ||
286 | int p, pnum; | ||
287 | |||
288 | /* params[1] = buf */ | ||
289 | /* params[2] = bufsize */ | ||
290 | /* params[3] = format_string */ | ||
291 | /* params[4] = first arg ... */ | ||
292 | if (params[0] < (Embryo_Cell)(3 * sizeof(Embryo_Cell))) return 0; | ||
293 | if (params[2] <= 0) return 0; | ||
294 | STRGET(ep, s1, params[3]); | ||
295 | if (!s1) return -1; | ||
296 | s2 = alloca(params[2] + 1); | ||
297 | if (!s2) return -1; | ||
298 | s2[0] = 0; | ||
299 | pnum = (params[0] / sizeof(Embryo_Cell)) - 3; | ||
300 | for (p = 0, o = 0, i = 0; (s1[i]) && (o < (params[2] - 1)) && (p < (pnum + 1)); i++) | ||
301 | { | ||
302 | if ((!inesc) && (!insub)) | ||
303 | { | ||
304 | if (s1[i] == '\\') inesc = 1; | ||
305 | else if (s1[i] == '%') insub = 1; | ||
306 | if ((!inesc) && (!insub)) | ||
307 | { | ||
308 | s2[o] = s1[i]; | ||
309 | o++; | ||
310 | } | ||
311 | } | ||
312 | else | ||
313 | { | ||
314 | Embryo_Cell *cptr; | ||
315 | |||
316 | if (inesc) | ||
317 | { | ||
318 | switch (s1[i]) | ||
319 | { | ||
320 | case 't': | ||
321 | s2[o] = '\t'; | ||
322 | o++; | ||
323 | break; | ||
324 | case 'n': | ||
325 | s2[o] = '\n'; | ||
326 | o++; | ||
327 | break; | ||
328 | default: | ||
329 | s2[o] = s1[i]; | ||
330 | o++; | ||
331 | break; | ||
332 | } | ||
333 | inesc = 0; | ||
334 | } | ||
335 | if ((insub) && (s1[i] == '%')) pnum++; | ||
336 | if ((insub) && (p < pnum)) | ||
337 | { | ||
338 | switch (s1[i]) | ||
339 | { | ||
340 | case '%': | ||
341 | s2[o] = '%'; | ||
342 | o++; | ||
343 | break; | ||
344 | case 'c': | ||
345 | cptr = embryo_data_address_get(ep, params[4 + p]); | ||
346 | if (cptr) s2[o] = (char)(*cptr); | ||
347 | p++; | ||
348 | o++; | ||
349 | break; | ||
350 | case 'i': | ||
351 | case 'd': | ||
352 | case 'x': | ||
353 | case 'X': | ||
354 | { | ||
355 | char fmt[10] = ""; | ||
356 | char tmp[256] = ""; | ||
357 | int l; | ||
358 | |||
359 | if (s1[i] == 'i') strcpy(fmt, "%i"); | ||
360 | else if (s1[i] == 'd') strcpy(fmt, "%d"); | ||
361 | else if (s1[i] == 'x') strcpy(fmt, "%x"); | ||
362 | else if (s1[i] == 'X') strcpy(fmt, "%08x"); | ||
363 | cptr = embryo_data_address_get(ep, params[4 + p]); | ||
364 | if (cptr) snprintf(tmp, sizeof(tmp), fmt, (int)(*cptr)); | ||
365 | l = strlen(tmp); | ||
366 | if ((o + l) > (params[2] - 1)) | ||
367 | { | ||
368 | l = params[2] - 1 - o; | ||
369 | if (l < 0) l = 0; | ||
370 | tmp[l] = 0; | ||
371 | } | ||
372 | strcpy(s2 + o, tmp); | ||
373 | o += l; | ||
374 | p++; | ||
375 | } | ||
376 | break; | ||
377 | case 'f': | ||
378 | { | ||
379 | char tmp[256] = ""; | ||
380 | int l; | ||
381 | |||
382 | cptr = embryo_data_address_get(ep, params[4 + p]); | ||
383 | if (cptr) snprintf(tmp, sizeof(tmp), "%f", (double)EMBRYO_CELL_TO_FLOAT(*cptr)); | ||
384 | l = strlen(tmp); | ||
385 | if ((o + l) > (params[2] - 1)) | ||
386 | { | ||
387 | l = params[2] - 1 - o; | ||
388 | if (l < 0) l = 0; | ||
389 | tmp[l] = 0; | ||
390 | } | ||
391 | strcpy(s2 + o, tmp); | ||
392 | o += l; | ||
393 | p++; | ||
394 | } | ||
395 | break; | ||
396 | case 's': | ||
397 | { | ||
398 | char *tmp; | ||
399 | int l; | ||
400 | |||
401 | STRGET(ep, tmp, params[4 + p]); | ||
402 | l = strlen(tmp); | ||
403 | if ((o + l) > (params[2] - 1)) | ||
404 | { | ||
405 | l = params[2] - 1 - o; | ||
406 | if (l < 0) l = 0; | ||
407 | tmp[l] = 0; | ||
408 | } | ||
409 | strcpy(s2 + o, tmp); | ||
410 | o += l; | ||
411 | p++; | ||
412 | } | ||
413 | break; | ||
414 | default: | ||
415 | break; | ||
416 | } | ||
417 | insub = 0; | ||
418 | } | ||
419 | else if (insub) | ||
420 | insub = 0; | ||
421 | } | ||
422 | } | ||
423 | s2[o] = 0; | ||
424 | |||
425 | STRSET(ep, params[1], s2); | ||
426 | return o; | ||
427 | } | ||
428 | |||
429 | static Embryo_Cell | ||
430 | _embryo_str_strstr(Embryo_Program *ep, Embryo_Cell *params) | ||
431 | { | ||
432 | char *s1, *s2, *p; | ||
433 | |||
434 | /* params[1] = str */ | ||
435 | /* params[2] = ndl */ | ||
436 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
437 | STRGET(ep, s1, params[1]); | ||
438 | STRGET(ep, s2, params[2]); | ||
439 | if ((!s1) || (!s2)) return -1; | ||
440 | p = strstr(s1, s2); | ||
441 | if (!p) return -1; | ||
442 | return (Embryo_Cell)(p - s1); | ||
443 | } | ||
444 | |||
445 | static Embryo_Cell | ||
446 | _embryo_str_strchr(Embryo_Program *ep, Embryo_Cell *params) | ||
447 | { | ||
448 | char *s1, *s2, *p; | ||
449 | |||
450 | /* params[1] = str */ | ||
451 | /* params[2] = ch */ | ||
452 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
453 | STRGET(ep, s1, params[1]); | ||
454 | STRGET(ep, s2, params[2]); | ||
455 | if ((!s1) || (!s2)) return -1; | ||
456 | p = strchr(s1, s2[0]); | ||
457 | if (!p) return -1; | ||
458 | return (Embryo_Cell)(p - s1); | ||
459 | } | ||
460 | |||
461 | static Embryo_Cell | ||
462 | _embryo_str_strrchr(Embryo_Program *ep, Embryo_Cell *params) | ||
463 | { | ||
464 | char *s1, *s2, *p; | ||
465 | |||
466 | /* params[1] = str */ | ||
467 | /* params[2] = ch */ | ||
468 | if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; | ||
469 | STRGET(ep, s1, params[1]); | ||
470 | STRGET(ep, s2, params[2]); | ||
471 | if ((!s1) || (!s2)) return -1; | ||
472 | p = strrchr(s1, s2[0]); | ||
473 | if (!p) return -1; | ||
474 | return (Embryo_Cell)(p - s1); | ||
475 | } | ||
476 | |||
477 | /* functions used by the rest of embryo */ | ||
478 | |||
479 | void | ||
480 | _embryo_str_init(Embryo_Program *ep) | ||
481 | { | ||
482 | embryo_program_native_call_add(ep, "atoi", _embryo_str_atoi); | ||
483 | embryo_program_native_call_add(ep, "fnmatch", _embryo_str_fnmatch); | ||
484 | embryo_program_native_call_add(ep, "strcmp", _embryo_str_strcmp); | ||
485 | embryo_program_native_call_add(ep, "strncmp", _embryo_str_strncmp); | ||
486 | embryo_program_native_call_add(ep, "strcpy", _embryo_str_strcpy); | ||
487 | embryo_program_native_call_add(ep, "strncpy", _embryo_str_strncpy); | ||
488 | embryo_program_native_call_add(ep, "strlen", _embryo_str_strlen); | ||
489 | embryo_program_native_call_add(ep, "strcat", _embryo_str_strcat); | ||
490 | embryo_program_native_call_add(ep, "strncat", _embryo_str_strncat); | ||
491 | embryo_program_native_call_add(ep, "strprep", _embryo_str_strprep); | ||
492 | embryo_program_native_call_add(ep, "strnprep", _embryo_str_strnprep); | ||
493 | embryo_program_native_call_add(ep, "strcut", _embryo_str_strcut); | ||
494 | embryo_program_native_call_add(ep, "snprintf", _embryo_str_snprintf); | ||
495 | embryo_program_native_call_add(ep, "strstr", _embryo_str_strstr); | ||
496 | embryo_program_native_call_add(ep, "strchr", _embryo_str_strchr); | ||
497 | embryo_program_native_call_add(ep, "strrchr", _embryo_str_strrchr); | ||
498 | } | ||
diff --git a/libraries/embryo/src/lib/embryo_time.c b/libraries/embryo/src/lib/embryo_time.c deleted file mode 100644 index 90c14cf..0000000 --- a/libraries/embryo/src/lib/embryo_time.c +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #ifndef EFL_HAVE_GETTIMEOFDAY | ||
6 | # error "Your platform isn't supported yet" | ||
7 | #endif | ||
8 | |||
9 | #include <sys/time.h> | ||
10 | #include <time.h> | ||
11 | |||
12 | #ifdef _MSC_VER | ||
13 | # include <winsock2.h> | ||
14 | #endif | ||
15 | |||
16 | #ifdef HAVE_EVIL | ||
17 | # include <Evil.h> | ||
18 | #endif | ||
19 | |||
20 | #ifdef HAVE_EXOTIC | ||
21 | # include <Exotic.h> | ||
22 | #endif | ||
23 | |||
24 | #include "Embryo.h" | ||
25 | #include "embryo_private.h" | ||
26 | |||
27 | /* exported time api */ | ||
28 | |||
29 | static Embryo_Cell | ||
30 | _embryo_time_seconds(Embryo_Program *ep __UNUSED__, Embryo_Cell *params __UNUSED__) | ||
31 | { | ||
32 | struct timeval timev; | ||
33 | double t; | ||
34 | float f; | ||
35 | |||
36 | gettimeofday(&timev, NULL); | ||
37 | t = (double)(timev.tv_sec - ((timev.tv_sec / (60 * 60 * 24)) * (60 * 60 * 24))) | ||
38 | + (((double)timev.tv_usec) / 1000000); | ||
39 | f = (float)t; | ||
40 | return EMBRYO_FLOAT_TO_CELL(f); | ||
41 | } | ||
42 | |||
43 | static Embryo_Cell | ||
44 | _embryo_time_date(Embryo_Program *ep, Embryo_Cell *params) | ||
45 | { | ||
46 | static time_t last_tzset = 0; | ||
47 | struct timeval timev; | ||
48 | struct tm *tm; | ||
49 | time_t tt; | ||
50 | |||
51 | if (params[0] != (8 * sizeof(Embryo_Cell))) return 0; | ||
52 | gettimeofday(&timev, NULL); | ||
53 | tt = (time_t)(timev.tv_sec); | ||
54 | if ((tt > (last_tzset + 1)) || | ||
55 | (tt < (last_tzset - 1))) | ||
56 | { | ||
57 | last_tzset = tt; | ||
58 | tzset(); | ||
59 | } | ||
60 | tm = localtime(&tt); | ||
61 | if (tm) | ||
62 | { | ||
63 | Embryo_Cell *cptr; | ||
64 | double t; | ||
65 | float f; | ||
66 | |||
67 | cptr = embryo_data_address_get(ep, params[1]); | ||
68 | if (cptr) *cptr = tm->tm_year + 1900; | ||
69 | cptr = embryo_data_address_get(ep, params[2]); | ||
70 | if (cptr) *cptr = tm->tm_mon + 1; | ||
71 | cptr = embryo_data_address_get(ep, params[3]); | ||
72 | if (cptr) *cptr = tm->tm_mday; | ||
73 | cptr = embryo_data_address_get(ep, params[4]); | ||
74 | if (cptr) *cptr = tm->tm_yday; | ||
75 | cptr = embryo_data_address_get(ep, params[5]); | ||
76 | if (cptr) *cptr = (tm->tm_wday + 6) % 7; | ||
77 | cptr = embryo_data_address_get(ep, params[6]); | ||
78 | if (cptr) *cptr = tm->tm_hour; | ||
79 | cptr = embryo_data_address_get(ep, params[7]); | ||
80 | if (cptr) *cptr = tm->tm_min; | ||
81 | cptr = embryo_data_address_get(ep, params[8]); | ||
82 | t = (double)tm->tm_sec + (((double)timev.tv_usec) / 1000000); | ||
83 | f = (float)t; | ||
84 | if (cptr) *cptr = EMBRYO_FLOAT_TO_CELL(f); | ||
85 | |||
86 | } | ||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | /* functions used by the rest of embryo */ | ||
91 | |||
92 | void | ||
93 | _embryo_time_init(Embryo_Program *ep) | ||
94 | { | ||
95 | embryo_program_native_call_add(ep, "seconds", _embryo_time_seconds); | ||
96 | embryo_program_native_call_add(ep, "date", _embryo_time_date); | ||
97 | } | ||