| Stability | stable |
|---|---|
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Compiler.Instruction
Description
Synopsis
- data Instruction
- = Push Immediate
- | Pop
- | Dup
- | Swap
- | Add
- | Sub
- | Mul
- | Div
- | Mod
- | Eq
- | TEq
- | Lt
- | Le
- | Not
- | And
- | Or
- | Jump Int
- | JumpIfFalse Int
- | JumpIfTrue Int
- | Call Int
- | TailCall Int
- | CallIndirect
- | Ret Int
- | LoadLocal Int
- | StoreLocal Int
- | LoadGlobal Int
- | StoreGlobal Int
- | LoadCapture Int
- | StoreCapture Int
- | MakeClosure Int Int
- | GetFuncAddr Int
- | BuildStruct Int
- | GetStructField Int
- | AttrUpdate
- | Cast Word8
- | TypeOf
- | SizeOf
- | Cons
- | Head
- | Tail
- | Nth
- | NthUpdate
- | BuildList Int
- | Open
- | Read
- | Write
- | Close
- | Input
- | Halt
- | Exit
- | CheckStack Int
- | Nop
- data Immediate
- immediateToTypeID :: Immediate -> Word8
- immediateSize :: Immediate -> Int
- getInstCode :: Instruction -> Word8
- instructionSize :: Instruction -> Int
Documentation
data Instruction Source #
The Instruction set used by compiler/VM
@details Each constructor represents a single concrete virtual machine instruction. Numeric opcodes and layout are defined in ASM_SPEC.md (version 0x02).
@return N/A (this documents the type)
Constructors
| Push Immediate | 0x01 PUSH [Type] [Value] |
| Pop | 0x02 POP |
| Dup | 0x03 DUP |
| Swap | 0x04 SWAP |
| Add | 0x10 ADD |
| Sub | 0x11 SUB |
| Mul | 0x12 MUL |
| Div | 0x13 DIV |
| Mod | 0x14 MOD |
| Eq | 0x20 EQ |
| TEq | 0x26 TEQ |
| Lt | 0x21 LT |
| Le | 0x25 LE |
| Not | 0x22 NOT |
| And | 0x23 AND |
| Or | 0x24 OR |
| Jump Int | 0x30 JUMP [off] |
| JumpIfFalse Int | 0x31 JUMP_IF_FALSE [off] |
| JumpIfTrue Int | 0x32 JUMP_IF_TRUE [off] |
| Call Int | 0x40 CALL [off] |
| TailCall Int | 0x41 TAILCALL [off] |
| CallIndirect | 0x42 CALL_INDIRECT [address on stack] |
| Ret Int | 0x43 RET [stack size] |
| LoadLocal Int | 0x50 LOAD_LOCAL [idx] |
| StoreLocal Int | 0x51 STORE_LOCAL [idx] |
| LoadGlobal Int | 0x52 LOAD_GLOBAL [idx] |
| StoreGlobal Int | 0x53 STORE_GLOBAL [idx] |
| LoadCapture Int | 0x54 LOAD_CAPTURE [idx] |
| StoreCapture Int | 0x55 STORE_CAPTURE [idx] |
| MakeClosure Int Int | 0x60 MAKE_CLOSURE [addr] [n_captures] |
| GetFuncAddr Int | 0x61 GET_FUNC_ADDR [id] |
| BuildStruct Int | 0x62 BUILD_STRUCT [n_fields] |
| GetStructField Int | 0x63 GET_STRUCT_FIELD [idx] |
| AttrUpdate | 0x64 ATTR_UPDATE [struct] [idx] [value] |
| Cast Word8 | 0x80 CAST [TypeID] |
| TypeOf | 0x81 TYPEOF |
| SizeOf | 0x82 SIZEOF |
| Cons | 0x90 CONS |
| Head | 0x91 HEAD [list] |
| Tail | 0x92 TAIL [list] |
| Nth | 0x93 NTH [list] [idx] |
| NthUpdate | 0x95 NTH_UPDATE [list] [idx] [value] |
| BuildList Int | 0x94 BUILD_LIST [n_elements] |
| Open | 0xA0 OPEN |
| Read | 0xA1 READ |
| Write | 0xA2 WRITE |
| Close | 0xA3 CLOSE |
| Input | 0xA4 INPUT |
0x70 PRINT | |
| Halt | 0x71 HALT |
| Exit | 0x72 EXIT |
| CheckStack Int | 0xFE CHECK_STACK [N] |
| Nop | 0xFF NOP |
Instances
| Show Instruction Source # | |
Defined in Compiler.Instruction Methods showsPrec :: Int -> Instruction -> ShowS # show :: Instruction -> String # showList :: [Instruction] -> ShowS # | |
| Eq Instruction Source # | |
Defined in Compiler.Instruction | |
| Ord Instruction Source # | |
Defined in Compiler.Instruction Methods compare :: Instruction -> Instruction -> Ordering # (<) :: Instruction -> Instruction -> Bool # (<=) :: Instruction -> Instruction -> Bool # (>) :: Instruction -> Instruction -> Bool # (>=) :: Instruction -> Instruction -> Bool # max :: Instruction -> Instruction -> Instruction # min :: Instruction -> Instruction -> Instruction # | |
Immediate values pushed by PUSH.
@details Immediate represents the different immediate payloads that can be encoded after a PUSH opcode. The TypeID encoding follows ASM_SPEC.md (version 0x02).
@return N/A (this documents the type)
Instances
| Show Immediate Source # | |
| Eq Immediate Source # | |
| Ord Immediate Source # | |
immediateToTypeID :: Immediate -> Word8 Source #
Map an Immediate to the TypeID byte used by PUSH.
@args - imm: the Immediate value whose TypeID is requested
@details Returns the one-byte TypeID used by the binary format to encode immediates as specified in the PUSH Type Table of ASM_SPEC.md.
@return
The TypeID as a Word8.
immediateSize :: Immediate -> Int Source #
Size in bytes of the immediate payload (not counting the TypeID byte).
@args - imm: the Immediate whose payload size is requested
@details This helper returns the number of bytes that follow the TypeID for the immediate payload. It is useful for computing instruction sizes and label offsets during assembly.
@return
The payload size in bytes as Int.
getInstCode :: Instruction -> Word8 Source #
Opcode mapping for each instruction as defined in doc/ASM_SPEC.md.
@args
- instr: the Instruction to map to its opcode byte
@details This function centralizes the numeric opcode mapping, ensuring the compiler and assembler use the same byte values when serializing to the .gla format. It returns the opcode byte for a given concrete instruction.
@return
The opcode as a Word8.
instructionSize :: Instruction -> Int Source #
Computes the size in bytes of a given instruction, including its payload.
@args
- instr: the Instruction whose size is to be computed
@details Returns the total number of bytes required to encode the instruction, including opcode and any immediate or address payloads. Used for offset calculations and binary serialization.
@return
The instruction size in bytes as Int.