Skip to content

Commit

Permalink
Fix warnings from using deprecated compatibility modules in Base
Browse files Browse the repository at this point in the history
  • Loading branch information
juusaw committed Apr 18, 2019
1 parent da114b3 commit af5478e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/interpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct
and merge1 a b c = match a, b, c with
| a, l1, [] -> a :: l1
| a, l1, (b::l2) ->
if a<=b then a :: merge1 b l2 l1
if a <= b then a :: merge1 b l2 l1
else b :: merge1 a l1 l2

let rec member a b = match a, b with
Expand Down Expand Up @@ -168,7 +168,7 @@ struct
(VAL [], VAL [_]) -> VAL [0]
| (VAL [n1], VAL [n2]) ->
if n2=0 then raise (RunError ("modulo by 0", p))
else VAL [n1 mod n2]
else VAL [n1 % n2]
| _ -> raise (RunError ("illegal arg to mod", p)))
| Syntax.D (e1, p) ->
(match (evalExp e1 table depth) with
Expand Down
8 changes: 4 additions & 4 deletions src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open Base
open Lexing
open Parser

let currentLine = ref 1
let lineStartPos = ref [0]

Expand All @@ -12,11 +13,10 @@ let rec getPos lexbuf = getLineCol (lexeme_start lexbuf)

and getLineCol p l s = match p, l, s with
pos, line, (p1::ps) ->
if pos>=p1 then (line, pos-p1)
if pos >= p1 then (line, pos - p1)
else getLineCol pos (line - 1) ps
| _, _, [] -> (0,0) (* should not happen *)


exception LexicalError of string * (int * int) (* (message, (line, column)) *)

let lexerError lexbuf s =
Expand Down Expand Up @@ -72,11 +72,11 @@ rule token = parse
token lexbuf } (* newlines *)
| "\\" [^ '\n' '\012']*
{ token lexbuf } (* comment *)
| ['0'-'9']+ { match int_of_string_opt (lexeme lexbuf) with
| ['0'-'9']+ { match Caml.int_of_string_opt (lexeme lexbuf) with
None -> lexerError lexbuf "Bad integer"
| Some i -> Parser.NUM (i, getPos lexbuf)
}
| "0."['0'-'9']+ { match float_of_string_opt (lexeme lexbuf) with
| "0."['0'-'9']+ { match Caml.float_of_string_opt (lexeme lexbuf) with
None -> lexerError lexbuf "Bad number"
| Some p -> Parser.FLOAT (p, getPos lexbuf)
}
Expand Down
26 changes: 13 additions & 13 deletions src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ open Parser
module Main =
struct

let print s = Pervasives.print_string s
let print s = Caml.Pervasives.print_string s

let times n f = List.init n ~f:(fun _ -> f())

let stringVal l =
String.concat
~sep:" "
(List.map
~f:(fun n -> if n >= 0 then string_of_int n
else "-" ^ string_of_int (~-n))
~f:(fun n -> if n >= 0 then Int.to_string n
else "-" ^ Int.to_string (~-n))
l)

let rec stringIVal = function
Expand All @@ -34,11 +34,11 @@ struct
let roll = fun _ -> printVal (Interpreter.rollDice (Syntax.Syntax.optimize_tco dice)) in
List.hd (times n roll)

let errorMess s = print s (* TODO: To stderr? *)
let print_error = print (* TODO: To stderr? *)

let findDef str =
match String.split_on_chars ~on:['='] str with
[name;valString] -> (match int_of_string_opt valString with
[name;valString] -> (match Caml.int_of_string_opt valString with
None -> None
| Some (value) -> Some (name,value))
| _ -> None
Expand All @@ -50,20 +50,20 @@ struct
try
match run source count (fun d -> d) with
_ -> ()
with Parsing.YYexit _ -> errorMess "Parser-exit\n"
with Caml.Parsing.YYexit _ -> print_error "Parser-exit\n"
| Parser.Error ->
let (lin,col)
= Lexer.getLineCol 0
(!Lexer.currentLine)
(!Lexer.lineStartPos) in
errorMess ("Parse-error at line "
^ string_of_int lin ^ ", column " ^ string_of_int col)
print_error ("Parse-error at line "
^ Int.to_string lin ^ ", column " ^ Int.to_string col)
| Lexer.LexicalError (mess,(lin,col)) ->
errorMess ("Lexical error: " ^mess^ " at line "
^ string_of_int lin ^ ", column " ^ string_of_int col)
print_error ("Lexical error: " ^mess^ " at line "
^ Int.to_string lin ^ ", column " ^ Int.to_string col)
| Interpreter.RunError (mess,(lin,col)) ->
errorMess ("Runtime error: " ^mess^ " at line "
^ string_of_int lin ^ ", column " ^ string_of_int col)
| Sys_error s -> errorMess ("Exception: " ^ s)
print_error ("Runtime error: " ^mess^ " at line "
^ Int.to_string lin ^ ", column " ^ Int.to_string col)
| Sys_error s -> print_error ("Exception: " ^ s)

end
4 changes: 4 additions & 0 deletions src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module S = Syntax

module Printf = Caml.Printf

module Obj = Caml.Obj

module Pervasives = Caml.Pervasives

let p0 = (0,0)

let fst x = let y, _ = x in y
Expand Down
4 changes: 2 additions & 2 deletions src/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct

let rec string_of_exp exp =
match exp with
NUM (i, _) -> string_of_int i
NUM (i, _) -> Int.to_string i
| EMPTY -> "{}"
| ID (x, _) -> x
| CONC (e1, e2, _) -> "{" ^ string_of_exp e1 ^ ", " ^ string_of_exp e2 ^ "}"
Expand Down Expand Up @@ -124,7 +124,7 @@ struct
| VCONCL (e1, e2, _) -> "(" ^ string_of_exp e1 ^ " |> " ^ string_of_exp e2 ^ ")"
| VCONCR (e1, e2, _) -> "(" ^ string_of_exp e1 ^ " <| " ^ string_of_exp e2 ^ ")"
| VCONCC (e1, e2, _) -> "(" ^ string_of_exp e1 ^ " <> " ^ string_of_exp e2 ^ ")"
| QUESTION (q, _) -> "?" ^ string_of_float q
| QUESTION (q, _) -> "?" ^ Float.to_string q
| PAIR (e1, e2, _) -> "[" ^ string_of_exp e1 ^ " , " ^ string_of_exp e2 ^ "]"
| FIRST (e1, _) -> "%1( " ^ string_of_exp e1 ^ ")"
| SECOND (e1, _) -> "%2( " ^ string_of_exp e1 ^ ")"
Expand Down

0 comments on commit af5478e

Please sign in to comment.