diff --git a/library/init/lean/ir/extract_cpp.lean b/library/init/lean/ir/extract_cpp.lean index 691d7c9b7b..7a195f8038 100644 --- a/library/init/lean/ir/extract_cpp.lean +++ b/library/init/lean/ir/extract_cpp.lean @@ -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 diff --git a/library/init/lean/ir/format.lean b/library/init/lean/ir/format.lean index ca7471daea..0179db28f3 100644 --- a/library/init/lean/ir/format.lean +++ b/library/init/lean/ir/format.lean @@ -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" diff --git a/library/init/lean/ir/ir.lean b/library/init/lean/ir/ir.lean index 7f1b312be9..3fba59b078 100644 --- a/library/init/lean/ir/ir.lean +++ b/library/init/lean/ir/ir.lean @@ -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 diff --git a/library/init/lean/ir/parser.lean b/library/init/lean/ir/parser.lean index 1b5cf5d912..fcd9427b32 100644 --- a/library/init/lean/ir/parser.lean +++ b/library/init/lean/ir/parser.lean @@ -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 := diff --git a/library/init/lean/ir/type_check.lean b/library/init/lean/ir/type_check.lean index 51d82a2941..226021b4e0 100644 --- a/library/init/lean/ir/type_check.lean +++ b/library/init/lean/ir/type_check.lean @@ -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` -/