neater build system

This commit is contained in:
2022-01-20 20:07:42 +11:00
committed by aaron-jack-manning
parent d295103284
commit a8cdd2411f
16 changed files with 157 additions and 83 deletions

3
lib/bool.ml Normal file
View File

@ -0,0 +1,3 @@
open FromStdlib open Exposed
let of_string = stdlib_bool_of_string_opt

2
lib/bool.mli Normal file
View File

@ -0,0 +1,2 @@
(** Converts the string to a bool, returning option type to account for invalid strings. *)
val of_string : string -> bool option

3
lib/char.ml Normal file
View File

@ -0,0 +1,3 @@
open FromStdlib open Exposed
let of_int = stdlib_char_of_int

2
lib/char.mli Normal file
View File

@ -0,0 +1,2 @@
(** Converts an int to a char. *)
val of_int : int -> char

View File

@ -1,6 +1,11 @@
open FromStdlib open Exposed
let ( + ) a b = stdlib_plus_float a b
let ( - ) a b = stdlib_minus_float a b
let ( * ) a b = stdlib_multiply_float a b
let ( / ) a b = stdlib_divide_float a b
let of_string = stdlib_float_of_string_opt

View File

@ -5,3 +5,6 @@ val ( - ) : float -> float -> float
val ( * ) : float -> float -> float
val ( / ) : float -> float -> float
(** Converts the string to a float, returning option type to account for invalid strings. *)
val of_string : string -> float option

View File

@ -4,6 +4,20 @@ let failwith = Stdlib.failwith
let printf = Printf.printf
external ( |> ) : 'a -> ('a -> 'b) -> 'b = "%revapply"
external ignore : 'a -> unit = "%ignore"
external stdlib_int_of_char : char -> int = "%identity"
let stdlib_char_of_int = char_of_int
let stdlib_string_of_bool = string_of_bool
let stdlib_bool_of_string = bool_of_string
let stdlib_bool_of_string_opt = bool_of_string_opt
let stdlib_string_of_int = string_of_int
external stdlib_int_of_string : string -> int = "caml_int_of_string"
let stdlib_int_of_string_opt = int_of_string_opt
let stdlib_string_of_float = string_of_float
external stdlib_float_of_string : string -> float = "caml_float_of_string"
let stdlib_float_of_string_opt = float_of_string_opt
external stdlib_plus_int : int -> int -> int = "%addint"
external stdlib_minus_int : int -> int -> int = "%subint"
@ -42,4 +56,7 @@ external ( >= ) : 'a -> 'a -> bool = "%greaterequal"
external not : bool -> bool = "%boolnot"
external ( or ) : bool -> bool -> bool = "%sequor"
external ( & ) : bool -> bool -> bool = "%sequand"
external ( & ) : bool -> bool -> bool = "%sequand"

View File

