Autoformat.

This commit is contained in:
Simon Forman 2022-09-24 13:13:44 -07:00
parent 977928362c
commit 813502532b
1 changed files with 15 additions and 13 deletions

View File

@ -169,26 +169,28 @@ let joy stack expression dictionary = (stack @ expression, dictionary)
exception StackUnderflow of string exception StackUnderflow of string
exception ValueError of string exception ValueError of string
let pop_int : joy_list -> int * joy_list = fun stack -> let pop_int : joy_list -> int * joy_list =
fun stack ->
match stack with match stack with
| [] -> raise (StackUnderflow "Not enough values on stack.") | [] -> raise (StackUnderflow "Not enough values on stack.")
| head :: tail -> | head :: tail -> (
match head with match head with
| JoyInt i -> (i, tail) | JoyInt i -> (i, tail)
| _ -> raise (ValueError "Not an integer.") | _ -> raise (ValueError "Not an integer."))
let joy_eval sym stack expression dictionary = let joy_eval sym stack expression dictionary =
match sym with match sym with
| "+" -> | "+" ->
let (a, s0) = pop_int(stack) in let a, s0 = pop_int stack in
let (b, s1) = pop_int(s0) in let b, s1 = pop_int s0 in
((JoyInt (a + b) :: s1), expression, dictionary) (JoyInt (a + b) :: s1, expression, dictionary)
| "-" -> | "-" ->
let (a, s0) = pop_int(stack) in let a, s0 = pop_int stack in
let (b, s1) = pop_int(s0) in let b, s1 = pop_int s0 in
((JoyInt (b - a) :: s1), expression, dictionary) (JoyInt (b - a) :: s1, expression, dictionary)
| _ -> let func = dictionary sym in | _ ->
(stack, (func @ expression), dictionary) let func = dictionary sym in
(stack, func @ expression, dictionary)
let rec joy : joy_list -> joy_list -> joy_dict -> joy_list * joy_dict = let rec joy : joy_list -> joy_list -> joy_dict -> joy_list * joy_dict =
fun stack expression dictionary -> fun stack expression dictionary ->