aboutsummaryrefslogtreecommitdiff
path: root/Sjit/Compile.dcl
blob: 7cb74e3ccf32c862b1e6040dff5a586c8f807458 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
	| Ret
	| Halt

	| IAddRet
	| IMulRet
	| ISubRet
	| IDivRet

:: Program :== {!Instr}

:: CompileState =
	{ vars      :: !Map String Int
	, funs      :: !Map String Int
	, sp        :: !Int
	, pc        :: !Int
	, blocks    :: ![!Program!]
	, new_block :: ![!Instr!]
	, 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