Commit d5d6ca9b authored by Julien Lopez's avatar Julien Lopez
Browse files

[TESTS][LAMBDA][MINOR] Refactor code for operators; minor fix on test generator

parent 6de48306
......@@ -249,41 +249,17 @@ and parse_match_value env l list toptype = function
(type_of_ptype toptype) in
(t, Patterns.Constr(t), list, l, is_subtype)
let plus = fun l -> match l with
let rec arith_op f = function
| Value.Integer(x) :: Value.Integer(y) :: [] ->
Value.Integer(Big_int.big_int_of_int ((Big_int.int_of_big_int x) +
(Big_int.int_of_big_int y)))
| _ -> raise Error
let minus = fun l -> match l with
| Value.Integer(x) :: Value.Integer(y) :: [] ->
Value.Integer(Big_int.big_int_of_int ((Big_int.int_of_big_int x) -
(Big_int.int_of_big_int y)))
| _ -> raise Error
let mult = fun l -> match l with
| Value.Integer(x) :: Value.Integer(y) :: [] ->
Value.Integer(Big_int.big_int_of_int ((Big_int.int_of_big_int x) *
(Big_int.int_of_big_int y)))
| _ -> raise Error
let div = fun l -> match l with
| Value.Integer(x) :: Value.Integer(y) :: [] ->
Value.Integer(Big_int.big_int_of_int ((Big_int.int_of_big_int x) /
(Big_int.int_of_big_int y)))
| _ -> raise Error
let modulo = fun l -> match l with
| Value.Integer(x) :: Value.Integer(y) :: [] ->
Value.Integer(Big_int.big_int_of_int ((Big_int.int_of_big_int x) mod
(Big_int.int_of_big_int y)))
Value.Integer(Big_int.big_int_of_int (f (Big_int.int_of_big_int x)
(Big_int.int_of_big_int y)))
| _ -> raise Error
let to_typed expr =
Eval.register_op "+" plus;
Eval.register_op "-" minus;
Eval.register_op "*" mult;
Eval.register_op "/" div;
Eval.register_op "%" modulo;
Eval.register_op "+" (arith_op ( + ));
Eval.register_op "-" (arith_op ( - ));
Eval.register_op "*" (arith_op ( * ));
Eval.register_op "/" (arith_op ( / ));
Eval.register_op "%" (arith_op ( mod ));
let env, _, expr = _to_typed Compile.empty_toplevel Locals.empty expr in
env, expr
......@@ -14,7 +14,7 @@ module ExprParser = struct
EXTEND Gram
GLOBAL: exp_eoi;
exp_eoi: [[e = LIST0 expression SEP ";;"; `EOI -> e]];
exp_eoi: [[e = LIST1 expression SEP ";;"; `EOI -> e]];
expression: [[ x = LIDENT; "="; l = LIST1 (LIST0 token) SEP "|" ->
Rule(_loc, x, l) ]];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment