target.dcl 5.22 KB
Newer Older
1 2 3 4 5
definition module target

import StdEnv
import StdMaybe
import interpretergen
6
from wasm import :: Type
7 8 9

class wasm_type a :: !a -> Type

10
instance wasm_type TWord, TPtrOffset, TBool, TChar, TShort, TInt, TReal, (TPtr t)
11

12 13 14 15 16
:: Target
:: Expr t

start :: Target
bootstrap :: ![String] -> [String]
17
collect_instructions :: !Options ![Target] -> [String]
18 19 20 21 22

instr_unimplemented :: !Target -> Target
instr_halt :: !Target -> Target
instr_divLU :: !Target -> Target
instr_mulUUL :: !Target -> Target
23
instr_RtoAC :: !Target -> Target
24 25

lit_word  :: !Int -> Expr TWord
26
lit_hword :: !Int -> Expr TPtrOffset
27 28 29 30
lit_char  :: !Char -> Expr TChar
lit_short :: !Int -> Expr TShort
lit_int   :: !Int -> Expr TInt

31
instance to_word TPtrOffset, TChar, TInt, TShort, (TPtr t), TReal
32
instance to_bool TWord
33 34 35 36 37 38
instance to_char TWord
instance to_int TWord
instance to_real TWord
instance to_word_ptr  TWord, (TPtr t)
instance to_char_ptr  TWord, (TPtr t)
instance to_short_ptr TWord, (TPtr t)
39
instance to_ptr_offset TWord, TPtrOffset, TShort
40 41 42 43 44 45 46 47

instance + (Expr t)
instance - (Expr t)
instance * (Expr t)
instance / (Expr t)
instance ^ (Expr TReal)
(%.)  infixl 6 :: !(Expr TInt) !(Expr TInt) -> Expr TInt

48 49 50 51 52 53
(==.) infix  4 :: !(Expr a) !(Expr a) -> Expr TBool
(<>.) infix  4 :: !(Expr a) !(Expr a) -> Expr TBool
(<.)  infix  4 :: !(Expr a) !(Expr a) -> Expr TBool
(>.)  infix  4 :: !(Expr a) !(Expr a) -> Expr TBool
(<=.) infix  4 :: !(Expr a) !(Expr a) -> Expr TBool
(>=.) infix  4 :: !(Expr a) !(Expr a) -> Expr TBool
54

55
(&&.) infixr 3 :: !(Expr TBool) !(Expr TBool) -> Expr TBool
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

(&.) infixl 6 :: !(Expr TWord) !(Expr TWord) -> Expr TWord
(|.) infixl 6 :: !(Expr TWord) !(Expr TWord) -> Expr TWord
(<<.) infix 7 :: !(Expr TWord) !(Expr TWord) -> Expr TWord
(>>.) infix 7 :: !(Expr a) !(Expr a) -> Expr a
xorI          :: !(Expr TWord) !(Expr TWord) -> Expr TWord
~.            :: !(Expr TWord) -> Expr TWord

absR    :: !(Expr TReal) -> Expr TReal
acosR   :: !(Expr TReal) -> Expr TReal
asinR   :: !(Expr TReal) -> Expr TReal
atanR   :: !(Expr TReal) -> Expr TReal
cosR    :: !(Expr TReal) -> Expr TReal
entierR :: !(Expr TReal) -> Expr TInt
expR    :: !(Expr TReal) -> Expr TReal
lnR     :: !(Expr TReal) -> Expr TReal
log10R  :: !(Expr TReal) -> Expr TReal
negR    :: !(Expr TReal) -> Expr TReal
sinR    :: !(Expr TReal) -> Expr TReal
sqrtR   :: !(Expr TReal) -> Expr TReal
tanR    :: !(Expr TReal) -> Expr TReal
ItoR    :: !(Expr TInt)  -> Expr TReal
RtoI    :: !(Expr TReal) -> Expr TInt

80
if_i64_or_i32 :: !(Target -> Target) !(Target -> Target) !Target -> Target
81 82
if_i64_or_i32_expr :: !(Expr t) !(Expr t) -> Expr t

83
if_expr :: !(Expr TBool) !(Expr t) !(Expr t) -> Expr t
84 85 86 87 88 89 90 91 92

