diff --git a/build/.ninja_deps b/build/.ninja_deps index 8eaeabe..09ee869 100644 Binary files a/build/.ninja_deps and b/build/.ninja_deps differ diff --git a/build/.ninja_log b/build/.ninja_log index 266c597..4d5a985 100644 --- a/build/.ninja_log +++ b/build/.ninja_log @@ -1,23 +1,24 @@ # ninja log v7 -13 4576 1781796718440262330 CMakeFiles/saqut.dir/src/core/sourcefile.cpp.o 20f68631dd335029 -13 4805 1781796718441539505 CMakeFiles/saqut.dir/src/lexer/lexer.cpp.o 5fd259c0401f3e22 -1 2117 1781796771817437208 CMakeFiles/saqut.dir/src/tokenizer/tokenizer.cpp.o fbabe80dcb141239 -4580 9322 1781796723007277591 CMakeFiles/saqut.dir/src/parser/parser.cpp.o 59cdb5935c541b26 -21 6876 1781796718448262357 CMakeFiles/saqut.dir/src/parser/nodes/program.cpp.o 9313cba8d8daffed -16 6700 1781796718443848488 CMakeFiles/saqut.dir/src/parser/nodes/identifier.cpp.o e3b5b38d75fcd2ca -15 7814 1781796718443331391 CMakeFiles/saqut.dir/src/parser/nodes/expressions.cpp.o 5f5bb01381a3c3ad -16 7589 1781796718444498682 CMakeFiles/saqut.dir/src/parser/nodes/literal.cpp.o 55743f37408c5f -21 7502 1781796718449424977 CMakeFiles/saqut.dir/src/parser/nodes/statements.cpp.o 3c8869307381c930 -14 6864 1781796718442362341 CMakeFiles/saqut.dir/src/parser/nodes/binary_expr.cpp.o 5cc8b697133bcf64 -15 6733 1781796718442847556 CMakeFiles/saqut.dir/src/parser/nodes/declarations.cpp.o c3d262615ede4c95 -1 4629 1781801148234045650 CMakeFiles/saqut.dir/src/main.cpp.o 3cfef7a665d5bf87 -4629 4900 1781801152862380672 saqut f2e198803c4dbffb -0 22 1781801180493522122 build.ninja 1876a59d627a585 -0 22 1781801180493522122 /home/saqut/Masaüstü/saqutcompiler/build/cmake_install.cmake 1876a59d627a585 -6733 11112 1781796725160284765 CMakeFiles/saqut.dir/src/symbol/symbol_collector.cpp.o ec4e483b8ddb4007 -4805 9685 1781796723232278341 CMakeFiles/saqut.dir/src/semantic/structural_validator.cpp.o 248faa3675024351 -6700 10405 1781796725127284655 CMakeFiles/saqut.dir/src/semantic/type_checker.cpp.o b29c133293d988b0 -1 850 1781801148235507662 CMakeFiles/saqut.dir/src/vm/interpreter.cpp.o b7dd80e002d68a1d -2 957 1781800866770475511 CMakeFiles/saqut.dir/src/ir/ir_function.cpp.o 10f5e8dfd1461d69 -2 718 1781800866771246136 CMakeFiles/saqut.dir/src/ir/ir_program.cpp.o 9518231d970828da -2 3169 1781800866771136888 CMakeFiles/saqut.dir/src/ir/ir_generator.cpp.o 10a1ed4e1f52e530 +9 5791 1781873515650062507 CMakeFiles/saqut.dir/src/core/sourcefile.cpp.o 20f68631dd335029 +9 3695 1781873515651524062 CMakeFiles/saqut.dir/src/lexer/lexer.cpp.o 5fd259c0401f3e22 +9708 12809 1781873525349661682 CMakeFiles/saqut.dir/src/tokenizer/tokenizer.cpp.o fbabe80dcb141239 +5791 11306 1781873521432823562 CMakeFiles/saqut.dir/src/parser/parser.cpp.o 59cdb5935c541b26 +1858 10835 1781873517499986074 CMakeFiles/saqut.dir/src/parser/nodes/program.cpp.o 9313cba8d8daffed +13 9874 1781873515654358239 CMakeFiles/saqut.dir/src/parser/nodes/identifier.cpp.o e3b5b38d75fcd2ca +9 8261 1781873515651958819 CMakeFiles/saqut.dir/src/parser/nodes/expressions.cpp.o 5f5bb01381a3c3ad +1821 10344 1781873517461987644 CMakeFiles/saqut.dir/src/parser/nodes/literal.cpp.o 55743f37408c5f +3695 10921 1781873519336910172 CMakeFiles/saqut.dir/src/parser/nodes/statements.cpp.o 3c8869307381c930 +9 9708 1781873515651752771 CMakeFiles/saqut.dir/src/parser/nodes/binary_expr.cpp.o 5cc8b697133bcf64 +9 7206 1781873515651861333 CMakeFiles/saqut.dir/src/parser/nodes/declarations.cpp.o c3d262615ede4c95 +9 12161 1781873515651633537 CMakeFiles/saqut.dir/src/main.cpp.o 3cfef7a665d5bf87 +13474 13718 1781873529115506016 saqut f2e198803c4dbffb +0 22 1781873613334363371 build.ninja 1876a59d627a585 +0 22 1781873613334280893 /home/saqut/Masaüstü/saqutcompiler/build/cmake_install.cmake 1876a59d627a585 +8261 13474 1781873523902721486 CMakeFiles/saqut.dir/src/symbol/symbol_collector.cpp.o ec4e483b8ddb4007 +5962 11851 1781873521603816495 CMakeFiles/saqut.dir/src/semantic/structural_validator.cpp.o 248faa3675024351 +7206 12730 1781873522847765087 CMakeFiles/saqut.dir/src/semantic/type_checker.cpp.o b29c133293d988b0 +9874 11363 1781873525515654821 CMakeFiles/saqut.dir/src/vm/interpreter.cpp.o b7dd80e002d68a1d +9 1858 1781873515651218159 CMakeFiles/saqut.dir/src/ir/ir_function.cpp.o 10f5e8dfd1461d69 +9 1821 1781873515651428931 CMakeFiles/saqut.dir/src/ir/ir_program.cpp.o 9518231d970828da +9 5962 1781873515651343783 CMakeFiles/saqut.dir/src/ir/ir_generator.cpp.o 10a1ed4e1f52e530 +1 8 1781873534882267590 /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/cmake.verify_globs 1813c41e0f312d7e diff --git a/build/CMakeFiles/TargetDirectories.txt b/build/CMakeFiles/TargetDirectories.txt index 014db8d..6832478 100644 --- a/build/CMakeFiles/TargetDirectories.txt +++ b/build/CMakeFiles/TargetDirectories.txt @@ -1,3 +1,4 @@ /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/saqut.dir +/home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/test.dir /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/edit_cache.dir /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/rebuild_cache.dir diff --git a/build/CMakeFiles/VerifyGlobs.cmake b/build/CMakeFiles/VerifyGlobs.cmake new file mode 100644 index 0000000..c434746 --- /dev/null +++ b/build/CMakeFiles/VerifyGlobs.cmake @@ -0,0 +1,37 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by CMake Version 4.3 + +# ALL_GOLDEN_SQT at CMakeLists.txt:40 (file) +file(GLOB_RECURSE NEW_GLOB LIST_DIRECTORIES false "/home/saqut/Masaüstü/saqutcompiler/tests/golden/*.sqt") +set(OLD_GLOB + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/basic.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/precedence.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/fibonacci/fib.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/logic/short_circuit.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/basic.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/do_while_once.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/dce.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/folding.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.sqt" + "/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.sqt" + ) +if(NOT "${NEW_GLOB}" STREQUAL "${OLD_GLOB}") + message("-- GLOB mismatch!") + set(NEW_ONLY ${NEW_GLOB}) + set(OLD_ONLY ${OLD_GLOB}) + list(REMOVE_ITEM NEW_ONLY ${OLD_GLOB}) + list(REMOVE_ITEM OLD_ONLY ${NEW_GLOB}) + if(NEW_ONLY) + message("The following files were added:") + foreach(VAR_FILE IN LISTS NEW_ONLY) + message(" +${VAR_FILE}") + endforeach() + endif() + if(OLD_ONLY) + message("The following files were removed:") + foreach(VAR_FILE IN LISTS OLD_ONLY) + message(" -${VAR_FILE}") + endforeach() + endif() + file(TOUCH_NOCREATE "/home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/cmake.verify_globs") +endif() diff --git a/build/CMakeFiles/cmake.verify_globs b/build/CMakeFiles/cmake.verify_globs new file mode 100644 index 0000000..2b38fac --- /dev/null +++ b/build/CMakeFiles/cmake.verify_globs @@ -0,0 +1 @@ +# This file is generated by CMake for checking of the VerifyGlobs.cmake file diff --git a/build/CMakeFiles/rules.ninja b/build/CMakeFiles/rules.ninja index 5bf065a..f37793f 100644 --- a/build/CMakeFiles/rules.ninja +++ b/build/CMakeFiles/rules.ninja @@ -79,6 +79,15 @@ rule RERUN_CMAKE generator = 1 +############################################# +# Rule for re-checking globbed directories. + +rule VERIFY_GLOBS + command = /usr/bin/cmake -P /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/VerifyGlobs.cmake + description = Re-checking globbed directories... + generator = 1 + + ############################################# # Rule for cleaning all built files. diff --git a/build/CTestTestfile.cmake b/build/CTestTestfile.cmake new file mode 100644 index 0000000..53680f2 --- /dev/null +++ b/build/CTestTestfile.cmake @@ -0,0 +1,30 @@ +# CMake generated Testfile for +# Source directory: /home/saqut/Masaüstü/saqutcompiler +# Build directory: /home/saqut/Masaüstü/saqutcompiler/build +# +# This file includes the relevant testing commands required for +# testing this directory and lists subdirectories to be tested as well. +add_test(unit_tests "bash" "/home/saqut/Masaüstü/saqutcompiler/tests/run.sh") +set_tests_properties(unit_tests PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;31;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_arithmetic_basic "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/basic.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/basic.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_arithmetic_basic PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_arithmetic_precedence "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/precedence.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/precedence.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_arithmetic_precedence PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_fibonacci_fib "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/fibonacci/fib.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/fibonacci/fib.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_fibonacci_fib PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_logic_short_circuit "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/logic/short_circuit.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/logic/short_circuit.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_logic_short_circuit PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_loops_basic "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/basic.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/basic.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_loops_basic PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_loops_do_while_once "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/do_while_once.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/do_while_once.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_loops_do_while_once PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_opt_dce_ir_opt "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/dce.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/dce.ir_opt.expected" "-DCOMMAND=ir" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_opt_dce_ir_opt PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;64;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_opt_folding_ir_opt "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/folding.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/folding.ir_opt.expected" "-DCOMMAND=ir" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_opt_folding_ir_opt PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;64;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_opt_run_opt "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_opt_run_opt PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_opt_run_opt_run_opt "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.run_opt.expected" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_opt_run_opt_run_opt PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;80;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") +add_test(golden_string_hello "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake") +set_tests_properties(golden_string_hello PROPERTIES _BACKTRACE_TRIPLES "/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;51;add_test;/home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt;0;") diff --git a/build/Testing/Temporary/CTestCostData.txt b/build/Testing/Temporary/CTestCostData.txt new file mode 100644 index 0000000..6ea1398 --- /dev/null +++ b/build/Testing/Temporary/CTestCostData.txt @@ -0,0 +1,15 @@ +unit_tests 10 0.448247 +golden_arithmetic_basic 10 0.000867734 +golden_fibonacci_fib 10 0.00093354 +golden_string_hello 10 0.000870371 +golden_arithmetic_precedence 9 0.000954052 +golden_loops_basic 9 0.000971074 +golden_loops_do_while_once 9 0.000986343 +golden_opt_dce 2 0.00441751 +golden_opt_folding 2 0.00456844 +golden_opt_dce_ir_opt 7 0.00126134 +golden_opt_folding_ir_opt 7 0.00129602 +golden_opt_run_opt 5 0.00182007 +golden_opt_run_opt_run_opt 5 0.00185853 +golden_logic_short_circuit 1 0.00907537 +--- diff --git a/build/Testing/Temporary/LastTest.log b/build/Testing/Temporary/LastTest.log new file mode 100644 index 0000000..9f8eee4 --- /dev/null +++ b/build/Testing/Temporary/LastTest.log @@ -0,0 +1,196 @@ +Start testing: Jun 19 15:53 +03 +---------------------------------------------------------- +1/12 Testing: unit_tests +1/12 Test: unit_tests +Command: "/usr/bin/bash" "/home/saqut/Masaüstü/saqutcompiler/tests/run.sh" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"unit_tests" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- +=== test_type === +test_type: TUM TESTLER GECTI +=== test_diagnostic === +--- printAll --- +test.sqt:3:5: hata [E001]: x tanımsız +test.sqt:7:9: hata [E003]: int'e string atanamaz + ipucu: açık dönüşüm gerekiyor +test.sqt:12:1: uyarı [W001]: y kullanılmıyor +— 2 hata, 1 uyarı +--- toJson --- +{"diagnostics":[{"code":"E001","level":"error","location":{"column":5,"file":"test.sqt","line":3,"offset":40},"message":"x tanımsız"},{"code":"E003","hint":"açık dönüşüm gerekiyor","level":"error","location":{"column":9,"file":"test.sqt","line":7,"offset":88},"message":"int'e string atanamaz"},{"code":"W001","level":"warning","location":{"column":1,"file":"test.sqt","line":12,"offset":150},"message":"y kullanılmıyor"}],"errorCount":2,"warningCount":1} +test_diagnostic: TUM TESTLER GECTI +=== TUM TESTLER GECTI === + +Test time = 4.48 sec +---------------------------------------------------------- +Test Passed. +"unit_tests" end time: Jun 19 15:53 +03 +"unit_tests" time elapsed: 00:00:04 +---------------------------------------------------------- + +2/12 Testing: golden_arithmetic_basic +2/12 Test: golden_arithmetic_basic +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/basic.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/basic.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_arithmetic_basic" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_arithmetic_basic" end time: Jun 19 15:53 +03 +"golden_arithmetic_basic" time elapsed: 00:00:00 +---------------------------------------------------------- + +3/12 Testing: golden_arithmetic_precedence +3/12 Test: golden_arithmetic_precedence +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/precedence.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/arithmetic/precedence.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_arithmetic_precedence" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_arithmetic_precedence" end time: Jun 19 15:53 +03 +"golden_arithmetic_precedence" time elapsed: 00:00:00 +---------------------------------------------------------- + +4/12 Testing: golden_fibonacci_fib +4/12 Test: golden_fibonacci_fib +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/fibonacci/fib.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/fibonacci/fib.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_fibonacci_fib" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_fibonacci_fib" end time: Jun 19 15:53 +03 +"golden_fibonacci_fib" time elapsed: 00:00:00 +---------------------------------------------------------- + +5/12 Testing: golden_logic_short_circuit +5/12 Test: golden_logic_short_circuit +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/logic/short_circuit.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/logic/short_circuit.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_logic_short_circuit" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_logic_short_circuit" end time: Jun 19 15:53 +03 +"golden_logic_short_circuit" time elapsed: 00:00:00 +---------------------------------------------------------- + +6/12 Testing: golden_loops_basic +6/12 Test: golden_loops_basic +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/basic.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/basic.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_loops_basic" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_loops_basic" end time: Jun 19 15:53 +03 +"golden_loops_basic" time elapsed: 00:00:00 +---------------------------------------------------------- + +7/12 Testing: golden_loops_do_while_once +7/12 Test: golden_loops_do_while_once +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/do_while_once.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/loops/do_while_once.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_loops_do_while_once" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_loops_do_while_once" end time: Jun 19 15:53 +03 +"golden_loops_do_while_once" time elapsed: 00:00:00 +---------------------------------------------------------- + +8/12 Testing: golden_opt_dce_ir_opt +8/12 Test: golden_opt_dce_ir_opt +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/dce.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/dce.ir_opt.expected" "-DCOMMAND=ir" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_opt_dce_ir_opt" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_opt_dce_ir_opt" end time: Jun 19 15:53 +03 +"golden_opt_dce_ir_opt" time elapsed: 00:00:00 +---------------------------------------------------------- + +9/12 Testing: golden_opt_folding_ir_opt +9/12 Test: golden_opt_folding_ir_opt +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/folding.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/folding.ir_opt.expected" "-DCOMMAND=ir" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_opt_folding_ir_opt" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_opt_folding_ir_opt" end time: Jun 19 15:53 +03 +"golden_opt_folding_ir_opt" time elapsed: 00:00:00 +---------------------------------------------------------- + +10/12 Testing: golden_opt_run_opt +10/12 Test: golden_opt_run_opt +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_opt_run_opt" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_opt_run_opt" end time: Jun 19 15:53 +03 +"golden_opt_run_opt" time elapsed: 00:00:00 +---------------------------------------------------------- + +11/12 Testing: golden_opt_run_opt_run_opt +11/12 Test: golden_opt_run_opt_run_opt +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/opt/run_opt.run_opt.expected" "-DOPTIMIZED=1" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_opt_run_opt_run_opt" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_opt_run_opt_run_opt" end time: Jun 19 15:53 +03 +"golden_opt_run_opt_run_opt" time elapsed: 00:00:00 +---------------------------------------------------------- + +12/12 Testing: golden_string_hello +12/12 Test: golden_string_hello +Command: "/usr/bin/cmake" "-DBINARY=/home/saqut/Masaüstü/saqutcompiler/build/saqut" "-DSOURCE=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.sqt" "-DEXPECTED=/home/saqut/Masaüstü/saqutcompiler/tests/golden/string/hello.expected" "-P" "/home/saqut/Masaüstü/saqutcompiler/cmake/run_golden.cmake" +Directory: /home/saqut/Masaüstü/saqutcompiler/build +"golden_string_hello" start time: Jun 19 15:53 +03 +Output: +---------------------------------------------------------- + +Test time = 0.01 sec +---------------------------------------------------------- +Test Passed. +"golden_string_hello" end time: Jun 19 15:53 +03 +"golden_string_hello" time elapsed: 00:00:00 +---------------------------------------------------------- + +End testing: Jun 19 15:53 +03 diff --git a/build/Testing/Temporary/LastTestsFailed.log b/build/Testing/Temporary/LastTestsFailed.log new file mode 100644 index 0000000..3c52512 --- /dev/null +++ b/build/Testing/Temporary/LastTestsFailed.log @@ -0,0 +1 @@ +3:golden_fibonacci_fib diff --git a/build/build.ninja b/build/build.ninja index 60d00e8..e34c5cd 100644 --- a/build/build.ninja +++ b/build/build.ninja @@ -18,7 +18,7 @@ ############################################# # Minimal version of Ninja required by this file -ninja_required_version = 1.5 +ninja_required_version = 1.8 ############################################# @@ -241,6 +241,18 @@ build saqut: CXX_EXECUTABLE_LINKER__saqut_Debug CMakeFiles/saqut.dir/src/core/so TARGET_SUPPORT_DIR = CMakeFiles/saqut.dir +############################################# +# Utility command for test + +build CMakeFiles/test.util: CUSTOM_COMMAND + COMMAND = cd /home/saqut/Masaüstü/saqutcompiler/build && /usr/bin/ctest + DESC = Running tests... + pool = console + restat = 1 + +build test: phony CMakeFiles/test.util + + ############################################# # Utility command for edit_cache @@ -281,17 +293,31 @@ build all: phony saqut # Built-in targets +############################################# +# Phony target to force glob verification run. + +build /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/VerifyGlobs.cmake_force: phony + + +############################################# +# Re-run CMake to check if globbed directories changed. + +build /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/cmake.verify_globs: VERIFY_GLOBS | /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/VerifyGlobs.cmake_force + pool = console + restat = 1 + + ############################################# # Re-run CMake if any of its inputs changed. -build build.ninja /home/saqut/Masaüstü/saqutcompiler/build/cmake_install.cmake: RERUN_CMAKE | /home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt /usr/share/cmake/Modules/CMakeCXXInformation.cmake /usr/share/cmake/Modules/CMakeCommonLanguageInclude.cmake /usr/share/cmake/Modules/CMakeGenericSystem.cmake /usr/share/cmake/Modules/CMakeInitializeConfigs.cmake /usr/share/cmake/Modules/CMakeLanguageInformation.cmake /usr/share/cmake/Modules/CMakeSystemSpecificInformation.cmake /usr/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake /usr/share/cmake/Modules/Compiler/CMakeCommonCompilerMacros.cmake /usr/share/cmake/Modules/Compiler/GNU-CXX.cmake /usr/share/cmake/Modules/Compiler/GNU.cmake /usr/share/cmake/Modules/Internal/CMakeCXXLinkerInformation.cmake /usr/share/cmake/Modules/Internal/CMakeCommonLinkerInformation.cmake /usr/share/cmake/Modules/Linker/GNU-CXX.cmake /usr/share/cmake/Modules/Linker/GNU.cmake /usr/share/cmake/Modules/Platform/Linker/GNU.cmake /usr/share/cmake/Modules/Platform/Linker/Linux-GNU-CXX.cmake /usr/share/cmake/Modules/Platform/Linker/Linux-GNU.cmake /usr/share/cmake/Modules/Platform/Linux-GNU-CXX.cmake /usr/share/cmake/Modules/Platform/Linux-GNU.cmake /usr/share/cmake/Modules/Platform/Linux-Initialize.cmake /usr/share/cmake/Modules/Platform/Linux.cmake /usr/share/cmake/Modules/Platform/UnixPaths.cmake CMakeCache.txt CMakeFiles/4.3.3/CMakeCXXCompiler.cmake CMakeFiles/4.3.3/CMakeSystem.cmake +build build.ninja /home/saqut/Masaüstü/saqutcompiler/build/cmake_install.cmake /home/saqut/Masaüstü/saqutcompiler/build/CTestTestfile.cmake: RERUN_CMAKE /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/cmake.verify_globs | /home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/VerifyGlobs.cmake /usr/share/cmake/Modules/CMakeCXXInformation.cmake /usr/share/cmake/Modules/CMakeCommonLanguageInclude.cmake /usr/share/cmake/Modules/CMakeGenericSystem.cmake /usr/share/cmake/Modules/CMakeInitializeConfigs.cmake /usr/share/cmake/Modules/CMakeLanguageInformation.cmake /usr/share/cmake/Modules/CMakeSystemSpecificInformation.cmake /usr/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake /usr/share/cmake/Modules/Compiler/CMakeCommonCompilerMacros.cmake /usr/share/cmake/Modules/Compiler/GNU-CXX.cmake /usr/share/cmake/Modules/Compiler/GNU.cmake /usr/share/cmake/Modules/Internal/CMakeCXXLinkerInformation.cmake /usr/share/cmake/Modules/Internal/CMakeCommonLinkerInformation.cmake /usr/share/cmake/Modules/Linker/GNU-CXX.cmake /usr/share/cmake/Modules/Linker/GNU.cmake /usr/share/cmake/Modules/Platform/Linker/GNU.cmake /usr/share/cmake/Modules/Platform/Linker/Linux-GNU-CXX.cmake /usr/share/cmake/Modules/Platform/Linker/Linux-GNU.cmake /usr/share/cmake/Modules/Platform/Linux-GNU-CXX.cmake /usr/share/cmake/Modules/Platform/Linux-GNU.cmake /usr/share/cmake/Modules/Platform/Linux-Initialize.cmake /usr/share/cmake/Modules/Platform/Linux.cmake /usr/share/cmake/Modules/Platform/UnixPaths.cmake CMakeCache.txt CMakeFiles/4.3.3/CMakeCXXCompiler.cmake CMakeFiles/4.3.3/CMakeSystem.cmake pool = console ############################################# # A missing CMake input file is not an error. -build /home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt /usr/share/cmake/Modules/CMakeCXXInformation.cmake /usr/share/cmake/Modules/CMakeCommonLanguageInclude.cmake /usr/share/cmake/Modules/CMakeGenericSystem.cmake /usr/share/cmake/Modules/CMakeInitializeConfigs.cmake /usr/share/cmake/Modules/CMakeLanguageInformation.cmake /usr/share/cmake/Modules/CMakeSystemSpecificInformation.cmake /usr/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake /usr/share/cmake/Modules/Compiler/CMakeCommonCompilerMacros.cmake /usr/share/cmake/Modules/Compiler/GNU-CXX.cmake /usr/share/cmake/Modules/Compiler/GNU.cmake /usr/share/cmake/Modules/Internal/CMakeCXXLinkerInformation.cmake /usr/share/cmake/Modules/Internal/CMakeCommonLinkerInformation.cmake /usr/share/cmake/Modules/Linker/GNU-CXX.cmake /usr/share/cmake/Modules/Linker/GNU.cmake /usr/share/cmake/Modules/Platform/Linker/GNU.cmake /usr/share/cmake/Modules/Platform/Linker/Linux-GNU-CXX.cmake /usr/share/cmake/Modules/Platform/Linker/Linux-GNU.cmake /usr/share/cmake/Modules/Platform/Linux-GNU-CXX.cmake /usr/share/cmake/Modules/Platform/Linux-GNU.cmake /usr/share/cmake/Modules/Platform/Linux-Initialize.cmake /usr/share/cmake/Modules/Platform/Linux.cmake /usr/share/cmake/Modules/Platform/UnixPaths.cmake CMakeCache.txt CMakeFiles/4.3.3/CMakeCXXCompiler.cmake CMakeFiles/4.3.3/CMakeSystem.cmake: phony +build /home/saqut/Masaüstü/saqutcompiler/CMakeLists.txt /home/saqut/Masaüstü/saqutcompiler/build/CMakeFiles/VerifyGlobs.cmake /usr/share/cmake/Modules/CMakeCXXInformation.cmake /usr/share/cmake/Modules/CMakeCommonLanguageInclude.cmake /usr/share/cmake/Modules/CMakeGenericSystem.cmake /usr/share/cmake/Modules/CMakeInitializeConfigs.cmake /usr/share/cmake/Modules/CMakeLanguageInformation.cmake /usr/share/cmake/Modules/CMakeSystemSpecificInformation.cmake /usr/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake /usr/share/cmake/Modules/Compiler/CMakeCommonCompilerMacros.cmake /usr/share/cmake/Modules/Compiler/GNU-CXX.cmake /usr/share/cmake/Modules/Compiler/GNU.cmake /usr/share/cmake/Modules/Internal/CMakeCXXLinkerInformation.cmake /usr/share/cmake/Modules/Internal/CMakeCommonLinkerInformation.cmake /usr/share/cmake/Modules/Linker/GNU-CXX.cmake /usr/share/cmake/Modules/Linker/GNU.cmake /usr/share/cmake/Modules/Platform/Linker/GNU.cmake /usr/share/cmake/Modules/Platform/Linker/Linux-GNU-CXX.cmake /usr/share/cmake/Modules/Platform/Linker/Linux-GNU.cmake /usr/share/cmake/Modules/Platform/Linux-GNU-CXX.cmake /usr/share/cmake/Modules/Platform/Linux-GNU.cmake /usr/share/cmake/Modules/Platform/Linux-Initialize.cmake /usr/share/cmake/Modules/Platform/Linux.cmake /usr/share/cmake/Modules/Platform/UnixPaths.cmake CMakeCache.txt CMakeFiles/4.3.3/CMakeCXXCompiler.cmake CMakeFiles/4.3.3/CMakeSystem.cmake: phony ############################################# diff --git a/docs/adr/ADR-008-kisa-devre-mantiksal-operatorler.md b/docs/adr/ADR-008-kisa-devre-mantiksal-operatorler.md new file mode 100644 index 0000000..9c490c3 --- /dev/null +++ b/docs/adr/ADR-008-kisa-devre-mantiksal-operatorler.md @@ -0,0 +1,60 @@ +# ADR-008: && ve || kısa devre değerlendirmesi + +## Durum +Kabul edildi. + +## Bağlam +Mevcut kodda `&&` ve `||` çalışma anında bozuk: IR üretici bu operatörler için +`case` içermiyor, `default` koluna düşüp `LOAD_CONST 0` üretiyor — yani değişken +operandlarda her zaman `false` dönüyor. Yalnızca her iki operand sabit olduğunda +sabit katlama doğru sonucu veriyor. (Kanıt: `ir_generator.cpp:395-413`, +`constant_folding.hpp:107-112`; davranış referansı bölüm B.) + +## Karar +`&&` ve `||` **KISA DEVRE** değerlendirilir: + +- `a && b`: `a` false ise `b` **HİÇ değerlendirilmez**, sonuç `false`. +- `a || b`: `a` true ise `b` **HİÇ değerlendirilmez**, sonuç `true`. + +Bu, bu operatörlerin sıradan ikili işlem (iki tarafı hesapla sonra birleştir) +**DEĞİL**, bir dallanma olarak üretilmesi gerektiği anlamına gelir. + +IR şeması: + +``` +a && b: + slot_a = [a değerlendir] + result = freshSlot() + LOAD_CONST result, 0 ; varsayılan: false + JIF_FALSE slot_a → DONE ; a false? b'yi atla, result=0 kalsın + slot_b = [b değerlendir] + LOAD_SLOT result, slot_b ; result = b'nin değeri +DONE: + +a || b: + slot_a = [a değerlendir] + result = freshSlot() + LOAD_CONST result, 1 ; varsayılan: true + JIF_TRUE slot_a → DONE ; a true? b'yi atla, result=1 kalsın + slot_b = [b değerlendir] + LOAD_SLOT result, slot_b ; result = b'nin değeri +DONE: +``` + +`||` için `JIF_TRUE` opcode'u gerekir. `JIF_FALSE`'un simetriği olarak +`instruction.hpp`'e ve `interpreter.cpp`'e eklendi. `do-while` döngüsünün +mevcut `EQUAL_EQUAL(cond, 1)` geçici çözümü bu opcode'dan faydalanabilir +(ayrı düzeltme — bu ADR kapsamı dışı). + +## Gerekçe +- C-ailesi dillerin (C, Go, Java, JS, C#) tamamı kısa devre yapar; hedef kitle + bunu bekler. +- Performans artısı: gereksiz sağ-taraf değerlendirmesi atlanır; kısa devre + OLMAYAN versiyon her iki tarafı da her zaman hesaplayacağı için daha yavaştır. +- Niş ile uyumlu: derleyici "şu çağrı şu durumda atlandı" diye gösterebilir. + +## Sonuçlar +- Tek dezavantaj: mantıksal operatörün sağındaki yan etki koşullu çalışır. + Bu kabul edilir; yan etkiyi koşula gömmek zaten kötü kalıptır. +- Sabit katlama yolu (`constant_folding.hpp`) zaten doğru çalışıyordu ve + değiştirilmedi; bu düzeltme yalnızca değişken-operand (IR üretim) yolunu etkiler. diff --git a/src/ir/instruction.hpp b/src/ir/instruction.hpp index 9ce720f..b626984 100644 --- a/src/ir/instruction.hpp +++ b/src/ir/instruction.hpp @@ -20,6 +20,7 @@ // LESS/LEQ/... : dest, left, right (sonuç: 1=doğru, 0=yanlış) // JMP : jumpTarget // JIF_FALSE : cond, jumpTarget +// JIF_TRUE : cond, jumpTarget // CALL : dest, functionName, argSlots // RETURN : src // CALLHOST : functionName, argSlots @@ -64,7 +65,8 @@ enum class Opcode { // --- Kontrol akışı --- JMP, // Koşulsuz atlama: ip = jumpTarget - JIF_FALSE, // Koşullu atlama: slots[cond] == 0 ise ip = jumpTarget + JIF_FALSE, // Koşullu atlama: slots[cond] falsy ise ip = jumpTarget + JIF_TRUE, // Koşullu atlama: slots[cond] truthy ise ip = jumpTarget // --- Fonksiyon çağrısı --- CALL, // Başka bir saQut fonksiyonunu çağır. @@ -97,6 +99,7 @@ inline const char* opcodeName(Opcode op) { case Opcode::NOT_EQUAL: return "NOT_EQUAL"; case Opcode::JMP: return "JMP"; case Opcode::JIF_FALSE: return "JIF_FALSE"; + case Opcode::JIF_TRUE: return "JIF_TRUE"; case Opcode::CALL: return "CALL"; case Opcode::RETURN: return "RETURN"; case Opcode::CALLHOST: return "CALLHOST"; diff --git a/src/ir/ir_generator.cpp b/src/ir/ir_generator.cpp index 4931f84..f1c0996 100644 --- a/src/ir/ir_generator.cpp +++ b/src/ir/ir_generator.cpp @@ -405,6 +405,30 @@ int IRGenerator::generateExpression(ASTNode* node) { case TokenType::GREATER_EQUAL: return generateBinaryArithmetic(Opcode::GREATER_EQUAL, bin->Left, bin->Right); case TokenType::EQUAL_EQUAL: return generateBinaryArithmetic(Opcode::EQUAL_EQUAL, bin->Left, bin->Right); case TokenType::BANG_EQUAL: return generateBinaryArithmetic(Opcode::NOT_EQUAL, bin->Left, bin->Right); + + // Mantıksal operatörler: kısa devre dallanmasıyla üretilir (ADR-008). + // NOT: sıradan ikili işlem değil — b, a'nın değerine göre atlanabilir. + case TokenType::AMPERSAND_AMPERSAND: { + int slotA = generateExpression(bin->Left); + int result = freshSlot(); + emitLoadConst(result, 0); // varsayılan: false + int skipB = emitJumpIfFalse(slotA); // a false → b'yi atla + int slotB = generateExpression(bin->Right); + emitLoadSlot(result, slotB); // result = b + patchJump(skipB); + return result; + } + case TokenType::PIPE_PIPE: { + int slotA = generateExpression(bin->Left); + int result = freshSlot(); + emitLoadConst(result, 1); // varsayılan: true + int skipB = emitJumpIfTrue(slotA); // a true → b'yi atla + int slotB = generateExpression(bin->Right); + emitLoadSlot(result, slotB); // result = b + patchJump(skipB); + return result; + } + default: { // Bilinmeyen operatör — boş slot döndür int slot = freshSlot(); @@ -563,7 +587,14 @@ int IRGenerator::emitJumpIfFalse(int condSlot) { ins.cond = condSlot; ins.jumpTarget = -1; // henüz bilinmiyor — patchJump() bekliyor currentFunction_->instructions.push_back(std::move(ins)); - // Bu instruction'ın indeksini döndür (backpatch için) + return (int)currentFunction_->instructions.size() - 1; +} + +int IRGenerator::emitJumpIfTrue(int condSlot) { + Instruction ins(Opcode::JIF_TRUE); + ins.cond = condSlot; + ins.jumpTarget = -1; + currentFunction_->instructions.push_back(std::move(ins)); return (int)currentFunction_->instructions.size() - 1; } diff --git a/src/ir/ir_generator.hpp b/src/ir/ir_generator.hpp index f3329ce..eef4d7c 100644 --- a/src/ir/ir_generator.hpp +++ b/src/ir/ir_generator.hpp @@ -66,6 +66,9 @@ private: // Döndürülen indeks ileride patchJump() ile doldurulur (backpatch). int emitJumpIfFalse(int condSlot); + // JIF_TRUE talimatını -1 hedefle yazar, instruction indeksini döndürür. + int emitJumpIfTrue(int condSlot); + // Daha önce -1 hedefle yazılan jump'ın hedefini şu anki pozisyona doldur. void patchJump(int instrIndex); diff --git a/src/vm/interpreter.cpp b/src/vm/interpreter.cpp index be466c2..0ff74ea 100644 --- a/src/vm/interpreter.cpp +++ b/src/vm/interpreter.cpp @@ -112,6 +112,10 @@ int Interpreter::run() { if (!frame.slots[instr.cond].isTruthy()) frame.instructionPointer = instr.jumpTarget; break; + case Opcode::JIF_TRUE: + if (frame.slots[instr.cond].isTruthy()) + frame.instructionPointer = instr.jumpTarget; + break; // ── Fonksiyon çağrısı ───────────────────────────────────────────── case Opcode::CALL: { diff --git a/tests/golden/logic/short_circuit.expected b/tests/golden/logic/short_circuit.expected new file mode 100644 index 0000000..765931f --- /dev/null +++ b/tests/golden/logic/short_circuit.expected @@ -0,0 +1,5 @@ +S +evet_and +evet_or1 +S +evet_or2 diff --git a/tests/golden/logic/short_circuit.sqt b/tests/golden/logic/short_circuit.sqt new file mode 100644 index 0000000..71f25c3 --- /dev/null +++ b/tests/golden/logic/short_circuit.sqt @@ -0,0 +1,43 @@ +// Kısa devre (short-circuit) değerlendirmesini kanıtlayan golden test. +// +// Amaç: sadece "doğru sonuç veriyor" değil, sağ taraftaki yan etkinin +// ATLANDIĞINI çıktıdan kanıtlamak. Tüm operandlar değişken (sabit değil) +// — sabit katlama yolunu değil, IR üretim yolunu test eder. +// +// Beklenen çıktı analizi: +// f=0 && side() → kısa devre → "S" ÇIKMIYOR +// t=1 && side() → b çalışır → "S" ÇIKIYOR, "evet_and" +// t=1 || side() → kısa devre → "S" ÇIKMIYOR, "evet_or1" +// f=0 || side() → b çalışır → "S" ÇIKIYOR, "evet_or2" + +int side() { + print("S"); + return 1; +} + +int main() { + int f = 0; + int t = 1; + + // && false-left: side() atlanmalı, "S" çıkmamalı + if (f && side()) { + print("hatali_and"); + } + + // && true-left: side() çalışmalı → "S" çıkar, sonra "evet_and" + if (t && side()) { + print("evet_and"); + } + + // || true-left: side() atlanmalı, "S" çıkmamalı, yine de "evet_or1" çıkar + if (t || side()) { + print("evet_or1"); + } + + // || false-left: side() çalışmalı → "S" çıkar, sonra "evet_or2" + if (f || side()) { + print("evet_or2"); + } + + return 0; +}