ssxre/old/luno.h

82 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)
// Opcodes come with a mneomic.
//
// Mneomic operand notation:
// [ri]: register index (alternative 8-bit literal)
// [l8]: 8-bit literal
// [l16]: 16-bit literal (usually an offset to jump to)
enum class eLunoOpcode : uint8_t {
// Branch to label
JMP = 0x0, // jmp [l16]
// branch to label if [ri] != 0
BNZ = 0x1, // bnz [ri],[l16]
// branch to label if [ri] == 0
BEZ = 0x2, // bez [ri],[l16]
// TODO: probably more
// 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?
MAKE_TABLE = 0x14 // mktable [?]
// 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?
C_CALL = 0x21 // ccall [l8],[l8]
};
// Type repressenting a Luno opcode.
union tLunoInstruction {
uint32_t total_value;
struct {
eLunoOpcode opcode; // 8 bits...
uint8_t operand_1; // 16
uint8_t operand_2; // 24
uint8_t operand_3; // 32
};
// todo: operand decoding
};
} // namespace luno