Skip to content

Instantly share code, notes, and snippets.

@ebresafegaga
Created April 6, 2023 09:36
Show Gist options
  • Save ebresafegaga/9963892ff0430bfc831f5a8ceabf6eea to your computer and use it in GitHub Desktop.
Save ebresafegaga/9963892ff0430bfc831f5a8ceabf6eea to your computer and use it in GitHub Desktop.
type stack = int array
type machine = { ip : int; sp : int; mutable stack : stack }
(* Machine stack *)
module type S = sig
type t
type index
type elem
val alignment : int
val index :
t ->
index ->
offset:int ->
(elem, [ `Invalid_memory | `Stack_overflow ]) Either.t
val store :
t ->
index ->
offset:int ->
elem ->
(t, [ `Invalid_memory | `Stack_overflow ]) Either.t
end
(* Instruction list *)
module type I = sig
type t
val next : t -> Ast.instr option * t
end
(* Machine *)
module type M = sig
type t
type error
val step : t -> Ast.instr -> (t, error) Result.t
val exec : t -> Ast.program -> (t, error) Result.t
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment