diff --git a/src/javascript.ml b/src/javascript.ml index 0b8b4d7..f4315e2 100644 --- a/src/javascript.ml +++ b/src/javascript.ml @@ -1,10 +1,14 @@ open Main +let toString ival = match ival with + Some x -> Main.stringIVal x + | None -> "" + module Javascript = struct let () = Js.export_all (object%js - method run src = Main.main (Lexing.from_string (Js.to_string src)) 1 (Some 1) + method run src = toString (Main.run (Lexing.from_string (Js.to_string src)) 1 (fun d -> d)) end) end diff --git a/src/main.ml b/src/main.ml index 83e8398..57f37d9 100644 --- a/src/main.ml +++ b/src/main.ml @@ -31,7 +31,7 @@ struct let dice = let (decls,exp) = Parser.dice Lexer.token lb in (decls, defs exp) in - let roll = fun _ -> printVal (Interpreter.rollDice (Syntax.Syntax.optimize_tco dice)) in + let roll = fun _ -> Interpreter.rollDice (Syntax.Syntax.optimize_tco dice) in List.hd (times n roll) let print_error = print (* TODO: To stderr? *) @@ -49,7 +49,8 @@ struct | None -> Random.self_init () in try match run source count (fun d -> d) with - _ -> () + Some x -> printVal x + | None -> () with Caml.Parsing.YYexit _ -> print_error "Parser-exit\n" | Parser.Error -> let (lin,col)