OSDN Git Service

A first attempt at definitions.
authorSimon Forman <sforman@hushmail.com>
Sun, 5 Feb 2023 06:58:38 +0000 (22:58 -0800)
committerSimon Forman <sforman@hushmail.com>
Sun, 5 Feb 2023 06:58:38 +0000 (22:58 -0800)
implementations/C/convert_defs.py [new file with mode: 0644]

diff --git a/implementations/C/convert_defs.py b/implementations/C/convert_defs.py
new file mode 100644 (file)
index 0000000..a976b20
--- /dev/null
@@ -0,0 +1,55 @@
+import sys
+
+#list(open('../defs.txt'))
+defs = '''\
+abs dup 0 < [] [neg] branch
+anamorphism [pop []] swap [dip swons] genrec
+app1 grba infrst
+app2 [grba swap grba swap] dip [infrst] cons ii
+app3 3 appN
+appN [grabN] codi map reverse disenstacken
+at drop first
+average [sum] [size] cleave /
+b [i] dip i
+binary unary popd
+ccccons ccons ccons
+ccons cons cons
+clear [] swaack pop
+cleave fork popdd
+clop cleave popdd
+cmp [[>] swap] dipd [ifte] ccons [=] swons ifte
+codi cons dip
+codireco codi reco
+dinfrirst dip infrst
+dipd [dip] codi
+disenstacken ? [uncons ?] loop pop'''.splitlines()
+
+
+for line in defs:
+    name, body = line.split(None, 1)
+    print(f'{name}, def_{name}')
+
+print()
+print()
+print('void')
+print('init_defs(void)')
+print('{')
+for line in defs:
+    name, body = line.split(None, 1)
+    print(f'\tdef_{name}_body = text_to_expression({repr(body)});')
+print('}')
+
+
+
+print()
+print()
+for line in defs:
+    name, body = line.split(None, 1)
+    print(f'void def_{name}(JoyListPtr stack, JoyListPtr expression)')
+
+print()
+print()
+for line in defs:
+    name, body = line.split(None, 1)
+    print(f'void def_{name}(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) {{ push_quote(def_{name}_body, expression); }}')
+