-
Notifications
You must be signed in to change notification settings - Fork 0
General Documentation
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
A Cell is a singular piece of the Tape.
A cell holds a single word.
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.
An Element is a singular word on the Stack.
The Hand is a register that contains a singular label. The Hand is used for manipulating label data during runtime easily.
The Held Label is the label currently in the Hand.
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.
The Pointer Value is the word stored outside of the Tape and Stack.
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.
An Alias is the program-specific name for a function or label.
A Label is a named index of the Tape that can be jumped to.
Unsigned 16-bit number
Move the Pointer to the given index.
MOV [10] ; move pointer to index 10 ;flowchart LR
A[Index: 0] --MOV [10]--- B[Index: 10]
Move the Pointer right once.
INCP ; ptr++ ;flowchart LR
A[Index: 0] --INCP--- B[Index: 1]
Move the pointer left once.
DECP ; ptr-- ;flowchart RL
A[Index: 1] --DECP--- B[Index: 0]
Write the Pointer's position to Tape
WTP ; Tape[ptr] = ptr ;flowchart LR
A[Pointer Position] --WTP--- B["Tape[Pointer Position]"]
Read the Pointer's position to the Pointer Value
RDP ; ptrVal = ptr ;flowchart LR
A[Pointer Position] --RDP--- B[Pointer Value]
Set the Pointer Value to the given number
SET [10] ; ptrVal = 10 ;flowchart LR
A[Pointer Value: 0] --SET [10]--- B[Pointer Value: 10]
Increment the Pointer Value once
INCV ; ptrVal++ ;flowchart LR
A[Pointer Value: 0] --INCV--- B[Pointer Value: 1]
Decrement the Pointer Value once
DECV ; ptrVal-- ;flowchart RL
A[Pointer Value: 1] --DECV--- B[Pointer Value: 0]
Write the Pointer Value to Tape
WTV ; Tape[ptr] = ptrVale ;flowchart LR
A[Pointer Value] --WTV--- B["Tape[Pointer Position]"]
Read from Tape into the Pointer Value
RDP ; ptrVal = Tape[ptr] ;flowchart LR
A["Tape[Pointer Position]"] --RDP--- B[Pointer Value]
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]
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]"]
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]
Run a function linked to the given alias.
CALL [foo] ; foo() ;flowchart LR
A[foo] --"CALL [foo]"--- B["run(someFile.eBin)"]
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]
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]
Delete the label with the given alias
DLB [foo] ; Labels.remove(foo) ;flowchart LR
A[foo] --"DLB [foo]"--- B[ ]
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]
Move the given label to the Hand register
HOLD [foo] ; Hand = foo ;flowchart LR
A[foo] --"HAND [foo]"--- B[Hand: foo]
Remove the label in the Hand register
DROP ; Hand = null ;flowchart LR
A[Hand: foo] --"DROP"--- B[Hand: null]
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"]
Set the value at the held label to the value at the pointer position
TODOflowchart LR
TODO
Push Pointer Value to top of Stack and set Pointer Value to 0
PUSH ; Stack.add(ptrVal) ptrVal = 0;
Pop the top element from the Stack and set the Pointer Value to that element
POP ; ptrVal = Stack.pop() ;
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"]
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"]
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
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
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
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