From 64603667816c146cfa27d4a28ea4c9cec1f610a2 Mon Sep 17 00:00:00 2001 From: Jesse Chen Date: Wed, 1 Nov 2023 14:54:32 +0800 Subject: [PATCH] if --- doc/windows_qemu.md | 9 +++++++++ src/Token.hpp | 4 ++++ tests/cases/binaryExpression.pas | 8 ++------ tests/cases/if.pas | 9 +++++++++ tests/e2e.cpp | 6 +++--- 5 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 doc/windows_qemu.md create mode 100644 tests/cases/if.pas diff --git a/doc/windows_qemu.md b/doc/windows_qemu.md new file mode 100644 index 0000000..1a72070 --- /dev/null +++ b/doc/windows_qemu.md @@ -0,0 +1,9 @@ +# QEMU创建windows arm64 linux / openwrt + +### openwrt官方文档 +https://openwrt.org/docs/guide-user/virtualization/qemu + +### command +``` +"C:\Program Files\qemu\qemu-system-aarch64" -machine virt -cpu cortex-a57 -m 1024 -drive file=ubuntu-23.04-amd64.iso,index=0,media=disk,format=raw -device virtio-net,netdev=net0 -netdev user,id=net0 +``` \ No newline at end of file diff --git a/src/Token.hpp b/src/Token.hpp index 7c558e0..31cb457 100644 --- a/src/Token.hpp +++ b/src/Token.hpp @@ -42,6 +42,7 @@ enum Token : int { tok_assign_type = -16, tok_result = -17, + tok_if = -18, }; class Tokenizer { @@ -110,6 +111,9 @@ class Tokenizer { if (identifier == "var") { return Token::tok_var; } + if (identifier == "if") { + return Token::tok_if; + } return Token::tok_identifier; } diff --git a/tests/cases/binaryExpression.pas b/tests/cases/binaryExpression.pas index c1344d3..5040378 100644 --- a/tests/cases/binaryExpression.pas +++ b/tests/cases/binaryExpression.pas @@ -1,12 +1,8 @@ program Hello; var a:Integer; var b:Integer; -var c:Integer; -var d:Integer; begin a := 11; - b := 22; - c := 42; - d := (a+(c-b)); - writeln(d); + b := 42; + Result := (a+b); end. \ No newline at end of file diff --git a/tests/cases/if.pas b/tests/cases/if.pas new file mode 100644 index 0000000..4fcbb3a --- /dev/null +++ b/tests/cases/if.pas @@ -0,0 +1,9 @@ +program Hello; +var i:Integer; +begin +i := 1; +if i = 1 then +begin + writeln(i); +end; +end. \ No newline at end of file diff --git a/tests/e2e.cpp b/tests/e2e.cpp index 3020eb3..74abe8c 100644 --- a/tests/e2e.cpp +++ b/tests/e2e.cpp @@ -44,7 +44,7 @@ template void printAssemblyMachineCode(T &&runtime) { } TEST(compiler_e2e, parser) { - std::ifstream t(workspace / "tests" / "cases" / "return.pas"); + std::ifstream t(workspace / "tests" / "cases" / "if.pas"); std::stringstream buffer; buffer << t.rdbuf(); Tokenizer tokenizer(buffer.str()); @@ -53,8 +53,8 @@ TEST(compiler_e2e, parser) { auto program = parser.parse(); auto fun = createJitInt(program->codegen()); std::cout << "ptr: " << std::hex << (void *)fun << std::endl; - const int result = fun(); - std::cout << std::dec << result << std::endl; + // const int result = fun(); + // std::cout << std::dec << result << std::endl; // printAssemblyMachineCode(program->codegen()); }