From 34a7968d18be065e149bc6fdb6b9619f30fc5400 Mon Sep 17 00:00:00 2001 From: hanez Date: Wed, 1 Oct 2025 00:02:54 +0200 Subject: [PATCH] Updated ./scripts/check_op_includes.py for debugging and some fixes. (0.15.4) --- CMakeLists.txt | 2 +- Makefile | 9 +++-- README.md | 2 +- scripts/check_op_includes.py | 70 ++++++++++++++++++++++++------------ 4 files changed, 55 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e33b7ed..3e51a38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.16) -project(fun VERSION 0.15.3 LANGUAGES C) +project(fun VERSION 0.15.4 LANGUAGES C) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) diff --git a/Makefile b/Makefile index 45f8106..4defac2 100644 --- a/Makefile +++ b/Makefile @@ -82,12 +82,15 @@ threads-demo: fun FUN_LIB_DIR="$(FUN_LIB)" ./$(BUILD_DIR)/fun examples/threads_demo.fun # Additional convenience targets -.PHONY: verify-ops examples run-examples threads-demo +.PHONY: verify-ops examples run-examples threads-demo ops ops-quiet -# Verify that each OP_* in bytecode.h has a corresponding vm_case_*.inc include in vm.c -verify-ops: +# Shorthand aliases for opcode include check +ops: @./scripts/check_op_includes.py --verbose +ops-quiet: + @./scripts/check_op_includes.py + # Build and run all examples (searches for the fun binary automatically) examples run-examples: fun @FUN_LIB_DIR="$(FUN_LIB)" ./scripts/run_examples.sh diff --git a/README.md b/README.md index 4dfd837..b6a4ca7 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ cd fun Build: ``` -make # gmake on FeeBSD +make # gmake on FreeBSD ``` That's it! For testing it run: diff --git a/scripts/check_op_includes.py b/scripts/check_op_includes.py index fb65a79..a041799 100755 --- a/scripts/check_op_includes.py +++ b/scripts/check_op_includes.py @@ -19,7 +19,7 @@ BYTECODE = ROOT / "src" / "bytecode.h" VM_C = ROOT / "src" / "vm.c" OP_RE = re.compile(r'\bOP_([A-Z0-9_]+)\b') -INCLUDE_RE = re.compile(r'#include\s+"vm_case_([a-z0-9_]+)\.inc"') +INCLUDE_RE = re.compile(r'#include\s+"vm/(?:[a-z0-9_]+/)?([a-z0-9_]+)\.c"') def read_text(path: Path) -> str: try: @@ -43,31 +43,55 @@ def parse_opcodes_from_bytecode(text: str) -> set[str]: def parse_includes_from_vm(text: str) -> set[str]: incs = set(m.group(1) for m in INCLUDE_RE.finditer(text)) - # Convert include base names back to uppercase opcode tokens heuristically. - mapping = { - "nop":"NOP","halt":"HALT", - "load_const":"LOAD_CONST","load_local":"LOAD_LOCAL","store_local":"STORE_LOCAL", - "load_global":"LOAD_GLOBAL","store_global":"STORE_GLOBAL", - "pop":"POP","dup":"DUP","swap":"SWAP", - "call":"CALL","return":"RETURN","print":"PRINT","jump":"JUMP","jump_if_false":"JUMP_IF_FALSE", - "add":"ADD","sub":"SUB","mul":"MUL","div":"DIV", - "mod":"MOD","lt":"LT","lte":"LTE","gt":"GT","gte":"GTE", - "eq":"EQ","neq":"NEQ","and":"AND","or":"OR","not":"NOT", - "make_array":"MAKE_ARRAY","len":"LEN", - "index_get":"INDEX_GET","index_set":"INDEX_SET", - "arr_push":"ARR_PUSH","arr_pop":"ARR_POP","arr_set":"ARR_SET","arr_insert":"ARR_INSERT","arr_remove":"ARR_REMOVE", - "slice":"SLICE", - "to_number":"TO_NUMBER","to_string":"TO_STRING", - "split":"SPLIT","join":"JOIN","substr":"SUBSTR","find":"FIND", - "enumerate":"ENUMERATE","zip":"ZIP", - "min":"MIN","max":"MAX","clamp":"CLAMP","abs":"ABS","pow":"POW", - "random_seed":"RANDOM_SEED","random_int":"RANDOM_INT", - "make_map":"MAKE_MAP","keys":"KEYS","values":"VALUES","has_key":"HAS_KEY", - "read_file":"READ_FILE","write_file":"WRITE_FILE", + + # Drop support includes that are not opcode handlers + support_includes = {"thread_common"} + incs = {name for name in incs if name not in support_includes} + + # Map include base names to OP_* tokens. + overrides = { + # core + "nop": "NOP", "halt": "HALT", + "load_const": "LOAD_CONST", "load_local": "LOAD_LOCAL", "store_local": "STORE_LOCAL", + "load_global": "LOAD_GLOBAL", "store_global": "STORE_GLOBAL", + "pop": "POP", "dup": "DUP", "swap": "SWAP", + "call": "CALL", "return": "RETURN", "print": "PRINT", + "jump": "JUMP", "jump_if_false": "JUMP_IF_FALSE", + "line": "LINE", + # arithmetic/logic + "add": "ADD", "sub": "SUB", "mul": "MUL", "div": "DIV", "mod": "MOD", + "lt": "LT", "lte": "LTE", "gt": "GT", "gte": "GTE", + "eq": "EQ", "neq": "NEQ", "and": "AND", "or": "OR", "not": "NOT", + # arrays and slices + "make_array": "MAKE_ARRAY", "len": "LEN", + "index_get": "INDEX_GET", "index_set": "INDEX_SET", + "push": "PUSH", "apop": "APOP", "set": "SET", "insert": "INSERT", "remove": "REMOVE", + "slice": "SLICE", + # conversions and type/meta + "to_number": "TO_NUMBER", "to_string": "TO_STRING", + "cast": "CAST", "typeof": "TYPEOF", "uclamp": "UCLAMP", "sclamp": "SCLAMP", + # strings and iteration helpers + "split": "SPLIT", "join": "JOIN", "substr": "SUBSTR", "find": "FIND", + "enumerate": "ENUMERATE", "zip": "ZIP", + # maps and I/O + "make_map": "MAKE_MAP", "keys": "KEYS", "values": "VALUES", "has_key": "HAS_KEY", + "read_file": "READ_FILE", "write_file": "WRITE_FILE", + # os/env + "env": "ENV", "sleep_ms": "SLEEP_MS", + # math / RNG + "min": "MIN", "max": "MAX", "clamp": "CLAMP", "abs": "ABS", "pow": "POW", + "random_seed": "RANDOM_SEED", "random_int": "RANDOM_INT", + # bitwise and shifts/rotates + "band": "BAND", "bor": "BOR", "bxor": "BXOR", "bnot": "BNOT", + "shl": "SHL", "shr": "SHR", + "rol": "ROTL", "ror": "ROTR", + # threads + "thread_spawn": "THREAD_SPAWN", "thread_join": "THREAD_JOIN", } + tokens = set() for inc in incs: - tokens.add(mapping.get(inc, inc.upper())) + tokens.add(overrides.get(inc, inc.upper())) return tokens def main() -> int: