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 For more information about the Small language, see @ref Small_Page.
28 @section How_to_Use How to Use Embryo?
30 To use Embryo in your code, you need to do at least the following:
32 @li Include @ref Embryo.h.
33 @li Load the Embryo program using one of the
34 @ref Embryo_Program_Creation_Group.
35 @li Set up the native calls with @ref embryo_program_native_call_add.
36 @li Create a virtual machine with @ref embryo_program_vm_push.
37 @li Then run the program with @ref embryo_program_run.
39 @todo Clean up compiler code.
40 @todo Proper overview of the operation of the interpreter, that is how
41 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
48 with Embryo. For the full documentation, of which this is a summary, see
49 @htmlonly <a href=http://www.compuphase.com/smalldoc.pdf>Small Language Booklet</a>
51 @latexonly http://www.compuphase.com/smalldoc.pdf @endlatexonly
53 This summary assumes that you are familar with C. For a full list of
54 differences between C and Small, again, see the full documentation.
56 @section Small_Variables_Section Variables
58 @subsection Small_Type_Subsection Types
60 There is only one type, known as the "cell", which can hold an integer.
62 @subsection Small_Scope_Subsection Scope
64 The scope and usage of a variable depends on its declaration.
66 @li A local variable is normally declared with the @c new keyword. E.g.
67 @code new variable @endcode
68 @li A static function variable is defined within a function with the
70 @li A global static variable is one that is only available within the
71 file it was declared in. Again, use the @c static keyword, but outside
73 @li A stock variable is one that may not be compiled into a program if it
74 is not used. It is declared using @c stock.
75 @li A public variable is one that can be read by the host program using
76 @ref embryo_program_variable_find. It is declared using @c public
79 Remember that the keywords above are to be used on their own. That is,
80 for example: @code public testvar @endcode not:
81 @code new public testvar @endcode
83 @subsection Small_Constants_Subsection Constants
85 You can declare constants in two ways:
86 @li Using the preprocessor macro @c \#define.
87 @li By inserting @c const between the keyword and variable name of a
88 variable declaration. For example, to declare the variable @c var1
89 constant, you type @code new const var1 = 2 @endcode Now @c var1
92 @subsection Small_Arrays_Subsection Arrays
94 To declare an array, append square brackets to the end of the variable
95 name. The following examples show how to declare arrays. Note the
96 use of the ellipsis operator, which bases the array based on the last two
100 new msg[] = "A message."
101 new ints[] = {1, 3, 4}
102 new ints2[20] = {1, 3} // All other elements 0.
103 new ints3[10] = {1, ... } // All elements = 1
104 new ints4[10] = {10, 20, ... } // Elements = 10 -> 100.
105 // The difference can be negative.
106 new ints5[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
109 @note Array initialisers need to be constant.
111 @section Small_Func_Calls_Section Function Calls
113 A typical function declaration is as follows:
118 // over a couple of lines.
122 You can pass by reference. That is, the parameter you pass is changed
123 outside of the function. For example:
128 // The passed variable will be set to 10 outside of the function.
136 // Do something to the array
140 @note Arrays are passed by reference.
142 @section Small_Control_Subsection Control Structures.
144 Small has the following control structures, which similar to their C
146 @li @code if (expression) statement1 else statement2 @endcode
147 @li @code switch (expression) {
149 statement1 // Can only be one statement. Look Ma, no breaks!
150 case 1..3: // For values between 1 and 3 inclusive.
156 @li @code while(expression) statement @endcode
157 @li @code do statement while (expression) @endcode
158 @li @code for (init_expression; before_iter_test_expression; after_iter_expression) statement @endcode
160 @section Small_Preprocessor_Section Preprocessor
162 The following preprocessor directives are available:
163 @li @code #assert constant_expression @endcode
164 @li @code #define pattern replacement @endcode
165 @li @code #define pattern(%1,%2,...) replacement @endcode
166 @li @code #include filename @endcode
167 @li @code #if constant_expression
168 // Various bits of code
170 // Other bits of code
173 @li @code #undef pattern @endcode
179 @page Available_Native_Calls_Page Available Calls
181 Embryo provides a minimal set of native calls that can be used within
182 any Embryo script. Those calls are detailed here.
184 @note Some of the "core" functions here are also described in the full
185 Small documentation given
187 @todo Finish this section.
189 @section Args_ANC_Section Argument Functions
191 @subsection Numargs_Desc numargs
193 Returns the number of arguments passed to a function. Useful
194 when dealing with variable argument lists.
196 @subsection Getargs_Desc getarg(arg, index=0)
198 Retrieves the argument number @c arg. If the argument is an array,
199 use @c index to specify the index of the array to return.
201 @subsection Setargs_Desc setargs(arg, index=0, value)
203 Sets the argument number @c arg to the given @c arg. @c index specifies
204 the index of @c arg to set if @c arg is an array.
206 @section String_ANC_Section String Functions
208 Functions that work on strings.
210 @subsection Atoi_Desc atoi
212 Translates an number in string form into an integer.
214 @subsection Fnmatch_Desc fnmatch
216 Buggered if I know what this does?
218 @subsection Strcmp_Desc strcmp
220 String comparing function.
223 @section Float_ANC_Section Float Functions
225 @subsection Float_Desc float
227 @subsection Atof_Desc atof
229 @subsection Float_Mul_Desc float_mul
231 @subsection Float_Div_Desc float_div
233 @subsection Float_Add_Desc float_add
235 @subsection Float_Sub_Desc float_sub
237 @subsection Fract_Desc fract
239 @subsection Round_Desc round
241 @subsection Float_Cmp_Desc float_cmp
243 @subsection Sqrt_Desc sqrt
245 @subsection Pow_Desc pow
247 @subsection Log_Desc log
249 @subsection Sin_Desc sin
251 @subsection Cos_Desc cos
253 @subsection Tan_Desc tan
255 @subsection Abs_Desc abs
257 Returns the absolute value of the given float.
259 @section Time_ANC_Section Time Functions
261 @subsection Seconds_Desc seconds()
263 @subsection Date_Desc date
266 @section Rand_ANC_Section Random Functions
268 @subsection Rand_Desc rand()
270 Returns a random integer.
272 @subsection Randf_Desc randf()
274 Returns a random float.
280 @brief Embryo virtual machine library.
282 This file includes the routines needed for Embryo library interaction.
283 This is the @e only file you need to include.
287 // The following definitions are in Embryo.h, but I did not want to
288 // mess up the formatting of the file
291 @def EMBRYO_FUNCTION_NONE
292 An invalid/non-existant function.
296 @def EMBRYO_FUNCTION_MAIN
297 Start at program entry point. For use with @ref embryo_program_run.
301 @def EMBRYO_FUNCTION_CONT
302 Continue from last address. For use with @ref embryo_program_run.
306 @def EMBRYO_PROGRAM_OK
307 Program was run successfully.
311 @def EMBRYO_PROGRAM_SLEEP
312 The program's execution was interrupted by a Small @c sleep command.
316 @def EMBRYO_PROGRAM_FAIL
317 An error in the program caused it to fail.