Skip to content

General Documentation

Nadelio edited this page Mar 10, 2025 · 29 revisions

Terminology

Tape:

The Tape is the array of words that is the primary form of storage for a Hades program.
The size of the Tape is 65536 cells.
The Tape wraps around, so incrementing the Pointer past 65535 will wrap the Pointer around to 0.
Decrementing past 0 will also wrap the Pointer around to 65535

Cell:

A Cell is a singular piece of the Tape.
A cell holds a single word.

Stack:

The Stack is a data structure intended for temporary storage of various pieces of data.
In the standard library, it is used to hold parameters for functions.
The Stack can hold 256 elements.
If the Stack is overloaded, the program will throw an error and stop.

Element:

An Element is a singular word on the Stack.

Hand:

The Hand is a register that contains a singular label. The Hand is used for manipulating label data during runtime easily.

Held Label:

The Held Label is the label currently in the Hand.

Pointer:

The Pointer is the index of the current cell.
The Pointer is a data pointer, not an instruction pointer.
There are no instruction pointers in Hades that the user can modify.
The instruction pointer is handled by the interpreter.

Pointer Value:

The Pointer Value is the word stored outside of the Tape and Stack.

Function:

A Function is the Hades equivalent to a function in most other languages.
Functions interact with the same Tape and Stack as the main program.
Functions do not have different Pointers or Pointer Values.
Functions also inherit all of the labels and functions of the main program.

Alias:

An Alias is the program-specific name for a function or label.

Label:

A Label is a named index of the Tape that can be jumped to.

Word:

Unsigned 16-bit number

Pointer Commands

MOV [X]:

Move the Pointer to the given index.

MOV [10] ; move pointer to index 10 ;
flowchart LR
 A[Index: 0] --MOV [10]--- B[Index: 10]
Loading

INCP:

Move the Pointer right once.

INCP ; ptr++ ;
flowchart LR
 A[Index: 0] --INCP--- B[Index: 1]
Loading

DECP:

Move the pointer left once.

DECP ; ptr-- ;
flowchart RL
 A[Index: 1] --DECP--- B[Index: 0]
Loading

WTP:

Write the Pointer's position to Tape

WTP ; Tape[ptr] = ptr ;
flowchart LR
  A[Pointer Position] --WTP--- B["Tape[Pointer Position]"]
Loading

RDP:

Read the Pointer's position to the Pointer Value

RDP ; ptrVal = ptr ;
flowchart LR
 A[Pointer Position] --RDP--- B[Pointer Value]
Loading

Pointer Value Commands

SET [X]:

Set the Pointer Value to the given number

SET [10] ; ptrVal = 10 ;
flowchart LR
 A[Pointer Value: 0] --SET [10]--- B[Pointer Value: 10]
Loading

INCV:

Increment the Pointer Value once

INCV ; ptrVal++ ;
flowchart LR
 A[Pointer Value: 0] --INCV--- B[Pointer Value: 1]
Loading

DECV:

Decrement the Pointer Value once

DECV ; ptrVal-- ;
flowchart RL
 A[Pointer Value: 1] --DECV--- B[Pointer Value: 0]
Loading

WTV:

Write the Pointer Value to Tape

WTV ; Tape[ptr] = ptrVale ;
flowchart LR
  A[Pointer Value] --WTV--- B["Tape[Pointer Position]"]
Loading

RDV:

Read from Tape into the Pointer Value

RDP ; ptrVal = Tape[ptr] ;
flowchart LR
 A["Tape[Pointer Position]"] --RDP--- B[Pointer Value]
Loading

I/O Commands

OUT:

Print out the current cell's value + 32

OUT ; System.out.print((char) (Tape[ptr] + 32)) ;
flowchart LR
 A["Tape[ptr]"] --+32 -> OUT---C[STDOUT]
Loading

IN:

Read in from STDIN 2 bytes and store them as a word in the current cell

IN ; Tape[ptr] = (int) nextChar() ;
flowchart LR
 A[STDIN] --IN--- B["Tape[ptr]"]
Loading

Function Commands

CDP [file]/[X Y] [alias]:

