Rba - really bad assembly
Assembly? Honestly the string and module system are pushing it past most ASM languages and this is becoming closer to a simple C
The basics on writing a program in this language.
A variable is denoted with a character, all variables exist in a program, but are initalized to 0
All types are unsigned 64 bit ints (u64)
The & Operator gets the u64 value at an address:
For example OUT &100
will output the u64 at the 100th memory address, think of it like a pointer deference
2 types of constants
- Simple constants, a u64 number, can have underscores inbetween
111_222_333
- String constant, is the address of the string,
"Hello World!"
, reminder: parsed as json string, does support\n
and other escape sequences
Labels, any text which does not contain any of the following ",\;
VAR - Is variable or memory address, can be set to
VAL - Is variable or constant
- INC <LABEL>; adds set of functions from module
- MOV <VAL> <VAR>; sets variable to value
- SWAP <VAR> <VAR>; swaps 2 variables, (may be removed)
- ADD/SUB/MUL/DIV/MOD <VAR> <VAL>; preforms math operation, result stored in variable
- LABEL: <LABEL>; Represents a point which can be jumped to, can have the same name as module, does not interfere
- JZ/JNZ <VAL> <LABEL>; jumps to label if val is 0 (JZ) or not 0 (JNZ)
- CALL <LABEL> <VAL>, <VAL> ... <VAR?>; Calls function from module, comma seperated list of agruments, last variable is return value
- RCALL <LABEL> <VAR?>; Calls function with no arguments, (parser limitation (can be fixed))
- OUT <VAL>; Prints value as u64;
- NOP; does nothing
There are currently 2 simple modules in rba. Modules are one of the non-assmebly like features in the language
All writeable objects have a u64 handle
Included with INC io;
Handle for stdout, stderr and stdin and 0, 1, and 2 respectively
Functions
CALL write handle, ptr, num;
writesnum
bytes fromptr
intohandle
CALL read handle, ptr, num am;
reads at maxnum
bytes from handle and puts them intoptr
, returns amount of bytes read (intoam
)CALL open_file ptr, num handle;
takesnum
bytes fromptr
, parses them into utf8 bytes, and returns (writes intohandle
) file handle with that name, overrides any previous file with that nameCALL close_file handle;
closes file handle stored inhandle
RCALL stdout handle
RCALL stdin handle
RCALL stderr handle
, writes stdin, stderr, or stdout handle tohandle
Simple (useless/debugging) methods
Included with INC std;
Functions
CALL printc val;
does the same thing asOUT val;
can be called without stdCALL printa val;
readsval
, converts to utf8 character, and prints to consoleCALL addr_8 addr out;
reads u8 fromaddr
and returns (writes toout
) itCALL top_8 val out;
shiftsval
right 56 bits and returns (writes toout
) it
All C functions are also supported (only in JIT)
Notable functions
CALL malloc size Z;
returns (writes toZ
) asize
byte pointerCALL atol ptr N;
returns (writes toN
) the number in the stringptr
The program currently parses the text into tokens and runs them 2 ways
- JIT with cranelift - fully featured, reccomended
- Interpreting - only has 'malloc' and 'atol' as c functions, max of 3 arguments for all functions. Unlike JIT supported on all rust platforms with std