Skip to content

Commit 4dbff5d

Browse files
committed
support & in prototype
1 parent 5c9b022 commit 4dbff5d

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

autogen/args.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import unicode_literals
1616

1717
# Some replacements for reserved words
18-
replacements = {'char': 'character'}
18+
replacements = {'char': 'character', 'return': 'return_value'}
1919

2020
class PariArgument(object):
2121
"""
@@ -339,6 +339,29 @@ def c_convert_code(self):
339339
s += " {name} = precdl # Global PARI series precision\n"
340340
return s.format(name=self.name)
341341

342+
class PariArgumentGENPointer(PariArgumentObject):
343+
default = "NULL"
344+
def _typerepr(self):
345+
return "GEN*"
346+
def ctype(self):
347+
return "GEN*"
348+
def convert_code(self):
349+
"""
350+
Conversion to NULL or Gen
351+
"""
352+
s = " cdef bint _have_{name} = ({name} is not None)\n"
353+
s += " if _have_{name}:\n"
354+
s += " raise NotImplementedError(\"optional argument {name} not available\")\n"
355+
return s.format(name=self.name)
356+
def c_convert_code(self):
357+
"""
358+
Conversion Gen -> GEN
359+
"""
360+
s = " cdef GEN * {tmp} = NULL\n"
361+
return s.format(name=self.name, tmp=self.tmpname)
362+
def call_code(self):
363+
return self.tmpname
364+
342365

343366
pari_arg_types = {
344367
'G': PariArgumentGEN,
@@ -351,9 +374,9 @@ def c_convert_code(self):
351374
'p': PariArgumentPrec,
352375
'b': PariArgumentBitprec,
353376
'P': PariArgumentSeriesPrec,
377+
'&': PariArgumentGENPointer,
354378

355379
# Codes which are known but not actually supported yet
356-
'&': None,
357380
'V': None,
358381
'I': None,
359382
'E': None,

autogen/parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .paths import pari_share
2222

2323
paren_re = re.compile(r"[(](.*)[)]")
24-
argname_re = re.compile(r"[ {]*([A-Za-z_][A-Za-z0-9_]*)")
24+
argname_re = re.compile(r"[ {]*&?([A-Za-z_][A-Za-z0-9_]*)")
2525

2626
def read_pari_desc():
2727
"""
@@ -101,6 +101,10 @@ def parse_prototype(proto, help, initial_args=[]):
101101
>>> help = 'qfbred(x,{flag=0},{d},{isd},{sd})'
102102
>>> parse_prototype(proto, help)
103103
([GEN x, long flag=0, GEN d=NULL, GEN isd=NULL, GEN sd=NULL], GEN)
104+
>>> proto = "GD&"
105+
>>> help = "sqrtint(x,{&r})"
106+
>>> parse_prototype(proto, help)
107+
([GEN x, GEN* r=NULL], GEN)
104108
>>> parse_prototype("lp", "foo()", [str("TEST")])
105109
(['TEST', prec precision=0], long)
106110
"""

0 commit comments

Comments
 (0)