standalone exapunks vm in ocaml
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Put Host on Exa type

+24 -26
+2 -2
lib/Common.ml
··· 35 35 | TEST_LT of r_n * r_n 36 36 | TEST_GT of r_n * r_n 37 37 (* Movement *) 38 - (*| HOST of register*) 38 + | HOST of register 39 39 (* File Manipulation *) 40 40 | MAKE 41 41 | GRAB of r_n ··· 58 58 code : op_code Dynarray.t; 59 59 mutable ip : int; 60 60 labels : (string, int) Hashtbl.t; 61 - mutable host_name : string; 61 + mutable host : host; 62 62 } 63 63 64 64 and host = {
+1 -1
lib/Debugger.ml
··· 49 49 | None -> () 50 50 | Some exa -> 51 51 if not exa.dead then ( 52 - Printf.printf "== %s (%s) ==\n" exa.name exa.host_name; 52 + Printf.printf "== %s (%s) ==\n" exa.name exa.host.name; 53 53 Printf.printf "X: %s\n" (Value.show exa.x); 54 54 Printf.printf "T: %s\n" (Value.show exa.t); 55 55 Printf.printf "F: %s\n"
+3 -2
lib/Exa.ml
··· 2 2 License, v. 2.0. If a copy of the MPL was not distributed with this 3 3 file, You can obtain one at https://mozilla.org/MPL/2.0/. *) 4 4 5 + open Common 5 6 type t = Common.exa 6 7 7 - let create ?(code = Dynarray.create ()) (name : string) (host_name : string) : t = 8 + let create ?(code = Dynarray.create ()) (name : string) (host : host) : t = 8 9 { 9 10 name; 10 11 dead = false; ··· 17 18 code; 18 19 ip = 0; 19 20 labels = Hashtbl.create 0; 20 - host_name; 21 + host; 21 22 } 22 23 23 24 let length (exa : t) = Dynarray.length exa.code [@@inline always]
+3 -3
lib/OpCode.ml
··· 45 45 | TEST_EQ (left, right) -> testInstruction "TEST" left "=" right 46 46 | TEST_LT (left, right) -> testInstruction "TEST" left "<" right 47 47 | TEST_GT (left, right) -> testInstruction "TEST" left ">" right 48 - (*| HOST dest -> regInstruction "HOST" dest*) 48 + | HOST dest -> regInstruction "HOST" dest 49 49 | MAKE -> "MAKE" 50 50 | GRAB file -> rnInstruction "GRAB" file 51 51 | FILE dest -> regInstruction "FILE" dest ··· 102 102 | TEST_LT _, _ 103 103 | TEST_GT _, _ -> 104 104 false 105 - (*| HOST r1, HOST r2 -> Register.equal r1 r2*) 106 - (*| HOST _, _ -> false*) 105 + | HOST r1, HOST r2 -> Register.equal r1 r2 106 + | HOST _, _ -> false 107 107 | MAKE, MAKE -> true 108 108 | MAKE, _ -> false 109 109 | GRAB f1, GRAB f2 -> Register.equal_r_n f1 f2
+15 -18
lib/Vm.ml
··· 36 36 let place_exa (vm : t) (host : Host.t) (exa : Exa.t) : unit = 37 37 if Host.add host (E exa) then ( 38 38 Dynarray.add_last vm.exas (Some exa); 39 - exa.host_name <- host.name) 39 + exa.host <- host) 40 40 41 41 let create_exa (vm : t) (host : Host.t) (name : string) (code : string) : 42 42 (Exa.t, string) result = 43 43 Result.bind (Reader.parse_code code) (fun code -> 44 - let exa = Exa.create name host.name ~code in 44 + let exa = Exa.create name host ~code in 45 45 place_exa vm host exa; 46 46 Ok exa) 47 47 ··· 50 50 51 51 let get_host (vm : t) (hostname : string) = StringMap.find_opt vm.hosts hostname 52 52 53 - let get_file (vm : t) (hostname : string) (filename : string) = 54 - Option.bind (get_host vm hostname) (fun host -> Host.find_file host filename) 53 + let get_file (host : host) (filename : string) = Host.find_file host filename 55 54 56 55 (** FILE OPS **) 57 56 ··· 133 132 | Key s -> Key s 134 133 [@@inline always] 135 134 136 - let math_fn (exa : Exa.t) func (src : r_n) (i : r_n) (dest : register) : 137 - inst_result = 135 + let math_fn (exa : Exa.t) func (src : r_n) (i : r_n) (dest : register) : inst_result = 138 136 let left = value_of_r_n exa src in 139 137 let right = value_of_r_n exa i in 140 138 match (left, right) with ··· 258 256 add_file vm file; 259 257 pass () 260 258 261 - let grab (vm : t) (exa : Exa.t) (src : Register.r_n) : inst_result = 259 + let host (_vm : t) (_exa : Exa.t) (_dest : register) : inst_result = pass () 260 + 261 + let grab (exa : Exa.t) (src : r_n) : inst_result = 262 262 match value_of_r_n exa src with 263 263 | Error _ as e -> e 264 264 | Ok value -> ( ··· 267 267 | Int i -> string_of_int i 268 268 | Key k -> k 269 269 in 270 - match get_file vm exa.host_name filename with 270 + match get_file exa.host filename with 271 271 | None -> runtime_error "NO FILE TO GRAB" 272 272 | Some file -> 273 - (match get_host vm exa.host_name with 274 - | None -> () 275 - | Some host -> Host.remove host filename); 273 + Host.remove exa.host filename; 276 274 exa.f <- Some file; 277 275 exa.f_pos <- 0; 278 276 pass ()) ··· 308 306 end 309 307 | Some _, _ -> runtime_error "WRONG REGISTER" 310 308 311 - let drop (vm : t) (exa : Exa.t) : inst_result = 309 + let drop (exa : Exa.t) : inst_result = 312 310 match exa.f with 313 311 | None -> runtime_error "NO CURRENT FILE" 314 312 | Some file -> 315 313 if 316 - match get_host vm exa.host_name with 317 - | None -> false 318 - | Some host -> Host.add host (F file) 314 + Host.add exa.host (F file) 319 315 then ( 320 316 exa.f <- None; 321 317 exa.f_pos <- 0; ··· 361 357 | TEST_EQ (left, right) -> test_fn exa left test_eq right 362 358 | TEST_LT (left, right) -> test_fn exa left test_lt right 363 359 | TEST_GT (left, right) -> test_fn exa left test_gt right 360 + | HOST dest -> host vm exa dest 364 361 | MAKE -> make vm exa 365 - | GRAB id -> grab vm exa id 362 + | GRAB id -> grab exa id 366 363 | FILE dest -> fname exa dest 367 364 | SEEK value -> seek exa value 368 365 | VOID_F -> void exa F 369 - | DROP -> drop vm exa 366 + | DROP -> drop exa 370 367 | WIPE -> wipe vm exa 371 368 | TEST_EOF -> test_eof exa) 372 369 ··· 389 386 | None -> i := !i + 1 390 387 | Some exa -> ( 391 388 if exa.dead then 392 - let _ = drop vm exa in 389 + let _ = drop exa in 393 390 Dynarray.set vm.exas !i None 394 391 else 395 392 let ret = execute vm exa in