begin work on new device module system

This commit is contained in:
Lobo 2025-12-18 13:03:39 -03:00
parent 7b8871ffd9
commit 5769f6d470
11 changed files with 190 additions and 112 deletions

34
lib/Device.ml Normal file
View file

@ -0,0 +1,34 @@
module type DEVICE = sig
type state
val state : state
val can_handle : int -> bool
val dei : Machine.machine -> int -> int option
val dei2 : Machine.machine -> int -> int option
val deo : Machine.machine -> int -> int -> unit
end
module Compose (D1 : DEVICE) (D2 : DEVICE) : DEVICE = struct
type state = D1.state * D2.state
let state = (D1.state, D2.state)
let can_handle port = D1.can_handle port || D2.can_handle port
let dei mach port =
match (D1.can_handle port, D2.can_handle port) with
| true, false -> D1.dei mach port
| false, true -> D2.dei mach port
| _ -> None
let dei2 mach port =
match (D1.can_handle port, D2.can_handle port) with
| true, false -> D1.dei2 mach port
| false, true -> D2.dei2 mach port
| _ -> None
let deo mach port value =
match (D1.can_handle port, D2.can_handle port) with
| true, false -> D1.deo mach port value
| false, true -> D2.deo mach port value
| _ -> ()
end