This section describes the basics of Small, as compiled and interpreted with Embryo.
This summary assumes that you are familar with C. For a full list of differences between C and Small, again, see the full documentation.
Variables
Types
There is only one type, known as the "cell", which can hold an integer.
Scope
The scope and usage of a variable depends on its declaration.
- A local variable is normally declared with the
new
keyword. E.g.new variable - A static function variable is defined within a function with the
static
keyword. - A global static variable is one that is only available within the file it was declared in. Again, use the
static
keyword, but outside of any function. - A stock variable is one that may not be compiled into a program if it is not used. It is declared using
stock
. - A public variable is one that can be read by the host program using embryo_program_variable_find. It is declared using
public
keyword.
Remember that the keywords above are to be used on their own. That is, for example:
not:
Constants
You can declare constants in two ways:
- Using the preprocessor macro
#define
. - By inserting
const
between the keyword and variable name of a variable declaration. For example, to declare the variablevar1
constant, you typeNownew const var1 = 2var1
cannot be changed.
Arrays
To declare an array, append square brackets to the end of the variable name. The following examples show how to declare arrays. Note the use of the ellipsis operator, which bases the array based on the last two declared values:
- Note
- Array initialisers need to be constant.
Function Calls
A typical function declaration is as follows:
You can pass by reference. That is, the parameter you pass is changed outside of the function. For example:
To pass an array:
- Note
- Arrays are passed by reference.
Control Structures.
Small has the following control structures, which similar to their C counterparts:
- if (expression) statement1 else statement2
- switch (expression) {case 0:statement1 // Can only be one statement. Look Ma, no breaks!case 1..3: // For values between 1 and 3 inclusive.statement2default: // Optionalstatement3}
- while(expression) statement
- do statement while (expression)
- for (init_expression; before_iter_test_expression; after_iter_expression) statement
Preprocessor
The following preprocessor directives are available:
- #assert constant_expression
- #define pattern replacement
- #define pattern(%1,%2,...) replacement
- #include filename
- #if constant_expression// Various bits of code#else// Other bits of code#endif
- #undef pattern