1Small_Page(3)              Library Functions Manual              Small_Page(3)
2
3
4

NAME

6       Small_Page - Brief Introduction to Small This section describes the
7       basics of Small, as compiled and interpreted with Embryo.
8
9       For the full documentation, of which this is a summary, see
10
11       This summary assumes that you are familar with C. For a full list of
12       differences between C and Small, again, see the full documentation.
13

Variables

15   Types
16       There is only one type, known as the 'cell', which can hold an integer.
17
18   Scope
19       The scope and usage of a variable depends on its declaration.
20
21       · A local variable is normally declared with the new keyword. E.g.
22        new variable
23
24       · A static function variable is defined within a function with the
25         static keyword.
26       · A global static variable is one that is only available within the
27         file it was declared in. Again, use the static keyword, but outside
28         of any function.
29       · A stock variable is one that may not be compiled into a program if it
30         is not used. It is declared using stock.
31       · A public variable is one that can be read by the host program using
32         embryo_program_variable_find. It is declared using public keyword.
33       Remember that the keywords above are to be used on their own. That is,
34       for example:
35        public testvar
36
37        not:
38        new public testvar
39
40   Constants
41       You can declare constants in two ways:
42
43       · Using the preprocessor macro #define.
44       · By inserting const between the keyword and variable name of a
45         variable declaration. For example, to declare the variable var1
46         constant, you type
47        new const var1 = 2
48
49        Now var1 cannot be changed.
50   Arrays
51       To declare an array, append square brackets to the end of the variable
52       name. The following examples show how to declare arrays. Note the use
53       of the ellipsis operator, which bases the array based on the last two
54       declared values:
55       new msg[] = 'A message.'
56       new ints[] = {1, 3, 4}
57       new ints2[20] = {1, 3}         // All other elements 0.
58       new ints3[10] = {1, ... }      // All elements = 1
59       new ints4[10] = {10, 20, ... } // Elements = 10 -> 100.
60                                      // The difference can be negative.
61       new ints5[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
62       Note:
63           Array initialisers need to be constant.

Function Calls

65       A typical function declaration is as follows:
66       testfunc(param) {
67         // Do something ...
68         // over a couple of lines.
69       }
70       You can pass by reference. That is, the parameter you pass is changed
71       outside of the function. For example:
72       testfunc(&param) {
73         param = 10
74         // The passed variable will be set to 10 outside of the function.
75       }
76       To pass an array:
77       testfunc(param[]) {
78         // Do something to the array
79       }
80       Note:
81           Arrays are passed by reference.

Control Structures.

83       Small has the following control structures, which similar to their C
84       counterparts:
85
86       ·
87        if (expression) statement1 else statement2
88       ·
89        switch (expression) {
90         case 0:
91           statement1 // Can only be one statement.  Look Ma, no breaks!
92         case 1..3:   // For values between 1 and 3 inclusive.
93           statement2
94         default:     // Optional
95           statement3
96       }
97       ·
98        while(expression) statement
99       ·
100        do statement while (expression)
101       ·
102        for (init_expression; before_iter_test_expression; after_iter_expression) statement

Preprocessor

104       The following preprocessor directives are available:
105
106       ·
107        #assert constant_expression
108       ·
109        #define pattern replacement
110       ·
111        #define pattern(%1,%2,...) replacement
112       ·
113        #include filename
114       ·
115        #if constant_expression
116         // Various bits of code
117       #else
118         // Other bits of code
119       #endif
120       ·
121        #undef pattern
122Embryo                            2 Jul 2010                     Small_Page(3)
Impressum