Files
R8Forge/CMakeLists.txt
T
dsh 3f4149c9d0 examples: one runnable routine per macro group
SPEC is the contract and drv/ is what the tests sweep, but there was no place
that showed a reader how a group is actually used.  examples/ now has one stand
alone program per group, each ending in output calls:

    base_macros.r8asm    S5   set_0 vs erase, rol/ror, copy vs bit_copy vs
                              clb_bit_mov, step
    bit_adder.r8asm      S6   4 bit ripple carry adder built from
                              clb_bit_add_nc, then bit_raw_add for the
                              preserving variant
    byte_raw_ops.r8asm   S7.1 raw_add/raw_inc/raw_and/raw_or/raw_xor/raw_sub,
                              printing the operands afterwards to show the
                              whole point of the family: they survive
    byte_clobber.r8asm   S7.2 clb_add/sub/neg/inc_nc (operands eaten) and the
                              S7.3 clb_and residue (240 & 204 -> B = 12)
    byte_in_place.r8asm  S8   not/inc/neg/dec/add_ip and clb_nonzero
    sum_loop.r8asm       S5.1 clb_ones + loop/endloop: 1+2+...+N, count from
                              data rather than from the assembler
    mul_demo.r8asm       S9   82*141 and 2047*2047
    divmod_demo.r8asm    S7.6 2047/10 and 2047/1 (the case that used to hang),
                              reusing the scratch block on purpose
    digits_demo.r8asm    S7.7 1234 and 7 -> four ASCII digits

Every header carries a `;   out 1 2 3` line: the expected OUT stream, so the
file itself says what it prints.  The new r8forge_examples_test target runs all
of examples/*.r8asm and compares that line with the real output (a file without
the marker counts as a failure), printing the tape length and step count on the
way.  That makes examples the second place after byte_op_test that checks
behaviour instead of just "it assembles", and keeps the examples from rotting as
the macros change.  The six %synth examples get the marker too: their inputs are
all zero, so they print 0 0.

All 15 examples pass.  The values in the headers were checked with
r8forge_tape_run (the second interpreter) as well as the test's own machine.

Docs: SPEC S10.3 has the table and the convention, S11 gets the test row, and
README gets a short section plus the layout list.  AGENTS records the examples
in the handoff baseline and the "verified" table.
2026-11-07 22:34:15 +08:00

51 lines
1.9 KiB
CMake

cmake_minimum_required(VERSION 3.10)
project(R8Forge)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(include)
find_package(Threads REQUIRED)
add_library(r8forge_core src/r8asm.cc src/synth.cc)
target_link_libraries(r8forge_core PUBLIC Threads::Threads)
# 别再 set(CMAKE_CXX_FLAGS ...) 了:那会把默认 flag 整个换掉,MSVC 下丢 /EHsc、
# 还会把 -O3 塞进 Debug 和 /RTC1 打架。Release 配置本来就带 -O3 / /O2 和 NDEBUG。
if(NOT MSVC)
add_compile_options($<$<CONFIG:Release>:-march=native>)
endif()
add_executable(r8forge tests/asm_test.cc)
target_link_libraries(r8forge r8forge_core)
add_executable(r8forge_synth_test tests/synth_test.cc)
target_link_libraries(r8forge_synth_test r8forge_core)
add_executable(r8forge_derive src/derive.cc)
target_link_libraries(r8forge_derive r8forge_core)
# A second, independent ROT-8 interpreter: runs a .rot8 file with no assembler
# and no macros involved, so its verdict can be checked against r8forge_derive.
add_executable(r8forge_tape_run tests/tape_run.cc)
# Runs the byte level library macros (raw_add / raw_and / raw_or / raw_xor /
# raw_inc) over every input combination.
add_executable(r8forge_byte_op_test tests/byte_op_test.cc)
target_link_libraries(r8forge_byte_op_test r8forge_core)
# Checks that every %macro in asm/ carries a doc comment in the house format.
add_executable(r8forge_macro_docs_test tests/macro_docs_test.cc)
# Runs every examples/*.r8asm as a stand alone program and compares its OUT
# stream with the `; out ...` line in the file header.
add_executable(r8forge_examples_test tests/examples_test.cc)
target_link_libraries(r8forge_examples_test r8forge_core)
add_executable(r8forge_cost_par tests/cost_par.cc)
target_link_libraries(r8forge_cost_par r8forge_core)
add_executable(r8forge_cost_search tests/cost_search.cc)
target_link_libraries(r8forge_cost_search r8forge_core)