mirror of https://github.com/rusefi/bldc.git
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
This commit is contained in:
parent
3d7749c5f2
commit
9a20ef543b
|
@ -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);
|
||||
|
|
18
src/tokpar.c
18
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++;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue