From 9a20ef543b1ff7fd0eb598d55953ee7e26ee2b67 Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Sun, 6 Mar 2022 20:14:10 +0100 Subject: [PATCH] Squashed 'lispBM/lispBM/' changes from 9b375671..e81f234f e81f234f create_ctx changes to when it invokes gc to free up enough space for a context 55d7617d a first go at some escape characters. newline and backslash so far git-subtree-dir: lispBM/lispBM git-subtree-split: e81f234fdcac5728ef04ae9144e3aa7ed55306fa --- src/eval_cps.c | 26 ++++++++++++++------------ src/tokpar.c | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/eval_cps.c b/src/eval_cps.c index 24ea16fd..5960dba5 100644 --- a/src/eval_cps.c +++ b/src/eval_cps.c @@ -701,16 +701,21 @@ lbm_cid lbm_create_ctx(lbm_value program, lbm_value env, uint32_t stack_size) { if (lbm_type_of(program) != LBM_PTR_TYPE_CONS) return -1; - if (lbm_memory_num_free() < stack_size + (sizeof(eval_context_t)/4) ) { - gc(NIL, NIL); - } - if (lbm_memory_num_free() < stack_size + (sizeof(eval_context_t)/4) ) { - return -1; - } - eval_context_t *ctx = NULL; ctx = (eval_context_t*)lbm_memory_allocate(sizeof(eval_context_t) / 4); - if (ctx == NULL) return -1; // no more contexts possible! + if (ctx == NULL) { + gc(program,env); + ctx = (eval_context_t*)lbm_memory_allocate(sizeof(eval_context_t) / 4); + } + if (ctx == NULL) return -1; + + if (!lbm_stack_allocate(&ctx->K, stack_size)) { + gc(program,env); + if (!lbm_stack_allocate(&ctx->K, stack_size)) { + lbm_memory_free((uint32_t*)ctx); + return -1; + } + } lbm_int cid = lbm_memory_address_to_ix((uint32_t*)ctx); @@ -727,10 +732,7 @@ lbm_cid lbm_create_ctx(lbm_value program, lbm_value env, uint32_t stack_size) { ctx->next = NULL; ctx->id = cid; - if (!lbm_stack_allocate(&ctx->K, stack_size)) { - lbm_memory_free((uint32_t*)ctx); - return -1; - } + if (!lbm_push_u32(&ctx->K, lbm_enc_u(DONE))) { lbm_stack_free(&ctx->K); lbm_memory_free((uint32_t*)ctx); diff --git a/src/tokpar.c b/src/tokpar.c index a9962051..f8d73dcc 100644 --- a/src/tokpar.c +++ b/src/tokpar.c @@ -194,6 +194,14 @@ int tok_symbol(lbm_tokenizer_char_stream_t *str) { return (int)n; } +static char translate_escape_char(char c) { + switch(c) { + case '\\': return '\\'; + case 'n': return '\n'; + default: return '\\'; + } +} + int tok_string(lbm_tokenizer_char_stream_t *str) { unsigned int i = 0; @@ -221,7 +229,15 @@ int tok_string(lbm_tokenizer_char_stream_t *str) { clear_sym_str(); for (i = 0; i < len; i ++) { - sym_str[i] = get(str); + char c = get(str); + if (c == '\\') { + if (i + 1 < len) { + char escaped = get(str); + c = translate_escape_char(escaped); + len-=1; + } + } + sym_str[i] = c; n++; }