Skip to content

Commit

Permalink
CURRENT TESTS PASSED
Browse files Browse the repository at this point in the history
  (data $fest (i32.const 65552) "\18\00\01\00\03\00\00\00def\00")
  (data $test (i32.const 65564) "$\00\01\00\03\00\00\00abc\00")
  • Loading branch information
pannous committed Dec 9, 2024
1 parent 6529e7d commit 6c8f237
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
4 changes: 2 additions & 2 deletions source/Angle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ Node extractModifiers(Node &expression) {
Node &groupFunctionDefinition(Node &expression, Function &context) {
auto first = expression.first();
Node modifieres = extractModifiers(expression);
auto kw = expression.containsAny(function_keywords);
auto kw = expression.containsAny(function_keywords, false); // todo fest='def' QUOTED!!
if (expression.index(kw) != 0) error("function keywords must be first");
expression.children++;
expression.length--;
Expand Down Expand Up @@ -2088,7 +2088,7 @@ Node &analyze(Node &node, Function &function) {
return node;// nothing to be analyzed!
}
// if(function_keywords.contains(firstName))
if (node.containsAny(function_keywords))
if (node.containsAny(function_keywords, false))
return groupFunctionDefinition(node, function);

if (type == operators or type == call or isFunction(node)) //todo merge/clean
Expand Down
5 changes: 3 additions & 2 deletions source/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,10 +1325,11 @@ bool Node::contains(const char *string) {
}


chars Node::containsAny(List<chars> strings) {
chars Node::containsAny(List<chars> strings, bool allow_quoted/*=true*/) {
for (Node &chile: *this)
for (chars string: strings)
if (chile.name == string)return string;
if (chile.name == string and (allow_quoted or chile.kind != Kind::strings))
return string;
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion source/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ class Node {

bool contains(const char *string);

chars containsAny(List<chars> strings);
chars containsAny(List<chars> strings, bool allow_quoted = true);

int size();

Expand Down
2 changes: 1 addition & 1 deletion source/Wasp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool eval_via_emit = true;// << todo! assert_is(…)

// WE DON'T NEED THIS in main, we can just use CANONICAL ABI lowering, e.g. for strings: [i32, i32]
// WE DO NEED THIS for easier WASM to js calls, avoiding new_string
bool use_wasm_strings = false;// stringref in wat
bool use_wasm_strings = false;// stringref in wat // used to work with wasm-as but Chrome removed flag?
bool use_wasm_structs = false;// struct in wat
bool use_wasm_arrays = false; // array in wat

Expand Down
8 changes: 8 additions & 0 deletions source/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ void testForLoops() {
// assert_emit("sum=0;for i=1..3;sum+=i;sum", 6);
}

void testNamedDataSections() {
assert_emit("fest='def';test='abc'", "abc");
exit(0);
}

void testAutoSmarty() {
assert_emit("11", 11);
assert_emit("'c'", 'c');
Expand Down Expand Up @@ -3528,6 +3533,9 @@ void pleaseFix() {
// 2022-12-28 : 3 sec WITH runtime_emit, wasmedge on M1 WOW ALL TESTS PASSING
// ⚠️ CANNOT USE assert_emit in WASM! ONLY via void testRun();
void testCurrent() {
// testNamedDataSections();
assert_is("1 2 3", Node(1, 2, 3, 0))

testForLoops();
testParamizedKeys();
testAutoSmarty();
Expand Down
37 changes: 28 additions & 9 deletions source/wasm_emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,15 +745,20 @@ Code emitWasmArray(Node &node, Function &context) {

// just register the name for custom section here
void addNamedDataSegment(int pointer, Node &node) {
if (not node.name.empty()) { // todo: end this segment even if next one not named.
named_data_segments++;
data_segment_offsets.add(pointer);
data_segment_names.add(node.name);
// todo: un-redundant:
String name = "data";
if (not node.name.empty())
name = node.name;
else if (node.parent and not node.parent->name.empty())
name = node.parent->name;
// else todow("all data_segments should have names!");
// { // todo: end this segment even if next one not named.
named_data_segments++;
data_segment_offsets.add(pointer);
data_segment_names.add(name);
// todo: un-redundant:
// referenceIndices.insert_or_assign(node.name, pointer);
// referenceDataIndices.insert_or_assign(node.name, pointer + array_header_length);
// referenceMap[node.name] = node;
} else todow("all data_segments should have names!");
}

// todo emitPrimitiveArray vs just emitNode as it is (with child*)
Expand Down Expand Up @@ -1347,6 +1352,8 @@ Code emitString(Node &node, Function &context) {

int last_pointer = data_index_end;
String &string = *node.value.string;

addNamedDataSegment(last_pointer, node.parent and not node.parent->name.empty() ? *node.parent : node);
referenceMap[string] = node;
if (string and referenceIndices.has(string)) {
// todo: reuse same strings even if different pointer, aor make same pointer before
Expand Down Expand Up @@ -3702,7 +3709,7 @@ Code emitDataSections() { // needs memory section too!
for (int i = 0; i <= named_data_segments; i++) {
datas.addByte(00);// memory id always 0 until multi-memory
datas.addByte(0x41);// opcode for i32.const offset: followed by unsignedLEB128 value:
int offset = runtime_data_offset ? runtime_data_offset : 0;
int offset = runtime_data_offset; // or 0
int end = data_index_end;
if (i > 0)offset = data_segment_offsets[i - 1]; // runtime_data_offset builtin ?
if (i < named_data_segments)end = data_segment_offsets[i];
Expand Down Expand Up @@ -3849,8 +3856,20 @@ Code emitNameSection() {
auto localNames = Code(local_names) + encodeVector(Code(usedLocals) + localNameMap);
auto typeNames = Code(type_names) + encodeVector(Code(usedTypes) + typeNameMap);
auto globalNames = Code(global_names) + encodeVector(Code(usedGlobals) + globalNameMap);
int named_data_segments = 1;
auto dataNames = Code(data_names) + encodeVector(Code(1)/*count*/ + Code(0) /*index*/ + Code("wasp_data"));

// custom data section for data names split in emitDataSections
// auto dataNames = Code(data_names) + encodeVector(Code(1)/*count*/ + Code(0) /*index*/ + Code("wasp_data"));
auto dataNames = Code();
dataNames.addInt(named_data_segments + 1); // Total count of named data segments
dataNames.addInt(0); // Index of the data segment
dataNames.add(Code("wasp_data")); // Name of the data segment
for (int i = 1; i <= named_data_segments; i++) {
dataNames.addInt(i); // Index of the data segment
String &name = data_segment_names[i - 1];
dataNames.add(Code(name)); // Name of the data segment
}
dataNames = Code(data_names) + encodeVector(dataNames);

auto fieldNames = Code(field_names) + encodeVector(Code(usedFields) + fieldNameMap);// usedTypes ??

// The name section is a custom section whose name string is itself β€˜πš—πšŠπš–πšŽβ€™.
Expand Down

0 comments on commit 6c8f237

Please sign in to comment.