5 These routines are used for Embryo.
7 @page Embryo Library Documentation
12 @author Carsten Haitzler <raster\@rasterman.com>
13 @author Compuphase http://www.compuphase.com
16 @section intro What is Embryo?
18 Embryo is a tiny library designed to interpret limited Small programs
19 compiled by the included compiler, @c embryo_cc. It is mostly a cleaned
20 up and smaller version of the original Small abstract machine. The
21 compiler is mostly untouched.
23 Small was renamed to Pawn.
24 For more information about the Pawn language, see
25 @htmlonly <a href=http://www.compuphase.com/pawn/pawn.htm>Pawn</a>
27 @latexonly http://www.compuphase.com/pawn/pawn.htm @endlatexonly
28 For the basics about the Small language, see @ref Small_Page.
30 @section How_to_Use How to Use Embryo?
32 To use Embryo in your code, you need to do at least the following:
35 @li Load the Embryo program using one of the
36 @ref Embryo_Program_Creation_Group.
37 @li Set up the native calls with #embryo_program_native_call_add.
38 @li Create a virtual machine with #embryo_program_vm_push.
39 @li Then run the program with @ref embryo_program_run.
41 @todo Clean up compiler code.
42 @todo Proper overview of the operation of the interpreter, that is how
43 the heap, stack, virtual machines, etc fit together.
45 @page Small_Page Brief Introduction to Small
47 This section describes the basics of Small, as compiled and interpreted
50 This summary assumes that you are familar with C. For a full list of
51 differences between C and Small, again, see the full documentation.
53 @section Small_Variables_Section Variables
55 @subsection Small_Type_Subsection Types
57 There is only one type, known as the "cell", which can hold an integer.
59 @subsection Small_Scope_Subsection Scope
61 The scope and usage of a variable depends on its declaration.
63 @li A local variable is normally declared with the @c new keyword. E.g.
64 @code new variable @endcode
65 @li A static function variable is defined within a function with the
67 @li A global static variable is one that is only available within the
68 file it was declared in. Again, use the @c static keyword, but outside
70 @li A stock variable is one that may not be compiled into a program if it
71 is not used. It is declared using @c stock.
72 @li A public variable is one that can be read by the host program using
73 #embryo_program_variable_find. It is declared using @c public
76 Remember that the keywords above are to be used on their own. That is,
77 for example: @code public testvar @endcode not:
78 @code new public testvar @endcode
80 @subsection Small_Constants_Subsection Constants
82 You can declare constants in two ways:
83 @li Using the preprocessor macro @c \#define.
84 @li By inserting @c const between the keyword and variable name of a
85 variable declaration. For example, to declare the variable @c var1
86 constant, you type @code new const var1 = 2 @endcode Now @c var1
89 @subsection Small_Arrays_Subsection Arrays
91 To declare an array, append square brackets to the end of the variable
92 name. The following examples show how to declare arrays. Note the
93 use of the ellipsis operator, which bases the array based on the last two
97 new msg[] = "A message."
98 new ints[] = {1, 3, 4}
99 new ints2[20] = {1, 3} // All other elements 0.
100 new ints3[10] = {1, ... } // All elements = 1
101 new ints4[10] = {10, 20, ... } // Elements = 10 -> 100.
102 // The difference can be negative.
103 new ints5[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
106 @note Array initialisers need to be constant.
108 @section Small_Func_Calls_Section Function Calls
110 A typical function declaration is as follows:
115 // over a couple of lines.
119 You can pass by reference. That is, the parameter you pass is changed
120 outside of the function. For example:
125 // The passed variable will be set to 10 outside of the function.
133 // Do something to the array
137 @note Arrays are passed by reference.
139 @section Small_Control_Subsection Control Structures.
141 Small has the following control structures, which similar to their C
143 @li @code if (expression) statement1 else statement2 @endcode
144 @li @code switch (expression) {
146 statement1 // Can only be one statement. Look Ma, no breaks!
147 case 1..3: // For values between 1 and 3 inclusive.
153 @li @code while(expression) statement @endcode
154 @li @code do statement while (expression) @endcode
155 @li @code for (init_expression; before_iter_test_expression; after_iter_expression) statement @endcode
157 @section Small_Preprocessor_Section Preprocessor
159 The following preprocessor directives are available:
160 @li @code #assert constant_expression @endcode
161 @li @code #define pattern replacement @endcode
162 @li @code #define pattern(%1,%2,...) replacement @endcode
163 @li @code #include filename @endcode
164 @li @code #if constant_expression
165 // Various bits of code
167 // Other bits of code
170 @li @code #undef pattern @endcode
173 @page Available_Native_Calls_Page Available Calls
175 Embryo provides a minimal set of native calls that can be used within
176 any Embryo script. Those calls are detailed here.
178 @note Some of the "core" functions here are also described in the full
179 Small documentation given
181 @todo Finish this section.
183 @section Args_ANC_Section Argument Functions
185 @subsection Numargs_Desc numargs
187 Returns the number of arguments passed to a function. Useful
188 when dealing with variable argument lists.
190 @subsection Getargs_Desc getarg(arg, index=0)
192 Retrieves the argument number @c arg. If the argument is an array,
193 use @c index to specify the index of the array to return.
195 @subsection Setargs_Desc setargs(arg, index=0, value)
197 Sets the argument number @c arg to the given @c arg. @c index specifies
198 the index of @c arg to set if @c arg is an array.
200 @section String_ANC_Section String Functions
202 Functions that work on strings.
204 @subsection Atoi_Desc atoi
206 Translates an number in string form into an integer.
208 @subsection Fnmatch_Desc fnmatch
210 Buggered if I know what this does?
212 @subsection Strcmp_Desc strcmp
214 String comparing function.
217 @section Float_ANC_Section Float Functions
219 @subsection Float_Desc float
221 @subsection Atof_Desc atof
223 @subsection Float_Mul_Desc float_mul
225 @subsection Float_Div_Desc float_div
227 @subsection Float_Add_Desc float_add
229 @subsection Float_Sub_Desc float_sub
231 @subsection Fract_Desc fract
233 @subsection Round_Desc round
235 @subsection Float_Cmp_Desc float_cmp
237 @subsection Sqrt_Desc sqrt
239 @subsection Pow_Desc pow
241 @subsection Log_Desc log
243 @subsection Sin_Desc sin
245 @subsection Cos_Desc cos
247 @subsection Tan_Desc tan
249 @subsection Abs_Desc abs
251 Returns the absolute value of the given float.
253 @section Time_ANC_Section Time Functions
255 @subsection Seconds_Desc seconds()
257 @subsection Date_Desc date
260 @section Rand_ANC_Section Random Functions
262 @subsection Rand_Desc rand()
264 Returns a random integer.
266 @subsection Randf_Desc randf()
268 Returns a random float.
271 @brief Embryo virtual machine library.
273 This file includes the routines needed for Embryo library interaction.
274 This is the @e only file you need to include.
278 // The following definitions are in Embryo.h, but I did not want to
279 // mess up the formatting of the file
282 @def EMBRYO_FUNCTION_NONE
283 An invalid/non-existent function.
287 @def EMBRYO_FUNCTION_MAIN
288 Start at program entry point. For use with @ref embryo_program_run.
292 @def EMBRYO_FUNCTION_CONT
293 Continue from last address. For use with @ref embryo_program_run.
297 @def EMBRYO_PROGRAM_OK
298 Program was run successfully.
302 @def EMBRYO_PROGRAM_SLEEP
303 The program's execution was interrupted by a Small @c sleep command.
307 @def EMBRYO_PROGRAM_FAIL
308 An error in the program caused it to fail.
319 # ifdef EFL_EMBRYO_BUILD
321 # define EAPI __declspec(dllexport)
324 # endif /* ! DLL_EXPORT */
326 # define EAPI __declspec(dllimport)
327 # endif /* ! EFL_EMBRYO_BUILD */
331 # define EAPI __attribute__ ((visibility("default")))
338 #endif /* ! _WIN32 */
344 #define EMBRYO_VERSION_MAJOR 1
345 #define EMBRYO_VERSION_MINOR 8
347 typedef struct _Embryo_Version
355 EAPI extern Embryo_Version *embryo_version;
357 /* potential error values */
358 typedef enum _Embryo_Error
361 /* reserve the first 15 error codes for exit codes of the abstract machine */
362 EMBRYO_ERROR_EXIT, /** Forced exit */
363 EMBRYO_ERROR_ASSERT, /** Assertion failed */
364 EMBRYO_ERROR_STACKERR, /** Stack/heap collision */
365 EMBRYO_ERROR_BOUNDS, /** Index out of bounds */
366 EMBRYO_ERROR_MEMACCESS, /** Invalid memory access */
367 EMBRYO_ERROR_INVINSTR, /** Invalid instruction */
368 EMBRYO_ERROR_STACKLOW, /** Stack underflow */
369 EMBRYO_ERROR_HEAPLOW, /** Heap underflow */
370 EMBRYO_ERROR_CALLBACK, /** No callback, or invalid callback */
371 EMBRYO_ERROR_NATIVE, /** Native function failed */
372 EMBRYO_ERROR_DIVIDE, /** Divide by zero */
373 EMBRYO_ERROR_SLEEP, /** Go into sleepmode - code can be restarted */
375 EMBRYO_ERROR_MEMORY = 16, /** Out of memory */
376 EMBRYO_ERROR_FORMAT, /** Invalid file format */
377 EMBRYO_ERROR_VERSION, /** File is for a newer version of the Embryo_Program */
378 EMBRYO_ERROR_NOTFOUND, /** Function not found */
379 EMBRYO_ERROR_INDEX, /** Invalid index parameter (bad entry point) */
380 EMBRYO_ERROR_DEBUG, /** Debugger cannot run */
381 EMBRYO_ERROR_INIT, /** Embryo_Program not initialized (or doubly initialized) */
382 EMBRYO_ERROR_USERDATA, /** Unable to set user data field (table full) */
383 EMBRYO_ERROR_INIT_JIT, /** Cannot initialize the JIT */
384 EMBRYO_ERROR_PARAMS, /** Parameter error */
385 EMBRYO_ERROR_DOMAIN, /** Domain error, expression result does not fit in range */
388 /* program run return values */
389 typedef enum _Embryo_Status
391 EMBRYO_PROGRAM_FAIL = 0,
392 EMBRYO_PROGRAM_OK = 1,
393 EMBRYO_PROGRAM_SLEEP = 2,
394 EMBRYO_PROGRAM_BUSY = 3,
395 EMBRYO_PROGRAM_TOOLONG = 4
398 typedef unsigned int Embryo_UCell;
399 typedef int Embryo_Cell;
400 /** An invalid cell reference */
401 #define EMBRYO_CELL_NONE 0x7fffffff
403 typedef struct _Embryo_Program Embryo_Program;
404 typedef int Embryo_Function;
405 /* possible function type values that are enumerated */
406 #define EMBRYO_FUNCTION_NONE 0x7fffffff /* An invalid/non existent function */
407 #define EMBRYO_FUNCTION_MAIN -1 /* Start at program entry point */
408 #define EMBRYO_FUNCTION_CONT -2 /* Continue from last address */
416 #if defined _MSC_VER || defined __SUNPRO_C
417 /** Float to Embryo_Cell */
418 # define EMBRYO_FLOAT_TO_CELL(f) (((Embryo_Float_Cell *)&(f))->c)
419 /** Embryo_Cell to float */
420 # define EMBRYO_CELL_TO_FLOAT(c) (((Embryo_Float_Cell *)&(c))->f)
422 /** Float to Embryo_Cell */
423 # define EMBRYO_FLOAT_TO_CELL(f) ((Embryo_Float_Cell) f).c
424 /** Embryo_Cell to float */
425 # define EMBRYO_CELL_TO_FLOAT(c) ((Embryo_Float_Cell) c).f
430 * @defgroup Embryo_Library_Group Embryo
433 * Functions that start up and shutdown the Embryo library.
438 * Initialises the Embryo library.
439 * @return The number of times the library has been initialised without being
441 * @ingroup Embryo_Library_Group
443 EAPI int embryo_init(void);
446 * @brief Shuts down the Embryo library.
447 * @return The number of times the library has been initialised without being
449 * @ingroup Embryo_Library_Group
451 EAPI int embryo_shutdown(void);
455 * @defgroup Embryo_Program_Creation_Group Program Creation and Destruction Functions
456 * @ingroup Embryo_Library_Group
458 * Functions that set up programs, and destroy them.
462 * @brief Creates a new Embryo program, with bytecode data that can be freed.
464 * @param[in] data Pointer to the bytecode of the program.
465 * @param[in] size Number of bytes of bytecode.
466 * @return A new Embryo program.
467 * @ingroup Embryo_Program_Creation_Group
469 EAPI Embryo_Program *embryo_program_new(void *data, int size);
472 * @brief Creates a new Embryo program, with bytecode data that cannot be
475 * @param[in] data Pointer to the bytecode of the program.
476 * @param[in] size Number of bytes of bytecode.
477 * @return A new Embryo program.
478 * @ingroup Embryo_Program_Creation_Group
480 EAPI Embryo_Program *embryo_program_const_new(void *data, int size);
483 * @brief Creates a new Embryo program based on the bytecode data stored in the
486 * @param[in] file Filename of the given file.
487 * @return A new Embryo program.
488 * @ingroup Embryo_Program_Creation_Group
490 EAPI Embryo_Program *embryo_program_load(const char *file);
493 * @brief Frees the given Embryo program.
495 * @param[in] ep The given program.
496 * @ingroup Embryo_Program_Creation_Group
498 EAPI void embryo_program_free(Embryo_Program *ep);
502 * @defgroup Embryo_Func_Group Function Functions
503 * @ingroup Embryo_Library_Group
505 * @brief Functions that deal with Embryo program functions.
509 * @brief Adds a native program call to the given Embryo program.
511 * @param[in] ep The given Embryo program.
512 * @param[in] name The name for the call used in the script.
513 * @param[in] func The function to use when the call is made.
514 * @ingroup Embryo_Func_Group
517 EAPI void embryo_program_native_call_add(Embryo_Program *ep, const char *name, Embryo_Cell (*func) (Embryo_Program *ep, Embryo_Cell *params));
521 * @defgroup Embryo_Program_VM_Group Virtual Machine Functions
522 * @ingroup Embryo_Library_Group
524 * Functions that deal with creating and destroying virtual machine sessions
525 * for a given program.
527 * A given embryo program can have multiple virtual machine sessions running.
528 * This is useful when you have a native call that in turn calls a function in
529 * the embryo program. The native call can start a new virtual machine
530 * session to run the function it needs. Once completed, the session can be
531 * popped off the program's stack, and the native call can return its value
532 * to the old session.
534 * A new virtual machine session is created by pushing a new virtual machine
535 * onto the session stack of a program using #embryo_program_vm_push.
536 * The current virtual machine session can be destroyed by calling
537 * @ref embryo_program_vm_pop.
541 * @brief Resets the current virtual machine session of the given program.
542 * @param ep The given program.
543 * @ingroup Embryo_Program_VM_Group
546 EAPI void embryo_program_vm_reset(Embryo_Program *ep);
549 * @brief Starts a new virtual machine session for the given program.
551 * See @ref Embryo_Program_VM_Group for more information about how this works.
553 * @param[in] ep The given program.
554 * @ingroup Embryo_Program_VM_Group
556 EAPI void embryo_program_vm_push(Embryo_Program *ep);
559 * @brief Frees the current virtual machine session associated with the given program.
561 * See @ref Embryo_Program_VM_Group for more information about how this works.
562 * Note that you will need to retrieve any return data or data on the stack
565 * @param[in] ep The given program.
566 * @ingroup Embryo_Program_VM_Group
568 EAPI void embryo_program_vm_pop(Embryo_Program *ep);
572 * @defgroup Embryo_Swap_Group Byte Swapping Functions
573 * @ingroup Embryo_Library_Group
575 * @brief Functions that are used to ensure that integers passed to the
576 * virtual machine are in small endian format. These functions are
577 * used to ensure that the virtual machine operates correctly on big
582 * @brief Ensures that the given unsigned short integer is in the small
584 * @param v Pointer to the given integer.
585 * @ingroup Embryo_Swap_Group
587 EAPI void embryo_swap_16(unsigned short *v);
590 * @brief Ensures that the given unsigned integer is in the small endian
593 * @param[in] v Pointer to the given integer.
594 * @ingroup Embryo_Swap_Group
596 EAPI void embryo_swap_32(unsigned int *v);
599 * @brief Returns the function in the given program with the given name.
601 * @param[in] ep The given program.
602 * @param[in] name The given function name.
603 * @return The function if successful. Otherwise, @c EMBRYO_FUNCTION_NONE.
604 * @ingroup Embryo_Func_Group
606 EAPI Embryo_Function embryo_program_function_find(Embryo_Program *ep, const char *name);
610 * @defgroup Embryo_Public_Variable_Group Public Variable Access Functions
611 * @ingroup Embryo_Library_Group
613 * @brief In an Embryo program, a global variable can be declared public, as
614 * described in @ref Small_Scope_Subsection. The functions here allow
615 * the host program to access these public variables.
619 * @brief Retrieves the location of the public variable in the given program
620 * with the given name.
621 * @param ep The given program.
622 * @param name The given name.
623 * @return The address of the variable if found. @c EMBRYO_CELL_NONE
625 * @ingroup Embryo_Public_Variable_Group
627 EAPI Embryo_Cell embryo_program_variable_find(Embryo_Program *ep, const char *name);
630 * @brief Retrieves the number of public variables in the given program.
632 * @param[in] ep The given program.
633 * @return The number of public variables.
634 * @ingroup Embryo_Public_Variable_Group
636 EAPI int embryo_program_variable_count_get(Embryo_Program *ep);
639 * @brief Retrieves the location of the public variable in the given program
640 * with the given identifier.
642 * @param[in] ep The given program.
643 * @param[in] num The identifier of the public variable.
644 * @return The virtual machine address of the variable if found.
645 * @c EMBRYO_CELL_NONE otherwise.
646 * @ingroup Embryo_Public_Variable_Group
648 EAPI Embryo_Cell embryo_program_variable_get(Embryo_Program *ep, int num);
652 * @defgroup Embryo_Error_Group Error Functions
653 * @ingroup Embryo_Library_Group
655 * Functions that set and retrieve error codes in Embryo programs.
659 * @brief Sets the error code for the given program to the given code.
660 * @param ep The given program.
661 * @param error The given error code.
662 * @ingroup Embryo_Error_Group
664 EAPI void embryo_program_error_set(Embryo_Program *ep, Embryo_Error error);
667 * @brief Retrieves the current error code for the given program.
669 * @param[in] ep The given program.
670 * @return The current error code.
671 * @ingroup Embryo_Error_Group
673 EAPI Embryo_Error embryo_program_error_get(Embryo_Program *ep);
677 * @defgroup Embryo_Program_Data_Group Program Data Functions
678 * @ingroup Embryo_Library_Group
680 * Functions that set and retrieve data associated with the given
685 * @brief Sets the data associated to the given program.
686 * @param ep The given program.
687 * @param data New bytecode data.
688 * @ingroup Embryo_Program_Data_Group
690 EAPI void embryo_program_data_set(Embryo_Program *ep, void *data);
693 * @brief Retrieves the data associated to the given program.
694 * @param ep The given program.
695 * @ingroup Embryo_Program_Data_Group
697 EAPI void *embryo_program_data_get(Embryo_Program *ep);
700 * @brief Retrieves a string describing the given error code.
702 * @param[in] error The given error code.
703 * @return String describing the given error code. If the given code is not
704 * known, the string "(unknown)" is returned.
705 * @ingroup Embryo_Error_Group
707 EAPI const char *embryo_error_string_get(Embryo_Error error);
711 * @defgroup Embryo_Data_String_Group Embryo Data String Functions
712 * @ingroup Embryo_Library_Group
714 * Functions that operate on strings in the memory of a virtual machine.
718 * @brief Retrieves the length of the string starting at the given cell.
719 * @param ep The program the cell is part of.
720 * @param str_cell Pointer to the first cell of the string.
721 * @return The length of the string. @c 0 is returned if there is an error.
722 * @ingroup Embryo_Data_String_Group
724 EAPI int embryo_data_string_length_get(Embryo_Program *ep, Embryo_Cell *str_cell);
727 * @brief Copies the string starting at the given cell to the given buffer.
729 * @param[in] ep The program the cell is part of.
730 * @param[in] str_cell Pointer to the first cell of the string.
731 * @param[out] dst The given buffer.
732 * @ingroup Embryo_Data_String_Group
734 EAPI void embryo_data_string_get(Embryo_Program *ep, Embryo_Cell *str_cell, char *dst);
737 * @brief Copies string in the given buffer into the virtual machine memory
738 * starting at the given cell.
740 * @param[in] ep The program the cell is part of.
741 * @param[in] src The given buffer.
742 * @param[in] str_cell Pointer to the first cell to copy the string to.
743 * @ingroup Embryo_Data_String_Group
745 EAPI void embryo_data_string_set(Embryo_Program *ep, const char *src, Embryo_Cell *str_cell);
748 * @brief Retreives a pointer to the address in the virtual machine given by the
751 * @param[in] ep The program whose virtual machine address is being queried.
752 * @param[in] addr The given cell.
753 * @return A pointer to the cell at the given address.
754 * @ingroup Embryo_Data_String_Group
756 EAPI Embryo_Cell *embryo_data_address_get(Embryo_Program *ep, Embryo_Cell addr);
761 * @defgroup Embryo_Heap_Group Heap Functions
762 * @ingroup Embryo_Library_Group
764 * The heap is an area of memory that can be allocated for program
765 * use at runtime. The heap functions here change the amount of heap
770 * @brief Increases the size of the heap of the given virtual machine by the given
771 * number of Embryo_Cells.
773 * @param[in] ep The program with the given virtual machine.
774 * @param[in] cells The given number of Embryo_Cells.
775 * @return The address of the new memory region on success.
776 * @c EMBRYO_CELL_NONE otherwise.
777 * @ingroup Embryo_Heap_Group
779 EAPI Embryo_Cell embryo_data_heap_push(Embryo_Program *ep, int cells);
782 * @brief Decreases the size of the heap of the given virtual machine down to the
785 * @param[in] ep The program with the given virtual machine.
786 * @param[in] down_to The given size.
787 * @ingroup Embryo_Heap_Group
789 EAPI void embryo_data_heap_pop(Embryo_Program *ep, Embryo_Cell down_to);
794 * @defgroup Embryo_Run_Group Program Run Functions
795 * @ingroup Embryo_Library_Group
797 * Functions that are involved in actually running functions in an
802 * @brief Returns the number of virtual machines are running for the given program.
803 * @param ep The given program.
804 * @return The number of virtual machines running.
805 * @ingroup Embryo_Run_Group
807 EAPI int embryo_program_recursion_get(Embryo_Program *ep);
810 * @brief Runs the given function of the given Embryo program in the current
811 * virtual machine. The parameter @p fn can be found using
812 * @ref embryo_program_function_find.
814 * @note For Embryo to be able to run a function, it must have been
815 * declared @c public in the Small source code.
817 * @param[in] ep The given program.
818 * @param[in] func The given function. Normally "main", in which case the
819 * constant @c EMBRYO_FUNCTION_MAIN can be used.
820 * @return @c EMBRYO_PROGRAM_OK on success. @c EMBRYO_PROGRAM_SLEEP if the
821 * program is halted by the Small @c sleep call.
822 * @c EMBRYO_PROGRAM_FAIL if there is an error.
823 * @c EMBRYO_PROGRAM_TOOLONG if the program executes for longer than
824 * it is allowed to in abstract machine instruction count.
825 * @ingroup Embryo_Run_Group
827 EAPI Embryo_Status embryo_program_run(Embryo_Program *ep, Embryo_Function func);
830 * @brief Retreives the return value of the last called function of the given
833 * @param[in] ep The given program.
834 * @return An Embryo_Cell representing the return value of the function
835 * that was last called.
836 * @ingroup Embryo_Run_Group
838 EAPI Embryo_Cell embryo_program_return_value_get(Embryo_Program *ep);
841 * @brief Sets the maximum number of abstract machine cycles any given program run
842 * can execute before being put to sleep and returning.
844 * @param[in] ep The given program.
845 * @param[in] max The number of machine cycles as a limit.
847 * This sets the maximum number of abstract machine (virtual machine)
848 * instructions that a single run of an embryo function (even if its main)
849 * can use before embryo embryo_program_run() reutrns with the value
850 * EMBRYO_PROGRAM_TOOLONG. If the function fully executes within this number
851 * of cycles, embryo_program_run() will return as normal with either
852 * EMBRYO_PROGRAM_OK, EMBRYO_PROGRAM_FAIL or EMBRYO_PROGRAM_SLEEP. If the
853 * run exceeds this instruction count, then EMBRYO_PROGRAM_TOOLONG will be
854 * returned indicating the program exceeded its run count. If the app wishes
855 * to continue running this anyway - it is free to process its own events or
856 * whatever it wants and continue the function by calling
857 * embryo_program_run(program, EMBRYO_FUNCTION_CONT); which will start the
858 * run again until the instruction count is reached. This can keep being done
859 * to allow the calling program to still be able to control things outside the
860 * embryo function being called. If the maximum run cycle count is 0 then the
861 * program is allowed to run forever only returning when it is done.
863 * It is important to note that abstract machine cycles are NOT the same as
864 * the host machine cpu cycles. They are not fixed in runtime per cycle, so
865 * this is more of a helper tool than a way to HARD-FORCE a script to only
866 * run for a specific period of time. If the cycle count is set to something
867 * low like 5000 or 1000, then every 1000 (or 5000) cycles control will be
868 * returned to the calling process where it can check a timer to see if a
869 * physical runtime limit has been elapsed and then abort running further
870 * assuming a "runaway script" or keep continuing the script run. This
871 * limits resolution to only that many cycles which do not take a determined
872 * amount of time to execute, as this varies from cpu to cpu and also depends
873 * on how loaded the system is. Making the max cycle run too low will
874 * impact performance requiring the abstract machine to do setup and teardown
875 * cycles too often comapred to cycles actually executed.
877 * Also note it does NOT include nested abstract machines. IF this abstract
878 * machine run calls embryo script that calls a native function that in turn
879 * calls more embryo script, then the 2nd (and so on) levels are not included
880 * in this run count. They can set their own max instruction count values
883 * The default max cycle run value is 0 in any program until set with this
886 * @ingroup Embryo_Run_Group
888 EAPI void embryo_program_max_cycle_run_set(Embryo_Program *ep, int max);
891 * @brief Retreives the maximum number of abstract machine cycles a program is allowed
894 * @param[in] ep The given program.
895 * @return The number of cycles a run cycle is allowed to run for this
898 * This returns the value set by embryo_program_max_cycle_run_set(). See
899 * embryo_program_max_cycle_run_set() for more information.
901 * @ingroup Embryo_Run_Group
903 EAPI int embryo_program_max_cycle_run_get(Embryo_Program *ep);
908 * @defgroup Embryo_Parameter_Group Function Parameter Functions
909 * @ingroup Embryo_Library_Group
911 * Functions that set parameters for the next function that is called.
915 * @brief Pushes an Embryo_Cell onto the function stack to use as a parameter for
916 * the next function that is called in the given program.
917 * @param ep The given program.
918 * @param cell The Embryo_Cell to push onto the stack.
919 * @return @c 1 if successful. @c 0 otherwise.
920 * @ingroup Embryo_Parameter_Group
922 EAPI int embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell);
925 * @brief Pushes a string onto the function stack to use as a parameter for the
926 * next function that is called in the given program.
928 * @param[in] ep The given program.
929 * @param[in] str The string to push onto the stack.
930 * @return @c 1 if successful. @c 0 otherwise.
931 * @ingroup Embryo_Parameter_Group
933 EAPI int embryo_parameter_string_push(Embryo_Program *ep, const char *str);
936 * @brief Pushes an array of Embryo_Cells onto the function stack to be used as
937 * parameters for the next function that is called in the given program.
939 * @param[in] ep The given program.
940 * @param[in] cells The array of Embryo_Cells.
941 * @param[in] num The number of cells in @p cells.
942 * @return @c 1 if successful. @c 0 otherwise.
943 * @ingroup Embryo_Parameter_Group
945 EAPI int embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num);