definition module Sjit.Compile from Data.Either import :: Either from Data.Map import :: Map from Data.Maybe import :: Maybe from Sjit.Syntax import :: Function :: Instr = PushRef !Int | PushI !Int | Put !Int | Pop !Int | Call !Int | Jmp !Int | JmpCond !Cond !Int | Ret | Halt | Op !Op | PlaceHolder !Int !Int // only used during compilation :: Op = OAdd | OMul | OSub | ODiv :: Cond = CEq | CNe | CLt | CLe | CGt | CGe | CTrue :: Program :== {!Instr} :: CompileState = { vars :: !Map String Int , funs :: !Map String Int , sp :: !Int , pc :: !Int , blocks :: ![!Program!] , new_block :: ![!Instr!] , placeholder :: !Int , jitst :: !JITState } :: JITState = { n_instr :: !Int , code_start :: !Int , code_len :: !Int , code_ptr :: !Int , mapping :: !Int } appendProgram :: !Bool !Program !JITState -> JITState bootstrap :: (!Program, !CompileState) compile :: !Function !CompileState -> Either String CompileState