Auto-generate defintions from defs.txt
But it doesn't yet handle names with non-C-indentifier characters in them.
This commit is contained in:
parent
291b6caa75
commit
8bda5d511a
|
|
@ -0,0 +1,27 @@
|
||||||
|
%compare-strncmp
|
||||||
|
%readonly-tables
|
||||||
|
%struct-type
|
||||||
|
%{
|
||||||
|
#include "joy.h"
|
||||||
|
#include "definitions.h"
|
||||||
|
%}
|
||||||
|
struct dict_entry;
|
||||||
|
%%
|
||||||
|
"%", tdiv_r
|
||||||
|
*, mul
|
||||||
|
+, add
|
||||||
|
-, sub
|
||||||
|
/, tdiv_q
|
||||||
|
bool, truthy
|
||||||
|
branch, branch
|
||||||
|
clear, clear
|
||||||
|
cmp, cmp_joyfunc
|
||||||
|
cons, cons
|
||||||
|
concat, concat
|
||||||
|
dip, dip
|
||||||
|
dup, dup
|
||||||
|
i, i_joyfunc
|
||||||
|
pop, pop
|
||||||
|
stack, stack
|
||||||
|
swaack, swaack
|
||||||
|
swap, swap
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
/*
|
||||||
|
Auto-generated file by convert_defs.py --keywords
|
||||||
|
Do not edit.
|
||||||
|
*/
|
||||||
|
|
||||||
%compare-strncmp
|
%compare-strncmp
|
||||||
%readonly-tables
|
%readonly-tables
|
||||||
%struct-type
|
%struct-type
|
||||||
|
|
@ -25,7 +30,6 @@ pop, pop
|
||||||
stack, stack
|
stack, stack
|
||||||
swaack, swaack
|
swaack, swaack
|
||||||
swap, swap
|
swap, swap
|
||||||
swons, def_swons
|
|
||||||
abs, def_abs
|
abs, def_abs
|
||||||
anamorphism, def_anamorphism
|
anamorphism, def_anamorphism
|
||||||
app1, def_app1
|
app1, def_app1
|
||||||
|
|
@ -45,3 +49,5 @@ codireco, def_codireco
|
||||||
dinfrirst, def_dinfrirst
|
dinfrirst, def_dinfrirst
|
||||||
dipd, def_dipd
|
dipd, def_dipd
|
||||||
disenstacken, def_disenstacken
|
disenstacken, def_disenstacken
|
||||||
|
swons, def_swons
|
||||||
|
infra, def_infra
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,16 @@ joy: ${OBJS} $(STATIC_GCLIB)
|
||||||
joy.o: joy.h
|
joy.o: joy.h
|
||||||
|
|
||||||
definitions.c: defs.txt convert_defs.py
|
definitions.c: defs.txt convert_defs.py
|
||||||
python convert_defs.py > definitions.c
|
python convert_defs.py > $@
|
||||||
|
|
||||||
definitions.h: defs.txt convert_defs.py
|
definitions.h: defs.txt convert_defs.py
|
||||||
python convert_defs.py --header > definitions.h
|
python convert_defs.py --header > $@
|
||||||
|
|
||||||
definitions.o: definitions.h
|
definitions.o: definitions.h
|
||||||
|
|
||||||
|
KEYWORDS.txt: KEYWORDS.in defs.txt convert_defs.py
|
||||||
|
python convert_defs.py --keywords > $@
|
||||||
|
|
||||||
# Gperf doesn't add anything to '{""}' unused entries in the wordlist.
|
# Gperf doesn't add anything to '{""}' unused entries in the wordlist.
|
||||||
# This causes "warning: missing field 'func' initializer [-Wmissing-field-initializers]"
|
# This causes "warning: missing field 'func' initializer [-Wmissing-field-initializers]"
|
||||||
# which is promoted to an error and holds up the show.
|
# which is promoted to an error and holds up the show.
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ ccccons ccons ccons
|
||||||
ccons cons cons
|
ccons cons cons
|
||||||
cleave fork popdd
|
cleave fork popdd
|
||||||
clop cleave popdd
|
clop cleave popdd
|
||||||
cmp [[>] swap] dipd [ifte] ccons [=] swons ifte
|
|
||||||
codi cons dip
|
codi cons dip
|
||||||
codireco codi reco
|
codireco codi reco
|
||||||
dinfrirst dip infrst
|
dinfrirst dip infrst
|
||||||
|
|
@ -62,6 +61,12 @@ if sys.argv[-1] == '--header':
|
||||||
print(f'void def_{name}(JoyListPtr stack, JoyListPtr expression);')
|
print(f'void def_{name}(JoyListPtr stack, JoyListPtr expression);')
|
||||||
|
|
||||||
|
|
||||||
|
elif sys.argv[-1] == '--keywords':
|
||||||
|
sys.stdout.write(open('KEYWORDS.in').read())
|
||||||
|
for line in defs:
|
||||||
|
name, body = line.split(None, 1)
|
||||||
|
print(f'{name}, def_{name}')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
print('''
|
print('''
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ JoyList def_ccccons_body;
|
||||||
JoyList def_ccons_body;
|
JoyList def_ccons_body;
|
||||||
JoyList def_cleave_body;
|
JoyList def_cleave_body;
|
||||||
JoyList def_clop_body;
|
JoyList def_clop_body;
|
||||||
JoyList def_cmp_body;
|
|
||||||
JoyList def_codi_body;
|
JoyList def_codi_body;
|
||||||
JoyList def_codireco_body;
|
JoyList def_codireco_body;
|
||||||
JoyList def_dinfrirst_body;
|
JoyList def_dinfrirst_body;
|
||||||
|
|
@ -59,7 +58,6 @@ JoyList def_infra_body;
|
||||||
def_ccons_body = text_to_expression("cons cons");
|
def_ccons_body = text_to_expression("cons cons");
|
||||||
def_cleave_body = text_to_expression("fork popdd");
|
def_cleave_body = text_to_expression("fork popdd");
|
||||||
def_clop_body = text_to_expression("cleave popdd");
|
def_clop_body = text_to_expression("cleave popdd");
|
||||||
def_cmp_body = text_to_expression("[[>] swap] dipd [ifte] ccons [=] swons ifte");
|
|
||||||
def_codi_body = text_to_expression("cons dip");
|
def_codi_body = text_to_expression("cons dip");
|
||||||
def_codireco_body = text_to_expression("codi reco");
|
def_codireco_body = text_to_expression("codi reco");
|
||||||
def_dinfrirst_body = text_to_expression("dip infrst");
|
def_dinfrirst_body = text_to_expression("dip infrst");
|
||||||
|
|
@ -88,7 +86,6 @@ void def_ccccons(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression
|
||||||
void def_ccons(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_ccons_body, expression); }
|
void def_ccons(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_ccons_body, expression); }
|
||||||
void def_cleave(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_cleave_body, expression); }
|
void def_cleave(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_cleave_body, expression); }
|
||||||
void def_clop(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_clop_body, expression); }
|
void def_clop(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_clop_body, expression); }
|
||||||
void def_cmp(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_cmp_body, expression); }
|
|
||||||
void def_codi(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_codi_body, expression); }
|
void def_codi(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_codi_body, expression); }
|
||||||
void def_codireco(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_codireco_body, expression); }
|
void def_codireco(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_codireco_body, expression); }
|
||||||
void def_dinfrirst(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_dinfrirst_body, expression); }
|
void def_dinfrirst(__attribute__((unused)) JoyListPtr stack, JoyListPtr expression) { push_quote_onto_expression(def_dinfrirst_body, expression); }
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ void def_ccccons(JoyListPtr stack, JoyListPtr expression);
|
||||||
void def_ccons(JoyListPtr stack, JoyListPtr expression);
|
void def_ccons(JoyListPtr stack, JoyListPtr expression);
|
||||||
void def_cleave(JoyListPtr stack, JoyListPtr expression);
|
void def_cleave(JoyListPtr stack, JoyListPtr expression);
|
||||||
void def_clop(JoyListPtr stack, JoyListPtr expression);
|
void def_clop(JoyListPtr stack, JoyListPtr expression);
|
||||||
void def_cmp(JoyListPtr stack, JoyListPtr expression);
|
|
||||||
void def_codi(JoyListPtr stack, JoyListPtr expression);
|
void def_codi(JoyListPtr stack, JoyListPtr expression);
|
||||||
void def_codireco(JoyListPtr stack, JoyListPtr expression);
|
void def_codireco(JoyListPtr stack, JoyListPtr expression);
|
||||||
void def_dinfrirst(JoyListPtr stack, JoyListPtr expression);
|
void def_dinfrirst(JoyListPtr stack, JoyListPtr expression);
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,11 @@
|
||||||
#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf@gnu.org>."
|
#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf@gnu.org>."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#line 4 "KEYWORDS.txt"
|
#line 9 "KEYWORDS.txt"
|
||||||
|
|
||||||
#include "joy.h"
|
#include "joy.h"
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#line 8 "KEYWORDS.txt"
|
#line 13 "KEYWORDS.txt"
|
||||||
struct dict_entry;
|
struct dict_entry;
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
/* maximum key range = 61, duplicates = 0 */
|
/* maximum key range = 61, duplicates = 0 */
|
||||||
|
|
@ -59,7 +59,7 @@ keyword_hash (register const char *str, register size_t len)
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 30, 62,
|
62, 62, 62, 62, 62, 62, 62, 62, 30, 62,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 0, 0,
|
62, 62, 62, 62, 62, 62, 62, 15, 0, 0,
|
||||||
20, 0, 62, 62, 30, 10, 62, 5, 25, 5,
|
20, 0, 62, 62, 30, 10, 62, 5, 25, 5,
|
||||||
0, 0, 10, 62, 0, 0, 0, 15, 5, 10,
|
0, 0, 10, 62, 0, 0, 0, 15, 5, 10,
|
||||||
62, 10, 62, 62, 62, 62, 62, 62, 62, 62,
|
62, 10, 62, 62, 62, 62, 62, 62, 62, 62,
|
||||||
|
|
@ -95,7 +95,7 @@ in_word_set (register const char *str, register size_t len)
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
TOTAL_KEYWORDS = 38,
|
TOTAL_KEYWORDS = 39,
|
||||||
MIN_WORD_LENGTH = 1,
|
MIN_WORD_LENGTH = 1,
|
||||||
MAX_WORD_LENGTH = 12,
|
MAX_WORD_LENGTH = 12,
|
||||||
MIN_HASH_VALUE = 1,
|
MIN_HASH_VALUE = 1,
|
||||||
|
|
@ -105,98 +105,99 @@ in_word_set (register const char *str, register size_t len)
|
||||||
static const struct dict_entry wordlist[] =
|
static const struct dict_entry wordlist[] =
|
||||||
{
|
{
|
||||||
{""},
|
{""},
|
||||||
#line 37 "KEYWORDS.txt"
|
#line 41 "KEYWORDS.txt"
|
||||||
{"b", def_b},
|
{"b", def_b},
|
||||||
#line 35 "KEYWORDS.txt"
|
|
||||||
{"at", def_at},
|
|
||||||
#line 29 "KEYWORDS.txt"
|
|
||||||
{"abs", def_abs},
|
|
||||||
#line 19 "KEYWORDS.txt"
|
|
||||||
{"cons", cons},
|
|
||||||
#line 40 "KEYWORDS.txt"
|
|
||||||
{"ccons", def_ccons},
|
|
||||||
#line 20 "KEYWORDS.txt"
|
|
||||||
{"concat", concat},
|
|
||||||
#line 39 "KEYWORDS.txt"
|
#line 39 "KEYWORDS.txt"
|
||||||
{"ccccons", def_ccccons},
|
{"at", def_at},
|
||||||
|
#line 33 "KEYWORDS.txt"
|
||||||
|
{"abs", def_abs},
|
||||||
|
#line 24 "KEYWORDS.txt"
|
||||||
|
{"cons", cons},
|
||||||
#line 44 "KEYWORDS.txt"
|
#line 44 "KEYWORDS.txt"
|
||||||
|
{"ccons", def_ccons},
|
||||||
|
#line 25 "KEYWORDS.txt"
|
||||||
|
{"concat", concat},
|
||||||
|
#line 43 "KEYWORDS.txt"
|
||||||
|
{"ccccons", def_ccccons},
|
||||||
|
#line 48 "KEYWORDS.txt"
|
||||||
{"codireco", def_codireco},
|
{"codireco", def_codireco},
|
||||||
{""},
|
{""},
|
||||||
#line 25 "KEYWORDS.txt"
|
|
||||||
{"stack", stack},
|
|
||||||
#line 23 "KEYWORDS.txt"
|
|
||||||
{"i", i_joyfunc},
|
|
||||||
#line 36 "KEYWORDS.txt"
|
|
||||||
{"average", def_average},
|
|
||||||
#line 24 "KEYWORDS.txt"
|
|
||||||
{"pop", pop},
|
|
||||||
#line 43 "KEYWORDS.txt"
|
|
||||||
{"codi", def_codi},
|
|
||||||
#line 28 "KEYWORDS.txt"
|
|
||||||
{"swons", def_swons},
|
|
||||||
#line 30 "KEYWORDS.txt"
|
#line 30 "KEYWORDS.txt"
|
||||||
|
{"stack", stack},
|
||||||
|
#line 28 "KEYWORDS.txt"
|
||||||
|
{"i", i_joyfunc},
|
||||||
|
#line 40 "KEYWORDS.txt"
|
||||||
|
{"average", def_average},
|
||||||
|
#line 29 "KEYWORDS.txt"
|
||||||
|
{"pop", pop},
|
||||||
|
#line 47 "KEYWORDS.txt"
|
||||||
|
{"codi", def_codi},
|
||||||
|
#line 52 "KEYWORDS.txt"
|
||||||
|
{"swons", def_swons},
|
||||||
|
#line 34 "KEYWORDS.txt"
|
||||||
{"anamorphism", def_anamorphism},
|
{"anamorphism", def_anamorphism},
|
||||||
{""},
|
{""},
|
||||||
#line 18 "KEYWORDS.txt"
|
#line 23 "KEYWORDS.txt"
|
||||||
{"cmp", cmp_joyfunc},
|
{"cmp", cmp_joyfunc},
|
||||||
#line 45 "KEYWORDS.txt"
|
#line 49 "KEYWORDS.txt"
|
||||||
{"dinfrirst", def_dinfrirst},
|
{"dinfrirst", def_dinfrirst},
|
||||||
{""},
|
#line 53 "KEYWORDS.txt"
|
||||||
#line 26 "KEYWORDS.txt"
|
{"infra", def_infra},
|
||||||
|
#line 31 "KEYWORDS.txt"
|
||||||
{"swaack", swaack},
|
{"swaack", swaack},
|
||||||
#line 47 "KEYWORDS.txt"
|
#line 51 "KEYWORDS.txt"
|
||||||
{"disenstacken", def_disenstacken},
|
{"disenstacken", def_disenstacken},
|
||||||
#line 21 "KEYWORDS.txt"
|
#line 26 "KEYWORDS.txt"
|
||||||
{"dip", dip},
|
{"dip", dip},
|
||||||
#line 27 "KEYWORDS.txt"
|
#line 32 "KEYWORDS.txt"
|
||||||
{"swap", swap},
|
{"swap", swap},
|
||||||
{""},
|
{""},
|
||||||
#line 38 "KEYWORDS.txt"
|
#line 42 "KEYWORDS.txt"
|
||||||
{"binary", def_binary},
|
{"binary", def_binary},
|
||||||
{""},
|
{""},
|
||||||
#line 22 "KEYWORDS.txt"
|
#line 27 "KEYWORDS.txt"
|
||||||
{"dup", dup},
|
{"dup", dup},
|
||||||
#line 15 "KEYWORDS.txt"
|
#line 20 "KEYWORDS.txt"
|
||||||
{"bool", truthy},
|
{"bool", truthy},
|
||||||
#line 17 "KEYWORDS.txt"
|
#line 22 "KEYWORDS.txt"
|
||||||
{"clear", clear},
|
{"clear", clear},
|
||||||
#line 41 "KEYWORDS.txt"
|
#line 45 "KEYWORDS.txt"
|
||||||
{"cleave", def_cleave},
|
{"cleave", def_cleave},
|
||||||
{""}, {""},
|
{""}, {""},
|
||||||
#line 46 "KEYWORDS.txt"
|
#line 50 "KEYWORDS.txt"
|
||||||
{"dipd", def_dipd},
|
{"dipd", def_dipd},
|
||||||
{""},
|
{""},
|
||||||
#line 16 "KEYWORDS.txt"
|
#line 21 "KEYWORDS.txt"
|
||||||
{"branch", branch},
|
{"branch", branch},
|
||||||
{""}, {""},
|
{""}, {""},
|
||||||
#line 42 "KEYWORDS.txt"
|
#line 46 "KEYWORDS.txt"
|
||||||
{"clop", def_clop},
|
{"clop", def_clop},
|
||||||
{""},
|
{""},
|
||||||
#line 14 "KEYWORDS.txt"
|
#line 19 "KEYWORDS.txt"
|
||||||
{"/", tdiv_q},
|
{"/", tdiv_q},
|
||||||
{""}, {""},
|
{""}, {""},
|
||||||
#line 34 "KEYWORDS.txt"
|
#line 38 "KEYWORDS.txt"
|
||||||
{"appN", def_appN},
|
{"appN", def_appN},
|
||||||
{""},
|
{""},
|
||||||
#line 13 "KEYWORDS.txt"
|
#line 18 "KEYWORDS.txt"
|
||||||
{"-", sub},
|
{"-", sub},
|
||||||
{""}, {""},
|
{""}, {""},
|
||||||
#line 33 "KEYWORDS.txt"
|
#line 37 "KEYWORDS.txt"
|
||||||
{"app3", def_app3},
|
{"app3", def_app3},
|
||||||
{""},
|
{""},
|
||||||
#line 12 "KEYWORDS.txt"
|
#line 17 "KEYWORDS.txt"
|
||||||
{"+", add},
|
{"+", add},
|
||||||
{""}, {""},
|
{""}, {""},
|
||||||
#line 32 "KEYWORDS.txt"
|
#line 36 "KEYWORDS.txt"
|
||||||
{"app2", def_app2},
|
{"app2", def_app2},
|
||||||
{""},
|
{""},
|
||||||
#line 11 "KEYWORDS.txt"
|
#line 16 "KEYWORDS.txt"
|
||||||
{"*", mul},
|
{"*", mul},
|
||||||
{""}, {""},
|
{""}, {""},
|
||||||
#line 31 "KEYWORDS.txt"
|
#line 35 "KEYWORDS.txt"
|
||||||
{"app1", def_app1},
|
{"app1", def_app1},
|
||||||
{""},
|
{""},
|
||||||
#line 10 "KEYWORDS.txt"
|
#line 15 "KEYWORDS.txt"
|
||||||
{"%", tdiv_r}
|
{"%", tdiv_r}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue