From e13c0a7114b1a5383917453a1af9860fe6783bc5 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Sat, 1 Jun 2024 20:46:55 +0200 Subject: [PATCH] Berry coc parser keeps order of variables (#21542) --- CHANGELOG.md | 1 + lib/libesp32/berry/tools/coc/hash_map.py | 25 ++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd5643e83..4f27303a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. ### Changed - TCP bridge increased baudrate selection (#21528) +- Berry coc parser keeps order of variables ### Fixed - uDisplay Parallel display on Core3 (#21529) diff --git a/lib/libesp32/berry/tools/coc/hash_map.py b/lib/libesp32/berry/tools/coc/hash_map.py index 9d3da5365..c842c9e0f 100644 --- a/lib/libesp32/berry/tools/coc/hash_map.py +++ b/lib/libesp32/berry/tools/coc/hash_map.py @@ -27,6 +27,13 @@ class hash_map: self.bucket = [] self.resize(2) + var_count = 0 + # replace any 'var' by its slot number + for (key, value) in map.items(): + if value == "var": + map[key] = var_count + var_count += 1 + for key in sorted(map.keys()): self.insert(key, map[key]) @@ -115,27 +122,21 @@ class hash_map: # Compute entries in the hash for modules or classes ################################################################################# # return a list (entiry, var_count) - def entry_modify(self, ent, var_count): + def entry_modify(self, ent): ent.key = escape_operator(ent.key) - if ent.value == "var": - ent.value = "be_const_var(" + str(var_count) + ")" - var_count += 1 + if isinstance(ent.value, int): + ent.value = "be_const_var(" + str(ent.value) + ")" else: ent.value = "be_const_" + ent.value - return (ent, var_count) + return ent # generate the final map def entry_list(self): l = [] - var_count = 0 self.resize(self.count) for it in self.bucket: - (ent, var_count) = self.entry_modify(it, var_count) - # print(f"ent={ent} var_count={var_count}") - # # ex: ent= var_count=0 - # # ex: ent= var_count=0 - l.append(ent) + l.append(self.entry_modify(it)) return l def var_count(self): @@ -143,7 +144,7 @@ class hash_map: self.resize(self.count) for it in self.bucket: - if it.value == "var": count += 1 + if isinstance(it.value, int): count += 1 return count if __name__ == '__main__':