Commit 25585565 authored by Adam P. Goucher's avatar Adam P. Goucher

Infer API function signatures from lifelib.cpp source code

parent a97c0f27
Pipeline #61878087 passed with stages
in 8 minutes and 27 seconds
......@@ -10,8 +10,19 @@ except ImportError:
import pickle
import base64
import re
__all__ = ['tzcount', 'call_underlying', 'WrappedLibrary', 'binstring', 'regstring']
__all__ = ['tzcount', 'call_underlying', 'WrappedLibrary', 'binstring', 'regstring', 'restypes', 'apilines']
pythlib_dir = os.path.dirname(os.path.abspath(__file__))
lifelib_dir = os.path.abspath(os.path.join(pythlib_dir, '..'))
with open(os.path.join(lifelib_dir, 'lifelib.cpp')) as f:
apilines = [x.replace('{', ';') for x in f if re.match('^ [a-z]', x)]
apitypes = dict([x.split('(')[0].strip().split()[::-1] for x in apilines])
api2res = {'void': None, 'void*': c_void_p, 'bool': c_bool, 'int64_t': c_int64, 'uint64_t': c_uint64, 'int': None}
restypes = {k : api2res[v] for (k, v) in apitypes.items()}
def binstring(x):
......@@ -65,21 +76,6 @@ def ensure_stack(required):
return None
restypes = {'DeletePattern': None, 'GetBeszelIndex': c_uint64, 'GetUlqomaIndex': c_uint64, 'GetDiameterOfPattern': None,
'AdvancePattern': c_void_p, 'GetSemisolidForPattern': c_void_p, 'BooleanPatternMutable': None,
'BooleanPatternImmutable': c_void_p, 'TransformPattern': c_void_p, 'ShiftPattern': c_void_p,
'FindPeriodOrAdvance': c_void_p, 'GetDTOfPattern': c_int64, 'GetDXOfPattern': c_int64,
'GetDYOfPattern': c_int64, 'GetApgcodeOfPattern': None, 'SavePatternRLE': None, 'SavePatternMC': None,
'GetPopulationOfPattern': None, 'CreateLifetree': c_void_p, 'CreatePatternFromRLE': c_void_p,
'CreateRectangle': c_void_p, 'DeleteLifetree': None, 'GetPatternBox': None, 'PatternEquality': c_bool,
'PatternNonempty': c_bool, 'MatchLive': c_void_p, 'MatchLiveAndDead': c_void_p, 'GetRuleOfPattern': None,
'GetSolidForPattern': c_void_p, 'GetOriginState': c_uint64, 'GetCells': None, 'SetCells': None,
'CreatePatternFromFile': c_void_p, 'MakeSpaceshipStream': c_void_p, 'GetCompiledVersion': None,
'GetCoords': None, 'GetPatternBound': c_uint64, 'GetSubpops': None, 'Hashsoup': c_void_p,
'FindConnectedComponent': c_void_p, 'GetOneCell': c_void_p, 'CopyPattern': c_void_p, 'GetWechslerOfPattern': None,
'BitshiftPattern': c_void_p}
def call_underlying(lifelib, fname_and_args):
fname = regstring(fname_and_args[0])
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