aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-03-04 23:24:43 -0500
committerKevinOConnor <kevin@koconnor.net>2019-03-17 19:38:18 -0400
commit7d73a35805a61a40f49d0840741434ab9548d638 (patch)
treebe0fa334caf5ffa96a272c44a38de5f560041a47 /scripts
parentb28e95ca1aa2860c0869041c29a3ba27054e5967 (diff)
downloadkutter-7d73a35805a61a40f49d0840741434ab9548d638.tar.gz
kutter-7d73a35805a61a40f49d0840741434ab9548d638.tar.xz
kutter-7d73a35805a61a40f49d0840741434ab9548d638.zip
command: Support evaluating C expressions in DECL_CONSTANT()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/buildcommands.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py
index 1c3448fe..46e6dc36 100644
--- a/scripts/buildcommands.py
+++ b/scripts/buildcommands.py
@@ -101,19 +101,36 @@ Handlers.append(HandleStaticStrings())
# Constants
######################################################################
+def decode_integer(value):
+ value = value.strip()
+ if len(value) != 7 or value[0] not in '-+':
+ error("Invalid encoded integer '%s'" % (value,))
+ out = sum([(ord(c) - 48) << (i*6) for i, c in enumerate(value[1:])])
+ if value[0] == '-':
+ out -= 1<<32
+ return out
+
# Allow adding build time constants to the data dictionary
class HandleConstants:
def __init__(self):
self.constants = {}
- self.ctr_dispatch = { '_DECL_CONSTANT': self.decl_constant }
+ self.ctr_dispatch = {
+ '_DECL_CONSTANT': self.decl_constant,
+ '_DECL_CONSTANT_STR': self.decl_constant_str,
+ }
+ def set_value(self, name, value):
+ if name in self.constants and self.constants[name] != value:
+ error("Conflicting definition for constant '%s'" % name)
+ self.constants[name] = value
def decl_constant(self, req):
name, value = req.split()[1:]
+ self.set_value(name, decode_integer(value))
+ def decl_constant_str(self, req):
+ name, value = req.split()[1:]
value = value.strip()
if value.startswith('"') and value.endswith('"'):
value = value[1:-1]
- if name in self.constants and self.constants[name] != value:
- error("Conflicting definition for constant '%s'" % name)
- self.constants[name] = value
+ self.set_value(name, value)
def update_data_dictionary(self, data):
data['config'] = self.constants
def generate_code(self, options):