Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Python.thy
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ declare [[default_code_width = 2000]]
code_identifier
code_module Code_Numeral \<rightharpoonup> (Python) Arith

(* Panic *)
(* Panic, by a helper function, since Code.abort occurs in expression position *)
code_printing
constant Code.abort \<rightharpoonup> (Python) "raise RuntimeError(\"_\")"
constant Code.abort \<rightharpoonup> (Python) "'_abort"

(* unit *)
code_printing
Expand Down
7 changes: 5 additions & 2 deletions code_python.ML
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ val python_reserved_words =
"raise", "return", "try", "while", "with", "yield", "match", "case"]

(* these are symbols we use in addition to the standard reserved words *)
@ ["dataclass", "Any", "Callable", "_unimplemented", "functools"];;
@ ["dataclass", "Any", "Callable", "_unimplemented", "_abort", "functools"];;

type eqtn = {
patterns: iterm list, (* left hand side pattern list *)
Expand Down Expand Up @@ -1067,7 +1067,10 @@ fun serialize_python undefineds _ ctxt { module_name, reserved_syms,
val unimplemented_def = Pretty.chunks
[Pretty.str "def _unimplemented(name):",
indent_block 4 (Pretty.str "raise NotImplementedError(name)")]
in ([mod_name ^ ".py"], Pretty.chunks2 (imports_block :: unimplemented_def :: stmt_ps))
val abort_def = Pretty.chunks
[Pretty.str "def _abort(msg, thunk):",
indent_block 4 (Pretty.str "raise RuntimeError(msg)")]
in ([mod_name ^ ".py"], Pretty.chunks2 (imports_block :: unimplemented_def :: abort_def :: stmt_ps))
end;

val p = map print_one_module module_stmts
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example/Example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class Red:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def weight(a_dict, x, xa1):
match (x, xa1):
case (xa, []):
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_class_dicts/HOL.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class equal:
equala: Callable
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_class_dicts/Int.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@functools.cache
def equal_int():
return HOL.equal(equala = lambda a, b: (a == b))
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_class_dicts/Num.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class One:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class ord:
less_eq: Callable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def equal_proda(a_dict, b_dict, x0, x1):
match (x0, x1):
case ((x1a, x2), (y1, y2)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def sup_apply_bool(b):
return (b)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class super_op:
sup_apply: Callable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def cn_add(x, y):
return ((x + y))

Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_code_numerals/Num.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class One:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def swap(x0):
match x0:
case Product_Type.Pair(x, y):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class Nil:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class Pair:
a: Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def sum_ends(a):
return (((a[0]) + (a[(max(0, (len(a)) - 1))])))

Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_iarray/HOL.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class equal:
equala: Callable
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_iarray/IArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def equal_iarray(a_dict, asa, bs):
return (List.equal_list(a_dict, (list(asa)), (list(bs))))
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_iarray/List.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def equal_list(a_dict, x0, x1):
match (x0, x1):
case ([], [x21, *x22]):
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_iarray/Nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@functools.cache
def equal_nat():
return HOL.equal(equala = lambda a, b: (a == b))
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_iarray/Num.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class One:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

product = ((6 * 7))

def checksum(x, y):
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_int_arith/Num.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class One:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@functools.cache
def one_integer():
return Groups.one(onea = lambda : 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

test_bit = (Arith.bit_integer(10, 1))

test_sgn = (Arith.sgn_integer(-42))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class one:
onea: Callable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class One:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class power:
one_power: Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def doubled(xs):
return (list(map(lambda n: (n + n), xs)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class Nonea:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

example = ([1, 2, 3])

def prepend(x, xs):
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_lists/Num.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class One:
pass
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_nat/Example_nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

nat_sum = ((6 + 7))

nat_eq_test = ((4 == 4))
Expand Down
3 changes: 3 additions & 0 deletions test/diff/golden/Python_Examples.Example_nat/Num.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class One:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def peel_positive_head(x0):
match x0:
case []:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

@dataclass(frozen=True)
class One:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
def _unimplemented(name):
raise NotImplementedError(name)

def _abort(msg, thunk):
raise RuntimeError(msg)

def fact(n):
if ((n == 0)):
return (1)
Expand Down
Loading
Loading