@@ -30,21 +30,21 @@ type vm = {
3030}
3131
3232(* Get the current frame *)
33- let current_frame (vm : vm ) : frame = vm.frames.(vm.frame_index)
33+ let [ @ inline] current_frame (vm : vm ) : frame = vm.frames.(vm.frame_index)
3434
3535(* Push a new frame *)
36- let push_frame (vm : vm ) (f : frame ) : unit =
36+ let [ @ inline] push_frame (vm : vm ) (f : frame ) : unit =
3737 vm.frame_index < - vm.frame_index + 1 ;
3838 vm.frames.(vm.frame_index) < - f
3939
4040(* Pop the current frame *)
41- let pop_frame (vm : vm ) : frame =
41+ let [ @ inline] pop_frame (vm : vm ) : frame =
4242 let f = vm.frames.(vm.frame_index) in
4343 vm.frame_index < - vm.frame_index - 1 ;
4444 f
4545
4646(* Get current instructions from current frame *)
47- let current_instructions (vm : vm ) : bytes = (current_frame vm).cl.fn.instructions
47+ let [ @ inline] current_instructions (vm : vm ) : bytes = (current_frame vm).cl.fn.instructions
4848
4949let create (bytecode : Compiler.bytecode ) : vm =
5050 (* Wrap the main program in a "main" closure *)
@@ -80,39 +80,39 @@ let create_with_globals (bytecode : Compiler.bytecode) (globals : Value.value ar
8080 sp = 0 ;
8181 }
8282
83- let push (vm : vm ) (value : Value.value ) : (unit, string) result =
83+ let [ @ inline] push (vm : vm ) (value : Value.value ) : (unit , string ) result =
8484 if vm.sp > = stack_size then
8585 Error " stack overflow"
8686 else (
87- vm.stack.( vm.sp) < - value;
87+ Array. unsafe_set vm.stack vm.sp value;
8888 vm.sp < - vm.sp + 1 ;
8989 Ok () )
9090
91- let pop (vm : vm ) : Value.value =
92- let value = vm.stack. (vm.sp - 1 ) in
91+ let [ @ inline] pop (vm : vm ) : Value. value =
92+ let value = Array. unsafe_get vm.stack (vm.sp - 1 ) in
9393 vm.sp < - vm.sp - 1 ;
9494 value
9595
9696(* For testing: get the last popped element (still on stack, just below sp) *)
97- let last_popped_stack_elem (vm : vm ) : Value.value = vm.stack.( vm.sp)
97+ let last_popped_stack_elem (vm : vm ) : Value.value = Array. unsafe_get vm.stack vm.sp
9898
99- let execute_binary_integer_op (op : Code.opcode ) (l : int64 ) (r : int64 ) : int64 =
99+ let [ @ inline] execute_binary_integer_op (op : Code.opcode ) (l : int64 ) (r : int64 ) : int64 =
100100 match op with
101101 | Code. OpAdd -> Int64. add l r
102102 | Code. OpSub -> Int64. sub l r
103103 | Code. OpMul -> Int64. mul l r
104104 | Code. OpDiv -> Int64. div l r
105105 | _ -> 0L
106106
107- let execute_binary_float_op (op : Code.opcode ) (l : float ) (r : float ) : float =
107+ let [ @ inline] execute_binary_float_op (op : Code.opcode ) (l : float ) (r : float ) : float =
108108 match op with
109109 | Code. OpAdd -> l +. r
110110 | Code. OpSub -> l -. r
111111 | Code. OpMul -> l *. r
112112 | Code. OpDiv -> l /. r
113113 | _ -> 0.0
114114
115- let execute_binary_op (vm : vm ) (op : Code.opcode ) : unit =
115+ let [ @ inline] execute_binary_op (vm : vm ) (op : Code.opcode ) : unit =
116116 let right = pop vm in
117117 let left = pop vm in
118118 match (left, right) with
@@ -138,7 +138,7 @@ let execute_binary_op (vm : vm) (op : Code.opcode) : unit =
138138 | _ -> ()
139139
140140(* Execute comparison operations - always returns a boolean *)
141- let execute_comparison (vm : vm ) (op : Code.opcode ) : unit =
141+ let [ @ inline] execute_comparison (vm : vm ) (op : Code.opcode ) : unit =
142142 let right = pop vm in
143143 let left = pop vm in
144144 let result =
@@ -184,7 +184,7 @@ let run (vm : vm) : (unit, string) result =
184184 let frame = current_frame vm in
185185 let ins = frame.cl.fn.instructions in
186186 let ip = frame.ip in
187- let op_byte = Char. code (Bytes. get ins ip) in
187+ let op_byte = Char. code (Bytes. unsafe_get ins ip) in
188188
189189 (* Use unsafe_of_int for fast opcode dispatch - we trust the compiler emitted valid opcodes *)
190190 (match Code. unsafe_of_int op_byte with
0 commit comments