Files
sols.dev/docs/index.html
2026-01-21 16:26:54 +11:00

190 lines
13 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Solstice Docs</title>
<link rel="stylesheet" href="https://sols.dev/index.css">
<link rel="stylesheet" href="index.css">
<script src="highlight.js"></script>
</head>
<body>
<div class="box">
<div class="twopane">
<div class="sidebar">
<h3>Navigation</h3>
<ul>
<li><strong><a href="#core_concepts">Core Concepts</a></strong></li>
<li><strong><a href="#type_system">Type System</a></strong></li>
<li><a href="#value_types">Value Types</a></li>
<li><a href="#type_checker">Type Checker</a></li>
<li><strong><a href="#inline_ground">Inline Ground</a></strong></li>
<li><strong><a href="#builtins">Built In Functions</a></strong></li>
<li><a href="#input_string_msg__string">input(string msg) string</a></li>
<li><a href="#print_string_msg__string">print(string msg) string</a></li>
<li><a href="#println_string_msg__string">println(string msg) string</a></li>
<li><strong><a href="#nativecompiler">Native Compiler</a></strong></li>
</ul>
</div>
<div class="content">
<h1>Solstice Docs</h1>
<p>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.</p>
<p>See a mistake? Report it at <a href="https://chookspace.com/max/sols.dev">this site's repository</a>.
<p>Happy coding!</p>
<div id="core_concepts">
<h2>Core Concepts</h2>
<p>Solstice is a high level programming language. It compiles to Ground's bytecode.</p>
<h3>The <code>solstice</code> command</h3>
<p>Solstice's compiler is invoked via the <code>solstice</code> command. It provides some options:</p>
<ul>
<li><code>-o</code> or <code>--output</code>: Tells Solstice where to output a compiled file.</li>
<li><code>-t</code> or <code>--type</code>: 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 <a href="#nativecompiler">here</a> for details.</li>
</ul>
<p>Example usage:</p>
<pre class="code"><code>solstice fib.sols -o fib.grnd</code></pre>
<pre class="code"><code>solstice fib.sols</code></pre>
<h3>Writing Solstice code</h3>
<p>Solstice code consists of four main things: values, identifiers, operators, and code blocks.</p>
<ul>
<li>Values: these are your literal values in your program, like <code>"Hello!"</code>, <code>32</code>, or <code>true</code>. More on values and the Solstice type system later.</li>
<li>Identifiers: these are names of variables. They normally hold something in them.</li>
<li>Operators: these make up the actual logic of your program. Operators are thing like <code>+</code>, <code>=</code>, or <code>if</code>. (if and while are operators in Solstice.)</li>
<li>Code blocks: this is the collection of values, identifiers, and operators, usually in between <code>{</code> and <code>}</code>.</li>
</ul>
<h3>Comments</h3>
<p>You can type <code>//</code> to insert a comment into your program. The rest of your line will be commented out.
<h3>puts</h3>
<p>The <code>puts</code> command in Solstice is used to print out a value. It is not a function, but a built in operator, similar to <code>+</code> or <code>=</code>.</p>
<p>Use it like this:</p>
<pre class="code"><code>puts "Hello, World!"
puts 3.14
puts true
puts "You can print out anything with puts!"</code></pre>
<h3>Variables</h3>
<p>Solstice variables are quite simple. Assign values with <code>=</code>, and read them with the variable name.</p>
<pre class="code"><code>x = 5
puts x</code></pre>
<p>Types are automatically inferred by Solstice.</p>
<h3>Maths</h3>
<p>You can use <code>+</code> (add), <code>-</code> (subtract), <code>*</code> (multiply), and <code>/</code> (divide) to do math.</p>
<p>Math operations take two values on either side, and perform the operation. Order of operations is supported.</p>
<pre class="code"><code>x = 5 + 3
y = 10
puts x + y</code></pre>
<h3>Control Flow and Equalities</h3>
<p>Solstice supports <code>if</code> and <code>while</code> statements, as well as the <code>==</code>, <code>!=</code>, <code>></code>, <code>>=</code>, <code><</code>, and <code><=</code> operations.</p>
<p>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.</p>
<pre class="code"><code>puts 5 == 5
puts 5 != 5</code></pre>
<p><code>if</code> and <code>while</code> statements take a conditional, and then a code block afterwards. See these examples:</p>
<pre class="code"><code>x = 5
if x &gt; 10 {
puts "x is bigger than 10"
}
if x &lt; 10 {
puts "x is smaller than 10"
}
if x == 10 {
puts "x is 10"
}
number = 0
while number &lt; 10 {
number = number + 1
puts number
}</<code></pre>
</code>
<h3>Functions</h3>
<p><strong>Note:</strong> Functions in Solstice are currently in beta. Type checking for functions is currently experimental, and arguments may not work as intended. Be warned!</p>
<p>In Solstice, function definitions have a syntax like this: <pre class="code"><code>def functionName(type arg1, type arg2, type arg3) returnType {
// code goes here
}</code></pre></p>
<p>Your types can be <code>int</code>, <code>double</code>, <code>string</code>, <code>bool</code>, or <code>char</code> (see the "Type System" section for more details)</p>
<p>Return a value (which must be the same type as your <code>returnType</code>) with <code>return value</code>.</p>
<p>Here's an example function:</p>
<pre class="code"><code>def add(int a, int b) int {
return a + b
}</code></pre>
<h3>Calling Functions</h3>
<p>Function calling is done like in most other programming languages, with the syntax <code>function(arg1, arg2, arg3)</code>.</p>
<h3>That's it!</h3>
<p>You now know everything you need to know about Solstice to start programming! You can continue reading for more information.</p>
</div>
<div id="type_system">
<h2>Type System</h2>
<p>Solstice's type system is currently a work in progress, but what is so far implemented will be detailed.</p>
<div id="value_types">
<h3>Value Types</h3>
<ul>
<li><code>int</code>: Signed 64 bit integer</li>
<li><code>double</code>: Double prescision floating point number</li>
<li><code>string</code>: Character array</li>
<li><code>char</code>: A single character</li>
<li><code>bool</code>: Either true or false</li>
</ul>
</div>
<div id="type_checker">
<h3>Type Checker</h3>
<p>Solstice statically checks types at compile time to ensure your data is used as intended. These are the details of the type checker.</p>
<ul>
<li>Types of variables when setting with <code>=</code> are autoinferred and cannot be provided by the user. All variables must have a value.</li>
<li>When setting a variable with <code>=</code>, it's type must not mutate in any way.</li>
<li>Functions must have types annotated. There is no "any" type.</li>
<li>When using operators, integers are able to promote to doubles where required. No other types can automatically convert.</li>
<li>All equality operators require the same type on both sides of the equality.</li>
</ul>
</div>
</div>
<div id="inline_ground">
<h2>Inline Ground</h2>
<p>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.</p>
<p>Inline Ground is not vetted by the type checker. <strong>Be careful when modifying existing variables with inline ground!</strong> The type checker is not aware of any values created inside inline Ground.</p>
<p>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.</p>
<p>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 <a href="https://chookspace.com/ground/cground/src/branch/master/docs/syntax.md">here</a>.</p>
<pre class="code"><code>ground {
set &x 5
println $x
}</code></pre>
</div>
<div id="builtins">
<h2>Built In Functions</h2>
<div id="input_string_msg__string">
<h3>input(string msg) string</h3>
<p>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.</p>
<pre class="code"><code>guess = input("What is the password? ")
if guess == "password123" {
puts "Good job!"
}</code></pre>
</div>
<div id="print_string_msg__string">
<h3>print(string msg) string</h3>
<p>Prints a string to the console.</p>
<pre class="code"><code>print("Hello, World!")</code></pre>
</div>
<div id="println_string_msg__string">
<h3>println(string msg) string</h3>
<p>Prints a string to the console. Appends a new line afterwards.</p>
<pre class="code"><code>println("Hello, World!")</code></pre>
</div>
</div>
<div id="nativecompiler">
<h2>Native Compiler</h2>
<p>Ground has recently added a Ground->Native compiler which allows much faster execution of Ground programs.</p>
<p>However, this is quite early in development, and only supports some features:</p>
<ul>
<li>int data type - No other data type is currently supported.</li>
<li>No functions at present</li>
</ul>
<p>To try the native compiler, use this command:</p>
<pre class="code"><code>solstice program.sols -o program -t native --nostdlib</code></pre>
<h3>Debugging</h3>
<p>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.</p>
</div>
</div>
</div>
</div>
</body>
</html>