@ -1,23 +1,43 @@
val failwith : string -> 'a
val printf : ('a, out_channel, unit) format -> 'a
external ( |> ) : 'a -> ('a -> 'b) -> 'b = "%revapply"
external ignore : 'a -> unit = "%ignore"
external stdlib_int_of_char : char -> int = "%identity"
val stdlib_char_of_int : int -> char
val stdlib_string_of_bool : bool -> string
val stdlib_bool_of_string : string -> bool
val stdlib_bool_of_string_opt : string -> bool option
val stdlib_string_of_int : int -> string
external stdlib_int_of_string : string -> int = "caml_int_of_string"
val stdlib_int_of_string_opt : string -> int option
val stdlib_string_of_float : float -> string
external stdlib_float_of_string : string -> float = "caml_float_of_string"
val stdlib_float_of_string_opt : string -> float option
external stdlib_plus_int : int -> int -> int = "%addint"
external stdlib_minus_int : int -> int -> int = "%subint"
external stdlib_multiply_int : int -> int -> int = "%mulint"
external stdlib_divide_int : int -> int -> int = "%divint"
external stdlib_mod_int : int -> int -> int = "%modint"
external stdlib_plus_float : float -> float -> float = "%addfloat"
external stdlib_minus_float : float -> float -> float = "%subfloat"
external stdlib_multiply_float : float -> float -> float = "%mulfloat"
external stdlib_divide_float : float -> float -> float = "%divfloat"
external stdlib_string_length : string -> int = "%string_length"
val stdlib_string_concat : string -> string -> string
external ( = ) : 'a -> 'a -> bool = "%equal"
external ( <> ) : 'a -> 'a -> bool = "%notequal"
external ( < ) : 'a -> 'a -> bool = "%lessthan"
external ( > ) : 'a -> 'a -> bool = "%greaterthan"
external ( <= ) : 'a -> 'a -> bool = "%lessequal"
external ( >= ) : 'a -> 'a -> bool = "%greaterequal"
external not : bool -> bool = "%boolnot"
external ( or ) : bool -> bool -> bool = "%sequor"
external ( & ) : bool -> bool -> bool = "%sequand"
external ( & ) : bool -> bool -> bool = "%sequand"

View File

@ -1,8 +1,16 @@
open FromStdlib
let ( + ) a b = stdlib_plus_int a b
let ( - ) a b = stdlib_minus_int a b
let ( * ) a b = stdlib_multiply_int a b
let ( / ) a b = stdlib_divide_int a b
let ( mod ) a b = stdlib_mod_int a b
let of_char = stdlib_int_of_char
let of_string = stdlib_int_of_string_opt

View File

@ -6,4 +6,10 @@ val ( * ) : int -> int -> int
val ( / ) : int -> int -> int
val ( mod ) : int -> int -> int
val ( mod ) : int -> int -> int
(** Converts the char to an int. *)
val of_char : char -> int
(** Converts the string to an int, returning option type to account for invalid strings. *)
val of_string : string -> int option

View File

@ -1,8 +1,8 @@
STANDARD_FLAGS = -S -O3
STANDARD_FLAGS = -O3
STANDARD_COMPILE = ocamlopt $(STANDARD_FLAGS) -nopervasives -c
LIB_NAME = library
# compiles the entire custom standard library
compile:
build:
# fromStdlib manages things that need to be exposed from the standard library
ocamlopt $(STANDARD_FLAGS) -c fromStdlib.mli fromStdlib.ml
@ -20,7 +20,11 @@ compile:
$(STANDARD_COMPILE) set.mli set.ml
$(STANDARD_COMPILE) tree.mli tree.ml
$(STANDARD_COMPILE) string.mli string.ml
$(STANDARD_COMPILE) char.mli char.ml
$(STANDARD_COMPILE) bool.mli bool.ml
ocamlopt -a fromStdlib.cmx exposed.cmx int.cmx float.cmx option.cmx stack.cmx list.cmx map.cmx queue.cmx set.cmx tree.cmx string.cmx -o $(LIB_NAME).cmxa
# clean removes all except source files. autogenerated mli files are also removed.
clean:
rm -f *.o *.a *.s *.cmi *.cmx *.cmxa *.cmo *.cma
rm -f *.o *.a *.s *.cmi *.cmx *.cmxa *.cmo *.cma

View File

@ -2,4 +2,10 @@ open FromStdlib open Exposed
let ( + ) = stdlib_string_concat
let length = stdlib_string_length
let length = stdlib_string_length
let of_int = stdlib_string_of_int
let of_float = stdlib_string_of_float
let of_bool = stdlib_string_of_bool

View File

@ -2,4 +2,13 @@
val ( + ) : string -> string -> string
(** Calculates the length of the provided string. *)
val length : string -> int
val length : string -> int
(** Converts an int to a string. *)
val of_int : int -> string
(** Converts a float to a string. *)
val of_float : float -> string
(** Converts a boolean to a string. *)
val of_bool : bool -> string