Static Scheme is an implementation of Lisp for StaticOS. Its features are that its static typed, without any GC and with a tiny core. Through the document, you will notice a lot of tokens preceded by a `:`. This is because every user defined instances are preceded by it. This include, macros, variables, functions, etc. This document aims to explain how the language works. However, keep it mind that the language is still not completed and that it will be revised as well as this document. Types ------------------------------------------------------------------------ Data types are limited to these: - u8: Unsigned 8-bit integer - u16: Unsigned 16-bit integer - u32: Unsigned 32-bit integer - u64: Unsigned 64-bit integer - ptr: Pointers. Pointers are 64-bit in size just like u64 These data types are used in s-expressions for accessing memory as well as in inline assembly. Besides these core types there is also the record type. The record is much like `struct` in C. It has entries that can be either records themselves or part of the core types. Variables ------------------------------------------------------------------------ Variables are defined using the `var` s-expression and their values can be changed using the `set` s-expression. Upon creation a variable can be given a value. However, this excludes arrays and records. This is a snippet of code: ``` (var u16 :emptyVar) ; Variable created with what is in RAM (var u32 :initVar 33) ; Variable created with a value (set :emptyVar 56) ; Value set for variable (var [u8 5] :array 5) ; ILLEGAL. Cannot set an array (var [u8 5] :array) ; LEGAL ``` The only exception is when it comes to strings. A string can be created in the following way: ``` (var [u8] :string "Hello World!") ``` Note that the language bans array sizes set by variables. Arrays can only be created with constants. Here is an example: ``` (var [u16 4] :arr4) ; Legal (var [u16 :i] :arrai) ; Illegal ``` Memory ------------------------------------------------------------------------ Memory access is handled by using the `set` s-expression just like variables. However, the syntax is a little different. For instance, trying tying to write to VGA would be something like this: ``` (var ptr :vga 0hB8000) ; Stores the VGA address (set [u16 (+ :vga 10)] 0h1F41) ; Writes the letter 'A' at position 5 ``` Whenever memory access is being written to, the address must be enclosed between `[]`. The square brackets can ONLY be used for destinations and not the sources. Hence you cannot have: ``` (set :vga [0h1F41]) ``` Assembly ------------------------------------------------------------------------ The compiler comes with an assembler within it for AMD64. Assembly is done directly in the source file with inline. You cannot have separate assembly file. For examples see Boot/boot.ss, Boot/rboot.ss and Boot/pboot.ss. Functions ------------------------------------------------------------------------ Arguments passed in functions go from left to right. This means that when a void functions with 2 arguments is called, the first argument is at RBP + 0h18 and the second at 0h10. If a value is returned its placed at the furthest position of the stack. In this example if the function was non-void it would be 0h20. S-Expressions ------------------------------------------------------------------------ This is a list of all s-expressions and their definitions. - @: Fetchs the address of a variable - get: Gets a value at address. (i.e: get u8, get u16, get :record) - sizeof: Much like C it returns the size of a variable. There are some arithmetic and logic s-expressions: - * : Multiplications - / : Division - + : Addition - - : Substraction - > : Greater than - < : Lesser than - >=: Greater or equal than - <=: Less or equal than - & : And - !=: Not equal - = : Equal