PetterS / quickjs

Thin Python wrapper of https://bellard.org/quickjs/
https://github.com/bellard/QuickJS
MIT License
177 stars 19 forks source link

Fix #61: compile with BigInt support and add conversion to Python #68

Closed qwenger closed 2 years ago

qwenger commented 2 years ago

Fix #61.

AFAIAC, we can restrict ourselves to BigInt, BigInt64Array and BigUint64Array (the standard set) without enabling quickjs-specific extensions (BigFloat, BigDecimal, use math, ...).

Currently I implemented the JS -> Python conversion. I am unsure about the other direction:

>>> import quickjs
>>> ctx = quickjs.Context()
>>> ctx.set("a", 10**100)
OverflowError: Python int too large to convert to C long

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: <method 'set' of '_quickjs.Context' objects> returned a result with an error set

So I see three possible paths:

NOTE: currently, in the other direction, a Python float is returned when the value does not fit in a C long. So the second path may be the most reasonable. EDIT: see the tentative implementation in #71.