From 785fbdeb33b717852709280a602a8fc58dde64ca Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Sat, 16 Aug 2025 18:14:56 +0200 Subject: [PATCH] Compiler: handle feature numeric value * accept `$cpnfig feature=value` in recipe.txt * support feature values in preprocessor expressions * simplify `Compiler.addFeature()`: feature value is specified as feature=value * add string_map module * simplify option parsing, add `argarg` for options with an argument * add `-DFeature[=value]` to define features from the command line * enable test --- common/build_target.c2 | 7 +- common/string_list.c2 | 2 +- common/string_map.c2 | 153 +++++++++++++++++++++++++++ compiler/compiler.c2 | 26 +++-- compiler/main.c2 | 19 +++- parser/c2_parser.c2 | 6 +- parser/c2_tokenizer.c2 | 22 ++-- recipe.txt | 3 + test/c_generator/defines/defines.c2t | 12 ++- tools/c2cat.c2 | 10 +- 10 files changed, 221 insertions(+), 39 deletions(-) create mode 100644 common/string_map.c2 diff --git a/common/build_target.c2 b/common/build_target.c2 index ca57bec17..b0de1ae0c 100644 --- a/common/build_target.c2 +++ b/common/build_target.c2 @@ -18,6 +18,7 @@ module build_target; import file_list local; import src_loc local; import string_list; +import string_map; import string_pool; import warning_flags; @@ -110,7 +111,7 @@ public type Target struct @(opaque) { bool backend_fast; bool optional; - string_list.List features; + string_map.Map features; List libs; string_list.List exports; PluginList plugins; @@ -152,10 +153,10 @@ public fn u32 Target.numFiles(const Target* t) { return t.files.getCount(); } public fn u32 Target.numAsmFiles(const Target* t) { return t.asm_files.getCount(); } -public fn const string_list.List* Target.getFeatures(const Target* t) { return &t.features; } +public fn const string_map.Map* Target.getFeatures(const Target* t) { return &t.features; } public fn void Target.addFeature(Target* t, u32 feature) { - t.features.add(feature); + t.features.addNameValue(feature, "1"); } public fn void Target.removeFeature(Target* t, u32 feature) { diff --git a/common/string_list.c2 b/common/string_list.c2 index c39d9bdcd..e524febd2 100644 --- a/common/string_list.c2 +++ b/common/string_list.c2 @@ -75,7 +75,7 @@ public fn void List.addStr(List* l, const char* str) { l.add(l.pool.addStr(str, true)); } -public fn bool List.contains(const List* l, const char* name) { +public fn bool List.contains(const List* l, const char* name) @(unused) { for (u32 i=0; i