Skip to content

Commit

Permalink
Initialize the Heap with custom capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoLR10 committed Oct 16, 2024
1 parent 196b144 commit fc46639
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/evaluator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ module Heap = struct
FT.set heap index elem

let empty = FT.empty

let rec initialize (heap : 'a t) (size : int) (default : 'a) =
if size = 0 then heap else initialize (push heap default) (size - 1) default
end

module AbstractMachine = struct
module Cell = struct
type t = Structure of int | Reference of int | Functor of string * int
type t =
| Structure of int
| Reference of int
| Functor of string * int
| Empty
end

open Cell
Expand Down Expand Up @@ -59,6 +66,10 @@ module AbstractMachine = struct
let h_register = h_register + 1 in
{ heap; registers; h_register }

let initialize () : computer =
{ heap = Heap.empty; registers = IM.empty ~eq:( = ); h_register = 0 }
let initialize (heap_size : int) : computer =
{
heap = Heap.initialize Heap.empty heap_size Empty;
registers = IM.empty ~eq:( = );
h_register = 0;
}
end

0 comments on commit fc46639

Please sign in to comment.