Crate sage

source ·
Expand description

The Sage Programming Language

🌿🌱Sage🪴🍃

Sage advice for your coding conundrums!

🚧 🏗️ ⚠️ This language is under construction! ⚠️ 🏗️ 🚧


(The sage compiler itself can be compiled to web assembly to be executed on the web. This allows a sage compiler + interpreter to be hosted on a static web page and run embedded sage scripts. This web implementation compiles sage LIR code into sage virtual machine code, and then feeds it to a builtin virtual machine interpreter. The compiler can also switch to various backends, such as the C source code generator, or assembly output.)

This crate implements a compiler for the sage programming language and its low level virtual machine.

Checkout the git repository and the Discord server!

What is Sage?

Sage is a programming language with a low level virtual machine based on a Turing tape. The sage virtual machine has a read/write head and a single register. The read/write head moves around the tape, and uses the register as an accumulator. All worldly input is done through a single instruction, and all worldly output is done through a single instruction. Functionality which cannot be achieved with any algorithm, such as using an operating system’s system calls to write to persistent memory, is also done through two instructions: one for sending values to the virtual machine’s foreign function interface, and one for receiving. The goal of the virtual machine is to allow algorithms to be expressed in the same time complexity as they would on x86, but with the smallest possible number of instructions. This allows sage code to be maximally portable: sage’s core instruction set could be implemented in hardware much easier than any modern architecture due to its very small pool of opcodes and their simplicity.

Index

  1. The Lower Intermediate Representation
  2. The Assembly Language
  3. The Virtual Machine
  4. Target Backends

Stages of IR

Here are the current stages of IR:

  1. LIR (Lower Intermediate Representation)
  2. Core / Standard Assembly (an assembly language for the VM)
  3. Core / Standard Virtual Machine Code (which is built for a given target)

Backend

This compiler is unique in the way that it handles portability. The language’s backend is split in two: the Core variant, and the Standard variant. The Core variant is guaranteed to compile to all targets, and the Standard variant is akin to a standard library of instructions (which are implemented for most targets).

This makes sage uniquely equipped to compile to very limited arcitectures: the Core instruction set for the virtual machine is almost guaranteed to be a subset of most CPU architectures.

The Core instructions are required to be implemented by every target. These instructions are guaranteed to be supported by every target.

The standard instructions are not guaranteed) to be wholly implemented by every target, or at all. A target for Linux on x86 will certainly implement all the standard instructions, but a thermostat might implement only a few or none.

TheTwentyandFourStandardInstructions
Memory and FundamentalAllocateFreeSet(n: float)ToIntToFloatPower
TrigonometrySineCosineTangentArcSineArcCosineArcTangent
ArithmeticIsNonNegative?AddSubtractMultiplyDivideRemainder
WorldlyGetCharPutCharGetIntPutIntGetFloatPutFloat

Modules

Constants

  • The UNICODE character art for the logo of the language.
  • The UNICODE character art for the logo of the language, using ANSI escape codes for color.
  • The value of the NULL pointer constant.