-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix load-global-var bytecode. (#1377)
The wide variant wasn't immediately following the non-wide one.
- Loading branch information
Showing
33 changed files
with
355 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2023 Toitware ApS. | ||
// Use of this source code is governed by a Zero-Clause BSD license that can | ||
// be found in the tests/LICENSE file. | ||
|
||
#include <string> | ||
|
||
#include "../../src/top.h" | ||
#include "../../src/bytecodes.h" | ||
|
||
namespace toit { | ||
|
||
using namespace compiler; | ||
|
||
#define BYTECODE_NAME(name, length, format, print) #name, | ||
const char* ALL_BYTECODE_NAMES[] { | ||
BYTECODES(BYTECODE_NAME) "ILLEGAL" | ||
}; | ||
#undef BYTECODE_NAME | ||
|
||
static bool ends_with(const std::string& str, const std::string& suffix) { | ||
return str.size() >= suffix.size() && | ||
str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
int count = sizeof(ALL_BYTECODE_NAMES) / sizeof(ALL_BYTECODE_NAMES[0]); | ||
std::string last; | ||
for (int i = 0; i < count; i++) { | ||
auto current = std::string(ALL_BYTECODE_NAMES[i]); | ||
if (ends_with(current, "WIDE")) { | ||
printf("checking %s\n", current.c_str()); | ||
if (last + "_WIDE" != current) { | ||
FATAL("WIDE bytecode must be non-wide + 1"); | ||
} | ||
} | ||
last = current; | ||
} | ||
return 0; | ||
} | ||
|
||
} | ||
|
||
int main(int argc, char** argv) { | ||
toit::throwing_new_allowed = true; | ||
return toit::main(argc, argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2023 Toitware ApS. | ||
// Use of this source code is governed by a Zero-Clause BSD license that can | ||
// be found in the tests/LICENSE file. | ||
|
||
#include <string> | ||
#include <stdio.h> | ||
|
||
#include "../../src/bytecodes.h" | ||
|
||
namespace toit { | ||
|
||
using namespace compiler; | ||
|
||
struct Bytecode { | ||
const char* name; | ||
int length; | ||
const char* format; | ||
const char* print; | ||
}; | ||
|
||
#define BYTECODE_STRUCT(name_, length_, format_, print_) \ | ||
{ .name=#name_, .length=length_, .format=#format_, .print=print_ }, | ||
const Bytecode ALL_BYTECODES[] { | ||
BYTECODES(BYTECODE_STRUCT) | ||
{ .name="ILLEGAL", .length=0, .format="", .print="" } | ||
}; | ||
#undef BYTECODE_STRUCT | ||
|
||
int main(int argc, char** argv) { | ||
int count = sizeof(ALL_BYTECODES) / sizeof(ALL_BYTECODES[0]); | ||
// Don't print the illegal one. | ||
for (int i = 0; i < count - 1; i++) { | ||
printf("%s %d %s %s\n", | ||
ALL_BYTECODES[i].name, | ||
ALL_BYTECODES[i].length, | ||
ALL_BYTECODES[i].format, | ||
ALL_BYTECODES[i].print); | ||
} | ||
return 0; | ||
} | ||
|
||
} | ||
|
||
int main(int argc, char** argv) { | ||
return toit::main(argc, argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (C) 2023 Toitware ApS. | ||
// Use of this source code is governed by a Zero-Clause BSD license that can | ||
// be found in the tests/LICENSE file. | ||
import expect show * | ||
import host.file | ||
import ...tools.snapshot | ||
|
||
parse_bytecodes bytes: | ||
str := bytes.to_string | ||
lines := str.split "\n" | ||
lines.map --in_place: it.trim | ||
lines.filter --in_place: it != "" | ||
return lines.map: | line/string | | ||
space := line.index_of " " | ||
name := line[..space] | ||
size := int.parse line[space + 1..space + 2] | ||
format_space := line.index_of " " (space + 3) | ||
format := line[space + 3..format_space] | ||
description := line[format_space + 1..] | ||
[name, size, format, description] | ||
|
||
main args: | ||
c_bytecode_list := parse_bytecodes (file.read_content args[0]) | ||
expect_equals BYTE_CODES.size c_bytecode_list.size | ||
used_c_formats := {} | ||
format_mapping := {:} | ||
BYTE_CODES.size.repeat: | ||
toit_bytecode /Bytecode := BYTE_CODES[it] | ||
c_bytecode := c_bytecode_list[it] | ||
if not format_mapping.contains toit_bytecode.format: | ||
format_mapping[toit_bytecode.format] = c_bytecode[2] | ||
expect_not (used_c_formats.contains c_bytecode[2]) | ||
used_c_formats.add c_bytecode[2] | ||
expect_equals toit_bytecode.name c_bytecode[0] | ||
expect_equals toit_bytecode.size c_bytecode[1] | ||
expect_equals format_mapping[toit_bytecode.format] c_bytecode[2] | ||
expect_equals toit_bytecode.description c_bytecode[3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.