aboutsummaryrefslogtreecommitdiff
path: root/Sjit/Compile.dcl
blob: d373e42340358000224fef764db8ded43e47a916 (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
46
47
48
49
50
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
	| JmpTrue !Int
	| Ret
	| Halt

	| IAdd
	| IMul
	| ISub
	| IDiv

	| PlaceHolder !Int !Int // only used during compilation

:: 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