Make it compile

This commit is contained in:
Přemysl Eric Janouch 2017-05-17 23:22:43 +02:00
parent e290683f0c
commit f7bce11c70
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 16 additions and 42 deletions

58
ell.c
View File

@ -435,8 +435,7 @@ parse (const char *s, const char **error) {
// --- Runtime ----------------------------------------------------------------- // --- Runtime -----------------------------------------------------------------
struct context { struct context {
struct item *stack; ///< The current top of the stack struct item variables; ///< List of variables
size_t stack_size; ///< Number of items on the stack
char *error; ///< Error information char *error; ///< Error information
bool error_is_fatal; ///< Whether the error can be catched bool error_is_fatal; ///< Whether the error can be catched
@ -460,23 +459,13 @@ struct fn *g_functions; ///< Maps words to functions
static void static void
context_init (struct context *ctx) { context_init (struct context *ctx) {
ctx->stack = NULL; memset (ctx, 0, sizeof *ctx);
ctx->stack_size = 0;
ctx->error = NULL;
ctx->error_is_fatal = false;
ctx->memory_failure = false;
ctx->user_data = NULL;
} }
static void static void
context_free (struct context *ctx) { context_free (struct context *ctx) {
item_free_list (ctx->stack); item_free_list (ctx->variables.head);
ctx->stack = NULL;
free (ctx->error); free (ctx->error);
ctx->error = NULL;
} }
static bool static bool
@ -493,22 +482,6 @@ set_error (struct context *ctx, const char *format, ...) {
return false; return false;
} }
static bool
push (struct context *ctx, struct item *item) {
// The `item' is typically a result from new_<type>(), thus when it is null,
// that function must have failed. This is a shortcut for convenience.
if (!item) {
ctx->memory_failure = true;
return false;
}
assert (item->next == NULL);
item->next = ctx->stack;
ctx->stack = item;
ctx->stack_size++;
return true;
}
static bool execute (struct context *, struct item *); static bool execute (struct context *, struct item *);
static bool static bool
@ -588,12 +561,11 @@ register_script (const char *name, struct item *script) {
static bool static bool
execute (struct context *ctx, struct item *script) { execute (struct context *ctx, struct item *script) {
for (; script; script = script->next) { for (; script; script = script->next) {
if (script->type != ITEM_STRING) { // TODO: this should be a list
if (!push (ctx, new_clone (script))) // -> if the first item is a STRING, resolve it
return false; // -> but handle special forms
} // -> assign the rest of the items to variables
else if (!call_function (ctx, script->value)) // -> recurse
return false;
} }
return true; return true;
} }
@ -628,14 +600,16 @@ init_runtime_library_scripts (void) {
return ok; return ok;
} }
defn (fn_print) { static struct item *
check_stack (1); var (struct context *ctx, const char *name) {
struct item *item = pop (ctx); // TODO: go through the "ctx->variables" list of lists and look for "name"
struct user_info *info = ctx->user_data; return NULL;
}
defn (fn_print) {
struct buffer buf = BUFFER_INITIALIZER; struct buffer buf = BUFFER_INITIALIZER;
item_to_str (item, &buf); struct item *item = var (ctx, "1");
item_free (item); buffer_append (&buf, item->value, item->len);
buffer_append_c (&buf, '\0'); buffer_append_c (&buf, '\0');
if (buf.memory_failure) { if (buf.memory_failure) {
ctx->memory_failure = true; ctx->memory_failure = true;