Skip to content

Commit 7653c3b

Browse files
committed
initial work on bindings generator, using CppHeaderParser and ply. llvm-gcc only for now
1 parent 15db951 commit 7653c3b

145 files changed

Lines changed: 23502 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/runner.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def path_from_root(*pathelems):
2929
EMMAKEN = path_from_root('tools', 'emmaken.py')
3030
AUTODEBUGGER = path_from_root('tools', 'autodebugger.py')
3131
DFE = path_from_root('tools', 'dead_function_eliminator.py')
32+
BINDINGS_GENERATOR = path_from_root('tools', 'bindings_generator.py')
3233

3334
# Global cache for tests (we have multiple TestCase instances; this object lets them share data)
3435

@@ -2565,7 +2566,7 @@ def hook(filename):
25652566
### Integration tests
25662567

25672568
def test_scriptaclass(self):
2568-
src = '''
2569+
header = '''
25692570
struct ScriptMe {
25702571
int value;
25712572
ScriptMe(int val);
@@ -2574,10 +2575,20 @@ def test_scriptaclass(self):
25742575
// as a library)
25752576
void mulVal(int mul);
25762577
};
2578+
'''
2579+
header_filename = os.path.join(self.get_dir(), 'header.h')
2580+
open(header_filename, 'w').write(header)
2581+
2582+
src = '''
2583+
#include "header.h"
2584+
25772585
ScriptMe::ScriptMe(int val) : value(val) { }
25782586
int ScriptMe::getVal() { return value; }
25792587
void ScriptMe::mulVal(int mul) { value *= mul; }
25802588
'''
2589+
2590+
# Way 1: use demangler and namespacer
2591+
25812592
script_src = '''
25822593
var sme = Module._.ScriptMe.__new__(83); // malloc(sizeof(ScriptMe)), ScriptMe::ScriptMe(sme, 83) / new ScriptMe(83) (at addr sme)
25832594
Module._.ScriptMe.mulVal(sme, 2); // ScriptMe::mulVal(sme, 2) sme.mulVal(2)
@@ -2596,6 +2607,31 @@ def post(filename):
25962607
open(filename, 'w').write(src)
25972608
self.do_test(src, '*166*\n*ok*', post_build=post)
25982609

2610+
# Way 2: use CppHeaderParser
2611+
2612+
if COMPILER != LLVM_GCC: return self.skip() # FIXME: proper support for aliases, which clang generates here
2613+
2614+
basename = os.path.join(self.get_dir(), 'bindingtest')
2615+
Popen(['python', BINDINGS_GENERATOR, basename, header_filename], stdout=PIPE, stderr=STDOUT).communicate()[0]
2616+
2617+
src = src + '\n#include "bindingtest.c"\n'
2618+
2619+
script_src_2 = '''
2620+
var sme = new ScriptMe(83);
2621+
sme.mulVal(2);
2622+
print('*' + sme.getVal() + '*');
2623+
print('*ok*');
2624+
'''
2625+
2626+
def post2(filename):
2627+
src = open(filename, 'r').read().replace(
2628+
'// {{MODULE_ADDITIONS}',
2629+
'''load('bindingtest.js')''' + '\n\n' + script_src_2 + '\n\n' +
2630+
'// {{MODULE_ADDITIONS}'
2631+
)
2632+
open(filename, 'w').write(src)
2633+
self.do_test(src, '*166*\n*ok*', post_build=post2)
2634+
25992635
### Tests for tools
26002636

26012637
def test_safe_heap(self):

0 commit comments

Comments
 (0)