1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en" >
6 <title>The Voodoo Programming Language
</title>
7 <link rel=
"stylesheet" href=
"style.css" type=
"text/css" />
11 <h1>The Voodoo Programming Language
</h1><p class=
"first">A Voodoo program consists of a data, function
12 definitions, and code. All of these are introduced by magic words such
13 as
<code>function
</code>,
<code>call
</code>, and
14 <code>string
</code>. Any part of the program may be preceded by a
15 label, and labels can be referred to from the code. Finally, a program
16 is divided into a data section and a code section.
</p>
18 <h2>Hello World in Voodoo
</h2>
20 <p class=
"first">To quickly get a feeling for a programming language,
21 it is often instructive to look at a simple yet complete program.
22 The following is an implementation of the traditional
23 Hello World program in Voodoo:
</p>
26 #### Hello world in Voodoo
30 string
"Hello, world!\x00"
43 <p class=
"first">When compiled and linked with a library that provides
44 an appropriate implementation of the
<code>puts
</code> function, this
45 program will print
<q>Hello, world!
</q>.
</p>
47 <p>What follows is a more formal description of the Voodoo
48 programming language.
</p>
54 <p class=
"first">Comments start with a hash mark (#) and run until
55 the end of the line. The following is an example comment:
</p>
58 # This is an example comment
63 <p class=
"first">Integers consist of an optional plus or minus sign,
64 followed by one or more digits. Examples of valid integers:
</p>
74 <p class=
"first">Strings consist of zero or more characters enclosed in double
75 quotes. Examples of valid strings:
</p>
84 <p class=
"first">Symbols consist of letters, digits, underscores, and
85 hyphens, although only a letter or an underscore is allowed as the first
86 character of a symbol. Examples of valid symbols:
</p>
93 <h2>Escape Sequences
</h2>
95 <p class=
"first">To facilitate entering special characters and to
96 inhibit the special meaning certain characters normally have, an
97 escape mechanism is provided. Escape sequences start with a backslash,
98 and have the following meanings:
</p>
101 \\ An actual backslash character
102 \
" A double quote character
104 \r A carriage return character
106 \xXX The character with hexadecimal value XX
107 \<space> A space character
108 \<newline> Line continuation character. The newline
109 and any leading whitespace on the next line
113 <p class="first
">Examples of the usage of the escape characters:</p>
115 <table summary="Example Escape Sequences
"><tr>
116 <td><code>"Hello
world\n
"</code></td>
117 <td>A string with a newline in it</td>
119 <td><code>"\\\
""</code></td>
120 <td>A string consisting of a backslash followed by a double quote
</td>
122 <td><code>call foo \
<br />
124 <td>Same as:
<code>call
foo
bar
</code></td>
129 <p class=
"first">Places in a program can be marked with labels, so
130 that the place can be referred to from the code by mentioning the
131 label. A label consists of a symbol followed by a colon. When
132 referring to a label, only the symbol is used.
</p>
134 <p class=
"first">For example:
</p>
141 <p class=
"first">declares a word with the value
12, and a label 'foo'
142 that refers to the place where this value is stored. For example, if
143 the value happens to be loaded at the address
71234, writing 'foo' in
144 the program will have the same effect as writing
71234 in the same
149 <p class=
"first">Values are the smallest unit of data in a Voodoo
150 program. Examples of values are:
</p>
152 <table summary=
"Example Values"><tr>
153 <td><code>12</code></td>
154 <td>The integer
12</td>
156 <td><code>x
</code></td>
157 <td>The value of x (may be a label or a local variable)
</td>
160 <p class=
"first">In the rest of this document, '
<x
>',
161 '
<y
>' and '
<z
>' will be used to indicate
162 arbitrary values.
</p>
166 <p class=
"first">Voodoo code consists of actions. Actions consist of a
167 magic word, usually followed by a number of values. This section lists
168 all actions supported by Voodoo. In the list below, '
<x
>',
169 '
<y
>', and '
<z
>' denote values, '
<symbol
>' denotes a
170 symbol, and '
<expr
>' denotes an expression.
171 (expressions are discussed further on).
</p>
174 <dt><code>call
<x
> <y
> <z
> …</code></dt>
175 <dd>Calls the function
<x
> with the arguments
<y
>
176 <z
> …. There may be zero or more arguments.
</dd>
178 <dt><code>goto
<x
></code></dt>
179 <dd>Continues the program at location
<x
>, rather than at the
180 next action after the goto.
</dd>
182 <dt><code>let
<symbol
> <expr
></code></dt>
183 <dd>Introduces a local variable
<symbol
>, and initializes it to
184 the result of evaluating
<expr
>.
186 This action is only allowed on function level; that is, between
187 <code>function
</code> and the corresponding
<code>end function
</code>,
188 and not inside an
<code>if
… end if
</code> block.
190 The scope of a variable introduced by
<code>let
</code> includes
191 every statement after the
<code>let
</code> action and before the
192 <code>end function
</code> that ends the function in which the
193 variable is introduced.
</dd>
195 <dt><code>return
<expr
></code></dt>
196 <dd>Evaluates
<expr
> and returns the result from the current
199 <dt><code>set
<symbol
> <expr
></code></dt>
200 <dd>Evaluates
<expr
> and assigns the result to
201 <symbol
>.
<symbol
> may not be a label, because labels cannot be
204 <dt><code>set-byte
<base
> <offset
> <x
></code></dt>
205 <dd>Sets the byte at
<base
> +
<offset
> to
<x
>.
206 <offset
> is given as a number of bytes.
</dd>
208 <dt><code>set-word
<base
> <offset
> <x
></code></dt>
209 <dd>Sets the word at
<base
> + WORDSIZE *
<offset
> to
<x
>.
211 The address computed by
<base
> + WORDSIZE *
<offset
>
212 is expected to be a multiple of the word size.
213 The behavior of
<code>set-word
</code> is undefined if this condition
217 <dt><code>tail-call
<x
> <y
> <z
> ...
</code></dt>
218 <dd>Performs a tail call to the function
<x
> with arguments
219 <y
> <z
> …. This has an effect similar to
220 'return call
<x
> <y
> <z
> ...', but re-uses
221 the call frame of the current function. This means that if
<x
>
222 takes fewer or at most as many arguments as the current function,
223 the tail call requires no extra space.
</dd>
228 <p class=
"first">Certain actions have the ability to evaluate
229 expressions. Expressions can be simple values, but expressions can
230 also perform computations on values. The following are valid
234 <dt><code>add
<x
> <y
></code></dt>
235 <dd>The result of adding
<y
> to
<x
>.
237 If the result of the addition cannot be represented in a single word,
238 the result of
<code>add
</code> is undefined.
</dd>
240 <dt><code>and
<x
> <y
></code></dt>
241 <dd>The bitwise and of
<x
> and
<y
>.
</dd>
243 <dt><code>call
<x
> <y
> <z
> ...
</code></dt>
244 <dd>Similar to the action call, this calls the function
<x
> with the
245 arguments
<y
> <z
> ... (there may be zero or more arguments). The
246 result of this expression is the value returned from the function.
</dd>
248 <dt><code>div
<x
> <y
></code></dt>
249 <dd>The (integer) result of dividing
<x
> by
<y
>.
251 If
<x
> ≥ 0 and
<y
> > 0, the result is the largest
252 integer equal to or less than the algebraic quotient of
<x
>
255 If either
<x
> or
<y
> is negative, the result is
256 implementation-defined.
258 If
<y
> is zero, the result is undefined.
</dd>
260 <dt><code>get-byte
<base
> <offset
></code></dt>
261 <dd>The value of the byte at address
<base
> +
<offset
>.
</dd>
263 <dt><code>get-word
<base
> <offset
></code></dt>
264 <dd>The value of the word at address
<base
> + (WORDSIZE *
267 The address computed as
<base
> + (WORDSIZE *
<offset
>) is
268 expected to be a multiple of the word size. If this condition is not met,
269 the behavior of
<code>get-word
</code> is undefined.
</dd>
271 <dt><code>mod
<x
> <y
></code></dt>
272 <dd>For
<x
> ≥ 0 and
<y
> > 0, returns
273 <x
> modulo
<y
>.
275 If either
<x
> or
<y
> is negative, the result is
276 implementation-defined.
278 If
<y
> is zero, the result is undefined.
</dd>
280 <dt><code>mul
<x
> <y
></code></dt>
281 <dd>The result of multiplying
<x
> by
<y
>.
283 If the algebraic result of
<x
> *
<y
> cannot be represented
284 in a single word, the result of
<code>mul
<x
> <y
></code>
285 contains only the low-order bits of the full result.
</dd>
287 <dt><code>not
<x
></code></dt>
288 <dd>The ones' complement of
<x
>; i.e. all the bits in
<x
>
291 <dt><code>or
<x
> <y
></code></dt>
292 <dd>The bitwise or of
<x
> and
<y
>.
</dd>
294 <dt><code>sub
<x
> <y
></code></dt>
295 <dd>The result of subtracting
<y
> from
<x
>.
297 If the result of the subtraction cannot be represented in a single
298 word, the result of
<code>sub
</code> is undefined.
</dd>
300 <dt><code>xor
<x
> <y
></code></dt>
301 <dd>The bitwise exclusive or of
<x
> and
<y
>.
</dd>
304 <h2>Conditionals
</h2>
306 <p class=
"first">Conditionals in Voodoo take the following form:
</p>
308 <pre><code>if
<test
>
309 ... some code here ...
311 ... other code here ...
312 ... more
"else if" parts ...
318 <p class=
"first">There can be any number of
<q>else if
</q> parts, and
319 the final
<q>else
</q> clause is optional. The tests that are provided
320 are the following:
</p>
323 <dt><code>ifeq
<x
> <y
></code></dt>
324 <dd>Tests if
<x
> is equal to
<y
>.
</dd>
326 <dt><code>ifge
<x
> <y
></code></dt>
327 <dd>Tests if
<x
> is greater than or equal to
<y
>.
</dd>
329 <dt><code>ifgt
<x
> <y
></code></dt>
330 <dd>Tests if
<x
> is strictly greater than
<y
>.
</dd>
332 <dt><code>ifle
<x
> <y
></code></dt>
333 <dd>Tests if
<x
> is less than or equal to
<y
>.
</dd>
335 <dt><code>iflt
<x
> <y
></code></dt>
336 <dd>Tests if
<x
> is strictly less than
<y
>.
</dd>
338 <dt><code>ifne
<x
> <y
></code></dt>
339 <dd>Tests if
<x
> is different from
<y
>.
</dd>
342 <h2>Function Definitions
</h2>
344 <p class=
"first">A function definition looks like:
</p>
352 <p class=
"first">Here, the function being defined takes
3 arguments,
353 which can be referred to as
<code>x
</code>,
<code>y
</code>, and
354 <code>z
</code> from the code inside the function body. A function may
355 have zero or more arguments and is practically always preceded by a
356 label, so that the function can be referenced from code.
</p>
358 <p>A function should only be entered using
<code>call
</code> or
359 <code>tail-call
</code>, and should only be left through a
360 <code>return
</code> action. Furthermore, a function should always
361 be called with the same number of arguments it was defined with.
362 Failing to meet any of these requirements results in undefined
367 <p class=
"first">A Voodoo program is divided in a number of sections.
368 In source code, these are introduced by a directive of the form
369 <code>section
<identifier
></code>, where
<identifier
> is an
370 identifier for the section.
</p>
372 <p>The following section identifiers are valid:
</p>
374 <table summary=
"Section Identifiers"><tr>
378 <td><code>code
</code></td>
379 <td>This section contains executable code
</td>
381 <td><code>data
</code></td>
382 <td>This section contains data
</td>
384 <td><code>functions
</code></td>
385 <td>This section contains function definitions
</td>
388 <p class=
"first">Example usage of the
<code>section
</code> directive:
</p>
392 # define data here ...
395 # define functions here ...
400 <p class=
"first">Many architectures require that data and/or code
401 obey certain alignment restrictions. For example, an architecture may
402 require that a word of data be at an address that is a multiple of the
403 word size. Voodoo provides the
<code>align
</code> directive, which
404 specifies the alignment for the next program element.
</p>
406 <p>Without any arguments,
<code>align
</code> inserts filler bytes
407 into the current section, so that the next element added to the section
408 will respect the default alignment for the section. The default
409 alignment for each section is implementation-dependent, but must ensure
410 that the alignment restrictions of the target platform are obeyed.
</p>
412 <p>When written as
<code>align
<n
></code>, where
<n
> is an
413 integer, the directive will insert filler bytes as necessary to align
414 the next element to be added to the section on a multiple of
<n
>
417 <p>The filler bytes inserted by
<code>align
</code> are unspecified.
418 In particular, they are not guaranteed to be valid code.
</p>
420 <p>Example uses of the
<code>align
</code> directive:
</p>
428 # Ensure that y is aligned according to
429 # the target platform's alignment restrictions
438 # Ensure that foo is aligned according to
439 # the target platform's alignment restrictions