From 2b7347deabd9f7cf3af6a6830ed70957d1157264 Mon Sep 17 00:00:00 2001 From: Xie Zicong Date: Wed, 8 Jan 2025 12:12:49 +0800 Subject: [PATCH] Fix related compilation warnings, release hello world test code and bytecode. --- prototype/compiler.cc | 2 ++ prototype/hello-world.aq | 4 ++++ prototype/hello-world.aqbc | Bin 0 -> 125 bytes prototype/vm.c | 16 ++++++++-------- 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 prototype/hello-world.aq create mode 100644 prototype/hello-world.aqbc diff --git a/prototype/compiler.cc b/prototype/compiler.cc index c5fad04..102cda3 100644 --- a/prototype/compiler.cc +++ b/prototype/compiler.cc @@ -4769,6 +4769,8 @@ void BytecodeGenerator::HandleStmt(StmtNode* stmt, body_code.push_back(Bytecode(_AQVM_OPERATOR_GOTO, body_name_ptr_index)); size_t void_name_index = global_memory_.Add(0x01, 3, "$0"); size_t void_name_ptr_index = global_memory_.Add(0x06, 8); + code.push_back(Bytecode(_AQVM_OPERATOR_PTR, void_name_index, + void_name_ptr_index)); code.push_back(Bytecode(_AQVM_OPERATOR_IF, condition_index, body_name_ptr_index, void_name_ptr_index)); break; diff --git a/prototype/hello-world.aq b/prototype/hello-world.aq new file mode 100644 index 0000000..302e182 --- /dev/null +++ b/prototype/hello-world.aq @@ -0,0 +1,4 @@ +int print(char* str){} +void main(){ + print("Hello World!"); +} \ No newline at end of file diff --git a/prototype/hello-world.aqbc b/prototype/hello-world.aqbc new file mode 100644 index 0000000000000000000000000000000000000000..8c03d604073a2e79d9d4038578c4487785d58cae GIT binary patch literal 125 zcmZ<^baG}u0QG{R%)Al=AIS1Z&B@7E2+uFdNl}DL2nq_O0fCYdkO2f@KsFmxl10S; au8a-EIDy>6%sd8G1~yh9c@Z`yK6wB(m=HDq literal 0 HcmV?d00001 diff --git a/prototype/vm.c b/prototype/vm.c index 1d782cf..6016171 100644 --- a/prototype/vm.c +++ b/prototype/vm.c @@ -1059,12 +1059,12 @@ int DIV(size_t result, size_t operand1, size_t operand2) { GetUint64tData(operand1) / GetUint64tData(operand2)); break; case 0x04: - SetFloatData(result, - GetUint64tData(operand1) / GetUint64tData(operand2)); + SetFloatData(result, (double)GetUint64tData(operand1) / + (double)GetUint64tData(operand2)); break; case 0x05: - SetDoubleData(result, - GetUint64tData(operand1) / GetUint64tData(operand2)); + SetDoubleData(result, (double)GetUint64tData(operand1) / + (double)GetUint64tData(operand2)); break; case 0x06: SetUint64tData(result, @@ -2464,13 +2464,13 @@ int THROW() { return 0; } int WIDE() { return 0; } void print(InternalObject args, size_t return_value) { - SetIntData(return_value, printf((char*)GetPtrData(*args.index))); + SetIntData(return_value, printf("%s", (char*)GetPtrData(*args.index))); } unsigned int hash(const char* str) { unsigned long hash = 5381; int c; - while (c = *str++) { + while ((c = *str++)) { hash = ((hash << 5) + hash) + c; } return hash % 1024; @@ -2495,7 +2495,7 @@ void* AddFunction(void* location) { void* origin_location = location; size_t all_size = is_big_endian ? *(uint64_t*)location : SwapUint64t(*(uint64_t*)location); - printf("AddFunction Size: %lu\n", all_size); + printf("AddFunction Size: %zu\n", all_size); size_t commands_size = all_size; location = (void*)((uintptr_t)location + 8); struct FuncList* table = &func_table[hash(location)]; @@ -2886,7 +2886,7 @@ int main(int argc, char* argv[]) { bytecode_file = (void*)((uintptr_t)bytecode_file + memory->size / 2); } - printf("Memory size: %lu\n", *(uint8_t*)bytecode_file); + printf("Memory size: %hhu\n", *(uint8_t*)bytecode_file); while (bytecode_file < bytecode_end) { printf("AddFunction\n");