Creates a function from the provided file/ROM position and links it to the given alias.
A function can have its alias changed multiple times throughout the course of a program using the CDP command and the same function.
Can using .ebin, .ebf, and .hds files as functions. (.ebin and .ebf files inherit their language/bytecode's limitations)

CDP [someFile.ebin] [foo] ; public static void foo(){...} ;
CDP [10 10] [bar] ; public static void bar(){...} ;
flowchart LR
 A[someFile.ebin] --"CDP [someFile.ebin] [foo]"--- B[foo]
Loading

CALL [alias]:

Run a function linked to the given alias.

CALL [foo] ; foo() ;
flowchart LR
 A[foo] --"CALL [foo]"--- B["run(someFile.eBin)"]
Loading

FUNC [alias] [body]:

Create a function scoped to the program file, this function is not revealed to other files when parsed or compiled.

FUNC [foo] [ ; void foo() { ptr++; } ;
  INCP
]
flowchart LR
 A["FUNC [foo] [INCP]"]--- B[foo]
Loading

Label Commands

CLB [alias]:

Create a label at the current pointer position with the given alias

CLB [foo] ; int foo = ptr ;
flowchart LR
 A["Tape[Pointer Position]"] --"CLB [foo]"--- B[foo]
Loading

DLB [alias]:

Delete the label with the given alias

DLB [foo] ; Labels.remove(foo) ;
flowchart LR
 A[foo] --"DLB [foo]"--- B[ ]
Loading

JLB [alias]:

Move Pointer to position of label connected to given alias

JLB [foo] ; ptr = foo ;
flowchart LR
 A[Pointer Position: 0] --"JLB [foo]"--- B[Pointer Position: foo]
Loading

HOLD [alias]:

Move the given label to the Hand register

HOLD [foo] ; Hand = foo ;
flowchart LR
 A[foo] --"HAND [foo]"--- B[Hand: foo]
Loading

DROP:

Remove the label in the Hand register

DROP ; Hand = null ;
flowchart LR
 A[Hand: foo] --"DROP"--- B[Hand: null]
Loading

SLB [num]:

Set the value at the held label to the given number

SLB [10] ; Tape[Hand] = 10 ;
flowchart LR
 A["Tape[foo] = 0"] --"SLB [10]"--- B["Tape[foo] = 10"]
Loading

SLV:

Set the value at the held label to the value at the pointer position

TODO
flowchart LR
 TODO
Loading

Stack Commands

PUSH:

Push Pointer Value to top of Stack and set Pointer Value to 0

PUSH ; Stack.add(ptrVal) ptrVal = 0;

Push Behavior Diagram

POP:

Pop the top element from the Stack and set the Pointer Value to that element

POP ; ptrVal = Stack.pop() ;

Push Behavior Diagram

Syscall Commands

SYS[arg1...arg5]:

Send a Syscall code to the CPU of the Chronos VM architecture.
The first argument is always the Syscall, and the 4 following arguments are parameters for the Syscall.
Syscalls can use a mix of numbers and labels.
The documentation for Syscall codes is in the Chronos VM Documentation

SYS [14 0 0 0 0] ; System.out.print(Tape[ptr]) ;
; [14 0 0 0 0] is the Syscall code for printing to terminal ;

; assume clearScreen is a label equal to 8 ;
SYS [clearScreen 0 0 0 0] ; Screen.clearScreen() ;
; [8 0 0 0 0] is the Syscall code for clearing the screen of the Chronos VM ;
flowchart LR
 B[Syscall] --"SYS [14 0 0 0 0]"--- A[CPU] --"PRINT TO TERMINAL"--- C["Terminal"]
 B --"SYS [foo 0 0 0 0]"--- F[Label Resolver] --"SYS [8 0 0 0 0]"--- D[CPU] --"CLEAR SCREEN"--- E["Screen"]
Loading

Miscellaneous Commands

WRT [X]:

Write the given number to the Tape at the current cell

WRT [10] ; Tape[ptr] = 10 ;
flowchart LR
 A["Tape[ptr]: 0"] --"WRT [10]"--- B["Tape[ptr]: 10"]
Loading

HLT:

End the currently running program.
Will end a function but not the main program if reached inside of a function.

HLT ; System.exit(0) ;
flowchart TD
 A["Programming running..."]
 B@{ shape: diamond, label: "If is function" }
 C["Stopping function"]
 D["Stopping program..."]
 A --"HLT"--- B --"Yes"--- C --"Jump back to parent program"--- A
 B --"No"--- D
Loading

LOOP [Body]:

Loop body until Tape[ptr] is 0.
Loop checks at the beginning of every iteration if Tape[ptr] is 0

LOOP [
 INCP
]
; while(Tape[ptr] != 0){ ptr++ } ;
flowchart LR
 A[Beginning of Loop]
 B{"Is Tape[ptr] zero?"}
 C[Loop body]
 D[End of Loop]
 E[Skip Loop]
 A --> B --"No"--- C --> D --> A
 B --"Yes"--- E
Loading

INT [Conditional] [alias]:

If the conditional evaluates to true, run the function connected to the alias Both sides of a conditional must be labels (until interpreter rebuild where better type support is added)

CLB [foo]
INCP
CLB [bar]
WRT [1]
INT [foo == bar] [baz]
; foo = 0 ;
; bar = 1 ;
; Tape[ptr] = 1 ;
; if(Tape[foo] == Tape[bar]){ baz() } ;
flowchart LR
 A[foo: 0]
 B[bar: 1]
 C[baz]
 D{Conditional: is equal}
 E[Skip]
 A & B --> D --True--- C
 D --False--- E
Loading

Comments:

Comments are always in the form of block comments Comments are sections of the program that are ignored by the compiler and interpreter Comments are normally reserved for notes and/or documentation

; this is a comment ;
; don't forget the second semi-colon! ;
flowchart LR
 A[Some Code]
 B@{ shape: braces, label: "Some Comment" }
 C[Some Other Code]
 A --> C
Loading