aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xluatablegen.py57
-rw-r--r--test/luwasm.xml50
2 files changed, 63 insertions, 44 deletions
diff --git a/luatablegen.py b/luatablegen.py
index 244a8d6..4d72ef9 100755
--- a/luatablegen.py
+++ b/luatablegen.py
@@ -274,6 +274,7 @@ def get_elem_count(elem):
def get_count_node(elem, parent):
if "count" in elem.attrib:
count_node_name = elem.attrib["count"][6:]
+ else: return None
for child in parent:
if child.tag == count_node_name:
return child
@@ -581,19 +582,21 @@ class TbgParser(object):
if kid.attrib["name"] == field_name: child = kid
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":
+ parent_node = get_def_node(struct_name, self.elems)
+ self_node = get_def_node(field_name, parent_node)
+ count = get_elem_count(self_node)
if field_type.find("self::") == 0:
- parent_node = get_def_node(struct_name, self.elems)
- self_node = get_def_node(field_name, parent_node)
- count = get_elem_count(self_node)
ptr = ""
if count != 1: ptr = "*"
child_node = get_def_node_tag(field_type[6:], self.elems)
- #print("parent node:" + parent_node.attrib["name"])
- #print("field type:" + field_type[6:])
- #if child_node != None: print("child_node:" + child_node.attrib["name"])
dummy = "\t"+child_node.attrib["name"] + ptr +"* "+field_name+" = "+"lua_touserdata(__ls,"+repr(rev_counter)+");\n"
else:
- dummy = "\t"+field_type +" "+field_name+" = "+"lua_touserdata(__ls,"+repr(rev_counter)+");\n"
+ ptr = str()
+ if count != 1: ptr = "*"
+ if type_resolver(child, self.elems) != field_type:
+ dummy = "\t"+type_resolver(child, self.elems) + ptr + " "+field_name+" = "+"lua_touserdata(__ls,"+repr(rev_counter)+");\n"
+ else:
+ dummy = "\t"+field_type+" "+field_name+" = "+"lua_touserdata(__ls,"+repr(rev_counter)+");\n"
elif lua_type == "number": pass
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
@@ -622,23 +625,39 @@ class TbgParser(object):
c_source.write(GETTER_GEN[0].replace("XXX", struct_name).replace("YYY", field_name))
c_source.write(GETTER_GEN[1].replace("XXX", struct_name))
c_source.write(GETTER_GEN[2])
+ parent = get_def_node(struct_name, self.elems)
+ #child = get_def_node(field_name, self.elems)
+ for kid in parent:
+ if field_name == kid.attrib["name"]: child = kid
+ count = get_elem_count(child)
+ count_node = get_count_node(child, parent)
+ count_node_name = str()
+ if count_node != None: count_node_name = count_node.attrib["name"]
+ if not child:
+ for kid in parent:
+ if kid.attrib["name"] == field_name: child = kid
if lua_type == "integer": dummy = "\tlua_pushinteger(__ls, dummy->"+field_name+");\n"
- elif lua_type == "lightuserdata": dummy = "\tlua_pushlightuserdata(__ls, dummy->"+field_name+");\n"
+ elif lua_type == "lightuserdata":
+ if count == 1:
+ dummy = "\tlua_pushlightuserdata(__ls, dummy->"+field_name+");\n"
+ else:
+ count_replacer = str()
+ if count > 1: count_replacer = repr(count)
+ else:
+ count_replacer = count_node_name
+ ref_node_type = get_def_node_tag(child.attrib["type"][6:], self.elems)
+ dummy = "lua_checkstack(__ls, 3);\nlua_newtable(__ls);\n"
+ dummy += "for (uint64_t i = 0; i < dummy->" + count_replacer + " ; ++i) {\nlua_pushinteger(__ls, i+1);\n"
+ if ref_node_type != None:
+ dummy += ref_node_type.attrib["name"]+ "_push_args(__ls, dummy->"+field_name+"[i]);\nnew_" + ref_node_type.attrib["name"] + "(__ls);\n"
+ else:
+ pass
+ #dummy += ref_node_type.attrib["name"]+ "_push_args(__ls, dummy->YYY[i]);\nnew_" + ref_node_type.attrib["name"] + "(__ls);\n"
+ dummy += "lua_settable(__ls, -3);\n}\n"
elif lua_type == "number": dummy = "\tlua_pushnumber(__ls, dummy->"+field_name+");\n"
elif lua_type == "string": dummy = "\tlua_pushstring(__ls, dummy->"+field_name+");\n"
elif lua_type == "boolean": dummy = "\tlua_pushboolean(__ls, dummy->"+field_name+");\n"
elif lua_type == "table":
- parent = get_def_node(struct_name, self.elems)
- #child = get_def_node(field_name, self.elems)
- for kid in parent:
- if field_name == kid.attrib["name"]: child = kid
- count = get_elem_count(child)
- count_node = get_count_node(child, parent)
- count_node_name = str()
- if count_node != None: count_node_name = count_node.attrib["name"]
- if not child:
- for kid in parent:
- if kid.attrib["name"] == field_name: child = kid
if count == 1:
dummy = "\tpush_" + type_resolver(child, self.elems) +"(__ls, dummy->"+field_name+");\n"
elif count > 1:
diff --git a/test/luwasm.xml b/test/luwasm.xml
index 3e10a40..3704b28 100644
--- a/test/luwasm.xml
+++ b/test/luwasm.xml
@@ -99,33 +99,33 @@
</Custom_Section>
</Read>
<Definition>
- <Init_Expr name="init_expr_t" isaggregate="true" luatype="table">
+ <Init_Expr name="init_expr_t" isaggregate="true" luatype="lightuserdata">
<Code name="code" type="string" count="1" size="-1" delimiter="11" luatype="integer"></Code>
</Init_Expr>
- <Resizable_Limit name="resizable_limit_t" isaggregate="true" luatype="table">
+ <Resizable_Limit name="resizable_limit_t" isaggregate="true" luatype="lightuserdata">
<Flags name="flags" encoding="leb128u" type="uint8" count="1" luatype="integer"></Flags>
<Initial name="initial" encoding="leb128u" type="uint32" count="1" luatype="integer"></Initial>
<Maximum name="maximum" encoding="leb128u" type="uint32" count="1" luatype="integer"></Maximum>
</Resizable_Limit>
- <Global_Type name="global_type_t" isaggregate="true" luatype="table">
+ <Global_Type name="global_type_t" isaggregate="true" luatype="lightuserdata">
<Value_Type name="value_type" type="uint32" count="1" luatype="integer"></Value_Type>
<Mutability name="mutability" encoding="leb128u" type="uint8" count="1" luatype="integer"></Mutability>
</Global_Type>
- <Table_Type name="table_type_t" isaggregate="true" luatype="table">
+ <Table_Type name="table_type_t" isaggregate="true" luatype="lightuserdata">
<Element_Type name="element_type" encoding="leb128u" type="uint8" count="1" luatype="integer"></Element_Type>
- <Resizable_Limit name="resizable_limit" count="1" type="self::Resizable_Limit" luatype="table"></Resizable_Limit>
+ <Resizable_Limit name="resizable_limit" count="1" type="self::Resizable_Limit" luatype="lightuserdata"></Resizable_Limit>
</Table_Type>
- <Memory_Type name="memory_type_t" isaggregate="true" luatype="table">
- <Resizable_Limit count="1" type="self::Resizable_Limit" name="resizable_limit" luatype="table"></Resizable_Limit>
+ <Memory_Type name="memory_type_t" isaggregate="true" luatype="lightuserdata">
+ <Resizable_Limit count="1" type="self::Resizable_Limit" name="resizable_limit" luatype="lightuserdata"></Resizable_Limit>
</Memory_Type>
- <Type_Section_Entry name="W_Type_Section_Entry" isaggregate="true" luatype="table">
+ <Type_Section_Entry name="W_Type_Section_Entry" isaggregate="true" luatype="lightuserdata">
<Form name="form" encoding="leb128u" type="uint8" count="1" luatype="integer"/>
<Param_Count name="param_count" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
<Param_Types name="param_types" encoding="leb128u" type="uint8" count="self::Param_Count" luatype="integer"/>
<Return_Count name="return_count" encoding="leb128u" type="uint8" luatype="integer"/>
<Return_Types name="return_types" encoding="leb128u" type="uint8" count="self::Return_Count" luatype="integer"/>
</Type_Section_Entry>
- <Import_Section_Entry name="W_Import_Section_Entry" isaggregate="true" luatype="table">
+ <Import_Section_Entry name="W_Import_Section_Entry" isaggregate="true" luatype="lightuserdata">
<Module_Length name="module_length" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
<Module_Str name="module_str" type="string" count="1" size="self::Module_Length" luatype="string"/>
<Field_Len name="field_len" encoding="leb128u" type="uint32" couny="1" luatype="integer"/>
@@ -133,42 +133,42 @@
<Kind name="kind" encoding="leb128u" type="uint8" count="1" luatype="integer"/>
<Type name="type" conditional="true" condition="self::Kind" type="FT::conditional" luatype="conditional">
<condition0 name="type" encoding="leb128u" type="uint32" luatype="integer">0</condition0>
- <condition1 name="type" type="self::Table_Type" luatype="table">1</condition1>
- <condition2 name="type" type="self::Memory_Type" luatype="table">2</condition2>
- <condition3 name="type" type="self::Global_Type" luatype="table">3</condition3>
+ <condition1 name="type" type="self::Table_Type" luatype="lightuserdata">1</condition1>
+ <condition2 name="type" type="self::Memory_Type" luatype="lightuserdata">2</condition2>
+ <condition3 name="type" type="self::Global_Type" luatype="lightuserdata">3</condition3>
</Type>
</Import_Section_Entry>
- <Global_Entry name="W_Global_Entry" isaggregate="true" luatype="table">
- <Global_Type name="type" type="self::Global_Type" count="1" luatype="table"/>
- <Init name="init" type="self::Init_Expr" count="1" luatype="table"/>
+ <Global_Entry name="W_Global_Entry" isaggregate="true" luatype="lightuserdata">
+ <Global_Type name="type" type="self::Global_Type" count="1" luatype="lightuserdata"/>
+ <Init name="init" type="self::Init_Expr" count="1" luatype="lightuserdata"/>
</Global_Entry>
- <Export_Entry name="W_Export_Entry" isaggregate="true" luatype="table">
+ <Export_Entry name="W_Export_Entry" isaggregate="true" luatype="lightuserdata">
<Field_Len name="field_len" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
<Field_Str name="field_str" type="string" count="1" size="self::Field_Len" luatype="string"/>
<Kind name="kind" encoding="leb128u" type="uint8" count="1" luatype="integer"/>
<Index name="index" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
</Export_Entry>
- <Element_Segment name="W_Element_Segment" isaggregate="true" luatype="table">
+ <Element_Segment name="W_Element_Segment" isaggregate="true" luatype="lightuserdata">
<Index name="index" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
- <Init name="init" type="self::Init_Expr" count="1" luatype="table"/>
+ <Init name="init" type="self::Init_Expr" count="1" luatype="lightuserdata"/>
<Num_Length name="num_length" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
<Elems name="elems" encoding="leb128u" type="uint32" count="self::Num_Length" luatype="integer"/>
</Element_Segment>
- <Local_Entry name="W_Local_Entry" isaggregate="true" luatype="table">
+ <Local_Entry name="W_Local_Entry" isaggregate="true" luatype="lightuserdata">
<Count name="count" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
<Type name="type" encoding="leb128u" type="uint16" count="self::Count" luatype="integer"/>
</Local_Entry>
- <Function_Body name="W_Function_Body" isaggregate="true" luatype="table">
+ <Function_Body name="W_Function_Body" isaggregate="true" luatype="lightuserdata">
<Body_size name="body_size" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
<Local_Count name="local_count" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
- <Local_Entries name="locals" type="self::Local_Entry" count="self::Local_Count" luatype="table"/>
- <Code name="code" type="uint8" count="self::Body_size" luatype="integer"/>
+ <Local_Entries name="locals" type="self::Local_Entry" count="self::Local_Count" luatype="lightuserdata"/>
+ <Code name="code" type="uchar" count="self::Body_size" luatype="integer"/>
</Function_Body>
- <Data_Segment name="W_Data_Segment" isaggregate="true" luatype="table">
+ <Data_Segment name="W_Data_Segment" isaggregate="true" luatype="lightuserdata">
<Index name="index" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
- <Offset name="offset" type="self::Init_Expr" count="1" luatype="table"/>
+ <Offset name="offset" type="self::Init_Expr" count="1" luatype="lightuserdata"/>
<Size name="size" encoding="leb128u" type="uint32" count="1" luatype="integer"/>
- <Data name="data" type="uint8" count="self::Size" luatype="table"/>
+ <Data name="data" type="uchar" count="self::Size" luatype="lightuserdata"/>
</Data_Segment>
</Definition>
</FT>