1
0
Fork 0
forked from fun/fun

Updated ./scripts/check_op_includes.py for debugging and some fixes. (0.15.4)

This commit is contained in:
Johannes Findeisen 2025-10-01 00:02:54 +02:00
commit 34a7968d18
4 changed files with 55 additions and 28 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16) 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 11)
set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_STANDARD_REQUIRED ON)

View file

@ -82,12 +82,15 @@ threads-demo: fun
FUN_LIB_DIR="$(FUN_LIB)" ./$(BUILD_DIR)/fun examples/threads_demo.fun FUN_LIB_DIR="$(FUN_LIB)" ./$(BUILD_DIR)/fun examples/threads_demo.fun
# Additional convenience targets # 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 # Shorthand aliases for opcode include check
verify-ops: ops:
@./scripts/check_op_includes.py --verbose @./scripts/check_op_includes.py --verbose
ops-quiet:
@./scripts/check_op_includes.py
# Build and run all examples (searches for the fun binary automatically) # Build and run all examples (searches for the fun binary automatically)
examples run-examples: fun examples run-examples: fun
@FUN_LIB_DIR="$(FUN_LIB)" ./scripts/run_examples.sh @FUN_LIB_DIR="$(FUN_LIB)" ./scripts/run_examples.sh

View file

@ -137,7 +137,7 @@ cd fun
Build: Build:
``` ```
make # gmake on FeeBSD make # gmake on FreeBSD
``` ```
That's it! For testing it run: That's it! For testing it run:

View file

@ -19,7 +19,7 @@ BYTECODE = ROOT / "src" / "bytecode.h"
VM_C = ROOT / "src" / "vm.c" VM_C = ROOT / "src" / "vm.c"
OP_RE = re.compile(r'\bOP_([A-Z0-9_]+)\b') 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: def read_text(path: Path) -> str:
try: try:
@ -43,31 +43,55 @@ def parse_opcodes_from_bytecode(text: str) -> set[str]:
def parse_includes_from_vm(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)) incs = set(m.group(1) for m in INCLUDE_RE.finditer(text))
# Convert include base names back to uppercase opcode tokens heuristically.
mapping = { # Drop support includes that are not opcode handlers
"nop":"NOP","halt":"HALT", support_includes = {"thread_common"}
"load_const":"LOAD_CONST","load_local":"LOAD_LOCAL","store_local":"STORE_LOCAL", incs = {name for name in incs if name not in support_includes}
"load_global":"LOAD_GLOBAL","store_global":"STORE_GLOBAL",
"pop":"POP","dup":"DUP","swap":"SWAP", # Map include base names to OP_* tokens.
"call":"CALL","return":"RETURN","print":"PRINT","jump":"JUMP","jump_if_false":"JUMP_IF_FALSE", overrides = {
"add":"ADD","sub":"SUB","mul":"MUL","div":"DIV", # core
"mod":"MOD","lt":"LT","lte":"LTE","gt":"GT","gte":"GTE", "nop": "NOP", "halt": "HALT",
"eq":"EQ","neq":"NEQ","and":"AND","or":"OR","not":"NOT", "load_const": "LOAD_CONST", "load_local": "LOAD_LOCAL", "store_local": "STORE_LOCAL",
"make_array":"MAKE_ARRAY","len":"LEN", "load_global": "LOAD_GLOBAL", "store_global": "STORE_GLOBAL",
"index_get":"INDEX_GET","index_set":"INDEX_SET", "pop": "POP", "dup": "DUP", "swap": "SWAP",
"arr_push":"ARR_PUSH","arr_pop":"ARR_POP","arr_set":"ARR_SET","arr_insert":"ARR_INSERT","arr_remove":"ARR_REMOVE", "call": "CALL", "return": "RETURN", "print": "PRINT",
"slice":"SLICE", "jump": "JUMP", "jump_if_false": "JUMP_IF_FALSE",
"to_number":"TO_NUMBER","to_string":"TO_STRING", "line": "LINE",
"split":"SPLIT","join":"JOIN","substr":"SUBSTR","find":"FIND", # arithmetic/logic
"enumerate":"ENUMERATE","zip":"ZIP", "add": "ADD", "sub": "SUB", "mul": "MUL", "div": "DIV", "mod": "MOD",
"min":"MIN","max":"MAX","clamp":"CLAMP","abs":"ABS","pow":"POW", "lt": "LT", "lte": "LTE", "gt": "GT", "gte": "GTE",
"random_seed":"RANDOM_SEED","random_int":"RANDOM_INT", "eq": "EQ", "neq": "NEQ", "and": "AND", "or": "OR", "not": "NOT",
"make_map":"MAKE_MAP","keys":"KEYS","values":"VALUES","has_key":"HAS_KEY", # arrays and slices
"read_file":"READ_FILE","write_file":"WRITE_FILE", "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() tokens = set()
for inc in incs: for inc in incs:
tokens.add(mapping.get(inc, inc.upper())) tokens.add(overrides.get(inc, inc.upper()))
return tokens return tokens
def main() -> int: def main() -> int: