Skip to content

Commit

Permalink
initial work on bindings generator, using CppHeaderParser and ply. ll…
Browse files Browse the repository at this point in the history
…vm-gcc only for now
  • Loading branch information
kripken committed Jul 4, 2011
1 parent 15db951 commit 7653c3b
Show file tree
Hide file tree
Showing 145 changed files with 23,502 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def path_from_root(*pathelems):
EMMAKEN = path_from_root('tools', 'emmaken.py')
AUTODEBUGGER = path_from_root('tools', 'autodebugger.py')
DFE = path_from_root('tools', 'dead_function_eliminator.py')
BINDINGS_GENERATOR = path_from_root('tools', 'bindings_generator.py')

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

Expand Down Expand Up @@ -2565,7 +2566,7 @@ def hook(filename):
### Integration tests

def test_scriptaclass(self):
src = '''
header = '''
struct ScriptMe {
int value;
ScriptMe(int val);
Expand All @@ -2574,10 +2575,20 @@ def test_scriptaclass(self):
// as a library)
void mulVal(int mul);
};
'''
header_filename = os.path.join(self.get_dir(), 'header.h')
open(header_filename, 'w').write(header)

src = '''
#include "header.h"
ScriptMe::ScriptMe(int val) : value(val) { }
int ScriptMe::getVal() { return value; }
void ScriptMe::mulVal(int mul) { value *= mul; }
'''

# Way 1: use demangler and namespacer

script_src = '''
var sme = Module._.ScriptMe.__new__(83); // malloc(sizeof(ScriptMe)), ScriptMe::ScriptMe(sme, 83) / new ScriptMe(83) (at addr sme)
Module._.ScriptMe.mulVal(sme, 2); // ScriptMe::mulVal(sme, 2) sme.mulVal(2)
Expand All @@ -2596,6 +2607,31 @@ def post(filename):
open(filename, 'w').write(src)
self.do_test(src, '*166*\n*ok*', post_build=post)

# Way 2: use CppHeaderParser

if COMPILER != LLVM_GCC: return self.skip() # FIXME: proper support for aliases, which clang generates here

basename = os.path.join(self.get_dir(), 'bindingtest')
Popen(['python', BINDINGS_GENERATOR, basename, header_filename], stdout=PIPE, stderr=STDOUT).communicate()[0]

src = src + '\n#include "bindingtest.c"\n'

script_src_2 = '''
var sme = new ScriptMe(83);
sme.mulVal(2);
print('*' + sme.getVal() + '*');
print('*ok*');
'''

def post2(filename):
src = open(filename, 'r').read().replace(
'// {{MODULE_ADDITIONS}',
'''load('bindingtest.js')''' + '\n\n' + script_src_2 + '\n\n' +
'// {{MODULE_ADDITIONS}'
)
open(filename, 'w').write(src)
self.do_test(src, '*166*\n*ok*', post_build=post2)

### Tests for tools

def test_safe_heap(self):
Expand Down
Loading

0 comments on commit 7653c3b

Please sign in to comment.