3131
3232#include " waforth_core.h"
3333#include " waforth_rt.h"
34+ #include " waforth_wabt_wasm-rt-exceptions-impl_c.h"
35+ #include " waforth_wabt_wasm-rt-exceptions_h.h"
36+ #include " waforth_wabt_wasm-rt-impl-tableops_inc.h"
3437#include " waforth_wabt_wasm-rt-impl_c.h"
3538#include " waforth_wabt_wasm-rt-impl_h.h"
39+ #include " waforth_wabt_wasm-rt-mem-impl-helper_inc.h"
40+ #include " waforth_wabt_wasm-rt-mem-impl_c.h"
3641#include " waforth_wabt_wasm-rt_h.h"
3742
3843namespace fs = std::filesystem;
@@ -121,7 +126,7 @@ wabt::Result compileToNative(wabt::Module &mod, const std::string &init, const s
121126 std::ostringstream wds;
122127 wds << " waforthc." << rand ();
123128 auto wd = fs::temp_directory_path () / wds.str ();
124- defer _ (nullptr , [=](...) { fs::remove_all (wd); });
129+ // defer _(nullptr, [=](...) { fs::remove_all(wd); });
125130 if (!fs::exists (wd) && !fs::create_directory (wd)) {
126131 std::cerr << " error creating working directory " << wd << std::endl;
127132 return wabt::Result::Error;
@@ -144,14 +149,31 @@ wabt::Result compileToNative(wabt::Module &mod, const std::string &init, const s
144149 wcopt.module_name = " waforth" ;
145150 wabt::FileStream c_stream ((wd / " _waforth.c" ).string ());
146151 wabt::FileStream h_stream ((wd / " _waforth.h" ).string ());
147- CHECK_RESULT (WriteC (&c_stream, &h_stream, " _waforth.h" , &mod, wcopt));
152+ CHECK_RESULT (WriteC ({ &c_stream} , &h_stream, &c_stream, " _waforth.h" , " " , &mod, wcopt));
148153 wabt::FileStream ((wd / " _waforth_rt.c" ).string ()).WriteData (waforth_rt, sizeof (waforth_rt));
149- wabt::FileStream ((wd / " wasm-rt-impl.c" ).string ()).WriteData (waforth_wabt_wasm_rt_impl_c, sizeof (waforth_wabt_wasm_rt_impl_c));
150- wabt::FileStream ((wd / " wasm-rt-impl.h" ).string ()).WriteData (waforth_wabt_wasm_rt_impl_h, sizeof (waforth_wabt_wasm_rt_impl_h));
151154 wabt::FileStream ((wd / " wasm-rt.h" ).string ()).WriteData (waforth_wabt_wasm_rt_h, sizeof (waforth_wabt_wasm_rt_h));
155+ wabt::FileStream ((wd / " wasm-rt-impl.h" ).string ()).WriteData (waforth_wabt_wasm_rt_impl_h, sizeof (waforth_wabt_wasm_rt_impl_h));
156+ wabt::FileStream ((wd / " wasm-rt-impl.c" ).string ()).WriteData (waforth_wabt_wasm_rt_impl_c, sizeof (waforth_wabt_wasm_rt_impl_c));
157+ wabt::FileStream ((wd / " wasm-rt-impl-tableops.inc" ).string ())
158+ .WriteData (waforth_wabt_wasm_rt_impl_tableops_inc, sizeof (waforth_wabt_wasm_rt_impl_tableops_inc));
159+ wabt::FileStream ((wd / " wasm-rt-exceptions.h" ).string ()).WriteData (waforth_wabt_wasm_rt_exceptions_h, sizeof (waforth_wabt_wasm_rt_exceptions_h));
160+ wabt::FileStream ((wd / " wasm-rt-exceptions-impl.c" ).string ())
161+ .WriteData (waforth_wabt_wasm_rt_exceptions_impl_c, sizeof (waforth_wabt_wasm_rt_exceptions_impl_c));
162+ wabt::FileStream ((wd / " wasm-rt-mem-impl.c" ).string ()).WriteData (waforth_wabt_wasm_rt_mem_impl_c, sizeof (waforth_wabt_wasm_rt_mem_impl_c));
163+ wabt::FileStream ((wd / " wasm-rt-mem-impl-helper.inc" ).string ())
164+ .WriteData (waforth_wabt_wasm_rt_mem_impl_helper_inc, sizeof (waforth_wabt_wasm_rt_mem_impl_helper_inc));
152165 }
153166
154- std::vector<std::string> cmd = {cc, " -o" , outfile, (wd / " _waforth_rt.c" ).string (), (wd / " _waforth.c" ).string (), (wd / " wasm-rt-impl.c" ).string ()};
167+ std::vector<std::string> cmd = {
168+ cc,
169+ " -o" ,
170+ outfile,
171+ (wd / " _waforth_rt.c" ).string (),
172+ (wd / " _waforth.c" ).string (),
173+ (wd / " wasm-rt-impl.c" ).string (),
174+ (wd / " wasm-rt-exceptions-impl.c" ).string (),
175+ (wd / " wasm-rt-mem-impl.c" ).string (),
176+ };
155177 cmd.insert (cmd.end (), cflags.begin (), cflags.end ());
156178 if (runChild (cmd) != 0 ) {
157179 std::cerr << " error compiling" ;
@@ -346,21 +368,21 @@ wabt::Result compileToModule(std::vector<wabt::Module> &words, const std::vector
346368 wabt::Module &compiled, wabt::Errors &errors) {
347369 CHECK_RESULT (readModule (" waforth.wasm" , waforth_core, sizeof (waforth_core), compiled, errors));
348370
349- auto dsf = wabt::MakeUnique <wabt::DataSegmentModuleField>();
371+ auto dsf = std::make_unique <wabt::DataSegmentModuleField>();
350372 wabt::DataSegment &ds = dsf->data_segment ;
351373 ds.memory_var = wabt::Var (0 , wabt::Location ());
352- ds.offset .push_back (wabt::MakeUnique <wabt::ConstExpr>(wabt::Const::I32 (dataOffset)));
374+ ds.offset .push_back (std::make_unique <wabt::ConstExpr>(wabt::Const::I32 (dataOffset)));
353375 ds.data = data;
354376 compiled.AppendField (std::move (dsf));
355377
356- compiled.globals [HERE_GLOBAL_INDEX]->init_expr = wabt::ExprList{wabt::MakeUnique <wabt::ConstExpr>(wabt::Const::I32 (dataOffset + data.size ()))};
357- compiled.globals [LATEST_GLOBAL_INDEX]->init_expr = wabt::ExprList{wabt::MakeUnique <wabt::ConstExpr>(wabt::Const::I32 (latest))};
378+ compiled.globals [HERE_GLOBAL_INDEX]->init_expr = wabt::ExprList{std::make_unique <wabt::ConstExpr>(wabt::Const::I32 (dataOffset + data.size ()))};
379+ compiled.globals [LATEST_GLOBAL_INDEX]->init_expr = wabt::ExprList{std::make_unique <wabt::ConstExpr>(wabt::Const::I32 (latest))};
358380
359381 for (auto &word : words) {
360382 assert (word.funcs .size () == 1 );
361383 // compiled.funcs.push_back(word.funcs[0]);
362384
363- auto ff = wabt::MakeUnique <wabt::FuncModuleField>();
385+ auto ff = std::make_unique <wabt::FuncModuleField>();
364386 auto &f = ff->func ;
365387 f.name = word.funcs [0 ]->name ;
366388 f.decl = word.funcs [0 ]->decl ;
@@ -371,15 +393,15 @@ wabt::Result compileToModule(std::vector<wabt::Module> &words, const std::vector
371393
372394 assert (word.elem_segments .size () == 1 );
373395 auto elem = word.elem_segments [0 ];
374- auto esf = wabt::MakeUnique <wabt::ElemSegmentModuleField>();
396+ auto esf = std::make_unique <wabt::ElemSegmentModuleField>();
375397 wabt::ElemSegment &es = esf->elem_segment ;
376398 es.kind = elem->kind ;
377399 es.name = elem->name ;
378400 es.table_var = elem->table_var ;
379401 es.elem_type = elem->elem_type ;
380402 assert (elem->elem_type = wabt::Type::FuncRef);
381403 es.offset = std::move (elem->offset );
382- es.elem_exprs .push_back (wabt::ExprList{wabt::MakeUnique <wabt::RefFuncExpr>(wabt::Var (compiled.funcs .size () - 1 , wabt::Location ()))});
404+ es.elem_exprs .push_back (wabt::ExprList{std::make_unique <wabt::RefFuncExpr>(wabt::Var (compiled.funcs .size () - 1 , wabt::Location ()))});
383405 compiled.AppendField (std::move (esf));
384406 }
385407
0 commit comments