From a4b8d3f76f1fc7dbf0b83d141955ce9acec87ba7 Mon Sep 17 00:00:00 2001 From: attilavs2 Date: Mon, 17 Mar 2025 10:36:16 +0100 Subject: [PATCH] Fix flisp_alloc + misc --- src/config.h | 2 +- src/exec_common.c | 8 +++++--- src/parser.y | 10 +++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/config.h b/src/config.h index bf05a9d..02bb349 100755 --- a/src/config.h +++ b/src/config.h @@ -28,7 +28,7 @@ // Debug logs // 0 : None // 1 : All misc debug logs -#define LOG 1 +#define LOG 0 // TODO : Automate this #define INTERPR diff --git a/src/exec_common.c b/src/exec_common.c index 981d7ed..69a4329 100644 --- a/src/exec_common.c +++ b/src/exec_common.c @@ -104,6 +104,8 @@ int alloc_init(){ usage = NULL; if(!blocks || alloc_extend(EXT_BLOCK)) return 1; + // First 32bytes are reserved for null + alignement + usage[0] = 0xF; return 0; } @@ -118,8 +120,8 @@ u32 flisp_alloc(u32 size){ u32 curr_free = 0; while(pos < internal_size){ if(usage[pos/32/8]){ - for(int i = 0; i < 32; i++){ - if((usage[pos/32/8]>>i) & 1) + for(u32 opos = pos; pos < opos+32;){ + if((usage[pos/32/8]>>((pos/8)%32)) & 1) curr_free = 0; else curr_free+=8; @@ -140,7 +142,7 @@ u32 flisp_alloc(u32 size){ block->pos = pos-curr_free; block->size = size; for(u32 i = block->pos; i < block->pos+size; i+=8){ - usage[i/32/8] |= 1<<(i%32); + usage[i/32/8] |= 1<<((i/8)%32); } // Unvirtualize the memory memset(get_addr(block->pos),0xB00B5069,size); diff --git a/src/parser.y b/src/parser.y index e34edde..1d0f4cd 100644 --- a/src/parser.y +++ b/src/parser.y @@ -57,8 +57,12 @@ %% program: - expr_list ';' {print_ast($1);execute($1);} - | expr_list YYEOF {print_ast($1);execute($1);} + expr_list ';' + {print_ast($1);execute($1);} + | expr_list YYEOF + {print_ast($1);execute($1);} + | program expr_list ';' + {print_ast($2);execute($2);} ; type: @@ -161,7 +165,7 @@ int main(int argc, char *argv[]){ } else { printf("fLisp interactive env - v0.1\nFcalva 2025\n"); - printf("Under the terms of the GPL v2.0 license\n"); + printf("Under the terms of the GPL v3.0 license\n"); yyin = stdin; }