| 1 |
(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh |
| 2 |
* Jagannathan, and Stephen Weeks. |
| 3 |
* Copyright (C) 1997-2000 NEC Research Institute. |
| 4 |
* |
| 5 |
* MLton is released under a HPND-style license. |
| 6 |
* See the file MLton-LICENSE for details. |
| 7 |
*) |
| 8 |
|
| 9 |
structure SML90:> SML90 = |
| 10 |
struct |
| 11 |
type instream = TextIO.instream |
| 12 |
type outstream = TextIO.outstream |
| 13 |
exception Abs = Overflow |
| 14 |
exception Quot = Overflow |
| 15 |
exception Prod = Overflow |
| 16 |
exception Neg = Overflow |
| 17 |
exception Sum = Overflow |
| 18 |
exception Diff = Overflow |
| 19 |
exception Floor = Overflow |
| 20 |
exception Exp = Overflow |
| 21 |
exception Sqrt |
| 22 |
exception Ln |
| 23 |
exception Ord |
| 24 |
exception Mod = Div |
| 25 |
exception Io of string |
| 26 |
exception Interrupt |
| 27 |
|
| 28 |
local open Real.Math |
| 29 |
in |
| 30 |
val sqrt = fn x => if Real.< (x, 0.0) then raise Sqrt else sqrt x |
| 31 |
val exp = fn x => let val y = exp x |
| 32 |
in if Real.isFinite y |
| 33 |
then y |
| 34 |
else raise Exp |
| 35 |
end |
| 36 |
val ln = fn x => if Real.> (x, 0.0) then ln x else raise Ln |
| 37 |
val sin = sin |
| 38 |
val cos = cos |
| 39 |
val arctan = atan |
| 40 |
end |
| 41 |
|
| 42 |
fun ord s = |
| 43 |
if String.size s = 0 |
| 44 |
then raise Ord |
| 45 |
else Char.ord(String.sub(s, 0)) |
| 46 |
|
| 47 |
val chr = String.str o Char.chr |
| 48 |
fun explode s = List.map String.str (String.explode s) |
| 49 |
val implode = String.concat |
| 50 |
fun lookahead ins = |
| 51 |
case TextIO.lookahead ins of |
| 52 |
NONE => "" |
| 53 |
| SOME c => str c |
| 54 |
|
| 55 |
val std_in = TextIO.stdIn |
| 56 |
fun open_in f = |
| 57 |
TextIO.openIn f handle IO.Io _ => raise Io (concat ["Cannot open ", f]) |
| 58 |
fun input ins = |
| 59 |
TextIO.inputN ins handle IO.Io _ => raise Io "Input stream is closed" |
| 60 |
val close_in = TextIO.closeIn |
| 61 |
fun end_of_stream ins = TextIO.endOfStream ins handle _ => true |
| 62 |
val std_out = TextIO.stdOut |
| 63 |
fun open_out f = |
| 64 |
TextIO.openOut f |
| 65 |
handle IO.Io _ => raise Io (concat ["Cannot open ", f]) |
| 66 |
fun output (out, s) = |
| 67 |
TextIO.output (out, s) |
| 68 |
handle IO.Io _ => raise Io "Output stream is closed" |
| 69 |
val close_out = TextIO.closeOut |
| 70 |
end |