aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-21 10:45:36 +0800
committerMistivia <i@mistivia.com>2025-06-21 10:45:36 +0800
commit86742c415b34ae063bf8597d9228e9d37f0d7294 (patch)
tree297b2ae6a8b20bf74c9e54ec6628799c02425c0d /scripts
parent0afe446fa6e893448da949b1b6882c87b3b2701c (diff)
tail call optimazation
Diffstat (limited to 'scripts')
-rw-r--r--scripts/genprelude.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/genprelude.py b/scripts/genprelude.py
new file mode 100644
index 0000000..555485d
--- /dev/null
+++ b/scripts/genprelude.py
@@ -0,0 +1,31 @@
+def escape_c_string(s):
+ escape_chars = {
+ '\n': '\\n',
+ '\t': '\\t',
+ '\r': '\\r',
+ '\"': '\\"',
+ '\'': '\\\'',
+ '\\': '\\\\',
+ '\b': '\\b',
+ '\a': '\\a',
+ '\v': '\\v',
+ '\f': '\\f',
+ }
+ result = []
+ for c in s:
+ if c in escape_chars:
+ result.append(escape_chars[c])
+ else:
+ result.append(c)
+ return ''.join(result)
+
+import sys
+
+content = sys.stdin.read()
+escaped = escape_c_string(content)
+print(f"""
+#include "prelude.h"
+
+const char *prelude = "{escaped}";
+
+""")