dip
This commit is contained in:
parent
4b3117e349
commit
fe4ce60541
|
|
@ -15,6 +15,7 @@ bool, truthy
|
||||||
branch, branch
|
branch, branch
|
||||||
clear, clear
|
clear, clear
|
||||||
cmp, cmp_joyfunc
|
cmp, cmp_joyfunc
|
||||||
|
dip, dip
|
||||||
dup, dup
|
dup, dup
|
||||||
i, i_joyfunc
|
i, i_joyfunc
|
||||||
abs, def_abs
|
abs, def_abs
|
||||||
|
|
|
||||||
|
|
@ -578,6 +578,19 @@ clear(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
dip(JoyListPtr stack, JoyListPtr expression)
|
||||||
|
{
|
||||||
|
JoyList quote = pop_list_node(stack);
|
||||||
|
JoyList node = pop_any(stack);
|
||||||
|
JoyList x = EMPTY_LIST;
|
||||||
|
JoyListPtr xPtr = &x;
|
||||||
|
push_thing(node->head, xPtr);
|
||||||
|
push_quote(*xPtr, expression);
|
||||||
|
push_quote(quote, expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
dup(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression)
|
dup(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ void add(JoyListPtr stack, JoyListPtr expression);
|
||||||
void branch(JoyListPtr stack, JoyListPtr expression);
|
void branch(JoyListPtr stack, JoyListPtr expression);
|
||||||
void clear(JoyListPtr stack, JoyListPtr expression);
|
void clear(JoyListPtr stack, JoyListPtr expression);
|
||||||
void cmp_joyfunc(JoyListPtr stack, JoyListPtr expression);
|
void cmp_joyfunc(JoyListPtr stack, JoyListPtr expression);
|
||||||
|
void dip(JoyListPtr stack, JoyListPtr expression);
|
||||||
void dup(JoyListPtr stack, JoyListPtr expression);
|
void dup(JoyListPtr stack, JoyListPtr expression);
|
||||||
void i_joyfunc(JoyListPtr stack, JoyListPtr expression);
|
void i_joyfunc(JoyListPtr stack, JoyListPtr expression);
|
||||||
void mul(JoyListPtr stack, JoyListPtr expression);
|
void mul(JoyListPtr stack, JoyListPtr expression);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* ANSI-C code produced by gperf version 3.1 */
|
/* ANSI-C code produced by gperf version 3.1 */
|
||||||
/* Command-line: gperf --output-file=keywords.c --readonly-tables --enum --includes --hash-function-name=keyword_hash KEYWORDS.txt */
|
/* Command-line: gperf --output-file=keywords.c --readonly-tables --enum --includes --hash-function-name=keyword_hash KEYWORDS.txt */
|
||||||
/* Computed positions: -k'1,$' */
|
/* Computed positions: -k'2,$' */
|
||||||
|
|
||||||
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
|
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
|
||||||
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
|
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
#line 7 "KEYWORDS.txt"
|
#line 7 "KEYWORDS.txt"
|
||||||
struct dict_entry;
|
struct dict_entry;
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
/* maximum key range = 61, duplicates = 0 */
|
/* maximum key range = 44, duplicates = 0 */
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
__inline
|
__inline
|
||||||
|
|
@ -49,34 +49,44 @@ keyword_hash (register const char *str, register size_t len)
|
||||||
{
|
{
|
||||||
static const unsigned char asso_values[] =
|
static const unsigned char asso_values[] =
|
||||||
{
|
{
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 3, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 9, 45, 45,
|
||||||
62, 62, 30, 25, 62, 20, 62, 15, 62, 30,
|
45, 45, 31, 26, 45, 21, 45, 30, 45, 30,
|
||||||
25, 20, 62, 62, 62, 62, 62, 62, 62, 62,
|
25, 20, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 15, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 15, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 10, 0, 5,
|
45, 45, 45, 45, 45, 45, 45, 45, 20, 0,
|
||||||
0, 10, 62, 62, 10, 5, 62, 62, 20, 5,
|
15, 10, 45, 45, 5, 0, 45, 45, 10, 5,
|
||||||
5, 5, 0, 62, 5, 0, 10, 62, 62, 62,
|
0, 0, 10, 45, 0, 0, 0, 15, 0, 45,
|
||||||
62, 0, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 0, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||||
62, 62, 62, 62, 62, 62
|
45, 45, 45, 45, 45, 45
|
||||||
};
|
};
|
||||||
return len + asso_values[(unsigned char)str[len - 1]] + asso_values[(unsigned char)str[0]];
|
register unsigned int hval = len;
|
||||||
|
|
||||||
|
switch (hval)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
hval += asso_values[(unsigned char)str[1]];
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
case 1:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return hval + asso_values[(unsigned char)str[len - 1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct dict_entry *
|
const struct dict_entry *
|
||||||
|
|
@ -84,89 +94,85 @@ in_word_set (register const char *str, register size_t len)
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
TOTAL_KEYWORDS = 30,
|
TOTAL_KEYWORDS = 31,
|
||||||
MIN_WORD_LENGTH = 1,
|
MIN_WORD_LENGTH = 1,
|
||||||
MAX_WORD_LENGTH = 12,
|
MAX_WORD_LENGTH = 12,
|
||||||
MIN_HASH_VALUE = 1,
|
MIN_HASH_VALUE = 1,
|
||||||
MAX_HASH_VALUE = 61
|
MAX_HASH_VALUE = 44
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct dict_entry wordlist[] =
|
static const struct dict_entry wordlist[] =
|
||||||
{
|
{
|
||||||
{""},
|
{""},
|
||||||
#line 28 "KEYWORDS.txt"
|
#line 20 "KEYWORDS.txt"
|
||||||
{"b", def_b},
|
{"i", i_joyfunc},
|
||||||
|
#line 27 "KEYWORDS.txt"
|
||||||
|
{"at", def_at},
|
||||||
{""},
|
{""},
|
||||||
#line 18 "KEYWORDS.txt"
|
#line 35 "KEYWORDS.txt"
|
||||||
{"dup", dup},
|
{"codi", def_codi},
|
||||||
|
#line 32 "KEYWORDS.txt"
|
||||||
|
{"ccons", def_ccons},
|
||||||
|
#line 30 "KEYWORDS.txt"
|
||||||
|
{"binary", def_binary},
|
||||||
|
#line 31 "KEYWORDS.txt"
|
||||||
|
{"ccccons", def_ccccons},
|
||||||
|
#line 36 "KEYWORDS.txt"
|
||||||
|
{"codireco", def_codireco},
|
||||||
#line 37 "KEYWORDS.txt"
|
#line 37 "KEYWORDS.txt"
|
||||||
|
{"dinfrirst", def_dinfrirst},
|
||||||
|
#line 9 "KEYWORDS.txt"
|
||||||
|
{"%", tdiv_r},
|
||||||
|
#line 15 "KEYWORDS.txt"
|
||||||
|
{"branch", branch},
|
||||||
|
#line 39 "KEYWORDS.txt"
|
||||||
|
{"disenstacken", def_disenstacken},
|
||||||
|
#line 18 "KEYWORDS.txt"
|
||||||
|
{"dip", dip},
|
||||||
|
#line 14 "KEYWORDS.txt"
|
||||||
|
{"bool", truthy},
|
||||||
|
#line 16 "KEYWORDS.txt"
|
||||||
|
{"clear", clear},
|
||||||
|
#line 22 "KEYWORDS.txt"
|
||||||
|
{"anamorphism", def_anamorphism},
|
||||||
|
#line 28 "KEYWORDS.txt"
|
||||||
|
{"average", def_average},
|
||||||
|
#line 17 "KEYWORDS.txt"
|
||||||
|
{"cmp", cmp_joyfunc},
|
||||||
|
#line 38 "KEYWORDS.txt"
|
||||||
{"dipd", def_dipd},
|
{"dipd", def_dipd},
|
||||||
{""},
|
{""},
|
||||||
#line 29 "KEYWORDS.txt"
|
#line 29 "KEYWORDS.txt"
|
||||||
{"binary", def_binary},
|
{"b", def_b},
|
||||||
#line 9 "KEYWORDS.txt"
|
#line 12 "KEYWORDS.txt"
|
||||||
{"%", tdiv_r},
|
{"-", sub},
|
||||||
#line 17 "KEYWORDS.txt"
|
#line 21 "KEYWORDS.txt"
|
||||||
{"cmp", cmp_joyfunc},
|
|
||||||
#line 33 "KEYWORDS.txt"
|
|
||||||
{"clop", def_clop},
|
|
||||||
#line 31 "KEYWORDS.txt"
|
|
||||||
{"ccons", def_ccons},
|
|
||||||
#line 19 "KEYWORDS.txt"
|
|
||||||
{"i", i_joyfunc},
|
|
||||||
#line 30 "KEYWORDS.txt"
|
|
||||||
{"ccccons", def_ccccons},
|
|
||||||
#line 20 "KEYWORDS.txt"
|
|
||||||
{"abs", def_abs},
|
{"abs", def_abs},
|
||||||
#line 34 "KEYWORDS.txt"
|
#line 34 "KEYWORDS.txt"
|
||||||
{"codi", def_codi},
|
{"clop", def_clop},
|
||||||
#line 16 "KEYWORDS.txt"
|
|
||||||
{"clear", clear},
|
|
||||||
#line 15 "KEYWORDS.txt"
|
|
||||||
{"branch", branch},
|
|
||||||
#line 38 "KEYWORDS.txt"
|
|
||||||
{"disenstacken", def_disenstacken},
|
|
||||||
#line 35 "KEYWORDS.txt"
|
|
||||||
{"codireco", def_codireco},
|
|
||||||
#line 36 "KEYWORDS.txt"
|
|
||||||
{"dinfrirst", def_dinfrirst},
|
|
||||||
{""},
|
{""},
|
||||||
#line 32 "KEYWORDS.txt"
|
#line 33 "KEYWORDS.txt"
|
||||||
{"cleave", def_cleave},
|
{"cleave", def_cleave},
|
||||||
|
#line 11 "KEYWORDS.txt"
|
||||||
|
{"+", add},
|
||||||
|
#line 19 "KEYWORDS.txt"
|
||||||
|
{"dup", dup},
|
||||||
#line 26 "KEYWORDS.txt"
|
#line 26 "KEYWORDS.txt"
|
||||||
{"at", def_at},
|
|
||||||
{""},
|
|
||||||
#line 14 "KEYWORDS.txt"
|
|
||||||
{"bool", truthy},
|
|
||||||
{""},
|
|
||||||
#line 21 "KEYWORDS.txt"
|
|
||||||
{"anamorphism", def_anamorphism},
|
|
||||||
#line 27 "KEYWORDS.txt"
|
|
||||||
{"average", def_average},
|
|
||||||
{""},
|
|
||||||
#line 25 "KEYWORDS.txt"
|
|
||||||
{"appN", def_appN},
|
{"appN", def_appN},
|
||||||
{""},
|
{""},
|
||||||
#line 13 "KEYWORDS.txt"
|
#line 13 "KEYWORDS.txt"
|
||||||
{"/", tdiv_q},
|
{"/", tdiv_q},
|
||||||
{""}, {""},
|
#line 10 "KEYWORDS.txt"
|
||||||
#line 24 "KEYWORDS.txt"
|
{"*", mul},
|
||||||
|
{""},
|
||||||
|
#line 25 "KEYWORDS.txt"
|
||||||
{"app3", def_app3},
|
{"app3", def_app3},
|
||||||
{""}, {""}, {""}, {""},
|
{""}, {""}, {""}, {""},
|
||||||
#line 23 "KEYWORDS.txt"
|
#line 24 "KEYWORDS.txt"
|
||||||
{"app2", def_app2},
|
{"app2", def_app2},
|
||||||
{""},
|
{""}, {""}, {""}, {""},
|
||||||
#line 12 "KEYWORDS.txt"
|
#line 23 "KEYWORDS.txt"
|
||||||
{"-", sub},
|
{"app1", def_app1}
|
||||||
{""}, {""},
|
|
||||||
#line 22 "KEYWORDS.txt"
|
|
||||||
{"app1", def_app1},
|
|
||||||
{""}, {""}, {""}, {""}, {""}, {""},
|
|
||||||
#line 11 "KEYWORDS.txt"
|
|
||||||
{"+", add},
|
|
||||||
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
|
|
||||||
#line 10 "KEYWORDS.txt"
|
|
||||||
{"*", mul}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,11 @@
|
||||||
|
With a little bit of complexity we could improve efficiency (e.g. using
|
||||||
|
VList instead of singly-linked list.) But I want to tackle efficiency by
|
||||||
|
compilation, and write the compiler(s) in Prolog. I think that avoids
|
||||||
|
complexity compared to intricating the guts of the interpreter by hand,
|
||||||
|
and moves the unavoidable complexity into formal statements of logic that
|
||||||
|
can be evaulated by machine (aka Prolog.)
|
||||||
|
|
||||||
|
---------------------------------------
|
||||||
|
|
||||||
So how do we want to handle definitions? Read a defs.txt file at
|
So how do we want to handle definitions? Read a defs.txt file at
|
||||||
compile time? Build defs.c from defs.txt?
|
compile time? Build defs.c from defs.txt?
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue