Skip to content

Commit

Permalink
NEW LIST with std::shared_ptr<S[]> items;
Browse files Browse the repository at this point in the history
List<Function> variants; NOT OK! (undo!)
  • Loading branch information
pannous committed Dec 10, 2024
1 parent 17bb6cf commit 7db456e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions source/Angle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,16 @@ Signature &groupFunctionArgs(Function &function, Node &params) {
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;
}
Expand Down Expand Up @@ -1805,16 +1805,16 @@ 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;
auto ali = findLibraryFunction(alias, false);
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;
Expand Down
3 changes: 2 additions & 1 deletion source/Code.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Function *> variants;// = 20;//={.capacity=20};// multi dispatch!
List<Function> variants;// = 20;//={.capacity=20};// multi dispatch!
// List<Function *> variants;// = 20;//={.capacity=20};// multi dispatch!

// Code* code; // todo: use
Map<String, Local> locals; // todo: use, instead of global locals!
Expand Down
16 changes: 8 additions & 8 deletions source/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}


Expand Down
5 changes: 2 additions & 3 deletions source/wasm_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7db456e

Please sign in to comment.