From b02e09aaa9d199a84f4f02b9ee860550424da0e0 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Fri, 17 Aug 2018 14:43:46 +0430 Subject: update --- luatablegen.py | 50 +++++++++++++++++++++++++++++++++++++++++++------- run.sh | 14 +++++++------- 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) diff --git a/run.sh b/run.sh index 78ab9ea..3caad5d 100755 --- a/run.sh +++ b/run.sh @@ -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 @@ - 2 + 2 @@ -76,8 +76,8 @@ 10 - - + + -- cgit v1.2.3