Operators
Operators are bits of code intended to control how the program runs.
puts
Stands for “put something”. Prints debug info to the console, followed by a new line.
Formatting
-
int: The literal number, as formatted by C
printf("%" PRId64). -
double: The literal number, as formatted by C
printf("%f"). -
string: All characters in the string, as formatted by C
printf("%s"). -
char: The ASCII character corresponding to the number held, as formatted by C
printf("%c"). -
bool: If
trueor1, printtrue. Otherwise, printfalse. -
fun: Print
<function>. -
template: Print
<struct fields: { ... }>, where:...is a comma-seperated sequence ofkey: value, where:keyis the identifier of the field.valueis the properly formatted value in the field.
-
object: Print
<object fields: { ... }>, where:...is a comma-seperated sequence ofkey: value, where:keyis the identifier of the field.valueis the properly formatted value in the field.
if
Runs a block of code only if the provided condition is true.
Syntax:
if condition {
...
}
where:
conditionis an expression which evaluates to a boolean.- If this expression evaluates to
true, the code block will be run. - Brackets surrounding the condition are optional.
- If this expression evaluates to
...is the code to run if the condition is true.
Example:
if 2 + 2 == 4 {
puts "phew!"
}
while
Runs a block of code until the provided condition is false.
Syntax:
while condition {
...
}
where:
conditionis an expression which evaluates to a boolean.- If this expression evaluates to
false, the code block will not be run anymore. - Brackets surrounding the condition are optional.
- If this expression evaluates to
...is the code to run while the condition is true.
Example:
while true {
puts "To infinity and beyond!"
}
return
Returns a value from a function.
Syntax:
return value
where value is a value with the same type as the function’s return type.
ground
Inline Ground is potentially dangerous. Only use if you know what you’re doing!
Inserts inline Ground code into the generated program.
Syntax:
ground {
...
}
where ... is the Ground code to insert.
See here for details about Ground.
Note: Solstice cannot keep track of state inside ground blocks! Ground will allow you to do things without the overhead of the Solstice type checker.
To extract a value from a Ground block, do something like this:
x = 0
ground {
set &x 10
}
puts x
so the type checker can know what x is.
use
The use operator lets you import code from libraries, either from in the local folder or installed in the $SOLSTICE_LIBS directory, which defaults to /usr/lib/solstice.
When using use, Solstice will insert the selected file’s contents at that position.
Local use
Supply a string after use which is the path to the file to import, without the .sols extension.
use "parser/Node"
use "parser/parser"
Global use
Supply an identifier after use which is the name of the library to import, without the .sols extension.
use io