diff options
author | bloodstalker <thabogre@gmail.com> | 2018-08-17 10:13:46 +0000 |
---|---|---|
committer | bloodstalker <thabogre@gmail.com> | 2018-08-17 10:13:46 +0000 |
commit | b02e09aaa9d199a84f4f02b9ee860550424da0e0 (patch) | |
tree | d9e58e32b8b478ee47873f6a967ef770fb26c390 | |
parent | update (diff) | |
download | luatablegen-b02e09aaa9d199a84f4f02b9ee860550424da0e0.tar.gz luatablegen-b02e09aaa9d199a84f4f02b9ee860550424da0e0.zip |
update
Diffstat (limited to '')
-rwxr-xr-x | luatablegen.py | 50 | ||||
-rwxr-xr-x | run.sh | 14 | ||||
-rw-r--r-- | test/wasm.xml | 6 |
3 files changed, 53 insertions, 17 deletions
diff --git a/luatablegen.py b/luatablegen.py index 4921e5f..1bea2e6 100755 --- a/luatablegen.py +++ b/luatablegen.py @@ -88,6 +88,43 @@ LUA_SETMETA_NEW = ["setmetatable(XXX, {__call =\n", "\tfunction(selfAAA)\n", LUA_TO_GENERIC = "lua_to_YYY(__ls, ZZZ);\n" LUA_TO_GENERIC_DEF = "YYY lua_to_YYY(lua_State* ls, XXX array, ZZZ) {}\n" +def simple_type_resovler(type_str): + if type_str == "int8": + return "int8_t" + elif type_str == "uint8": + return "uint8_t" + elif type_str == "int16": + return "int16_t" + elif type_str == "uint16": + return "uint16_t" + elif type_str == "int32": + return "int32_t" + elif type_str == "uint32": + return "uint32_t" + elif type_str == "int64": + return "int64_t" + elif type_str == "uint64": + return "uint64_t" + elif type_str == "int128": + return "int128_t" + elif type_str == "uint128": + return "uint128_t" + elif type_str == "float": + return "float" + elif type_str == "double": + return "double" + elif type_str == "bool": + return "uint8_t" + elif type_str == "uchar": + return "uint8_t" + elif type_str == "schar": + return "int8_t" + elif type_str == "string": + return "char*" + elif type_str == "FT::conditional": + return "void*" + else: return type_str + def type_resolver(elem, elem_list): if "isaggregate" in elem.attrib: type_str = elem.attrib["name"] @@ -342,20 +379,19 @@ class TbgParser(object): c_source.write(NEW[0].replace("XXX", struct_name)) c_source.write("\tlua_checkstack(__ls, " + repr(len(field_names)) + ");\n") for lua_type, field_name, field_type in zip(lua_types, field_names, field_types): - if lua_type == "integer": dummy = "\t"+field_type +" "+field_name+" = "+"luaL_optinteger(__ls,"+repr(rev_counter)+",0);\n" + if lua_type == "integer": dummy = "\t"+simple_type_resovler(field_type) +" "+field_name+" = "+"luaL_optinteger(__ls,"+repr(rev_counter)+",0);\n" elif lua_type == "lightuserdata": dummy = "\t"+field_type +" "+field_name+" = "+"lua_touserdata(__ls,"+repr(rev_counter)+");\n" elif lua_type == "number": pass - elif lua_type == "string":dummy = "\t"+field_type +" "+field_name+" = "+"lua_tostring(__ls,"+repr(rev_counter)+");\n" + elif lua_type == "string":dummy = "\t"+simple_type_resovler(field_type) +" "+field_name+" = "+"lua_tostring(__ls,"+repr(rev_counter)+");\n" elif lua_type == "boolean": pass elif lua_type == "table": parent = get_def_node(struct_name, self.elems) child = get_def_node(field_name, self.elems) - if not child: - for child in parent: - if child.attrib["name"] == field_name: child = child + for kid in parent: + if kid.attrib["name"] == field_name: child = kid temp = self.gen_lua_table_push_call(child, rev_counter) temp2 = self.gen_luato_generic(struct_name, field_name, rev_counter) - dummy = temp[0]+"=" + temp2 + dummy = temp[0] + "=" + temp2 else: print("bad lua_type entry in the json file") sys.exit(1) @@ -385,7 +421,7 @@ class TbgParser(object): if not child: for kid in parent: if kid.attrib["name"] == field_name: child = kid - dummy = "\tpushluatable_" + type_resolver(child, self.elems) +"(__ls, _st->"+field_name+");\n" + dummy = "\tpushluatable_" + type_resolver(child, self.elems) +"(__ls, dummy->"+field_name+");\n" else: print("bad lua_type entry in the json file") sys.exit(1) @@ -3,10 +3,10 @@ cd $(dirname $0) if [[ -d ./out ]]; then :;else mkdir ./out;fi ./luatablegen.py --tbg ./test/wasmtablegen.json --out ./out --luaheader /home/bloodstalker/devi/hell2/bruiser/lua-5.3.4/src --pre ./test/wasmheader.txt --headeraggr ./out/wasm_tables.h --lualibpath ./out/wasm.lua --docpath ./out/wasm.md --xml ./test/wasm.xml --tbldefs ./out/ clang-format ./out/*.c ./out/*.h -i -#for filename in ./out/*.c; do -# gcc -c $filename > /dev/null 2>&1 -# if [[ $? != 0 ]]; then -# echo $filename did not compile. -# fi -#done -#rm *.o +for filename in ./out/*.c; do + gcc -c $filename > /dev/null 2>&1 + if [[ $? != 0 ]]; then + echo $filename did not compile. + fi +done +rm *.o diff --git a/test/wasm.xml b/test/wasm.xml index eb1048c..f0affc8 100644 --- a/test/wasm.xml +++ b/test/wasm.xml @@ -12,7 +12,7 @@ <Type_Section_Entry count="self::Count" type="self::Type_Section_Entry" name="entries" luatype="table"/> </Type_Section> <Import_Section name="W_Import_Section" count="1" type="" isaggregate="true" unordered="true" luatype="table"> - <ID name="id" type="uint8" encoding="leb128u" issign="true" luatype="table">2</ID> + <ID name="id" type="uint8" encoding="leb128u" issign="true" luatype="integer">2</ID> <PayloadLength name="payloadlength" type="uint32" encoding="leb128u" luatype="integer"/> <NameLength name="namelength" type="uint32" encoding="leb128u" luatype="integer"/> <Name name="name" type="string" size="self::NameLength" luatype="string"/> @@ -76,8 +76,8 @@ </Element_Section> <Code_Section name="W_Code_Section" count="1" isaggregate="true" unordered="true" luatype="table"> <ID name="id" type="uint8" encoding="leb128u" issign="true" luatype="integer">10</ID> - <PayloadLength name="payloadlength" type="uint32" encoding="leb128u" luatype="table"/> - <NameLength name="namelength" type="uint32" encoding="leb128u" luatype="table"/> + <PayloadLength name="payloadlength" type="uint32" encoding="leb128u" luatype="integer"/> + <NameLength name="namelength" type="uint32" encoding="leb128u" luatype="integer"/> <Name name="name" type="string" size="self::NameLength" luatype="string"/> <Count name="count" encoding="leb128u" type="uint32" count="1" luatype="integer"/> <Bodies name="bodies" type="self::Function_Body" count="self::Count" luatype="table"/> |