5 These routines are used for Embryo.
10 @mainpage Embryo Library Documentation
14 @version @PACKAGE_VERSION@
15 @author Carsten Haitzler <raster\@rasterman.com>
19 @section intro What is Embryo?
21 Embryo is a tiny library designed to interpret limited Small programs
22 compiled by the included compiler, @c embryo_cc. It is mostly a cleaned
23 up and smaller version of the original Small abstract machine. The
24 compiler is mostly untouched.
26 Small was renamed to Pawn.
27 For more information about the Pawn language, see
28 @htmlonly <a href=http://www.compuphase.com/pawn/pawn.htm>Pawn</a>
30 @latexonly http://www.compuphase.com/pawn/pawn.htm @endlatexonly
31 For the basics about the Small language, see @ref Small_Page.
33 @section How_to_Use How to Use Embryo?
35 To use Embryo in your code, you need to do at least the following:
37 @li Include @ref Embryo.h.
38 @li Load the Embryo program using one of the
39 @ref Embryo_Program_Creation_Group.
40 @li Set up the native calls with @ref embryo_program_native_call_add.
41 @li Create a virtual machine with @ref embryo_program_vm_push.
42 @li Then run the program with @ref embryo_program_run.
44 @todo Clean up compiler code.
45 @todo Proper overview of the operation of the interpreter, that is how
46 the heap, stack, virtual machines, etc fit together.
50 @page Small_Page Brief Introduction to Small
52 This section describes the basics of Small, as compiled and interpreted
55 This summary assumes that you are familar with C. For a full list of
56 differences between C and Small, again, see the full documentation.
58 @section Small_Variables_Section Variables
60 @subsection Small_Type_Subsection Types
62 There is only one type, known as the "cell", which can hold an integer.
64 @subsection Small_Scope_Subsection Scope
66 The scope and usage of a variable depends on its declaration.
68 @li A local variable is normally declared with the @c new keyword. E.g.
69 @code new variable @endcode
70 @li A static function variable is defined within a function with the
72 @li A global static variable is one that is only available within the
73 file it was declared in. Again, use the @c static keyword, but outside
75 @li A stock variable is one that may not be compiled into a program if it
76 is not used. It is declared using @c stock.
77 @li A public variable is one that can be read by the host program using
78 @ref embryo_program_variable_find. It is declared using @c public
81 Remember that the keywords above are to be used on their own. That is,
82 for example: @code public testvar @endcode not:
83 @code new public testvar @endcode
85 @subsection Small_Constants_Subsection Constants
87 You can declare constants in two ways:
88 @li Using the preprocessor macro @c \#define.
89 @li By inserting @c const between the keyword and variable name of a
90 variable declaration. For example, to declare the variable @c var1
91 constant, you type @code new const var1 = 2 @endcode Now @c var1
94 @subsection Small_Arrays_Subsection Arrays
96 To declare an array, append square brackets to the end of the variable
97 name. The following examples show how to declare arrays. Note the
98 use of the ellipsis operator, which bases the array based on the last two
102 new msg[] = "A message."
103 new ints[] = {1, 3, 4}
104 new ints2[20] = {1, 3} // All other elements 0.
105 new ints3[10] = {1, ... } // All elements = 1
106 new ints4[10] = {10, 20, ... } // Elements = 10 -> 100.
107 // The difference can be negative.
108 new ints5[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
111 @note Array initialisers need to be constant.
113 @section Small_Func_Calls_Section Function Calls
115 A typical function declaration is as follows:
120 // over a couple of lines.
124 You can pass by reference. That is, the parameter you pass is changed
125 outside of the function. For example:
130 // The passed variable will be set to 10 outside of the function.
138 // Do something to the array
142 @note Arrays are passed by reference.
144 @section Small_Control_Subsection Control Structures.
146 Small has the following control structures, which similar to their C
148 @li @code if (expression) statement1 else statement2 @endcode
149 @li @code switch (expression) {
151 statement1 // Can only be one statement. Look Ma, no breaks!
152 case 1..3: // For values between 1 and 3 inclusive.
158 @li @code while(expression) statement @endcode
159 @li @code do statement while (expression) @endcode
160 @li @code for (init_expression; before_iter_test_expression; after_iter_expression) statement @endcode
162 @section Small_Preprocessor_Section Preprocessor
164 The following preprocessor directives are available:
165 @li @code #assert constant_expression @endcode
166 @li @code #define pattern replacement @endcode
167 @li @code #define pattern(%1,%2,...) replacement @endcode
168 @li @code #include filename @endcode
169 @li @code #if constant_expression
170 // Various bits of code
172 // Other bits of code
175 @li @code #undef pattern @endcode
181 @page Available_Native_Calls_Page Available Calls
183 Embryo provides a minimal set of native calls that can be used within
184 any Embryo script. Those calls are detailed here.
186 @note Some of the "core" functions here are also described in the full
187 Small documentation given
189 @todo Finish this section.
191 @section Args_ANC_Section Argument Functions
193 @subsection Numargs_Desc numargs
195 Returns the number of arguments passed to a function. Useful
196 when dealing with variable argument lists.
198 @subsection Getargs_Desc getarg(arg, index=0)
200 Retrieves the argument number @c arg. If the argument is an array,
201 use @c index to specify the index of the array to return.
203 @subsection Setargs_Desc setargs(arg, index=0, value)
205 Sets the argument number @c arg to the given @c arg. @c index specifies
206 the index of @c arg to set if @c arg is an array.
208 @section String_ANC_Section String Functions
210 Functions that work on strings.
212 @subsection Atoi_Desc atoi
214 Translates an number in string form into an integer.
216 @subsection Fnmatch_Desc fnmatch
218 Buggered if I know what this does?
220 @subsection Strcmp_Desc strcmp
222 String comparing function.
225 @section Float_ANC_Section Float Functions
227 @subsection Float_Desc float
229 @subsection Atof_Desc atof
231 @subsection Float_Mul_Desc float_mul
233 @subsection Float_Div_Desc float_div
235 @subsection Float_Add_Desc float_add
237 @subsection Float_Sub_Desc float_sub
239 @subsection Fract_Desc fract
241 @subsection Round_Desc round
243 @subsection Float_Cmp_Desc float_cmp
245 @subsection Sqrt_Desc sqrt
247 @subsection Pow_Desc pow
249 @subsection Log_Desc log
251 @subsection Sin_Desc sin
253 @subsection Cos_Desc cos
255 @subsection Tan_Desc tan
257 @subsection Abs_Desc abs
259 Returns the absolute value of the given float.
261 @section Time_ANC_Section Time Functions
263 @subsection Seconds_Desc seconds()
265 @subsection Date_Desc date
268 @section Rand_ANC_Section Random Functions
270 @subsection Rand_Desc rand()
272 Returns a random integer.
274 @subsection Randf_Desc randf()
276 Returns a random float.
282 @brief Embryo virtual machine library.
284 This file includes the routines needed for Embryo library interaction.
285 This is the @e only file you need to include.
289 // The following definitions are in Embryo.h, but I did not want to
290 // mess up the formatting of the file
293 @def EMBRYO_FUNCTION_NONE
294 An invalid/non-existent function.
298 @def EMBRYO_FUNCTION_MAIN
299 Start at program entry point. For use with @ref embryo_program_run.
303 @def EMBRYO_FUNCTION_CONT
304 Continue from last address. For use with @ref embryo_program_run.
308 @def EMBRYO_PROGRAM_OK
309 Program was run successfully.
313 @def EMBRYO_PROGRAM_SLEEP
314 The program's execution was interrupted by a Small @c sleep command.
318 @def EMBRYO_PROGRAM_FAIL
319 An error in the program caused it to fail.