diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-08-15 18:16:37 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-08-15 18:16:37 -0700 |
commit | ea6f1cebc098aef798cfdb9dbd0097875b0a5aae (patch) | |
tree | e9e658e705b7bc746edea905e2f405974e525cce | |
parent | 10cfcfa316a13b94ac7cc1966809e01adafc5f45 (diff) |
allow generateStructInfo to work at runtime with structMetadata
-rw-r--r-- | src/jsifier.js | 1 | ||||
-rw-r--r-- | src/runtime.js | 6 | ||||
-rw-r--r-- | tests/runner.py | 7 |
3 files changed, 10 insertions, 4 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 078e57ea..3da296f1 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -840,6 +840,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { if (RUNTIME_TYPE_INFO) { Types.cleanForRuntime(); print('Runtime.typeInfo = ' + JSON.stringify(Types.types)); + print('Runtime.structMetadata = ' + JSON.stringify(Types.structMetadata)); } generated.forEach(function(item) { print(indentify(item.JS || '', 2)); }); print(Functions.generateIndexing()); diff --git a/src/runtime.js b/src/runtime.js index ad3c973d..abeb0d2a 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -183,11 +183,11 @@ Runtime = { var type, alignment; if (typeName) { offset = offset || 0; - type = typeof Types === 'undefined' ? Runtime.typeInfo[typeName] : Types.types[typeName]; + type = (typeof Types === 'undefined' ? Runtime.typeInfo : Types.types)[typeName]; if (!type) return null; - if (!struct) struct = Types.structMetadata[typeName.replace(/.*\./, '')]; + if (!struct) struct = (typeof Types === 'undefined' ? Runtime : Types).structMetadata[typeName.replace(/.*\./, '')]; if (!struct) return null; - assert(type.fields.length === struct.length, 'Number of named fields must match the type for ' + typeName); + assert(type.fields.length === struct.length, 'Number of named fields must match the type for ' + typeName + '. Perhaps due to inheritance, which is not supported yet?'); alignment = type.flatIndexes; } else { var type = { fields: struct.map(function(item) { return item[0] }) }; diff --git a/tests/runner.py b/tests/runner.py index 109bf42f..14493612 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -3164,6 +3164,8 @@ if 'benchmark' not in sys.argv: # Way 2: use CppHeaderParser + global RUNTIME_TYPE_INFO; RUNTIME_TYPE_INFO = 1 + header = ''' #include <stdio.h> @@ -3339,13 +3341,16 @@ Child2:9 print('|' + Runtime.typeInfo.UserStruct.fields + '|' + Runtime.typeInfo.UserStruct.flatIndexes + '|'); var t = Runtime.generateStructInfo(['x', { us: ['x', 'y', 'z'] }, 'y'], 'Encloser') print('|' + [t.x, t.us.x, t.us.y, t.us.z, t.y] + '|'); + print('|' + JSON.stringify(Runtime.generateStructInfo(null, 'UserStruct')) + '|'); } else { print('No type info.'); } ''' ) open(filename, 'w').write(src) - self.do_test(src, '*ok:5*\n|i32,i8,i16|0,4,6|\n|0,4,8,10,12|', post_build=post) + self.do_test(src, + '*ok:5*\n|i32,i8,i16|0,4,6|\n|0,4,8,10,12|\n|{"__size__":8,"x":0,"y":4,"z":6}|', + post_build=post) # Make sure that without the setting, we don't spam the .js with the type info RUNTIME_TYPE_INFO = 0 |