Skip to content

Commit

Permalink
BugFix: AgentPython was missing ID->id_t type conversion. (#1153)
Browse files Browse the repository at this point in the history
* BugFix: AgentPython was missing ID->id_t type conversion.

Improved detail in various codgen exceptions too.

* BugFix: #1147 broke Python 3.8.13

This variant has been tested on both 3.8.13 and 3.10.12
  • Loading branch information
Robadob authored Dec 1, 2023
1 parent 3801865 commit e8adb97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions swig/python/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from io import StringIO
from .codegen import CodeGenerator
from .codegen import CodeGenException
from typing import Callable, Union
from typing import Callable, Union, _SpecialForm
import ast
import inspect

Expand Down Expand Up @@ -51,7 +51,7 @@ def translate(function: Union[str, Callable]) -> str:
prepend_c_source = ""
# Find all annotated variables
for key, val in module_annontations.items():
if val.__name__ == "Final" or val.__name__ == "constant":
if (isinstance(val, _SpecialForm) and val._name == "Final") or val.__name__ == "constant":
# Locate the literal for that variable (Python will precompute anything e.g. math.sqrt(12.5))
for mem in module_members:
if key == mem[0]:
Expand Down
13 changes: 7 additions & 6 deletions swig/python/codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class CodeGenerator:
"Int32": "int_32",
"UInt32": "uint_32",
"Int64": "int_64",
"UInt64": "uint_64"
"UInt64": "uint_64",
"ID": "flamegpu::id_t"
}


Expand Down Expand Up @@ -197,7 +198,7 @@ def RaiseWarning(self, tree, str):
def RaiseError(self, tree, str):
raise CodeGenException(f"Error ({tree.lineno}, {tree.col_offset}): {str}")

############### Cutsom Unparsing methods ###############
############### Custom Unparsing methods ###############
# These are special versions of the ast unparsing #
# dispatch functions. #
########################################################
Expand Down Expand Up @@ -282,15 +283,15 @@ def dispatchType(self, tree):
"""
if isinstance(tree, ast.Name):
if tree.id not in self.basic_arg_types:
self.RaiseError(tree, "Not a supported type")
self.RaiseError(tree, "%s is not a supported type"%(tree.id))
self.write(tree.id)
elif isinstance(tree, ast.Attribute):
if not isinstance(tree.value, ast.Name) :
self.RaiseError(tree, "Not a supported type")
if not (tree.value.id == "numpy" or tree.value.id == "np"):
self.RaiseError(tree, "Not a supported type")
self.RaiseError(tree, "%s.%s is not a supported type"%(tree.value.id, tree.attr))
if tree.attr not in self.numpytypes:
self.RaiseError(tree, "Not a supported numpy type")
self.RaiseError(tree, "%s.%s is not a supported numpy type"%(tree.value.id, tree.attr))
self.write(self.numpytypes[tree.attr])
else:
self.RaiseError(tree, "Not a supported type")
Expand Down Expand Up @@ -450,7 +451,7 @@ def dispatchMemberFunction(self, t, t_parent):
self.write(py_func)
t_parent.call_type = "AgentOut"
else:
self.RaiseError(t, f"Unknown or unsupported nested attribute in {t.value.value.id}")
self.RaiseError(t, f"Unknown or unsupported nested attribute {t.value.attr} in {t.value.value.id}")
# Non nested member functions (e.g. x.y())
elif isinstance(t.value, ast.Name):
# pyflamegpu singleton
Expand Down
2 changes: 1 addition & 1 deletion tests/python/codegen/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def test_fgpu_supported_types(self):
self._checkExpected("a: numpy.float32", "float a;")
self._checkExpected("a: numpy.float64", "double a;")
# check unsupported
self._checkException("a: numpy.unsupported", "Not a supported numpy type")
self._checkException("a: numpy.unsupported", "numpy.unsupported is not a supported numpy type")


def test_fgpu_constexpr(self):
Expand Down

0 comments on commit e8adb97

Please sign in to comment.