Last change
on this file since 57 was
57,
checked in by mulligan, 11 years ago
|
More instructions implemented. Started cleaning up code by moving
related functions acting on datatypes (bits, etc.) into dedicated
modules.
|
File size:
751 bytes
|
Line | |
---|
1 | module type BIT = |
---|
2 | sig |
---|
3 | type bit |
---|
4 | |
---|
5 | val from_bool: bool -> bit |
---|
6 | val from_int: int -> bit |
---|
7 | |
---|
8 | val (-&-): bit -> bit -> bit |
---|
9 | val (-|-): bit -> bit -> bit |
---|
10 | val (-^-): bit -> bit -> bit |
---|
11 | val not: bit -> bit |
---|
12 | |
---|
13 | val pretty: bit -> string |
---|
14 | end;; |
---|
15 | |
---|
16 | module Bit: BIT = |
---|
17 | struct |
---|
18 | type bit = bool |
---|
19 | |
---|
20 | let from_bool b = b |
---|
21 | let from_int i = |
---|
22 | if i > 0 then |
---|
23 | true |
---|
24 | else |
---|
25 | false |
---|
26 | |
---|
27 | let (-&-) l r = |
---|
28 | match l with |
---|
29 | true -> r |
---|
30 | | false -> false |
---|
31 | let (-|-) l r = |
---|
32 | match l with |
---|
33 | true -> true |
---|
34 | | false -> r |
---|
35 | let (-^-) (l: bit) r = |
---|
36 | match l with |
---|
37 | true -> not r |
---|
38 | | false -> r |
---|
39 | let not l = |
---|
40 | match l with |
---|
41 | true -> false |
---|
42 | | false -> true |
---|
43 | |
---|
44 | let pretty l = |
---|
45 | match l with |
---|
46 | true -> "1b" |
---|
47 | | false -> "0b" |
---|
48 | end;; |
---|
Note: See
TracBrowser
for help on using the repository browser.