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:
@@ -47,7 +47,26 @@
|
||||
;; can pattern-match them.
|
||||
(list "raise" (fn (e) (raise e)))
|
||||
(list "failwith" (fn (msg) (raise (list "Failure" msg))))
|
||||
(list "invalid_arg" (fn (msg) (raise (list "Invalid_argument" msg)))))))
|
||||
(list "invalid_arg" (fn (msg) (raise (list "Invalid_argument" msg)))
|
||||
)
|
||||
;; Host primitives exposed for the OCaml stdlib (lib/ocaml/runtime.sx).
|
||||
;; Underscore-prefixed to avoid clashing with user names.
|
||||
(list "_string_length" (fn (s) (len s)))
|
||||
(list "_string_get" (fn (s) (fn (i) (nth s i))))
|
||||
(list "_string_sub" (fn (s) (fn (i) (fn (n) (slice s i (+ i n))))))
|
||||
(list "_string_concat" (fn (sep) (fn (xs) (join sep xs))))
|
||||
(list "_string_upper" (fn (s) (upper s)))
|
||||
(list "_string_lower" (fn (s) (lower s)))
|
||||
(list "_string_starts_with" (fn (p) (fn (s) (starts-with? s p))))
|
||||
(list "_int_of_string" (fn (s) (parse-number s)))
|
||||
(list "_string_of_int" (fn (i) (str i)))
|
||||
(list "_string_of_float" (fn (f) (str f)))
|
||||
(list "_char_code" (fn (c) (char-code c)))
|
||||
(list "_char_chr" (fn (n) (char-from-code n)))
|
||||
;; Print: prints to host stdout via println.
|
||||
(list "print_string" (fn (s) (begin (print s) nil)))
|
||||
(list "print_endline" (fn (s) (begin (println s) nil)))
|
||||
(list "print_int" (fn (i) (begin (print (str i)) nil))))))
|
||||
|
||||
(define ocaml-env-lookup
|
||||
(fn (env name)
|
||||
|
||||
Reference in New Issue
Block a user