begin_instruction :: !String !Target -> Target
end_instruction :: !Target -> Target
alias :: !String !(Target -> Target) !Target -> Target

nop :: !Target -> Target

(:.) infixr 1 :: !(Target -> Target) !(Target -> Target) !Target -> Target

93
new_local :: !t !(Expr t) !((Expr t) Target -> Target) !Target -> Target | wasm_type t
94 95 96

class (.=) infix 2 v e :: !(Expr v) !(Expr e) !Target -> Target
instance .=
97 98
	TWord TWord, TWord TPtrOffset, TWord TBool, TWord TChar, TWord TInt, TWord TShort,
	TPtrOffset TPtrOffset,
99 100
	TChar TChar,
	TInt TInt, TInt TWord,
101
	(TPtr t) (TPtr u)
102 103

class (+=) infix 2 v e :: !(Expr v) !(Expr e) !Target -> Target
104
instance += TWord TWord, TPtrOffset TPtrOffset
105 106

class (-=) infix 2 v e :: !(Expr v) !(Expr e) !Target -> Target
107
instance -= TWord TWord, TPtrOffset TPtrOffset, TShort TShort
108

109
class advance_ptr i :: !(Expr (TPtr v)) !i !Target -> Target | wasm_type v
110
instance advance_ptr Int, (Expr TPtrOffset)
111

112
class rewind_ptr i :: !(Expr (TPtr v)) !i !Target -> Target | wasm_type v
113
instance rewind_ptr Int, (Expr TPtrOffset)
114

115 116
class (@)  infix 8 a :: !(Expr (TPtr t)) !a -> Expr t | wasm_type t
class (@?) infix 8 a :: !(Expr (TPtr t)) !a -> Expr (TPtr t) | wasm_type t
117 118 119 120 121 122 123

instance @  Int, (Expr t)
instance @? Int, (Expr t)

begin_block :: !Target -> Target
end_block :: !Target -> Target

124
while_do :: !(Expr TBool) !(Target -> Target) !Target -> Target
125 126 127
break :: !Target -> Target

if_then_else ::
128 129
	!(Expr TBool) !(Target -> Target)
	![(Expr TBool, Target -> Target)]
130 131
	!(Maybe (Target -> Target))
	!Target -> Target
132
if_break_else :: !(Expr TBool) !(Target -> Target) !Target -> Target
133 134

class ensure_hp s :: !s !Target -> Target
135
instance ensure_hp Int, (Expr t) | to_ptr_offset t
136 137 138 139 140 141 142 143 144 145 146 147

A :: Expr (TPtr TWord)
B :: Expr (TPtr TWord)
Pc :: Expr (TPtr TWord)
Hp :: Expr (TPtr TWord)

BOOL_ptr :: Expr TWord
CHAR_ptr :: Expr TWord
INT_ptr :: Expr TWord
REAL_ptr :: Expr TWord
ARRAY__ptr :: Expr TWord
STRING__ptr :: Expr TWord
148
jmp_ap_ptr :: !Int -> Expr (TPtr TWord)
149 150 151 152
cycle_ptr :: Expr TWord
indirection_ptr :: Expr TWord
dNil_ptr :: Expr TWord
small_integer :: !(Expr TInt) -> Expr TWord
153
static_character :: !(Expr TChar) -> Expr TWord
Camil Staps's avatar
Camil Staps committed
154
static_boolean :: !(Expr TWord) -> Expr TWord
155
caf_list :: Expr (TPtr TWord)
156

157
push_c :: !(Expr (TPtr TWord)) !Target -> Target
158
pop_pc_from_c :: !Target -> Target
159

160 161
memcpy :: !(Expr (TPtr a)) !(Expr (TPtr b)) !(Expr TPtrOffset) !Target -> Target
strncmp :: !(Expr (TPtr TChar)) !(Expr (TPtr TChar)) !(Expr TPtrOffset) -> Expr TInt
162 163 164 165 166 167

putchar :: !(Expr TChar) !Target -> Target
print_bool :: !(Expr TWord) !Target -> Target
print_char :: !Bool !(Expr TChar) !Target -> Target
print_int :: !(Expr TInt) !Target -> Target
print_real :: !(Expr TReal) !Target -> Target