Skip to content

Commit 3285f7d

Browse files
author
mmatera
committed
improve Compile interface
1 parent 5d225dc commit 3285f7d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

mathics/builtin/compilation.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from types import FunctionType
1212

1313
from mathics.builtin.box.compilation import CompiledCodeBox
14-
from mathics.core.atoms import Complex, Integer, Real, String
14+
from mathics.core.atoms import Complex, Integer, Rational, Real, String
1515
from mathics.core.attributes import A_HOLD_ALL, A_PROTECTED
1616
from mathics.core.builtin import Builtin
1717
from mathics.core.convert.expression import to_mathics_list
@@ -235,12 +235,12 @@ def eval(self, argnames, expr, code, args, evaluation: Evaluation):
235235
try:
236236
spec_type = spec.type
237237
if spec_type is float:
238-
if isinstance(arg, (Integer, Real)):
238+
if isinstance(arg, (Integer, Rational, Real)):
239239
val = spec_type(arg.value)
240240
else:
241241
raise TypeError
242242
elif spec_type is int:
243-
if isinstance(arg, (Integer, Real)):
243+
if isinstance(arg, (Integer, Rational, Real)):
244244
val = spec_type(arg.value)
245245
# If arg.value was not an integer, show a message but accept it:
246246
if val != arg.value:
@@ -264,7 +264,7 @@ def eval(self, argnames, expr, code, args, evaluation: Evaluation):
264264
if isinstance(arg, Complex):
265265
value = arg.value
266266
val = complex(value[0].value, value[1].value)
267-
elif isinstance(arg, (Integer, Real)):
267+
elif isinstance(arg, (Integer, Rational, Real)):
268268
val = complex(arg.value)
269269
else:
270270
raise TypeError
@@ -286,4 +286,6 @@ def eval(self, argnames, expr, code, args, evaluation: Evaluation):
286286
except (TypeError, ctypes.ArgumentError):
287287
evaluation.message("CompiledFunction", "argerr", args)
288288
return
289+
except Exception:
290+
return
289291
return from_python(result)

mathics/core/convert/function.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ def expression_to_callable_and_args(
175175
return cfunc, args
176176
except KeyError:
177177
pass
178+
except RuntimeError:
179+
pass
178180

179181
# Last resource
180182
cfunc = expression_to_python_function(expr, args, evaluation)

0 commit comments

Comments
 (0)