The great librarificating rename

This commit is contained in:
Přemysl Eric Janouch 2017-05-30 02:43:42 +02:00
parent d579e68051
commit 8518c1a58f
Signed by: p
GPG Key ID: B715679E3A361BE6
3 changed files with 673 additions and 656 deletions

1235
ell.c

File diff suppressed because it is too large Load Diff

View File

@ -28,44 +28,44 @@ main (int argc, char *argv[]) {
} }
int c; int c;
struct buffer buf = BUFFER_INITIALIZER; struct ell_buffer buf = ELL_BUFFER_INITIALIZER;
while ((c = fgetc (fp)) != EOF) while ((c = fgetc (fp)) != EOF)
buffer_append_c (&buf, c); ell_buffer_append_c (&buf, c);
buffer_append_c (&buf, 0); ell_buffer_append_c (&buf, 0);
fclose (fp); fclose (fp);
struct parser parser; struct ell_parser p;
parser_init (&parser, buf.s, buf.len - 1); ell_parser_init (&p, buf.s, buf.len - 1);
const char *e = NULL; const char *e = NULL;
struct item *program = parser_run (&parser, &e); struct ell_v *program = ell_parser_run (&p, &e);
free (buf.s); free (buf.s);
if (e) { if (e) {
printf ("%s: %s\n", "parse error", e); printf ("%s: %s\n", "parse error", e);
return 1; return 1;
} }
parser_free (&parser); ell_parser_free (&p);
struct context ctx; struct ell ell;
context_init (&ctx); ell_init (&ell);
if (!init_runtime_library (&ctx)) if (!ell_std_initialize (&ell))
printf ("%s\n", "runtime library initialization failed"); printf ("%s\n", "runtime library initialization failed");
// In this one place we optimistically expect allocation to succeed // In this one place we optimistically expect allocation to succeed
struct item *args = NULL, **tail = &args; struct ell_v *args = NULL, **tail = &args;
for (int i = 2; i < argc; i++) for (int i = 2; i < argc; i++)
tail = &(*tail = new_string (argv[i], strlen (argv[i])))->next; tail = &(*tail = ell_string (argv[i], strlen (argv[i])))->next;
struct item *result = NULL; struct ell_v *result = NULL;
(void) execute_block (&ctx, program, args, &result); (void) ell_eval_block (&ell, program, args, &result);
item_free_list (result); ell_free_seq (result);
item_free_list (program); ell_free_seq (program);
const char *failure = ctx.error; const char *failure = ell.error;
if (ctx.memory_failure) if (ell.memory_failure)
failure = "memory allocation failure"; failure = "memory allocation failure";
if (failure) if (failure)
printf ("%s: %s\n", "runtime error", failure); printf ("%s: %s\n", "runtime error", failure);
context_free (&ctx); ell_free (&ell);
return 0; return 0;
} }

52
repl.c
View File

@ -22,23 +22,23 @@
#include <readline/history.h> #include <readline/history.h>
static void static void
run (struct context *ctx, struct item *program) { run (struct ell *ell, struct ell_v *program) {
struct item *result = NULL; struct ell_v *result = NULL;
(void) execute_block (ctx, program, NULL, &result); (void) ell_eval_block (ell, program, NULL, &result);
item_free_list (program); ell_free_seq (program);
const char *failure = ctx->error; const char *failure = ell->error;
if (ctx->memory_failure) if (ell->memory_failure)
failure = "memory allocation failure"; failure = "memory allocation failure";
if (failure) { if (failure) {
printf ("\x1b[31m%s: %s\x1b[0m\n", "runtime error", failure); printf ("\x1b[31m%s: %s\x1b[0m\n", "runtime error", failure);
free (ctx->error); free (ell->error);
ctx->error = NULL; ell->error = NULL;
ctx->memory_failure = false; ell->memory_failure = false;
} else { } else {
print_item_list (result); ell_print_seq (result);
putchar ('\n'); putchar ('\n');
item_free_list (result); ell_free_seq (result);
} }
} }
@ -49,7 +49,7 @@ init_readline (void) {
return 0; return 0;
} }
struct context ctx; static struct ell ell;
static char ** static char **
complete (const char *text, int start, int end) { complete (const char *text, int start, int end) {
@ -61,18 +61,18 @@ complete (const char *text, int start, int end) {
static char *buf[128]; static char *buf[128];
size_t n = 1, len = strlen (text); size_t n = 1, len = strlen (text);
for (struct item *item = ctx.globals; item; item = item->next) for (struct ell_v *v = ell.globals; v; v = v->next)
if (n < 127 && !strncmp (item->head->value, text, len)) if (n < 127 && !strncmp (v->head->string, text, len))
buf[n++] = format ("%s", item->head->value); buf[n++] = ell_format ("%s", v->head->string);
for (struct native_fn *iter = ctx.native; iter; iter = iter->next) for (struct ell_native_fn *iter = ell.native; iter; iter = iter->next)
if (n < 127 && !strncmp (iter->name, text, len)) if (n < 127 && !strncmp (iter->name, text, len))
buf[n++] = format ("%s", iter->name); buf[n++] = ell_format ("%s", iter->name);
if (n < 2) if (n < 2)
return NULL; return NULL;
// This never actually completes anything, just shows the options, // This never actually completes anything, just shows the options,
// we'd have to figure out the longest common prefix // we'd have to figure out the longest common prefix
buf[0] = format ("%s", text); buf[0] = ell_format ("%s", text);
buf[n++] = NULL; buf[n++] = NULL;
char **copy = malloc (sizeof *buf * n); char **copy = malloc (sizeof *buf * n);
@ -84,8 +84,8 @@ int
main (int argc, char *argv[]) { main (int argc, char *argv[]) {
(void) argc; (void) argc;
context_init (&ctx); ell_init (&ell);
if (!init_runtime_library (&ctx)) if (!ell_std_initialize (&ell))
printf ("%s\n", "runtime library initialization failed"); printf ("%s\n", "runtime library initialization failed");
using_history (); using_history ();
@ -96,21 +96,21 @@ main (int argc, char *argv[]) {
char *line; char *line;
while ((line = readline ("> "))) { while ((line = readline ("> "))) {
struct parser parser; struct ell_parser p;
parser_init (&parser, line, strlen (line)); ell_parser_init (&p, line, strlen (line));
add_history (line); add_history (line);
const char *e = NULL; const char *e = NULL;
struct item *program = parser_run (&parser, &e); struct ell_v *program = ell_parser_run (&p, &e);
free (line); free (line);
if (e) if (e)
printf ("\x1b[31m%s: %s\x1b[0m\n", "parse error", e); printf ("\x1b[31m%s: %s\x1b[0m\n", "parse error", e);
else else
run (&ctx, program); run (&ell, program);
parser_free (&parser); ell_parser_free (&p);
} }
putchar ('\n'); putchar ('\n');
context_free (&ctx); ell_free (&ell);
return 0; return 0;
} }