Merge commit '9a20ef543b1ff7fd0eb598d55953ee7e26ee2b67'

This commit is contained in:
Benjamin Vedder 2022-03-06 20:14:10 +01:00
commit 5b5160c545
2 changed files with 31 additions and 13 deletions

View File

@ -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);

View File

@ -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++;
}