parent
0f71dbe145
commit
2fc0435393
@ -0,0 +1,21 @@
|
||||
open Types
|
||||
|
||||
exception Bad_format
|
||||
|
||||
let tail s start =
|
||||
String.sub s start (String.length s - start)
|
||||
|
||||
(** Return a list of expected types from a format string *)
|
||||
let rec extract_formatters s =
|
||||
try
|
||||
let i = String.index s '%' in
|
||||
let ty = match s.[i+1] with
|
||||
| 'b' -> Initial.tbool
|
||||
| 'd' -> Initial.tint
|
||||
| 'f' -> Initial.tfloat
|
||||
| _ -> raise Bad_format
|
||||
in
|
||||
ty::(extract_formatters (tail s (i+1)))
|
||||
with
|
||||
| Invalid_argument _ -> raise Bad_format (* String.get failed*)
|
||||
| Not_found -> []
|
@ -1,44 +1,13 @@
|
||||
(* The printing module *)
|
||||
|
||||
(*
|
||||
type file
|
||||
|
||||
(*
|
||||
const file stdout
|
||||
const file stdin
|
||||
const file stderr
|
||||
|
||||
(* Basic Printing *)
|
||||
|
||||
unsafe val fun open(name :string) returns (file)
|
||||
unsafe val fun flush(file) returns ()
|
||||
unsafe val fun print_int(file,int) returns ()
|
||||
unsafe val fun print_float(file,float) returns ()
|
||||
unsafe val fun print_string(file,string) returns ()
|
||||
unsafe val fun print_bool(file, bool) returns ()
|
||||
unsafe val fun print_nl(file) returns ()
|
||||
*)
|
||||
unsafe val fun out_flush() returns ()
|
||||
unsafe val fun out_int(int) returns ()
|
||||
unsafe val fun out_float(float) returns ()
|
||||
unsafe val fun out_string(string) returns ()
|
||||
unsafe val fun out_bool( bool) returns ()
|
||||
unsafe val fun out_nl() returns ()
|
||||
|
||||
unsafe val fun err_flush() returns ()
|
||||
unsafe val fun err_int(int) returns ()
|
||||
unsafe val fun err_float(float) returns ()
|
||||
unsafe val fun err_string(string) returns ()
|
||||
unsafe val fun err_bool( bool) returns ()
|
||||
unsafe val fun err_nl() returns ()
|
||||
|
||||
(* Basic Parsing *)
|
||||
(*
|
||||
val fun read_int(file) returns (int)
|
||||
val fun read_float(file) returns (float)
|
||||
val fun read_string(file) returns (string)
|
||||
val fun read_bool(file) returns (bool)
|
||||
*)
|
||||
unsafe val fun in_int() returns (int)
|
||||
unsafe val fun in_float() returns (float)
|
||||
unsafe val fun in_string() returns (string)
|
||||
unsafe val fun in_bool() returns (bool)
|
||||
(* Basic Printing *)
|
||||
unsafe val fun printf(string;...) returns ()
|
||||
unsafe val fun fprintf(file;string;...) returns ()
|
||||
|
@ -0,0 +1,11 @@
|
||||
open Iostream
|
||||
|
||||
unsafe fun f(a:int) returns (o:int)
|
||||
var x:int;
|
||||
let
|
||||
x = a + 2;
|
||||
() = printf("Int is %d@.", x);
|
||||
() = printf("Bool is %b@.", x = 0);
|
||||
() = printf("Test");
|
||||
o = x - 1;
|
||||
tel
|
Loading…
Reference in New Issue