From 7db456eccbddff346fc62bea2700d4847899c3be Mon Sep 17 00:00:00 2001 From: pannous Date: Tue, 10 Dec 2024 12:53:01 +0100 Subject: [PATCH] NEW LIST with std::shared_ptr items; List variants; NOT OK! (undo!) --- source/Angle.cpp | 18 +++++++++--------- source/Code.h | 3 ++- source/tests.cpp | 16 ++++++++-------- source/wasm_reader.cpp | 5 ++--- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/source/Angle.cpp b/source/Angle.cpp index 0f426d0..bcaf7cd 100644 --- a/source/Angle.cpp +++ b/source/Angle.cpp @@ -375,16 +375,16 @@ Signature &groupFunctionArgs(Function &function, Node ¶ms) { function.is_polymorphic = true; // function.is_used … todo copy other attributes? function.signature = *new Signature();// empty - function.variants.add(&old_variant); - function.variants.add(&new_variant); + function.variants.add(old_variant); + function.variants.add(new_variant); } else if (function.is_polymorphic) { variant = new Function(); - for (Function *fun: function.variants) - if (fun->signature == signature) - return fun->signature;// signature; + for (Function &fun: function.variants) + if (fun.signature == signature) + return fun.signature;// signature; variant->name = function.name; variant->signature = signature; - function.variants.add(variant); + function.variants.add(*variant); } else if (!already_defined) { function.signature = signature; } @@ -1805,8 +1805,8 @@ Function *use_required(Function *function) { functions["proc_exit"].is_used = true; if (function->name == "puts") functions["fd_write"].is_used = true; - for (Function *variant: function->variants) { - addLibraryFunctionAsImport(*variant); + for (Function &variant: function->variants) { + addLibraryFunctionAsImport(variant); } for (String &alias: aliases(function->name)) { if (alias == function->name)continue; @@ -1814,7 +1814,7 @@ Function *use_required(Function *function) { if (ali)addLibraryFunctionAsImport(*ali); } for (auto vari: function->variants) { - vari->is_used = true; + vari.is_used = true; } // for(Function& dep:function.required) // dep.is_used = true; diff --git a/source/Code.h b/source/Code.h index 677f01b..5aafa0b 100644 --- a/source/Code.h +++ b/source/Code.h @@ -1302,7 +1302,8 @@ class Function { bool is_builtin = false;// hard coded functions, tests only? todo remove bool is_used = false;// called imports / buildins bool is_polymorphic = false;// IF polymorph, this 'Function' acts as abstract only, all REAL Functions are in variants - List variants;// = 20;//={.capacity=20};// multi dispatch! + List variants;// = 20;//={.capacity=20};// multi dispatch! +// List variants;// = 20;//={.capacity=20};// multi dispatch! // Code* code; // todo: use Map locals; // todo: use, instead of global locals! diff --git a/source/tests.cpp b/source/tests.cpp index dcdf3dd..d84e20a 100644 --- a/source/tests.cpp +++ b/source/tests.cpp @@ -409,12 +409,12 @@ void testPolymorphism() { auto function = functions["test"]; check_is(function.is_polymorphic, true); check_is(function.variants.size(), 2); - check_is(function.variants[0]->signature.size(), 1); + check_is(function.variants[0].signature.size(), 1); // check_is(function.variants[0].signature.parameters[0].type, (Type) strings); todo - check_is(function.variants[0]->signature.parameters[0].type, (Type) stringp); + check_is(function.variants[0].signature.parameters[0].type, (Type) stringp); auto variant = function.variants[1]; - check_is(variant->signature.size(), 1); - check_is(variant->signature.parameters[0].type, (Type) float32); + check_is(variant.signature.size(), 1); + check_is(variant.signature.parameters[0].type, (Type) float32); } void testPolymorphism2() { @@ -424,10 +424,10 @@ void testPolymorphism2() { auto function = functions["test"]; check_is(function.is_polymorphic, true); check_is(function.variants.size(), 2); - check_is(function.variants[0]->signature.size(), 1); - check_is(function.variants[0]->signature.parameters[0].type, (Type) int32); - check_is(function.variants[1]->signature.size(), 1); - check_is(function.variants[1]->signature.parameters[0].type, (Type) float32); + check_is(function.variants[0].signature.size(), 1); + check_is(function.variants[0].signature.parameters[0].type, (Type) int32); + check_is(function.variants[1].signature.size(), 1); + check_is(function.variants[1].signature.parameters[0].type, (Type) float32); } diff --git a/source/wasm_reader.cpp b/source/wasm_reader.cpp index 10ed97c..3464ed6 100644 --- a/source/wasm_reader.cpp +++ b/source/wasm_reader.cpp @@ -505,11 +505,10 @@ void consumeExportSection() { trace("function %s already has signature "s % func + fun.signature.serialize()); trace("function %s old code_index %d new code_index %d"s % func % fun.code_index % lower_index); Function &abstract = *new Function{.name=func, .module=module, .is_runtime=true, .is_polymorphic=true}; - abstract.variants.add(&fun); + abstract.variants.add(fun); module->functions[func] = abstract; -// fun = *abstract.variants.items[2]; + fun = abstract.variants.items[2]; fun = *new Function{.code_index=lower_index, .name=func, .module=fun.module, .is_runtime=true}; - abstract.variants.items[2] = &fun; } else { fun0.code_index = lower_index; fun.code_index = lower_index;