3 @mainpage Embryo Library Documentation
6 @author Carsten Haitzler <raster@rasterman.com>
10 @section intro What is Embryo?
12 Embryo is a tiny library designed to interpret limited Small programs
13 compiled by the included compiler, @c embryo_cc. It is mostly a cleaned
14 up and smaller version of the original Small abstract machine. The
15 compiler is mostly untouched.
17 For more information about the Small language, see @ref Small_Page.
19 @section How_to_Use How to Use Embryo?
21 To use Embryo in your code, you need to do at least the following:
23 @li Include @ref Embryo.h.
24 @li Load the Embryo program using one of the
25 @ref Embryo_Program_Creation_Group.
26 @li Set up the native calls with @ref embryo_program_native_call_add.
27 @li Create a virtual machine with @ref embryo_program_vm_push.
28 @li Then run the program with @ref embryo_program_run.
30 @todo Clean up compiler code.
31 @todo Proper overview of the operation of the interpreter, that is how
32 the heap, stack, virtual machines, etc fit together.
36 @page Small_Page Brief Introduction to Small
38 This section describes the basics of Small, as compiled and interpreted
39 with Embryo. For the full documentation, of which this is a summary, see
40 @htmlonly <a href=http://www.compuphase.com/smalldoc.pdf>Small Language Booklet</a>
42 @latexonly http://www.compuphase.com/smalldoc.pdf @endlatexonly
44 This summary assumes that you are familar with C. For a full list of
45 differences between C and Small, again, see the full documentation.
47 @section Small_Variables_Section Variables
49 @subsection Small_Type_Subsection Types
51 There is only one type, known as the "cell", which can hold an integer.
53 @subsection Small_Scope_Subsection Scope
55 The scope and usage of a variable depends on its declaration.
57 @li A local variable is normally declared with the @c new keyword. E.g.
58 @code new variable @endcode
59 @li A static function variable is defined within a function with the
61 @li A global static variable is one that is only available within the
62 file it was declared in. Again, use the @c static keyword, but outside
64 @li A stock variable is one that may not be compiled into a program if it
65 is not used. It is declared using @c stock.
66 @li A public variable is one that can be read by the host program using
67 @ref embryo_program_variable_find. It is declared using @c public
70 Remember that the keywords above are to be used on their own. That is,
71 for example: @code public testvar @endcode not:
72 @code new public testvar @endcode
74 @subsection Small_Constants_Subsection Constants
76 You can declare constants in two ways:
77 @li Using the preprocessor macro @c #define.
78 @li By inserting @c const between the keyword and variable name of a
79 variable declaration. For example, to declare the variable @c var1
80 constant, you type @code new const var1 = 2 @endcode Now @c var1
83 @subsection Small_Arrays_Subsection Arrays
85 To declare an array, append square brackets to the end of the variable
86 name. The following examples show how to declare arrays. Note the
87 use of the ellipsis operator, which bases the array based on the last two
91 new msg[] = "A message."
92 new ints[] = {1, 3, 4}
93 new ints2[20] = {1, 3} // All other elements 0.
94 new ints3[10] = {1, ... } // All elements = 1
95 new ints4[10] = {10, 20, ... } // Elements = 10 -> 100.
96 // The difference can be negative.
97 new ints5[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
100 @note Array initialisers need to be constant.
102 @section Small_Func_Calls_Section Function Calls
104 A typical function declaration is as follows:
109 // over a couple of lines.
113 You can pass by reference. That is, the parameter you pass is changed
114 outside of the function. For example:
119 // The passed variable will be set to 10 outside of the function.
127 // Do something to the array
131 @note Arrays are passed by reference.
133 @section Small_Control_Subsection Control Structures.
135 Small has the following control structures, which similar to their C
137 @li @code if (expression) statement1 else statement2 @endcode
138 @li @code switch (expression) {
140 statement1 // Can only be one statement. Look Ma, no breaks!
141 case 1..3: // For values between 1 and 3 inclusive.
147 @li @code while(expression) statement @endcode
148 @li @code do statement while (expression) @endcode
149 @li @code for (init_expression; before_iter_test_expression; after_iter_expression) statement @endcode
151 @section Small_Preprocessor_Section Preprocessor
153 The following preprocessor directives are available:
154 @li @code #assert constant_expression @endcode
155 @li @code #define pattern replacement @endcode
156 @li @code #define pattern(%1,%2,...) replacement @endcode
157 @li @code #include filename @endcode
158 @li @code #if constant_expression
159 // Various bits of code
161 // Other bits of code
164 @li @code #undef pattern @endcode
170 @page Available_Native_Calls_Page Available Calls
172 Embryo provides a minimal set of native calls that can be used within
173 any Embryo script. Those calls are detailed here.
175 @note Some of the "core" functions here are also described in the full
176 Small documentation given
178 @todo Finish this section.
180 @section Args_ANC_Section Argument Functions
182 @subsection Numargs_Desc numargs
184 Returns the number of arguments passed to a function. Useful
185 when dealing with variable argument lists.
187 @subsection Getargs_Desc getarg(arg, index=0)
189 Retrieves the argument number @c arg. If the argument is an array,
190 use @c index to specify the index of the array to return.
192 @subsection Setargs_Desc setargs(arg, index=0, value)
194 Sets the argument number @c arg to the given @c arg. @c index specifies
195 the index of @c arg to set if @c arg is an array.
197 @section String_ANC_Section String Functions
199 Functions that work on strings.
201 @subsection Atoi_Desc atoi
203 Translates an number in string form into an integer.
205 @subsection Fnmatch_Desc fnmatch
207 Buggered if I know what this does?
209 @subsection Strcmp_Desc strcmp
211 String comparing function.
214 @section Float_ANC_Section Float Functions
216 @subsection Float_Desc float
218 @subsection Atof_Desc atof
220 @subsection Float_Mul_Desc float_mul
222 @subsection Float_Div_Desc float_div
224 @subsection Float_Add_Desc float_add
226 @subsection Float_Sub_Desc float_sub
228 @subsection Fract_Desc fract
230 @subsection Round_Desc round
232 @subsection Float_Cmp_Desc float_cmp
234 @subsection Sqrt_Desc sqrt
236 @subsection Pow_Desc pow
238 @subsection Log_Desc log
240 @subsection Sin_Desc sin
242 @subsection Cos_Desc cos
244 @subsection Tan_Desc tan
246 @subsection Abs_Desc abs
248 Returns the absolute value of the given float.
250 @section Time_ANC_Section Time Functions
252 @subsection Seconds_Desc seconds()
254 @subsection Date_Desc date
257 @section Rand_ANC_Section Random Functions
259 @subsection Rand_Desc rand()
261 Returns a random integer.
263 @subsection Randf_Desc randf()
265 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-existant 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.