Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 27, 2022
1 parent 543c3e1 commit 8ef0b83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
16 changes: 10 additions & 6 deletions misc/generate_c_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from taichi_json import EntryBase, BuiltInType, Alias, Handle, Definition, \
Handle, Enumeration, BitField, Field, Structure, Union, Function, Module
from taichi_json import (Alias, BitField, BuiltInType, Definition, EntryBase,
Enumeration, Field, Function, Handle, Module,
Structure, Union)

#from os import system

Expand Down Expand Up @@ -50,17 +51,20 @@ def get_declr(x: EntryBase):
out = ["typedef enum " + get_type_name(x) + " {"]
for name, value in x.cases.items():
out += [f" {name.screaming_snake_case} = {value},"]
out += [f" {x.name.extend('max_enum').screaming_snake_case} = 0xffffffff,"]
out += [
f" {x.name.extend('max_enum').screaming_snake_case} = 0xffffffff,"
]
out += ["} " + get_type_name(x) + ";"]
return '\n'.join(out)

elif ty is BitField:
out = ["typedef enum " + get_type_name(x) + " {"]
for name, value in x.bits.items():
out += [f" {name.extend('bit').screaming_snake_case} = 1 << {value},"]
out += [
f" {name.extend('bit').screaming_snake_case} = 1 << {value},"
]
out += ["} " + get_type_name(x) + ";"]
out += [
f"typedef TiFlags {x.name.extend('flags').upper_camel_case};"]
out += [f"typedef TiFlags {x.name.extend('flags').upper_camel_case};"]
return '\n'.join(out)

elif ty is Structure:
Expand Down
24 changes: 15 additions & 9 deletions misc/generate_unity_language_binding.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from taichi_json import EntryBase, BuiltInType, Alias, Handle, Definition, \
Handle, Enumeration, BitField, Field, Structure, Union, Function, Module
import re

from taichi_json import (Alias, BitField, BuiltInType, Definition, EntryBase,
Enumeration, Field, Function, Handle, Module,
Structure, Union)


def get_type_name(x: EntryBase):
ty = type(x)
Expand Down Expand Up @@ -104,14 +106,18 @@ def get_declr(x: EntryBase):
out = ["public enum " + get_type_name(x) + " {"]
for name, value in x.cases.items():
out += [f" {name.screaming_snake_case} = {value},"]
out += [f" {x.name.extend('max_enum').screaming_snake_case} = 0x7fffffff,"]
out += [
f" {x.name.extend('max_enum').screaming_snake_case} = 0x7fffffff,"
]
out += ["}"]
return '\n'.join(out)

elif ty is BitField:
out = ["[Flags]", "public enum " + get_type_name(x) + " {"]
for name, value in x.bits.items():
out += [f" {name.extend('bit').screaming_snake_case} = 1 << {value},"]
out += [
f" {name.extend('bit').screaming_snake_case} = 1 << {value},"
]
out += ["};"]
return '\n'.join(out)

Expand Down Expand Up @@ -143,17 +149,17 @@ def get_declr(x: EntryBase):
"#if (UNITY_IOS || UNITY_TVOS || UNITY_WEBGL) && !UNITY_EDITOR",
' [DllImport ("__Internal")]',
"#else",
' [DllImport("taichi_unity")]' if x.vendor == "unity" else ' [DllImport("taichi_c_api")]',
' [DllImport("taichi_unity")]'
if x.vendor == "unity" else ' [DllImport("taichi_c_api")]',
"#endif",
"private static extern " + return_value_type + " " +
x.name.snake_case + "(",
',\n'.join(f" {get_c_function_param(param)}"
for param in x.params),
");",
"public static " + return_value_type +
" " + x.name.upper_camel_case + "(",
',\n'.join(f" {get_function_param(param)}"
for param in x.params),
"public static " + return_value_type + " " +
x.name.upper_camel_case + "(",
',\n'.join(f" {get_function_param(param)}" for param in x.params),
") {",
]
for param in x.params:
Expand Down
3 changes: 2 additions & 1 deletion misc/taichi_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def extend(self, subname):
subname = Name(subname)
assert isinstance(subname, Name)
assert len(subname._prefix) == 0 and len(subname._suffix) == 0
return Name('_'.join(self._segs + subname._segs), self._prefix, self._suffix)
return Name('_'.join(self._segs + subname._segs), self._prefix,
self._suffix)

@property
def segs(self):
Expand Down

0 comments on commit 8ef0b83

Please sign in to comment.