From 7b526b971ad9a017d34aa07441623e0cb226b093 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Tue, 25 Sep 2018 15:59:47 +0330 Subject: it's working for the most part, the getter methods are also registering lightuserdata with a respective global metatable --- bruiser/bruiser.cpp | 26 ++++++++++++------------- bruiser/lua-scripts/wasmtest.lua | 42 +++++++++++++++++++++++++++++++++++++--- bruiser/tablegen | 2 +- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 39dc664..54b632e 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -1829,7 +1829,7 @@ class LuaWrapper new_magic_number(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "magic"); + //PRINT_WITH_COLOR_LB(BLUE, "magic"); if (lib_ret->obj->version_container != NULL) { lua_pushstring(__ls, "version"); @@ -1837,7 +1837,7 @@ class LuaWrapper new_version(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "version"); + //PRINT_WITH_COLOR_LB(BLUE, "version"); if (lib_ret->obj->W_Type_Section_container != NULL) { lua_pushstring(__ls, "type_section"); @@ -1845,7 +1845,7 @@ class LuaWrapper new_W_Type_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "type section"); + //PRINT_WITH_COLOR_LB(BLUE, "type section"); if (lib_ret->obj->W_Import_Section_container != NULL) { lua_pushstring(__ls, "import_section"); @@ -1853,7 +1853,7 @@ class LuaWrapper new_W_Import_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "import section"); + //PRINT_WITH_COLOR_LB(BLUE, "import section"); if (lib_ret->obj->W_Function_Section_container != NULL) { lua_pushstring(__ls, "function_section"); @@ -1861,7 +1861,7 @@ class LuaWrapper new_W_Function_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "function section"); + //PRINT_WITH_COLOR_LB(BLUE, "function section"); if (lib_ret->obj->W_Table_Section_container != NULL) { lua_pushstring(__ls, "table_section"); @@ -1869,7 +1869,7 @@ class LuaWrapper new_W_Table_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "table section"); + //PRINT_WITH_COLOR_LB(BLUE, "table section"); if (lib_ret->obj->W_Memory_Section_container != NULL) { lua_pushstring(__ls, "memory_section"); @@ -1877,7 +1877,7 @@ class LuaWrapper new_W_Memory_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "memory section"); + //PRINT_WITH_COLOR_LB(BLUE, "memory section"); if (lib_ret->obj->W_Global_Section_container != NULL) { lua_pushstring(__ls, "global_section"); @@ -1885,7 +1885,7 @@ class LuaWrapper new_W_Global_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "global section"); + //PRINT_WITH_COLOR_LB(BLUE, "global section"); if (lib_ret->obj->W_Export_Section_container != NULL) { lua_pushstring(__ls, "export_section"); @@ -1893,7 +1893,7 @@ class LuaWrapper new_W_Export_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "export section"); + //PRINT_WITH_COLOR_LB(BLUE, "export section"); if (lib_ret->obj->W_Start_Section_container != NULL) { lua_pushstring(__ls, "start_section"); @@ -1901,7 +1901,7 @@ class LuaWrapper new_W_Start_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "start section"); + //PRINT_WITH_COLOR_LB(BLUE, "start section"); if (lib_ret->obj->W_Element_Section_container != NULL) { lua_pushstring(__ls, "element_section"); @@ -1909,7 +1909,7 @@ class LuaWrapper new_W_Element_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "element section"); + //PRINT_WITH_COLOR_LB(BLUE, "element section"); if (lib_ret->obj->W_Code_Section_container != NULL) { lua_pushstring(__ls, "code_section"); @@ -1917,7 +1917,7 @@ class LuaWrapper new_W_Code_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "code section"); + //PRINT_WITH_COLOR_LB(BLUE, "code section"); if (lib_ret->obj->W_Data_Section_container != NULL) { lua_pushstring(__ls, "data_section"); @@ -1925,7 +1925,7 @@ class LuaWrapper new_W_Data_Section(__ls); lua_settable(__ls, -3); } - PRINT_WITH_COLOR_LB(BLUE, "data section"); + //PRINT_WITH_COLOR_LB(BLUE, "data section"); return 1; } diff --git a/bruiser/lua-scripts/wasmtest.lua b/bruiser/lua-scripts/wasmtest.lua index 315c5f4..8942ad2 100644 --- a/bruiser/lua-scripts/wasmtest.lua +++ b/bruiser/lua-scripts/wasmtest.lua @@ -69,6 +69,13 @@ function demo4() io.write("name:"..tostring(a["table_section"]:name()).."\n") io.write("count:"..tostring(a["table_section"]:count()).."\n") io.write("entries:"..tostring(a["table_section"]:entries()).."\n") + for k, v in pairs(a["table_section"]:entries()) do + io.write(v:element_type().."\t") + io.write(tostring(v:resizable_limit()).."\t") + io.write(v:resizable_limit():flags().."\t") + io.write(v:resizable_limit():initial().."\t") + io.write(v:resizable_limit():maximum().."\n") + end else print(colors("%{red}".."section doesnt exist.")) end @@ -79,8 +86,12 @@ function demo4() io.write("payloadlength:"..tostring(a["memory_section"]:payloadlength()).."\n") io.write("namelength:"..tostring(a["memory_section"]:namelength()).."\n") io.write("name:"..tostring(a["memory_section"]:name()).."\n") + --for wasm v.1.0. memory section count is 1 --io.write("count:"..tostring(a["memory_section"]:count()).."\n") io.write("entries:"..tostring(a["memory_section"]:entries()).."\n") + io.write(a["memory_section"]:entries():resizable_limit():flags().."\t") + io.write(a["memory_section"]:entries():resizable_limit():initial().."\t") + io.write(a["memory_section"]:entries():resizable_limit():maximum().."\n") else print(colors("%{red}".."section doesnt exist.")) end @@ -93,6 +104,11 @@ function demo4() io.write("name:"..tostring(a["global_section"]:name()).."\n") io.write("count:"..tostring(a["global_section"]:count()).."\n") io.write("globals:"..tostring(a["global_section"]:globals()).."\n") + for k, v in pairs(a["global_section"]:globals()) do + io.write(v:global_type().."\t") + io.write(v:init().."\n") + io.write(v:init():code().."\n") + end else print(colors("%{red}".."section doesnt exist.")) end @@ -105,6 +121,12 @@ function demo4() io.write("name:"..tostring(a["export_section"]:name()).."\n") io.write("count:"..tostring(a["export_section"]:count()).."\n") io.write("entries:"..tostring(a["export_section"]:entries()).."\n") + for k, v in pairs(a["export_section"]:entries()) do + io.write(v:field_len().."\t") + io.write(v:field_str().."\t") + io.write(v:kind().."\t") + io.write(v:index().."\n") + end else print(colors("%{red}".."section doesnt exist.")) end @@ -128,6 +150,14 @@ function demo4() io.write("name:"..tostring(a["element_section"]:name()).."\n") io.write("count:"..tostring(a["element_section"]:count()).."\n") io.write("entries:"..tostring(a["element_section"]:entries()).."\n") + for k, v in pairs(a["element_section"]:entries()) do + io.write(v:index().."\t") + io.write(tostring(v:init()).."\t") + io.write(v:init():code().."\t") + io.write(v:num_length().."\t") + -- FIXME + io.write(v:elems().."\n") + end else print(colors("%{red}".."section doesnt exist.")) end @@ -141,9 +171,15 @@ function demo4() io.write("count:"..tostring(a["code_section"]:count()).."\n") io.write("bodies:"..tostring(a["code_section"]:bodies()).."\n") for k,v in pairs(a["code_section"]:bodies()) do - io.write(v:body_size()) - io.write(v:local_count()) - --io.write(v:locals()) + io.write(v:body_size().."\t") + io.write(v:local_count().."\t") + io.write(tostring(v:locals()).."\t") + print("number of locals:"..#v:locals()) + for i, j in pairs(v:locals()) do + io.write("locals count:"..j:count().."\t") + io.write("locals type:"..j:type().."\t") + end + io.write(v:code().."\n") end else print(colors("%{red}".."section doesnt exist.")) diff --git a/bruiser/tablegen b/bruiser/tablegen index 5d576cd..66e1d73 160000 --- a/bruiser/tablegen +++ b/bruiser/tablegen @@ -1 +1 @@ -Subproject commit 5d576cd5166087bfc3ab2c02565ae9025211aebe +Subproject commit 66e1d73de5160333a8552f4e28027e8dcd69cb3b -- cgit v1.2.3