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:

  • -o or --output: Tells Solstice where to output a compiled file.
  • -t or --type: Tells Solstice the type of file to output. This can either be "ground" or "program". "ground" outputs a .grnd program, and "program" outputs a compiled native executable. See here for details.

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, or true. 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 +, =, or if. (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).

Importing Other Code

Solstice allows you to write libraries in Solstice, or write wrappers for Ground libraries. Use the use keyword, followed by an identifier to import the library.

use io

println("Hello!")

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 integer
  • double: Double prescision floating point number
  • string: Character array
  • char: A single character
  • bool: Either true or false

Types of Functions, Templates, and Objects

The type signature of a function looks like this:

fun(argType, argType, argType) returnType

The type signature of a template looks like this:

template(fieldType fieldName, fieldType fieldName, fieldType fieldName)

The type signature of an object looks like this:

object(fieldType fieldName, fieldType fieldName, fieldType fieldName)

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.

Structs, templates and objects

Note: Structs, templates, and objects in Solstice are currently in beta. A lot of work in the type checker has been done, but accessing fields is still an issue.

In Solstice, you can create a struct to group various bits of data together. You can specify default values for each field with : or =.

struct Person {
    name: "John"
    age: 32
}

This struct generates a template named "Person" which can be used later to generate new objects.

You can use the new operator to create new instances of templates.

max = new Person

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

io library

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.

use io

guess = input("What is the password? ")
if guess == "password123" {
    puts "Good job!"
}

println(string msg) string

Prints a string to the console. Appends a new line afterwards.

use io

println("Hello, World!")

Native Compiler

Ground has recently added a Ground->Native compiler which allows much faster execution of Ground programs.

However, this is quite early in development, and only supports some features:

  • int data type - No other data type is currently supported.
  • No functions at present

To try the native compiler, use this command:

solstice program.sols --output program --type native

Debugging

Solstice will create a temporary folder in your current directory which you can remove called ".(outputname)_solsbuild". In this folder is the assembly and object file generated by the compiler. If you think that there's a bug with Ground or Solstice, you can use these to find the issue.