-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add cstruct * try to fix * unify the types of functions * update * fix loader * add MOBULA_FUNC template * fix * type
- Loading branch information
Showing
12 changed files
with
148 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from . import backend | ||
from .common import register, CUSTOM_OP_LIST | ||
from .common import register, register_cstruct, CUSTOM_OP_LIST | ||
from . import common | ||
common.backend = backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MOBULA_DLL ${return_value} ${func_idcode_hash}(${args_def}) { | ||
${return_statement} ${func_name}(${args_inst}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""version information""" | ||
__version__ = 2.32 | ||
__version__ = 2.4 | ||
|
||
OP_LOAD_MODULE_BUILD_VERSION = __version__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
struct MyStruct { | ||
int hello; | ||
float mobula; | ||
}; | ||
|
||
MOBULA_FUNC float hello(MyStruct *hi) { | ||
LOG(INFO) << "Hello Mobula: " << hi->hello << ", " << hi->mobula; | ||
return hi->hello + hi->mobula; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import ctypes | ||
import os | ||
|
||
import mobula | ||
from mobula.testing import assert_almost_equal, gradcheck | ||
|
||
# [TODO] change BUILD_PATH | ||
|
||
|
||
def test_custom_struct(): | ||
class MyStruct(ctypes.Structure): | ||
_fields_ = [ | ||
('hello', ctypes.c_int), | ||
('mobula', ctypes.c_float), | ||
] | ||
|
||
mobula.glue.register_cstruct('MyStruct', MyStruct) | ||
mobula.op.load('MyStruct', os.path.dirname(__file__)) | ||
|
||
res = mobula.func.hello((42, 39)) | ||
assert_almost_equal(res, 42 + 39) | ||
|
||
|
||
if __name__ == '__main__': | ||
test_custom_struct() |
Oops, something went wrong.