ocaml: phase 6 String/Char/Int/Float/Printf modules (+13 tests, 278 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 53s
Host primitives _string_length / _string_sub / _char_code / etc. exposed in the base env (underscore-prefixed to avoid user clash). lib/ocaml/ runtime.sx wraps them into OCaml-syntax modules: String (length, get, sub, concat, uppercase/lowercase_ascii, starts_with), Char (code, chr, lowercase/uppercase_ascii), Int (to_string, of_string, abs, max, min), Float.to_string, Printf stubs. Also added print_string / print_endline / print_int IO builtins.
This commit is contained in:
@@ -136,6 +136,40 @@
|
||||
match r with
|
||||
| Ok _ -> false
|
||||
| Error _ -> true
|
||||
end ;;
|
||||
|
||||
module String = struct
|
||||
let length s = _string_length s
|
||||
let get s i = _string_get s i
|
||||
let sub s i n = _string_sub s i n
|
||||
let concat sep xs = _string_concat sep xs
|
||||
let uppercase_ascii s = _string_upper s
|
||||
let lowercase_ascii s = _string_lower s
|
||||
let starts_with prefix s = _string_starts_with prefix s
|
||||
end ;;
|
||||
|
||||
module Char = struct
|
||||
let code c = _char_code c
|
||||
let chr n = _char_chr n
|
||||
let lowercase_ascii c = _string_lower c
|
||||
let uppercase_ascii c = _string_upper c
|
||||
end ;;
|
||||
|
||||
module Int = struct
|
||||
let to_string i = _string_of_int i
|
||||
let of_string s = _int_of_string s
|
||||
let abs n = if n < 0 then 0 - n else n
|
||||
let max a b = if a > b then a else b
|
||||
let min a b = if a < b then a else b
|
||||
end ;;
|
||||
|
||||
module Float = struct
|
||||
let to_string f = _string_of_float f
|
||||
end ;;
|
||||
|
||||
module Printf = struct
|
||||
let sprintf fmt = fmt
|
||||
let printf fmt = print_string fmt
|
||||
end")
|
||||
|
||||
(define ocaml-stdlib-loaded false)
|
||||
|
||||
Reference in New Issue
Block a user