a stack based virtual machine in c++. supports functions, labels, includes a custom assembler for itself. the project is mostly finished, but future me might make a register-based vm with a language attached
complete with a parser, a lexer, and an assembler.
everything is stack-based, the assembly is similar to forth, and everything is a function. the stack is shared between everything so functions have the whole stack instead of arguments passed to them as well as the return values.
there are still memory leaks, and the implementation is defined together with the declarations. this is done for faster iteration and will be sorted once the foundation is solid
make run to compile
programs are intended to be ran as ab run binary.ab and compiled with ab load source.aba
example prog.aba:
func printAlphabet
push 97
LOOP:
dup
printc
push 1
add
dup
push 123
cmpge
jmpz LOOP
push 10
printc
ret
end
call printAlphabet#define INSTRUCTION_LIST \
X(NONE, -1, "none") \
X(NOP, 0x00, "nop") \
X(PUSH, 0x01, "push") \
X(JMP, 0x02, "jmp") \
X(SWAP, 0x03, "swap") \
X(INSWAP, 0x04, "inswap") \
X(INDUP, 0x05, "indup") \
X(PRINT, 0x50, "print") \
X(PRINTC, 0x51, "printc") \
X(JMPZ, 0x07, "jmpz") \
X(JMPNZ, 0x08, "jmpnz") \
X(POP, 0x09, "pop") \
X(DUP, 0x0A, "dup") \
X(OVER, 0x0B, "over") \
X(ROT, 0x0C, "rot") \
X(ADD, 0x10, "add") \
X(MOD, 0x11, "mod") \
X(SUB, 0x12, "sub") \
X(MUL, 0x13, "mul") \
X(DIV, 0x14, "div") \
X(POW, 0x15, "pow") \
X(NEG, 0x16, "neg") \
X(CMPE, 0x40, "cmpe") \
X(CMPL, 0x41, "cmpl") \
X(CMPG, 0x42, "cmpg") \
X(CMPGE, 0x43, "cmpge") \
X(CMPLE, 0x44, "cmple") \
X(OR, 0x45, "or") \
X(XOR, 0x46, "xor") \
X(AND, 0x47, "and") \
X(NOT, 0x48, "not") \
X(LOAD, 0xF0, "load") \
X(STORE, 0xF1, "store") \
X(HALT, 0xFF, "halt") \
X(CALL, 0xE2, "call") \
X(RETURN, 0xE3, "ret")