84 lines
2.0 KiB
C++
84 lines
2.0 KiB
C++
// Prelimnary Luno Scripting Binary/Compiled Documentation
|
|
#include <cstdint>
|
|
|
|
namespace luno {
|
|
|
|
// Some notes:
|
|
//
|
|
// - Luno is *not* a VLE. All instructions are 4 bytes long, no matter what.
|
|
// I assume this was inspired by MIPS? either that,
|
|
// or easier bytecode. Which is always a good thing for
|
|
// developers.
|
|
//
|
|
// - It's also not very strongly typed. There are 6 types:
|
|
// Bool(?)
|
|
// Int
|
|
// Float
|
|
// Index (into Table?)
|
|
// Func
|
|
// Table (assocative container)
|
|
|
|
// Mneomic notation:
|
|
// [l8]: 8-bit literal
|
|
// [ri]: register index (alternative 8-bit literal)
|
|
// [l16]: 16-bit literal (usually an offset to jump to)
|
|
// [adr]: Address (alternative 16-bit literal)
|
|
|
|
enum class eLunoOpcode : std::uint8_t {
|
|
|
|
// branching
|
|
|
|
JMP = 0x0, // jmp [adr]
|
|
|
|
BEZ = 0x1, // bez [ri], [adr]
|
|
BNZ = 0x2, // bnz [ri], [adr]
|
|
|
|
BEQ = 0x3, // beq [ri], [ri], [adr]
|
|
BNE = 0x4, // bne [ri], [ri], [adr]
|
|
|
|
|
|
// Arithmetic instructions
|
|
ADD = 0xc, // add [ri],[ri]
|
|
SUB = 0xd, // sub [ri],[ri]
|
|
MUL = 0xe, // mul [ri],[ri]
|
|
DIV = 0xf, // div [ri],[ri]
|
|
|
|
// what's 0x10?
|
|
|
|
MOD = 0x11, // mod [ri],[ri]
|
|
|
|
// Table instructions? I dunno lol
|
|
|
|
MAKE_TABLE = 0x14 // mktable [?]
|
|
|
|
// Stack instructions are probably here
|
|
|
|
|
|
// not handled in retail Luno VM, so this is probably
|
|
// a debug halt.
|
|
HALT = 0x1a // halt
|
|
|
|
|
|
// Call C function from luno.
|
|
// First [l8] is funcnum, the second is a parameter to give to it?
|
|
// Could also be a 16-bit integer afterwards?
|
|
C_CALL = 0x21 // ccall [l8], [l8]
|
|
};
|
|
|
|
// Type repressenting a Luno opcode.
|
|
union tLunoInstruction {
|
|
std::uint32_t total_value;
|
|
|
|
struct {
|
|
eLunoOpcode opcode; // 8 bits...
|
|
std::uint8_t operandBytes[3];
|
|
};
|
|
|
|
// todo: operand decoding
|
|
|
|
|
|
|
|
};
|
|
|
|
} // namespace luno
|