feat(library/init/lean/ir): add emit_unop
This commit is contained in:
parent
c7153f7661
commit
fc840eab3f
5 changed files with 23 additions and 19 deletions
|
|
@ -152,19 +152,28 @@ match op with
|
|||
| binop.eq := emit_arith t x y z "==" "lean::big_eq"
|
||||
| binop.ne := emit_arith t x y z "!=" "lean::big_nq"
|
||||
|
||||
|
||||
/-- Emit `x := op(y)` -/
|
||||
def emit_x_op_y (x : var) (op : string) (y : var) : extract_m unit :=
|
||||
emit_var x >> emit " := " >> emit op >> emit "(" >> emit_var y >> emit ")"
|
||||
|
||||
def emit_unop (x : var) (t : type) (op : unop) (y : var) : extract_m unit :=
|
||||
match op with
|
||||
| unop.not := return () -- TODO
|
||||
| unop.neg := return () -- TODO
|
||||
| unop.scalar := return () -- TODO
|
||||
| unop.shared := return () -- TODO
|
||||
| unop.copy_array := return () -- TODO
|
||||
| unop.copy_sarray := return () -- TODO
|
||||
| unop.box := return () -- TODO
|
||||
| unop.unbox := return () -- TODO
|
||||
| unop.unbox_bignum := return () -- TODO
|
||||
| unop.box_bignum := return () -- TODO
|
||||
| unop.cast := return () -- TODO
|
||||
| unop.not :=
|
||||
(match t with
|
||||
| type.bool := emit_x_op_y x "!" y
|
||||
| _ := emit_x_op_y x "~" y)
|
||||
| unop.neg :=
|
||||
(match t with
|
||||
| type.object := emit_x_op_y x "lean::big_neg" y
|
||||
| _ := emit_x_op_y x "-" y)
|
||||
| unop.scalar := emit_x_op_y x "lean::is_scalar" y
|
||||
| unop.shared := emit_x_op_y x "lean::is_shared" y
|
||||
| unop.copy_array := emit_x_op_y x "lean::copy_array" y
|
||||
| unop.copy_sarray := emit_x_op_y x "lean::copy_sarray" y
|
||||
| unop.box := emit_x_op_y x "lean::box" y
|
||||
| unop.unbox := emit_x_op_y x "lean::unbox" y
|
||||
| unop.cast := emit_var x >> emit " := static_cast<" >> emit_type t >> emit ">(" >> emit_var y >> emit ")"
|
||||
|
||||
def emit_lit (x : var) (t : type) (l : literal) : extract_m unit :=
|
||||
return () -- TODO
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ def unop.to_format : unop → format
|
|||
| unop.not := "not" | unop.neg := "neg"
|
||||
| unop.scalar := "scalar" | unop.shared := "shared"
|
||||
| unop.box := "box" | unop.unbox := "unbox"
|
||||
| unop.box_bignum := "box_bignum" | unop.unbox_bignum := "unbox_bignum"
|
||||
| unop.cast := "cast"
|
||||
| unop.copy_array := "copy_array" | unop.copy_sarray := "copy_sarray"
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ instance type_has_dec_eq : decidable_eq type :=
|
|||
/- END of TEMPORARY HACK for (decidable_eq type) -/
|
||||
|
||||
inductive unop
|
||||
| not | neg | scalar | shared | cast | box | unbox | box_bignum | unbox_bignum
|
||||
| not | neg | scalar | shared | cast | box | unbox
|
||||
| copy_array | copy_sarray
|
||||
|
||||
inductive binop
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@ def parse_unop : parser unop :=
|
|||
<|> (keyword "copy_sarray" >> return unop.copy_sarray)
|
||||
<|> (keyword "box" >> return unop.box)
|
||||
<|> (keyword "unbox" >> return unop.unbox)
|
||||
<|> (keyword "box_bignum" >> return unop.box_bignum)
|
||||
<|> (keyword "unbox_bignum" >> return unop.unbox_bignum)
|
||||
<|> (keyword "cast" >> return unop.cast)
|
||||
|
||||
def parse_binop : parser binop :=
|
||||
|
|
|
|||
|
|
@ -49,10 +49,8 @@ match op with
|
|||
| unop.shared := t = type.object && r = type.bool
|
||||
| unop.copy_array := t = type.object && r = type.object
|
||||
| unop.copy_sarray := t = type.object && r = type.object
|
||||
| unop.box := t ≠ type.object && r = type.object
|
||||
| unop.unbox := t = type.object && r ≠ type.object
|
||||
| unop.unbox_bignum := t = type.object && (r = type.uint32 || r = type.int32)
|
||||
| unop.box_bignum := r = type.object && (t = type.uint32 || t = type.int32)
|
||||
| unop.unbox := t = type.object && (r = type.uint32 || r = type.int32)
|
||||
| unop.box := r = type.object && (t = type.uint32 || t = type.int32)
|
||||
| unop.cast := r ≠ type.object && r ≠ type.object
|
||||
|
||||
/-- Return `tt` iff the instruction `x : r := op y z` is type correct where `y z : t` -/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue