From db805ce7db997f9cd1ca9f01cd715a00ba6bc69b Mon Sep 17 00:00:00 2001 From: mohanson Date: Wed, 11 Sep 2024 12:21:36 +0800 Subject: [PATCH] Use awk to rewrite compile.lua --- tests/benchmark/Makefile | 2 +- tests/ckb_js_tests/Makefile | 4 ++-- tests/examples/Makefile | 2 +- tools/compile.awk | 14 ++++++++++++++ tools/compile.lua | 8 -------- 5 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 tools/compile.awk delete mode 100644 tools/compile.lua diff --git a/tests/benchmark/Makefile b/tests/benchmark/Makefile index 1901306..dfcaf80 100644 --- a/tests/benchmark/Makefile +++ b/tests/benchmark/Makefile @@ -14,7 +14,7 @@ define debug endef define compile-run - $(CKB-DEBUGGER) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -c | lua $(ROOT_DIR)/../../tools/compile.lua | xxd -r -p > $(ROOT_DIR)/../../build/$(1).bc + $(CKB-DEBUGGER) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > $(ROOT_DIR)/../../build/$(1).bc $(CKB-DEBUGGER) --read-file $(ROOT_DIR)/../../build/$(1).bc --bin $(BIN_PATH) -- -r | tee $(ROOT_DIR)/benchmark.txt endef diff --git a/tests/ckb_js_tests/Makefile b/tests/ckb_js_tests/Makefile index 428db8d..1d5f4f9 100644 --- a/tests/ckb_js_tests/Makefile +++ b/tests/ckb_js_tests/Makefile @@ -27,8 +27,8 @@ build/testdata_fs_modules.bin: test_data/fs_module/main.js test_data/fs_module/f fs_bytecode: mkdir -p ../../build/bytecode - $(CKB_DEBUGGER) --read-file test_data/fs_module/main.js --bin $(BIN_PATH) -- -c | lua $(ROOT_DIR)/../../tools/compile.lua | xxd -r -p > ../../build/bytecode/main.bc - $(CKB_DEBUGGER) --read-file test_data/fs_module/fib_module.js --bin $(BIN_PATH) -- -c | lua $(ROOT_DIR)/../../tools/compile.lua | xxd -r -p > ../../build/bytecode/fib_module.bc + $(CKB_DEBUGGER) --read-file test_data/fs_module/main.js --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > ../../build/bytecode/main.bc + $(CKB_DEBUGGER) --read-file test_data/fs_module/fib_module.js --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > ../../build/bytecode/fib_module.bc cd ../../build/bytecode && lua ../../tools/fs.lua pack ../../build/testdata_fs_modules_bc.bin main.bc fib_module.bc $(CKB_DEBUGGER) --max-cycles $(MAX_CYCLES) --read-file ../../build/testdata_fs_modules_bc.bin --bin $(BIN_PATH) -- -f -r 2>&1 | fgrep 'Run result: 0' diff --git a/tests/examples/Makefile b/tests/examples/Makefile index dae392f..3a9e34b 100644 --- a/tests/examples/Makefile +++ b/tests/examples/Makefile @@ -14,7 +14,7 @@ define debug endef define compile-run - $(CKB-DEBUGGER) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -c | lua $(ROOT_DIR)/../../tools/compile.lua | xxd -r -p > $(ROOT_DIR)/../../build/$(1).bc + $(CKB-DEBUGGER) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > $(ROOT_DIR)/../../build/$(1).bc $(CKB-DEBUGGER) --read-file $(ROOT_DIR)/../../build/$(1).bc --bin $(BIN_PATH) -- -r | fgrep 'Run result: 0' endef diff --git a/tools/compile.awk b/tools/compile.awk new file mode 100644 index 0000000..bacc338 --- /dev/null +++ b/tools/compile.awk @@ -0,0 +1,14 @@ +#!/usr/bin/awk -f + +{ + # Check if the line starts with "Script log: " + if ($0 ~ /^Script log: /) { + # Remove "Script log: " from the line + line_data = gensub(/^Script log: /, "", "g") + + # If the remaining line is not empty, print it + if (line_data != "") { + print line_data + } + } +} diff --git a/tools/compile.lua b/tools/compile.lua deleted file mode 100644 index f3a0bc8..0000000 --- a/tools/compile.lua +++ /dev/null @@ -1,8 +0,0 @@ -for line in io.lines() do - if line:find("^Script log: ") ~= nil then - local line_data = line:gsub("^Script log: ", "") - if line_data ~= "" then - print(line_data) - end - end -end