blob: e63017803a3fe5de1dde916cc793725fab354f35 (
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
51
52
53
54
55
56
57
|
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
|