Refactor to hopefully avoid compiler bugs
This commit is contained in:
parent
ffdcfd2789
commit
02f5ff2b20
10 changed files with 770 additions and 139 deletions
5
mem/decode.ml
Normal file
5
mem/decode.ml
Normal file
|
@ -0,0 +1,5 @@
|
|||
open import "prelude.ml"
|
||||
|
||||
class decode 'a begin
|
||||
val decode : int -> 'a
|
||||
end
|
77
mem/int.ml
Normal file
77
mem/int.ml
Normal file
|
@ -0,0 +1,77 @@
|
|||
open import "prelude.ml"
|
||||
open import "./decode.ml"
|
||||
open import "../dolphin.ml"
|
||||
|
||||
type u8 =
|
||||
U8 of int
|
||||
|
||||
instance show u8 begin
|
||||
let show (U8 x) = (show x) ^ "_u8"
|
||||
end
|
||||
|
||||
instance decode u8 begin
|
||||
let decode addr = U8 (Dolphin.read_value_8 addr)
|
||||
end
|
||||
|
||||
type s8 =
|
||||
S8 of int
|
||||
|
||||
instance show s8 begin
|
||||
let show (S8 x) = (show x) ^ "_s8"
|
||||
end
|
||||
|
||||
instance decode s8 begin
|
||||
let decode addr =
|
||||
let u8 = Dolphin.read_value_8 addr
|
||||
let signfix =
|
||||
if u8 > 127 then
|
||||
negate (256 - u8)
|
||||
else
|
||||
u8
|
||||
S8 signfix
|
||||
end
|
||||
|
||||
type u16 =
|
||||
U16 of int
|
||||
|
||||
instance show u16 begin
|
||||
let show (U16 x) = (show x) ^ "_u16"
|
||||
end
|
||||
|
||||
type s16 =
|
||||
S16 of int
|
||||
|
||||
instance show s16 begin
|
||||
let show (S16 x) = (show x) ^ "_s16"
|
||||
end
|
||||
|
||||
instance decode s16 begin
|
||||
let decode addr =
|
||||
let u16 = Dolphin.read_value_16 addr
|
||||
let signfix =
|
||||
if u16 > 32767 then
|
||||
negate (65536 - u16)
|
||||
else
|
||||
u16
|
||||
S16 signfix
|
||||
end
|
||||
|
||||
type u32 =
|
||||
U32 of int
|
||||
|
||||
instance show u32 begin
|
||||
let show (U32 x) = (show x) ^ "_u32"
|
||||
end
|
||||
|
||||
type s32 =
|
||||
S32 of int
|
||||
|
||||
instance show s32 begin
|
||||
let show (S32 x) =
|
||||
let signfix =
|
||||
if x > 2147483647 then
|
||||
negate (4294967296 - x)
|
||||
else
|
||||
x
|
||||
(show signfix) ^ "_s32"
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue