diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 1f0d0871..daae9b64 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -19,14 +19,11 @@ file(GLOB KVLANG_RUNTIME_SRC CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/src/*.c") set(KVLANG_GEN_SRC "${CMAKE_SOURCE_DIR}/src/rwir_special_gen.c") set(KVLANG_COERCE_SRC "${CMAKE_SOURCE_DIR}/src/rwir_coerce.c") set(KVLANG_DECODE_SRC "${CMAKE_SOURCE_DIR}/src/rwir_decode.c") -set(KVLANG_ISA_SIG_SRC "${CMAKE_SOURCE_DIR}/src/isa_sig.c") set(KVLANG_SLOTVIEW_SRC "${CMAKE_SOURCE_DIR}/src/xvaluebodyview.c") list(REMOVE_ITEM KVLANG_RUNTIME_SRC "${KVLANG_GEN_SRC}" "${KVLANG_COERCE_SRC}" - "${KVLANG_DECODE_SRC}" "${KVLANG_ISA_SIG_SRC}" - "${KVLANG_SLOTVIEW_SRC}") + "${KVLANG_DECODE_SRC}" "${KVLANG_SLOTVIEW_SRC}") list(APPEND KVLANG_RUNTIME_SRC "${KVLANG_DECODE_SRC}" "${KVLANG_GEN_SRC}" - "${KVLANG_COERCE_SRC}" "${KVLANG_ISA_SIG_SRC}" - "${KVLANG_SLOTVIEW_SRC}") + "${KVLANG_COERCE_SRC}" "${KVLANG_SLOTVIEW_SRC}") add_library(kvlang_runtime SHARED ${KVLANG_RUNTIME_SRC}) target_include_directories(kvlang_runtime PUBLIC include src) target_compile_definitions(kvlang_runtime PRIVATE _GNU_SOURCE) @@ -139,6 +136,10 @@ if(NOT APPLE) if(PYTHON3_EXE) add_test(NAME isa_conformance COMMAND "${WITH_C_RUNTIME}" "${PYTHON3_EXE}" "${CMAKE_SOURCE_DIR}/tests/isa_conformance.py") + add_test(NAME myrwircap_ids + COMMAND "${PYTHON3_EXE}" "${CMAKE_SOURCE_DIR}/tests/myrwircap_ids.py") + add_test(NAME myrwircap_ids_selftest + COMMAND "${PYTHON3_EXE}" "${CMAKE_SOURCE_DIR}/tests/myrwircap_ids.py" --selftest) endif() add_test(NAME specialize_gate COMMAND "${WITH_C_RUNTIME}" bash "${CMAKE_SOURCE_DIR}/tests/specialize_gate.sh") set_tests_properties(getmember_siblings kvset_invalid_head_shm pc_kvspace_source_shm crash_resume_shm param_address_shm delegate_shm scalar_wire pc_part_write_shm ro_rewrite_shm diff --git a/runtime/src/func_code.c b/runtime/src/func_code.c index ab9cf041..347479ae 100644 --- a/runtime/src/func_code.c +++ b/runtime/src/func_code.c @@ -200,17 +200,10 @@ static kvlangCodeRow_t *row_load(kvspace_t *kv, kvlangFuncCode_t *code, int s0, } row->handler_id = row->opcode_id >= 0 ? row->opcode_id : kvlangRwirRouteId(); - /* P1b3 typed_core:manifest core 具体项 = 签名列 BIN/CMP/UN(156 项)。 - * 装载期一次固化,执行期不查 manifest。 */ - if (row->opcode_id >= 0) { - uint32_t nsig = 0; - const kvlangIsaSig *sg = kvlangIsaSigs(&nsig); - if ((uint32_t)row->opcode_id < nsig) { - uint8_t k = sg[row->opcode_id].sig; - row->typed_core = - k == KV_ISA_BIN || k == KV_ISA_CMP || k == KV_ISA_UN; - } - } + /* typed_core:能力表里声明了定长结果类型的行(156 项),与派发同源。 */ + if (row->opcode_id >= 0) + row->typed_core = + kvlangRwirCaps()[row->opcode_id].result_kind != NULL; /* T-120 A:typed 行操作数 langtype 由 opcode 前缀承载(`int64·add`), * 装载期解析一次;cell->type 在 typed 行上通常为空。 */ row->view_pack = 0; diff --git a/runtime/src/isa_sig.c b/runtime/src/isa_sig.c deleted file mode 100644 index 88019783..00000000 --- a/runtime/src/isa_sig.c +++ /dev/null @@ -1,327 +0,0 @@ -/* P1b1 ISA 签名列:与 myrwircaps 同序、逐项一行(P1 spec 1.3/2.1)。 - * 独立 TU 且最后链接:不移动热 TU/热表的地址布局(见 CMake 注释)。 */ - -#include "runtime_internal.h" - -/* P1b1 ISA 签名表:与 myrwircaps 同序、逐项一行;发布期做形状校验。 - * sig: ANY=全 any 槽(arity 显式); BIN/CMP/UN=·op 特化; CAST=rp any / wp=kind。 - * 变参 entry dynamic=1,末读参类型发布时补 "..."。 */ -static const kvlangIsaSig isa_sig[] = { - {KV_ISA_CORE, KV_ISA_ANY, 1, 0, 0, KV_EFF_CONTROL}, /* call */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 0, 0, KV_EFF_CONTROL}, /* return */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 0, 0, KV_EFF_CONTROL}, /* goto */ - {KV_ISA_CORE, KV_ISA_ANY, 3, 0, 0, KV_EFF_CONTROL}, /* br */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* = */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* add */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* + */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·mod */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·bitand */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·bitor */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·bitxor */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·shl */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·shr */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int64·min */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* int64·neg */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* int64·abs */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* int64·sign */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int64·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int64·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int64·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int64·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int64·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int64·ge */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float64·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float64·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float64·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float64·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float64·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float64·min */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* float64·neg */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* float64·abs */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* float64·sign */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* float64·sqrt */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* float64·exp */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* float64·log */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float64·pow */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float64·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float64·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float64·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float64·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float64·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float64·ge */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int8·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int8·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int8·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int8·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int8·mod */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int8·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int8·min */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int8·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int8·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int8·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int8·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int8·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int8·ge */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int16·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int16·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int16·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int16·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int16·mod */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int16·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int16·min */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int16·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int16·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int16·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int16·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int16·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int16·ge */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int32·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int32·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int32·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int32·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int32·mod */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int32·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* int32·min */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int32·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int32·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int32·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int32·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int32·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* int32·ge */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint8·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint8·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint8·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint8·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint8·mod */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint8·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint8·min */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint8·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint8·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint8·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint8·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint8·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint8·ge */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint16·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint16·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint16·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint16·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint16·mod */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint16·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint16·min */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint16·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint16·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint16·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint16·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint16·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint16·ge */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint32·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint32·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint32·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint32·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint32·mod */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint32·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint32·min */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint32·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint32·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint32·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint32·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint32·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint32·ge */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·mod */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·min */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint64·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint64·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint64·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint64·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint64·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* uint64·ge */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* int8·neg */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* int8·abs */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* int16·neg */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* int16·abs */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* int32·neg */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* int32·abs */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·bitand */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·bitor */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·bitxor */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·shl */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* uint64·shr */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float32·add */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float32·sub */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float32·mul */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float32·div */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float32·max */ - {KV_ISA_CORE, KV_ISA_BIN, 2, 1, 0, KV_EFF_PURE}, /* float32·min */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* float32·neg */ - {KV_ISA_CORE, KV_ISA_UN, 1, 1, 0, KV_EFF_PURE}, /* float32·abs */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float32·eq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float32·neq */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float32·lt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float32·le */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float32·gt */ - {KV_ISA_CORE, KV_ISA_CMP, 2, 1, 0, KV_EFF_PURE}, /* float32·ge */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* sub */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 1, KV_EFF_PURE}, /* - */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* mul */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* × */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* div */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* ÷ */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* mod */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* % */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* eq */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* == */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* neq */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* != */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* ≠ */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* lt */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* < */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* gt */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* > */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* le */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* <= */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* ≤ */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* ge */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* >= */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* ≥ */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* and */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* && */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* or */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* || */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* not */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* ! */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* bitand */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* & */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* bitor */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* | */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* bitxor */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* ^ */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* shl */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* << */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* shr */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* >> */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* pow */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* sqrt */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* √ */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* exp */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* log */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* neg */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* abs */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* sign */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* max */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* min */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* bool */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* int8 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* int16 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* int32 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* int64 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* uint8 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* uint16 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* uint32 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* uint64 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* float32 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* float64 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* char/utf32 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* char/utf8 */ - {KV_ISA_CORE, KV_ISA_CAST, 1, 1, 0, KV_EFF_PURE}, /* char/ascii */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* compactarray·new */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* compactarray·copy */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* compactarray·fill */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* scatterarray·newscatter */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* scatterarray·newcompact */ - {KV_ISA_EXT, KV_ISA_ANY, 0, 1, 0, KV_EFF_PURE}, /* scatterarray·new */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* scatterarray·len */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* scatterarray·at */ - {KV_ISA_EXT, KV_ISA_ANY, 3, 1, 0, KV_EFF_PURE}, /* scatterarray·set */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* scatterarray·append */ - {KV_ISA_EXT, KV_ISA_ANY, 3, 1, 0, KV_EFF_PURE}, /* scatterarray·slice */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 1, KV_EFF_PURE}, /* obj */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 1, KV_EFF_PURE}, /* map */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 1, KV_EFF_PURE}, /* struct·new */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* compactarray·numel */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* compactarray·dim */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* compactarray·shape */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* compactarray·at */ - {KV_ISA_EXT, KV_ISA_ANY, 3, 1, 0, KV_EFF_PURE}, /* compactarray·set */ - {KV_ISA_EXT, KV_ISA_ANY, 3, 1, 0, KV_EFF_PURE}, /* compactarray·newreshape */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* compactarray·newreinterpret */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* compactarray·langtype */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* compactarray·bodylen */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* compactarray·parselangtype */ - {KV_ISA_EXT, KV_ISA_ANY, 3, 1, 0, KV_EFF_PURE}, /* string·set */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* string·char */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* string·ord */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* string·cmp */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* string·find */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* string·len */ - {KV_ISA_EXT, KV_ISA_ANY, 3, 1, 0, KV_EFF_PURE}, /* string·slice */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* string·concat */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* string·formatint */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* string·formatuint */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* string·parseint */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* string·parseuint */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* string·parsefloat */ - {KV_ISA_EXT, KV_ISA_ANY, 0, 1, 0, KV_EFF_READ}, /* time·now */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* time·sub */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* time·add */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·nanos */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·millis */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·seconds */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·minutes */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·hours */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·as_nanos */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·as_millis */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·as_seconds */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·as_minutes */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* time/duration·as_hours */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* time/duration·add */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* time/duration·sub */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* time/duration·before */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* time/duration·after */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* time·before */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_PURE}, /* time·after */ - {KV_ISA_EXT, KV_ISA_ANY, 0, 1, 0, KV_EFF_READ}, /* random·uint64 */ - {KV_ISA_EXT, KV_ISA_ANY, 0, 1, 0, KV_EFF_READ}, /* random·int63 */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_READ}, /* random·intn */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_READ}, /* kvspace·get */ - {KV_ISA_CORE, KV_ISA_ANY, 3, 1, 0, KV_EFF_WRITE}, /* kvspace·set */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_WRITE}, /* kvspace·del */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 1, 0, KV_EFF_WRITE}, /* kvspace·deltree */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 0, 0, KV_EFF_WRITE}, /* kvspace·cp */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 0, 0, KV_EFF_WRITE}, /* kvspace·cpdir */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 0, 0, KV_EFF_WRITE}, /* kvspace·cplist */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_READ}, /* kvspace·listlen */ - {KV_ISA_CORE, KV_ISA_ANY, 2, 1, 0, KV_EFF_READ}, /* kvspace·listat */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 0, 0, KV_EFF_WRITE}, /* kvspace·mkindex */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 0, 0, KV_EFF_WRITE}, /* kvspace·extindex */ - {KV_ISA_EXT, KV_ISA_ANY, 1, 0, 0, KV_EFF_WRITE}, /* kvspace·rmindexext */ - {KV_ISA_EXT, KV_ISA_ANY, 2, 1, 0, KV_EFF_READ | KV_EFF_WRITE}, /* kvspace·watch */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_PURE}, /* kvlang·abs */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 1, 0, KV_EFF_CONTROL | KV_EFF_WRITE}, /* vthread·create */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 0, 0, KV_EFF_CONTROL | KV_EFF_WRITE}, /* vthread·run */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 0, 0, KV_EFF_CONTROL | KV_EFF_WRITE}, /* vthread·call */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 0, 0, KV_EFF_CONTROL | KV_EFF_WRITE}, /* vthread·sleep */ - {KV_ISA_CORE, KV_ISA_ANY, 1, 0, 0, KV_EFF_CONTROL | KV_EFF_WRITE}, /* vthread·setstatus */ - {KV_ISA_CORE, KV_ISA_ANY, 0, 0, 0, KV_EFF_DEBUG}, /* debugger */ -}; - -_Static_assert(sizeof(isa_sig) / sizeof(isa_sig[0]) == 305, - "P1b1: isa_sig must have 305 rows"); -/* 本表只服务 runtime 自身的 typed_core 判定;isa_sig 是 runtime 私有快照, - * 不是 kvlang 概念,也不对外发布(#583)。 */ - -__attribute__((visibility("hidden"))) const kvlangIsaSig * -kvlangIsaSigs(uint32_t *n_out) { - if (n_out) - *n_out = (uint32_t)(sizeof(isa_sig) / sizeof(isa_sig[0])); - return isa_sig; -} diff --git a/runtime/src/runtime_internal.h b/runtime/src/runtime_internal.h index c0b4fa1b..4b3bf184 100644 --- a/runtime/src/runtime_internal.h +++ b/runtime/src/runtime_internal.h @@ -1073,34 +1073,6 @@ typedef struct { uint32_t result_width; } kvlangRwirCap; -/* P1b1 ISA 签名列:与 myrwircaps 同序、逐项一行(see workspace P1 spec §1.3/§2.1)。 - * rp/wp 类型由 sig 规则 + opcode 生成,不在发布器里另列 opcode 清单。 */ -enum { KV_ISA_CORE = 0, KV_ISA_EXT = 1 }; -enum { - KV_ISA_ANY = 0, /* 槽类型全 any(arity 显式;dynamic 时末读参 any...) */ - KV_ISA_BIN, /* ·op:rp=kind×2,wp=kind */ - KV_ISA_CMP, /* ·op:rp=kind×2,wp=bool */ - KV_ISA_UN, /* ·op:rp=kind,wp=kind */ - KV_ISA_CAST, /* rp=any,wp=opcode kind */ -}; -enum { - KV_EFF_PURE = 1, - KV_EFF_READ = 2, - KV_EFF_WRITE = 4, - KV_EFF_CONTROL = 8, - KV_EFF_IO = 16, - KV_EFF_DEBUG = 32, -}; -typedef struct { - uint8_t cls; - uint8_t sig; - uint8_t nr; - uint8_t nw; - uint8_t dynamic; - uint8_t effects; -} kvlangIsaSig; -__attribute__((visibility("hidden"))) const kvlangIsaSig *kvlangIsaSigs(uint32_t *n_out); - __attribute__((visibility("hidden"))) const kvlangRwirCap *kvlangRwirCaps(void); __attribute__((visibility("hidden"))) int kvlangRwirRouteId(void); __attribute__((visibility("hidden"))) int kvlangKvcpuRoute(kvlangFrame_t *f); diff --git a/runtime/tests/fixtures/myrwircap_ids.txt b/runtime/tests/fixtures/myrwircap_ids.txt new file mode 100644 index 00000000..840637b5 --- /dev/null +++ b/runtime/tests/fixtures/myrwircap_ids.txt @@ -0,0 +1,323 @@ +0 call - 0 +1 return - 0 +2 goto - 0 +3 br - 0 +4 = - 0 +5 add - 0 +6 + - 0 +7 int64·add int64 8 +8 int64·sub int64 8 +9 int64·mul int64 8 +10 int64·div int64 8 +11 int64·mod int64 8 +12 int64·bitand int64 8 +13 int64·bitor int64 8 +14 int64·bitxor int64 8 +15 int64·shl int64 8 +16 int64·shr int64 8 +17 int64·max int64 8 +18 int64·min int64 8 +19 int64·neg int64 8 +20 int64·abs int64 8 +21 int64·sign int64 8 +22 int64·eq bool 1 +23 int64·neq bool 1 +24 int64·lt bool 1 +25 int64·le bool 1 +26 int64·gt bool 1 +27 int64·ge bool 1 +28 float64·add float64 8 +29 float64·sub float64 8 +30 float64·mul float64 8 +31 float64·div float64 8 +32 float64·max float64 8 +33 float64·min float64 8 +34 float64·neg float64 8 +35 float64·abs float64 8 +36 float64·sign float64 8 +37 float64·sqrt float64 8 +38 float64·exp float64 8 +39 float64·log float64 8 +40 float64·pow float64 8 +41 float64·eq bool 1 +42 float64·neq bool 1 +43 float64·lt bool 1 +44 float64·le bool 1 +45 float64·gt bool 1 +46 float64·ge bool 1 +47 int8·add int8 1 +48 int8·sub int8 1 +49 int8·mul int8 1 +50 int8·div int8 1 +51 int8·mod int8 1 +52 int8·max int8 1 +53 int8·min int8 1 +54 int8·eq bool 1 +55 int8·neq bool 1 +56 int8·lt bool 1 +57 int8·le bool 1 +58 int8·gt bool 1 +59 int8·ge bool 1 +60 int16·add int16 2 +61 int16·sub int16 2 +62 int16·mul int16 2 +63 int16·div int16 2 +64 int16·mod int16 2 +65 int16·max int16 2 +66 int16·min int16 2 +67 int16·eq bool 1 +68 int16·neq bool 1 +69 int16·lt bool 1 +70 int16·le bool 1 +71 int16·gt bool 1 +72 int16·ge bool 1 +73 int32·add int32 4 +74 int32·sub int32 4 +75 int32·mul int32 4 +76 int32·div int32 4 +77 int32·mod int32 4 +78 int32·max int32 4 +79 int32·min int32 4 +80 int32·eq bool 1 +81 int32·neq bool 1 +82 int32·lt bool 1 +83 int32·le bool 1 +84 int32·gt bool 1 +85 int32·ge bool 1 +86 uint8·add uint8 1 +87 uint8·sub uint8 1 +88 uint8·mul uint8 1 +89 uint8·div uint8 1 +90 uint8·mod uint8 1 +91 uint8·max uint8 1 +92 uint8·min uint8 1 +93 uint8·eq bool 1 +94 uint8·neq bool 1 +95 uint8·lt bool 1 +96 uint8·le bool 1 +97 uint8·gt bool 1 +98 uint8·ge bool 1 +99 uint16·add uint16 2 +100 uint16·sub uint16 2 +101 uint16·mul uint16 2 +102 uint16·div uint16 2 +103 uint16·mod uint16 2 +104 uint16·max uint16 2 +105 uint16·min uint16 2 +106 uint16·eq bool 1 +107 uint16·neq bool 1 +108 uint16·lt bool 1 +109 uint16·le bool 1 +110 uint16·gt bool 1 +111 uint16·ge bool 1 +112 uint32·add uint32 4 +113 uint32·sub uint32 4 +114 uint32·mul uint32 4 +115 uint32·div uint32 4 +116 uint32·mod uint32 4 +117 uint32·max uint32 4 +118 uint32·min uint32 4 +119 uint32·eq bool 1 +120 uint32·neq bool 1 +121 uint32·lt bool 1 +122 uint32·le bool 1 +123 uint32·gt bool 1 +124 uint32·ge bool 1 +125 uint64·add uint64 8 +126 uint64·sub uint64 8 +127 uint64·mul uint64 8 +128 uint64·div uint64 8 +129 uint64·mod uint64 8 +130 uint64·max uint64 8 +131 uint64·min uint64 8 +132 uint64·eq bool 1 +133 uint64·neq bool 1 +134 uint64·lt bool 1 +135 uint64·le bool 1 +136 uint64·gt bool 1 +137 uint64·ge bool 1 +138 int8·neg int8 1 +139 int8·abs int8 1 +140 int16·neg int16 2 +141 int16·abs int16 2 +142 int32·neg int32 4 +143 int32·abs int32 4 +144 uint64·bitand uint64 8 +145 uint64·bitor uint64 8 +146 uint64·bitxor uint64 8 +147 uint64·shl uint64 8 +148 uint64·shr uint64 8 +149 float32·add float32 4 +150 float32·sub float32 4 +151 float32·mul float32 4 +152 float32·div float32 4 +153 float32·max float32 4 +154 float32·min float32 4 +155 float32·neg float32 4 +156 float32·abs float32 4 +157 float32·eq bool 1 +158 float32·neq bool 1 +159 float32·lt bool 1 +160 float32·le bool 1 +161 float32·gt bool 1 +162 float32·ge bool 1 +163 sub - 0 +164 - - 0 +165 mul - 0 +166 × - 0 +167 div - 0 +168 ÷ - 0 +169 mod - 0 +170 % - 0 +171 eq - 0 +172 == - 0 +173 neq - 0 +174 != - 0 +175 ≠ - 0 +176 lt - 0 +177 < - 0 +178 gt - 0 +179 > - 0 +180 le - 0 +181 <= - 0 +182 ≤ - 0 +183 ge - 0 +184 >= - 0 +185 ≥ - 0 +186 and - 0 +187 && - 0 +188 or - 0 +189 || - 0 +190 not - 0 +191 ! - 0 +192 bitand - 0 +193 & - 0 +194 bitor - 0 +195 | - 0 +196 bitxor - 0 +197 ^ - 0 +198 shl - 0 +199 << - 0 +200 shr - 0 +201 >> - 0 +202 pow - 0 +203 sqrt - 0 +204 √ - 0 +205 exp - 0 +206 log - 0 +207 neg - 0 +208 abs - 0 +209 sign - 0 +210 max - 0 +211 min - 0 +212 bool - 0 +213 int8 - 0 +214 int16 - 0 +215 int32 - 0 +216 int64 - 0 +217 uint8 - 0 +218 uint16 - 0 +219 uint32 - 0 +220 uint64 - 0 +221 float32 - 0 +222 float64 - 0 +223 char/utf32 - 0 +224 char/utf8 - 0 +225 char/ascii - 0 +226 array·new - 0 +227 array·fill - 0 +228 array·scatter - 0 +229 array·compact - 0 +230 array·append - 0 +231 array·slice - 0 +232 obj - 0 +233 map·new - 0 +234 struct·new - 0 +235 ndarray·numel - 0 +236 ndarray·dim - 0 +237 ndarray·shape - 0 +238 xv·at - 0 +239 xv·set - 0 +240 xv·reshape - 0 +241 xv·reinterpret - 0 +242 xv·langtype - 0 +243 xv·bodylen - 0 +244 xv·parselangtype - 0 +245 compactarray·copy - 0 +246 compactarray·newslice - 0 +247 compactarray·new - 0 +248 compactarray·fill - 0 +249 compactarray·numel - 0 +250 compactarray·dim - 0 +251 compactarray·shape - 0 +252 compactarray·at - 0 +253 compactarray·set - 0 +254 compactarray·newreshape - 0 +255 compactarray·newreinterpret - 0 +256 compactarray·langtype - 0 +257 compactarray·bodylen - 0 +258 compactarray·parselangtype - 0 +259 scatterarray·new - 0 +260 scatterarray·len - 0 +261 scatterarray·at - 0 +262 scatterarray·set - 0 +263 scatterarray·newscatter - 0 +264 scatterarray·newcompact - 0 +265 scatterarray·append - 0 +266 scatterarray·slice - 0 +267 string·set - 0 +268 string·char - 0 +269 string·ord - 0 +270 string·cmp - 0 +271 string·find - 0 +272 string·len - 0 +273 string·slice - 0 +274 string·concat - 0 +275 string·formatint - 0 +276 string·formatuint - 0 +277 string·parseint - 0 +278 string·parseuint - 0 +279 string·parsefloat - 0 +280 time·now - 0 +281 time·sub - 0 +282 time·add - 0 +283 time/duration·nanos - 0 +284 time/duration·millis - 0 +285 time/duration·seconds - 0 +286 time/duration·minutes - 0 +287 time/duration·hours - 0 +288 time/duration·as_nanos - 0 +289 time/duration·as_millis - 0 +290 time/duration·as_seconds - 0 +291 time/duration·as_minutes - 0 +292 time/duration·as_hours - 0 +293 time/duration·add - 0 +294 time/duration·sub - 0 +295 time/duration·before - 0 +296 time/duration·after - 0 +297 time·before - 0 +298 time·after - 0 +299 random·uint64 - 0 +300 random·int63 - 0 +301 random·intn - 0 +302 kvspace·get - 0 +303 kvspace·set - 0 +304 kvspace·del - 0 +305 kvspace·deltree - 0 +306 kvspace·cp - 0 +307 kvspace·cpdir - 0 +308 kvspace·cplist - 0 +309 kvspace·listlen - 0 +310 kvspace·listat - 0 +311 kvspace·mkindex - 0 +312 kvspace·extindex - 0 +313 kvspace·rmindexext - 0 +314 kvspace·watch - 0 +315 kvlang·abs - 0 +316 vthread·create - 0 +317 vthread·run - 0 +318 vthread·call - 0 +319 vthread·sleep - 0 +320 vthread·setstatus - 0 +321 debugger - 0 +322 - 0 diff --git a/runtime/tests/isa_conformance.py b/runtime/tests/isa_conformance.py index c157e1d7..e34801cd 100644 --- a/runtime/tests/isa_conformance.py +++ b/runtime/tests/isa_conformance.py @@ -11,8 +11,6 @@ import sys import tempfile -TERM = os.environ["KVLANG_TERM_BIN"] -LAYOUT = os.environ["KVLANG_LAYOUT_BIN"] SIGNED = {"int8", "int16", "int32", "int64"} UNSIGNED = {"uint8", "uint16", "uint32", "uint64"} @@ -107,6 +105,8 @@ def src(kind, op, arity, args, want): def main(): + term = os.environ["KVLANG_TERM_BIN"] + layout = os.environ["KVLANG_LAYOUT_BIN"] base = tempfile.mkdtemp(prefix="isa-conf-") fails = [] total = 0 @@ -125,17 +125,17 @@ def main(): except OSError: pass env = {**os.environ, "KVSPACE": dsn} - boot = subprocess.run([TERM, "-c", "print(\"boot\")"], env=env, + boot = subprocess.run([term, "-c", "print(\"boot\")"], env=env, capture_output=True, text=True) if boot.returncode != 0: fails.append((kind, op, "boot", boot.stderr[:120])) continue - lay = subprocess.run([LAYOUT, prog, dsn], env=env, + lay = subprocess.run([layout, prog, dsn], env=env, capture_output=True, text=True) if lay.returncode != 0: fails.append((kind, op, "layout", lay.stderr[:160])) continue - run = subprocess.run([TERM, "test"], env=env, + run = subprocess.run([term, "test"], env=env, capture_output=True, text=True) out = run.stdout.strip().splitlines() if run.returncode != 0 or not out or out[0] != "OK": diff --git a/runtime/tests/myrwircap_ids.py b/runtime/tests/myrwircap_ids.py new file mode 100755 index 00000000..59d0ca09 --- /dev/null +++ b/runtime/tests/myrwircap_ids.py @@ -0,0 +1,207 @@ +#!/usr/bin/env python3 +"""能力表编号契约:dump / compare / selftest。 + +以 runtime/src/myrwircaps.c 预处理后的表序为准(id = 表下标)。 +fixture 见 tests/fixtures/myrwircap_ids.txt,逐字节比对;错位时打印 +第一个错位的 index 与两边的名字。 +""" + +import argparse +import codecs +import contextlib +import io +import os +import re +import subprocess +import sys + +HERE = os.path.dirname(os.path.abspath(__file__)) +ROOT = os.path.dirname(os.path.dirname(HERE)) +SRC = os.path.join(ROOT, "runtime", "src", "myrwircaps.c") +FIXTURE = os.path.join(HERE, "fixtures", "myrwircap_ids.txt") +NONE_KINDS = {"((void *)0)", "NULL", "0", ""} + + +def split_fields(entry): + fields, cur, quoted, i = [], [], False, 0 + while i < len(entry): + c = entry[i] + if quoted: + cur.append(c) + if c == "\\" and i + 1 < len(entry): + cur.append(entry[i + 1]) + i += 2 + continue + if c == '"': + quoted = False + i += 1 + continue + if c == '"': + quoted = True + cur.append(c) + elif c == ",": + fields.append("".join(cur)) + cur = [] + else: + cur.append(c) + i += 1 + fields.append("".join(cur)) + return [f.strip() for f in fields] + + +def decode_literal(field): + raw = "".join(re.findall(r'"((?:[^"\\]|\\.)*)"', field)) + return codecs.decode(raw, "unicode_escape").encode("latin-1").decode("utf-8") + + +def preprocess(path=SRC): + proc = subprocess.run( + ["gcc", "-E", "-P", f"-I{ROOT}/runtime/include", + f"-I{ROOT}/runtime/src", path], + capture_output=True, text=True) + if proc.returncode != 0: + sys.exit(f"myrwircap_ids: preprocess failed: {proc.stderr.strip()}") + return proc.stdout + + +def parse_table(text): + try: + begin = text.index("myrwircaps[] = {") + body = text[begin:text.index("\n};", begin)].split("{", 1)[1] + except ValueError: + sys.exit("myrwircaps: table not found in preprocessed source") + entries, depth, start = [], 0, 0 + for i, c in enumerate(body): + if c == "{": + if depth == 0: + start = i + 1 + depth += 1 + elif c == "}": + depth -= 1 + if depth == 0: + entries.append(body[start:i]) + if not entries: + sys.exit("myrwircaps: empty table") + rows = [] + for index, entry in enumerate(entries): + fields = split_fields(entry) + name = decode_literal(fields[0]) + if len(fields) >= 4 and fields[3] not in NONE_KINDS: + kind = decode_literal(fields[3]) + else: + kind = "-" + width = fields[4] if len(fields) >= 5 else "0" + rows.append((index, name, kind, width)) + return rows + + +def format_rows(rows): + return "".join(f"{i}\t{n}\t{k}\t{w}\n" for i, n, k, w in rows) + + +def describe(row): + index, name, kind, width = row + label = name if name else "" + return f'name="{label}" result_kind="{kind}" width={width}' + + +def compare(actual, expected): + limit = min(len(actual), len(expected)) + for i in range(limit): + if actual[i] != expected[i]: + print(f"first mismatch at index {i}:") + print(f" myrwircaps {describe(actual[i])}") + print(f" fixture {describe(expected[i])}") + return 1 + if len(actual) != len(expected): + print(f"row count mismatch: myrwircaps {len(actual)} != fixture " + f"{len(expected)}; first extra at index {limit}") + extra = actual[limit] if len(actual) > limit else expected[limit] + print(f" {'myrwircaps' if len(actual) > limit else 'fixture'}" + f" {describe(extra)}") + return 1 + return 0 + + +def contract(rows): + if rows[-1][1]: + print(f"route tail missing: last row at index {len(rows) - 1} is " + f"{describe(rows[-1])}") + return 1 + typed = [n for _, n, k, _ in rows if k != "-"] + try: + sys.path.insert(0, HERE) + import isa_conformance + covered = {f"{kind}·{op}" for kind, op, *_ in isa_conformance.entries()} + except Exception as exc: # noqa: BLE001 + sys.exit(f"myrwircap_ids: cannot load isa_conformance: {exc}") + missing = set(typed) - covered + extra_ops = covered - set(typed) + if len(typed) != 156 or missing or extra_ops: + print(f"typed set mismatch: {len(typed)} rows, {len(missing)} " + f"not covered, {len(extra_ops)} extra") + if missing: + print(f" not covered: {sorted(missing)[:8]}") + if extra_ops: + print(f" extra: {sorted(extra_ops)[:8]}") + return 1 + print(f"ok: {len(rows)} rows, {len(typed)} typed, route at " + f"{len(rows) - 1}") + return 0 + + +def selftest(): + base = [(0, "call", "-", "0"), (1, "return", "-", "0")] + cases = [ + ("name", base, [(0, "call", "-", "0"), (1, "goto", "-", "0")], + ['index 1', "return", "goto"]), + ("kind", base, [(0, "call", "-", "0"), (1, "return", "bool", "0")], + ['index 1', 'result_kind="bool"']), + ("width", base, [(0, "call", "-", "0"), (1, "return", "-", "8")], + ['index 1', "width=8"]), + ("count", base, [(0, "call", "-", "0")], + ['index 1', "row count"]), + ] + failures = [] + for label, left, right, expect in cases: + buf = io.StringIO() + with contextlib.redirect_stdout(buf): + code = compare(left, right) + out = buf.getvalue() + if code == 0 or not all(e in out for e in expect): + failures.append((label, out)) + buf = io.StringIO() + with contextlib.redirect_stdout(buf): + code = compare(base, list(base)) + if code != 0: + failures.append(("equal", buf.getvalue())) + if failures: + for label, out in failures: + print(f"selftest failed: {label}\n{out}", file=sys.stderr) + return 1 + print(f"ok: selftest {len(cases)} mismatches + 1 equal") + return 0 + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--dump", action="store_true") + parser.add_argument("--selftest", action="store_true") + args = parser.parse_args() + if args.selftest: + return selftest() + actual = parse_table(preprocess()) + if args.dump: + sys.stdout.write(format_rows(actual)) + return 0 + with open(FIXTURE, encoding="utf-8") as f: + expected = [] + for line in f: + index, name, kind, width = line.rstrip("\n").split("\t") + expected.append((int(index), name, kind, width)) + rc = compare(actual, expected) + return contract(actual) if rc == 0 else rc + + +if __name__ == "__main__": + sys.exit(main())