Skip to content

Commit

Permalink
Saner relop implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Jan 9, 2024
1 parent 015c703 commit 296de28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions ECMA-SL/semantics/core/eval_operator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -654,10 +654,25 @@ let eq ((v1, v2) : Val.t * Val.t) : Val.t =
| (Arr arr1, Arr arr2) -> Bool (arr1 == arr2)
| _ -> Bool (v1 = v2)

let lt ((v1, v2) : Val.t * Val.t) : Val.t = Bool (v1 < v2)
let gt ((v1, v2) : Val.t * Val.t) : Val.t = Bool (v1 > v2)
let le ((v1, v2) : Val.t * Val.t) : Val.t = Bool (v1 <= v2)
let ge ((v1, v2) : Val.t * Val.t) : Val.t = Bool (v1 >= v2)
let lt = function
| Flt f, Int i -> Bool (f < float i)
| Int i, Flt f -> Bool (float i < f)
| v1, v2 -> Bool (v1 < v2)

let gt = function
| Flt f, Int i -> Bool (f > float i)
| Int i, Flt f -> Bool (float i > f)
| v1, v2 -> Bool (v1 > v2)

let le = function
| Flt f, Int i -> Bool (f <= float i)
| Int i, Flt f -> Bool (float i <= f)
| v1, v2 -> Bool (v1 <= v2)

let ge = function
| Flt f, Int i -> Bool (f >= float i)
| Int i, Flt f -> Bool (float i >= f)
| v1, v2 -> Bool (v1 >= v2)

let to_precision ((v1, v2) : Val.t * Val.t) : Val.t =
let op_lbl = label_of_binopt ToPrecision in
Expand Down
2 changes: 1 addition & 1 deletion ECMA-SL/syntax/share/val.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type t =
| Null
| Void
| Int of int
| Flt of float
| Flt of (float [@unboxed])
| Str of string
| Bool of bool
| Symbol of string
Expand Down

0 comments on commit 296de28

Please sign in to comment.