Commit e10f1fad authored by Raphaël Rieu-Helft's avatar Raphaël Rieu-Helft

Handle try/with for return/break type exceptions

parent 354ac9b7
......@@ -12,86 +12,85 @@ module ref.Ref
syntax type ref "%1"
syntax val ref "%1"
syntax converter ref "%1"
syntax val (!_) "%1"
syntax converter (!_) "%1"
syntax val (:=) "%1 = %2"
end
module mach.int.Unsigned
syntax constant zero_unsigned "0"
end
module mach.int.Int32
syntax val of_int "%1"
syntax converter of_int "%1"
syntax type int32 "int32_t"
syntax val (+) "(%1 + %2)"
syntax val (-) "(%1 - %2)"
syntax val (-_) "(-(%1))"
syntax val (*) "(%1 * %2)"
syntax val (/) "(%1 / %2)"
syntax val (%) "(%1 % %2)"
syntax val eq "(%1 == %2)"
syntax val (=) "(%1 == %2)"
syntax val ne "(%1 != %2)"
syntax val (<=) "(%1 <= %2)"
syntax val (<) "(%1 < %2)"
syntax val (>=) "(%1 >= %2)"
syntax val (>) "(%1 > %2)"
syntax val (+) "%1 + %2"
syntax val (-) "%1 - %2"
syntax val (-_) "-(%1)"
syntax val (*) "%1 * %2"
syntax val (/) "%1 / %2"
syntax val (%) "%1 % %2"
syntax val eq "%1 == %2"
syntax val (=) "%1 == %2"
syntax val ne "%1 != %2"
syntax val (<=) "%1 <= %2"
syntax val (<) "%1 < %2"
syntax val (>=) "%1 >= %2"
syntax val (>) "%1 > %2"
end
module mach.int.UInt32
prelude "void add_with_carry(...) { }"
syntax val of_int "%1"
syntax converter of_int "%1"
syntax constant zero_unsigned "0"
syntax type uint32 "uint32_t"
syntax val (+) "(%1 + %2)"
syntax val (-) "(%1 - %2)"
syntax val (-_) "(-(%1))"
syntax val (*) "(%1 * %2)"
syntax val (/) "(%1 / %2)"
syntax val (%) "(%1 % %2)"
syntax val eq "(%1 == %2)"
syntax val (=) "(%1 == %2)"
syntax val ne "(%1 != %2)"
syntax val (<=) "(%1 <= %2)"
syntax val (<) "(%1 < %2)"
syntax val (>=) "(%1 >= %2)"
syntax val (>) "(%1 > %2)"
syntax val (+) "%1 + %2"
syntax val (-) "%1 - %2"
syntax val (*) "%1 * %2"
syntax val (/) "%1 / %2"
syntax val (%) "%1 % %2"
syntax val eq "%1 == %2"
syntax val (=) "%1 == %2"
syntax val ne "%1 != %2"
syntax val (<=) "%1 <= %2"
syntax val (<) "%1 < %2"
syntax val (>=) "%1 >= %2"
syntax val (>) "%1 > %2"
end
module mach.c.C
syntax type ptr "(%1 *)"
syntax type ptr "%1 *"
syntax val malloc "malloc(%1 * sizeof(%v0))"
syntax val free "free(%1)"
syntax val realloc "realloc(%1, %2 * sizeof(%v0))"
syntax val is_null "(%1 == NULL)"
syntax val is_null "%1 == NULL"
syntax val null "NULL"
syntax val incr "%1+%2"
syntax val get "*(%1)"
syntax val get_ofs "*(%1+%2)"
syntax val set "*(%1) = %2"
syntax val set_ofs "*(%1+%2) = %3"
syntax val p2i "%1"
syntax converter p2i "%1"
syntax val break "break"
syntax val return32 "return (%1)"
syntax val print_space "printf(\" \")"
syntax val print_newline "printf(\"\\n\")"
syntax val print_uint32 "printf(\"%#x\",%1)"
syntax val print_uint32 "printf(\"%#010x\",%1)"
end
\ No newline at end of file
......@@ -37,6 +37,8 @@ module N
type t = ptr limb
exception Return32 int32
(** {2 Integer value of a natural number} *)
(** [value_sub x n m] denotes the integer represented by
......@@ -273,7 +275,7 @@ module N
};
res := Int32.of_int (-1)
end;
return32 !res;
raise Return32 !res;
end
else ()
done;
......@@ -305,7 +307,7 @@ module N
value_sub_concat (pelts x) x.offset (x.offset+k) (x.offset + p2i sz);
value_sub_lower_bound_tight (pelts x) x.offset (x.offset+k);
value_sub_lower_bound (pelts x) (x.offset+k) (x.offset + p2i sz);
return32 (Int32.of_int 0);
raise Return32 (Int32.of_int 0);
end
else begin
assert { 1+2=3 };
......@@ -2169,7 +2171,7 @@ module Main
print_newline ();
end;
free p;
let q = two_limbs (Limb.of_int 42) (Limb.of_int 28) in
let q = two_limbs (Limb.of_int 0xffffffff) (Limb.of_int 42) in
if not (is_null q)
then print q (Int32.of_int 0) (Int32.of_int 2);
free q;
......
......@@ -109,20 +109,6 @@ module C
!(result.data)[i] = !((old p).data)[i] }
ensures { plength result <> Int32.to_int sz -> p = old p }
(** break/return*)
exception Break
val break () : unit
raises { Break }
returns { _ -> false }
exception Return32 int32
val return32 (x:int32) : unit
raises { Return32 n -> x = n }
returns { _ -> false }
(** Printing *)
val print_space () : unit
......
This diff is collapsed.
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