standalone exapunks vm in ocaml
1(* This Source Code Form is subject to the terms of the Mozilla Public
2 License, v. 2.0. If a copy of the MPL was not distributed with this
3 file, You can obtain one at https://mozilla.org/MPL/2.0/. *)
4
5open Utils
6
7type register =
8 | X
9 | T
10 | F
11 | M
12
13and r_n =
14 | R of register
15 | N of int
16
17and op_code =
18 | NOOP
19 | COPY of r_n * register
20 (* Math *)
21 | ADDI of r_n * r_n * register
22 | SUBI of r_n * r_n * register
23 | MULI of r_n * r_n * register
24 | DIVI of r_n * r_n * register
25 | MODI of r_n * r_n * register
26 | SWIZ of r_n * r_n * register
27 (* Branching *)
28 | MARK of string
29 | JUMP of string
30 | TJMP of string
31 | FJMP of string
32 (* Testing *)
33 | TEST_EQ of r_n * r_n
34 | TEST_LT of r_n * r_n
35 | TEST_GT of r_n * r_n
36 (* Lifecycle *)
37 | REPL of string
38 | HALT
39 (* Movement *)
40 | LINK of r_n
41 | HOST of register
42 (* Communication *)
43 | MODE
44 | VOID_M
45 | TEST_MRD
46 (* File Manipulation *)
47 | MAKE
48 | GRAB of r_n
49 | FILE of register
50 | SEEK of r_n
51 | VOID_F
52 | DROP
53 | WIPE
54 | TEST_EOF
55
56and mode =
57 | LOCAL
58 | GLOBAL
59
60and exa = {
61 name : string;
62 mutable dead : bool;
63 mutable x : value;
64 mutable t : value;
65 mutable f : file option;
66 mutable f_pos : int;
67 (*mutable m : Value.t option;*)
68 mutable mode : mode;
69 code : op_code Dynarray.t;
70 mutable ip : int;
71 labels : int StringMap.t;
72 mutable host : host;
73 mutable waiting : bool;
74}
75
76and host = {
77 name : string;
78 grid_size : int;
79 mutable grid : obj StringMap.t;
80 mutable links : host IntMap.t;
81 mutable send : exa Queue.t;
82 mutable receive : exa Queue.t;
83}
84
85and value =
86 | Int of int
87 | Key of string
88
89and file = {
90 name : string;
91 mutable contents : value Dynarray.t;
92}
93
94and obj =
95 | F_o of file
96 | E_o of exa
97
98and syntax_error = {
99 line_num : int;
100 msg : string;
101 exa : string option;
102}
103
104and code = {
105 ops : op_code list;
106 errors : syntax_error list;
107 labels : int StringMap.t;
108}