-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorbit.ml
39 lines (32 loc) · 1.04 KB
/
orbit.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module B = Bigarray
module A = Bigarray.Array1
type ds = (float, B.float64_elt, B.c_layout) A.t
type is = (int32, B.int32_elt, B.c_layout) A.t
let ssize = 16384
let dss () : ds = A.create B.float64 B.c_layout ssize
let iss () : is = A.create B.int32 B.c_layout ssize
external read_prog : string -> (is * ds)
= "orbcaml_read_prog"
external orb_step : is -> ds -> ds -> bool ref -> (int -> float -> unit) -> unit
= "orbcaml_step"
let copy arr =
let brr = A.create (A.kind arr) (A.layout arr) (A.dim arr) in
A.blit arr brr;
brr
let orb_step_list insns data input rstat =
let lr = ref [] in
orb_step insns data input rstat (fun a v -> lr := (a,v)::!lr);
List.rev !lr
let orb_step_array insns data input rstat =
let lr = ref [] and mr = ref 0 in
orb_step insns data input rstat (fun a v ->
lr := (a,v)::!lr;
mr := max !mr (succ a));
let arr = Array.create !mr 0.0 in
List.iter (fun (a,v) -> arr.(a) <- v) !lr;
arr
let in_scene scene =
let arr = dss () in
A.fill arr 0.0;
A.set arr 0x3E80 (float_of_int scene);
arr