Skip to content

Commit

Permalink
Squashed 'lispBM/lispBM/' changes from c6dcb06d..3fc70a5c
Browse files Browse the repository at this point in the history
3fc70a5c Changing a number of fatal_errors to stack_errors and bugfix related to 64bit lbm

git-subtree-dir: lispBM/lispBM
git-subtree-split: 3fc70a5c88c7b6f0afe9f8e288bf4d918dbc50c4
  • Loading branch information
vedderb committed Apr 6, 2023
1 parent 3128d02 commit 26ec05a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
31 changes: 15 additions & 16 deletions src/eval_cps.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,6 @@ static void eval_callcc(eval_context_t *ctx) {
return;
}
}

lbm_array_header_t *arr = (lbm_array_header_t*)lbm_car(cont_array);
memcpy(arr->data, ctx->K.data, ctx->K.sp * sizeof(lbm_uint));

Expand Down Expand Up @@ -1707,7 +1706,7 @@ static void cont_progn_rest(eval_context_t *ctx) {

lbm_value *sptr = (lbm_value*)lbm_get_stack_ptr(&ctx->K, 3);
if (sptr == NULL) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}

Expand Down Expand Up @@ -1816,7 +1815,7 @@ static void apply_read_base(lbm_value *args, lbm_uint nargs, eval_context_t *ctx
lbm_value *sptr = (lbm_value*)lbm_get_stack_ptr(&ctx->K, 2);

if (sptr == NULL) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}

Expand Down Expand Up @@ -2031,7 +2030,7 @@ static void apply_map(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) {
}
lbm_value *sptr = lbm_get_stack_ptr(&ctx->K, 3);
if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}

Expand Down Expand Up @@ -2160,7 +2159,7 @@ static void application(eval_context_t *ctx, lbm_value *fun_args, lbm_uint arg_c

lbm_array_header_t *arr = (lbm_array_header_t*)lbm_car(c);

ctx->K.sp = arr->size >> 2;
ctx->K.sp = arr->size / sizeof(lbm_uint);
memcpy(ctx->K.data, arr->data, arr->size);

ctx->r = arg;
Expand Down Expand Up @@ -2223,7 +2222,7 @@ static void cont_closure_application_args(eval_context_t *ctx) {
lbm_uint* sptr = lbm_get_stack_ptr(&ctx->K, 5);

if (sptr == NULL) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}
lbm_value arg_env = (lbm_value)sptr[0];
Expand Down Expand Up @@ -2287,7 +2286,7 @@ static void cont_application_args(eval_context_t *ctx) {
lbm_uint *sptr = lbm_get_stack_ptr(&ctx->K,3);

if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}

Expand Down Expand Up @@ -2369,7 +2368,7 @@ static void cont_bind_to_key_rest(eval_context_t *ctx) {

lbm_value *sptr = lbm_get_stack_ptr(&ctx->K, 4);
if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}
lbm_value rest = sptr[1];
Expand Down Expand Up @@ -2405,7 +2404,7 @@ static void cont_if(eval_context_t *ctx) {

lbm_value *sptr = lbm_get_stack_ptr(&ctx->K, 3);
if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}

Expand Down Expand Up @@ -2535,7 +2534,7 @@ static void cont_map_first(eval_context_t *ctx) {

lbm_value *sptr = lbm_get_stack_ptr(&ctx->K, 6);
if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}
lbm_value ls = sptr[0];
Expand Down Expand Up @@ -2564,7 +2563,7 @@ static void cont_map_first(eval_context_t *ctx) {
static void cont_map_rest(eval_context_t *ctx) {
lbm_value *sptr = lbm_get_stack_ptr(&ctx->K, 6);
if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}
lbm_value ls = sptr[0];
Expand Down Expand Up @@ -2963,7 +2962,7 @@ static void cont_read_append_array(eval_context_t *ctx) {

lbm_uint *sptr = lbm_get_stack_ptr(&ctx->K, 4);
if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}

Expand Down Expand Up @@ -3005,7 +3004,7 @@ static void cont_read_append_continue(eval_context_t *ctx) {

lbm_value *sptr = lbm_get_stack_ptr(&ctx->K, 3);
if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}

Expand Down Expand Up @@ -3122,7 +3121,7 @@ static void cont_read_dot_terminate(eval_context_t *ctx) {

lbm_value *sptr = lbm_get_stack_ptr(&ctx->K, 3);
if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}

Expand Down Expand Up @@ -3239,7 +3238,7 @@ static void cont_application_start(eval_context_t *ctx) {

lbm_uint *sptr = lbm_get_stack_ptr(&ctx->K, 2);
if (sptr == NULL) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}
lbm_value args = (lbm_value)sptr[1];
Expand Down Expand Up @@ -3523,7 +3522,7 @@ static void cont_move_list_to_flash(eval_context_t *ctx) {

lbm_value *sptr = lbm_get_stack_ptr(&ctx->K, 3);
if (!sptr) {
error_ctx(ENC_SYM_FATAL_ERROR);
error_ctx(ENC_SYM_STACK_ERROR);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/fundamental.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ static lbm_value fundamental_type_of(lbm_value *args, lbm_uint nargs, eval_conte
static lbm_value fundamental_list_length(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) {
(void) ctx;
lbm_value result = ENC_SYM_EERROR;
if (nargs == 1 && lbm_is_list(args[0])) {
if (nargs == 1 && lbm_is_list_general(args[0])) {
int32_t len = (int32_t)lbm_list_length(args[0]);
result = lbm_enc_i(len);
}
Expand Down
21 changes: 7 additions & 14 deletions src/lbm_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,9 @@ int lbm_memory_free(lbm_uint *ptr) {
void* lbm_malloc(size_t size) {
lbm_uint alloc_size;

#ifndef LBM64
alloc_size = size >> 2;
if (size & 3) alloc_size ++;
#else
alloc_size = size >> 3;
if (size & 7) alloc_size ++;
#endif
alloc_size = size / sizeof(lbm_uint);
if (size % sizeof(lbm_uint)) alloc_size += 1;

if (memory_num_free - alloc_size < memory_reserve_level) {
lbm_request_gc();
return NULL;
Expand All @@ -383,13 +379,10 @@ void* lbm_malloc(size_t size) {

void* lbm_malloc_reserve(size_t size) {
lbm_uint alloc_size;
#ifndef LBM64
alloc_size = size >> 2;
if (size & 3) alloc_size ++;
#else
alloc_size = size >> 3;
if (size & 7) alloc_size ++;
#endif

alloc_size = size / sizeof(lbm_uint);
if (size % sizeof(lbm_uint)) alloc_size += 1;

if (memory_num_free - alloc_size < memory_reserve_level) {
lbm_request_gc();
}
Expand Down

0 comments on commit 26ec05a

Please sign in to comment.