diff --git a/cpp/emulator.cpp b/cpp/emulator.cpp index 1446b76..54b8d88 100644 --- a/cpp/emulator.cpp +++ b/cpp/emulator.cpp @@ -6,8 +6,8 @@ #include int main(int argc, char *argv[]) { - std::ifstream f; - std::streamsize fsize; + std::ifstream bytecode_if; + std::streamsize bytecode_size; uint8_t * bytecode; if (argc < 2) { @@ -18,14 +18,13 @@ int main(int argc, char *argv[]) { /* reading bytecode */ - f.open(argv[1], std::ios::binary | std::ios::ate); - fsize = f.tellg(); - f.seekg(0, std::ios::beg); + bytecode_if.open(argv[1], std::ios::binary | std::ios::ate); + bytecode_size = bytecode_if.tellg(); + bytecode_if.seekg(0, std::ios::beg); - bytecode = new uint8_t[fsize]; - f.read((char*)bytecode, fsize); - - VM vm(bytecode, sizeof(bytecode)); + bytecode = new uint8_t[bytecode_size]; + bytecode_if.read((char*)bytecode, bytecode_size); + VM vm(bytecode, bytecode_size); vm.run(); vm.status(); return 0; diff --git a/python/assembler.py b/python/assembler.py index 59a92e0..1e474e4 100644 --- a/python/assembler.py +++ b/python/assembler.py @@ -36,22 +36,23 @@ assembled = bytearray() def to_uint8(data): alphanum = re.compile("^[0-9]+$") if isinstance(data, int): - return struct.pack("".format(sys.argv[0])) + return + + with open(sys.argv[1], 'r') as f: gen = (line.strip("\n") for line in f if line != "\n") + flag = None for line in gen: if line.startswith(tuple(section_names)): @@ -105,6 +121,8 @@ def main(): assemble_data(line) elif flag == section_flags["CODE:"]: assemble_code(line) + if not flag: + sys.stderr.write("Nothing was assembled! Did you use the section delimiters?\n") with open("./out.gipu", 'wb') as f: f.write(assembled)