From 08befa80658d8a17e33d0bfb31f7e5f8e07d4b1e Mon Sep 17 00:00:00 2001 From: Torben Ewert Date: Sun, 5 Jul 2026 14:30:39 +0200 Subject: [PATCH] perf: keep current frame pointer directly in vm state --- lib/pinc_vm/vm.ml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/pinc_vm/vm.ml b/lib/pinc_vm/vm.ml index 4502c2f..226778f 100644 --- a/lib/pinc_vm/vm.ml +++ b/lib/pinc_vm/vm.ml @@ -8,7 +8,8 @@ exception TODO type t = { stack : Value.t Stack.t; mutable globals : Value.t Int32.Map.t; - mutable frames : Frame.t list; + mutable past_frames : Frame.t list; + mutable current_frame : Frame.t; constants : Value.t Int32.Map.t; } @@ -27,24 +28,26 @@ let make (bytecode : Bytecode.t) = constants = bytecode.constants; stack = Stack.make ~size:stack_size; globals = Int32.Map.empty; - frames = [ main_frame ]; + past_frames = []; + current_frame = main_frame; } ;; -let current_frame t = - match t.frames with - | [] -> assert false - | hd :: _ -> hd -;; +let current_frame t = t.current_frame -let push_frame t frame = t.frames <- frame :: t.frames +let push_frame t frame = + t.past_frames <- t.current_frame :: t.past_frames; + t.current_frame <- frame +;; let pop_frame t = - match t.frames with + match t.past_frames with | [] -> assert false | frame :: frames -> - t.frames <- frames; - frame + let current_frame = t.current_frame in + t.past_frames <- frames; + t.current_frame <- frame; + current_frame ;; let rec execute_binary_operation t op = -- 2.51.2