Solstice Docs
Welcome to the Solstice docs! Feel free to read in whichever order you like, or come back when you feel like it. You can read these head to tail if you want to understand the whole of the language as well.
See a mistake? Report it at this site's repository.
Happy coding!
Core Concepts
Solstice is a high level programming language. It compiles to Ground's bytecode.
The solstice command
Solstice's compiler is invoked via the solstice command. It provides some options:
-oor--output: Tells Solstice where to output a compiled file.-tor--type: Tells Solstice the type of file to output. At present, Solstice only supports Ground source files as an output type, but more types may be added in future.
Example usage:
solstice fib.sols -o fib.grnd
solstice fib.sols
Writing Solstice code
Solstice code consists of four main things: values, identifiers, operators, and code blocks.
- Values: these are your literal values in your program, like
"Hello!",32, ortrue. More on values and the Solstice type system later. - Identifiers: these are names of variables. They normally hold something in them.
- Operators: these make up the actual logic of your program. Operators are thing like
+,=, orif. (if and while are operators in Solstice.) - Code blocks: this is the collection of values, identifiers, and operators, usually in between
{and}.
Comments
You can type // to insert a comment into your program. The rest of your line will be commented out.
puts
The puts command in Solstice is used to print out a value. It is not a function, but a built in operator, similar to + or =.
Use it like this:
puts "Hello, World!"
puts 3.14
puts true
puts "You can print out anything with puts!"
Variables
Solstice variables are quite simple. Assign values with =, and read them with the variable name.
x = 5
puts x
Types are automatically inferred by Solstice.
Maths
You can use + (add), - (subtract), * (multiply), and / (divide) to do math.
Math operations take two values on either side, and perform the operation. Order of operations is supported.
x = 5 + 3
y = 10
puts x + y
Control Flow and Equalities
Solstice supports if and while statements, as well as the ==, !=, >, >=, <, and <= operations.
Conditionals work just like maths: two values on either side, check whether the condition is correct or not based on those values, and output a boolean.
puts 5 == 5
puts 5 != 5
if and while statements take a conditional, and then a code block afterwards. See these examples:
x = 5
if x > 10 {
puts "x is bigger than 10"
}
if x < 10 {
puts "x is smaller than 10"
}
if x == 10 {
puts "x is 10"
}
number = 0
while number < 10 {
number = number + 1
puts number
}
Functions
Note: Functions in Solstice are currently in beta. Type checking for functions is currently experimental, and arguments may not work as intended. Be warned!
In Solstice, function definitions have a syntax like this:
def functionName(type arg1, type arg2, type arg3) returnType {
// code goes here
}
Your types can be int, double, string, bool, or char (see the "Type System" section for more details)
Return a value (which must be the same type as your returnType) with return value.
Here's an example function:
def add(int a, int b) int {
return a + b
}
Calling Functions
Function calling is done like in most other programming languages, with the syntax function(arg1, arg2, arg3).
That's it!
You now know everything you need to know about Solstice to start programming! You can continue reading for more information.
Type System
Solstice's type system is currently a work in progress, but what is so far implemented will be detailed.
Value Types
int: Signed 64 bit integerdouble: Double prescision floating point numberstring: Character arraychar: A single characterbool: Either true or false
Type Checker
Solstice statically checks types at compile time to ensure your data is used as intended. These are the details of the type checker.
- Types of variables when setting with
=are autoinferred and cannot be provided by the user. All variables must have a value. - When setting a variable with
=, it's type must not mutate in any way. - Functions must have types annotated. There is no "any" type.
- When using operators, integers are able to promote to doubles where required. No other types can automatically convert.
- All equality operators require the same type on both sides of the equality.
Inline Ground
Since Solstice is built atop Ground, you can write Ground code inside Solstice code, usually to wrap a Ground function for the Solstice standard library.
Inline Ground is not vetted by the type checker. Be careful when modifying existing variables with inline ground! The type checker is not aware of any values created inside inline Ground.
If you would like the Solstice type checker to be aware of values created by Ground, initialise a variable with a blank of whatever type is made by Ground.
Variable names are the same inside inline Ground as they are in Solstice. Read Ground's syntax guide for an understanding on how it should work here.
ground {
set &x 5
println $x
}
Built In Functions
input(string msg) string
Gets user input from the console until the next line. The msg is used as a prompt for the user. Returns inputted characters from the console.
guess = input("What is the password? ")
if guess == "password123" {
puts "Good job!"
}
print(string msg) string
Prints a string to the console.
print("Hello, World!")
println(string msg) string
Prints a string to the console. Appends a new line afterwards.
println("Hello, World!")