Skip to content

Commit

Permalink
add helpers module
Browse files Browse the repository at this point in the history
  • Loading branch information
eWert-Online committed Apr 4, 2024
1 parent 48bbffa commit 25a0a72
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 264 deletions.
3 changes: 1 addition & 2 deletions lib/Pinc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ module Interpreter = struct
end

module StringMap = Pinc_Backend.StringMap
module Value = Pinc_Backend.Value
module Typer = Pinc_Backend.Typer
module Helpers = Pinc_Backend.Helpers
42 changes: 41 additions & 1 deletion lib/pinc_backend/Typer.ml → lib/pinc_backend/Helpers.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
open Interpreter.Types
module Value = struct
open Types.Type_Value

let null ?(loc = Pinc_Diagnostics.Location.none) () =
{ value_loc = loc; value_desc = Null }
;;

let char ?(loc = Pinc_Diagnostics.Location.none) c =
{ value_loc = loc; value_desc = Char c }
;;

let string ?(loc = Pinc_Diagnostics.Location.none) s =
{ value_loc = loc; value_desc = String s }
;;

let bool ?(loc = Pinc_Diagnostics.Location.none) b =
{ value_loc = loc; value_desc = Bool b }
;;

let int ?(loc = Pinc_Diagnostics.Location.none) i =
{ value_loc = loc; value_desc = Int i }
;;

let float ?(loc = Pinc_Diagnostics.Location.none) f =
{ value_loc = loc; value_desc = Float f }
;;

let array ?(loc = Pinc_Diagnostics.Location.none) l =
{ value_loc = loc; value_desc = Array l }
;;

let list ?(loc = Pinc_Diagnostics.Location.none) l =
{ value_loc = loc; value_desc = Array (Array.of_list l) }
;;

let record ?(loc = Pinc_Diagnostics.Location.none) m =
{ value_loc = loc; value_desc = Record m }
;;
end

module Expect = struct
open Types.Type_Value

let required fn value =
match fn value with
| None -> Pinc_Diagnostics.(error Location.none "required a value, but got null")
Expand Down
Loading

0 comments on commit 25a0a72

Please sign in to comment.