···22 License, v. 2.0. If a copy of the MPL was not distributed with this
33 file, You can obtain one at https://mozilla.org/MPL/2.0/. *)
4455+open Common
56type t = Common.exa
6777-let create ?(code = Dynarray.create ()) (name : string) (host_name : string) : t =
88+let create ?(code = Dynarray.create ()) (name : string) (host : host) : t =
89 {
910 name;
1011 dead = false;
···1718 code;
1819 ip = 0;
1920 labels = Hashtbl.create 0;
2020- host_name;
2121+ host;
2122 }
22232324let length (exa : t) = Dynarray.length exa.code [@@inline always]
+3-3
lib/OpCode.ml
···4545 | TEST_EQ (left, right) -> testInstruction "TEST" left "=" right
4646 | TEST_LT (left, right) -> testInstruction "TEST" left "<" right
4747 | TEST_GT (left, right) -> testInstruction "TEST" left ">" right
4848- (*| HOST dest -> regInstruction "HOST" dest*)
4848+ | HOST dest -> regInstruction "HOST" dest
4949 | MAKE -> "MAKE"
5050 | GRAB file -> rnInstruction "GRAB" file
5151 | FILE dest -> regInstruction "FILE" dest
···102102 | TEST_LT _, _
103103 | TEST_GT _, _ ->
104104 false
105105- (*| HOST r1, HOST r2 -> Register.equal r1 r2*)
106106- (*| HOST _, _ -> false*)
105105+ | HOST r1, HOST r2 -> Register.equal r1 r2
106106+ | HOST _, _ -> false
107107 | MAKE, MAKE -> true
108108 | MAKE, _ -> false
109109 | GRAB f1, GRAB f2 -> Register.equal_r_n f1 f2
+15-18
lib/Vm.ml
···3636let place_exa (vm : t) (host : Host.t) (exa : Exa.t) : unit =
3737 if Host.add host (E exa) then (
3838 Dynarray.add_last vm.exas (Some exa);
3939- exa.host_name <- host.name)
3939+ exa.host <- host)
40404141let create_exa (vm : t) (host : Host.t) (name : string) (code : string) :
4242 (Exa.t, string) result =
4343 Result.bind (Reader.parse_code code) (fun code ->
4444- let exa = Exa.create name host.name ~code in
4444+ let exa = Exa.create name host ~code in
4545 place_exa vm host exa;
4646 Ok exa)
4747···50505151let get_host (vm : t) (hostname : string) = StringMap.find_opt vm.hosts hostname
52525353-let get_file (vm : t) (hostname : string) (filename : string) =
5454- Option.bind (get_host vm hostname) (fun host -> Host.find_file host filename)
5353+let get_file (host : host) (filename : string) = Host.find_file host filename
55545655(** FILE OPS **)
5756···133132 | Key s -> Key s
134133[@@inline always]
135134136136-let math_fn (exa : Exa.t) func (src : r_n) (i : r_n) (dest : register) :
137137- inst_result =
135135+let math_fn (exa : Exa.t) func (src : r_n) (i : r_n) (dest : register) : inst_result =
138136 let left = value_of_r_n exa src in
139137 let right = value_of_r_n exa i in
140138 match (left, right) with
···258256 add_file vm file;
259257 pass ()
260258261261-let grab (vm : t) (exa : Exa.t) (src : Register.r_n) : inst_result =
259259+let host (_vm : t) (_exa : Exa.t) (_dest : register) : inst_result = pass ()
260260+261261+let grab (exa : Exa.t) (src : r_n) : inst_result =
262262 match value_of_r_n exa src with
263263 | Error _ as e -> e
264264 | Ok value -> (
···267267 | Int i -> string_of_int i
268268 | Key k -> k
269269 in
270270- match get_file vm exa.host_name filename with
270270+ match get_file exa.host filename with
271271 | None -> runtime_error "NO FILE TO GRAB"
272272 | Some file ->
273273- (match get_host vm exa.host_name with
274274- | None -> ()
275275- | Some host -> Host.remove host filename);
273273+ Host.remove exa.host filename;
276274 exa.f <- Some file;
277275 exa.f_pos <- 0;
278276 pass ())
···308306 end
309307 | Some _, _ -> runtime_error "WRONG REGISTER"
310308311311-let drop (vm : t) (exa : Exa.t) : inst_result =
309309+let drop (exa : Exa.t) : inst_result =
312310 match exa.f with
313311 | None -> runtime_error "NO CURRENT FILE"
314312 | Some file ->
315313 if
316316- match get_host vm exa.host_name with
317317- | None -> false
318318- | Some host -> Host.add host (F file)
314314+ Host.add exa.host (F file)
319315 then (
320316 exa.f <- None;
321317 exa.f_pos <- 0;
···361357 | TEST_EQ (left, right) -> test_fn exa left test_eq right
362358 | TEST_LT (left, right) -> test_fn exa left test_lt right
363359 | TEST_GT (left, right) -> test_fn exa left test_gt right
360360+ | HOST dest -> host vm exa dest
364361 | MAKE -> make vm exa
365365- | GRAB id -> grab vm exa id
362362+ | GRAB id -> grab exa id
366363 | FILE dest -> fname exa dest
367364 | SEEK value -> seek exa value
368365 | VOID_F -> void exa F
369369- | DROP -> drop vm exa
366366+ | DROP -> drop exa
370367 | WIPE -> wipe vm exa
371368 | TEST_EOF -> test_eof exa)
372369···389386 | None -> i := !i + 1
390387 | Some exa -> (
391388 if exa.dead then
392392- let _ = drop vm exa in
389389+ let _ = drop exa in
393390 Dynarray.set vm.exas !i None
394391 else
395392 let ret = execute vm exa in