diff --git a/bootstrap.fs b/bootstrap.fs index 745612d..41d044b 100644 --- a/bootstrap.fs +++ b/bootstrap.fs @@ -2399,6 +2399,9 @@ BLOCK-SIZE remaining-size ! then ; +\ Bootstrapping version of free do nothing. +: (free) ( addr -- ) ; + ( === File I/O === ) 3 constant SYS-READ @@ -2440,11 +2443,16 @@ BLOCK-SIZE remaining-size ! ( === Heap Memory === ) need-defined (allocate) +need-defined (free) : allocate ( size -- addr e ) (allocate) dup 0<> if success else ALLOCATE-ERROR then ; +: free ( addr -- ) + (free) +; + \ allocate heap memory : %allocate ( align size -- addr e ) over + allocate ?dup unless @@ -2604,7 +2612,7 @@ need-defined (read) 2rot -2rot 2tuck 2over 2nip 2swap 2dup 2drop 3dup 3drop depth rp0 rp@ rp! r> >r r@ rdrop rpick rdepth - allocate allot memcpy strlen streq strneq strcpy strcpy, + allocate free allot memcpy strlen streq strneq strcpy strcpy, cell cell+ cell- cells char+ char- chars align aligned +! -! if else then unless begin until again while repeat diff --git a/others/planck.c b/others/planck.c index 8b56f7a..1d58a12 100644 --- a/others/planck.c +++ b/others/planck.c @@ -207,5 +207,6 @@ defcode("(allocate)", allocate) { push((cell) p); next(); } +defcode("(free)", free_) { free((void*) pop()); } #endif diff --git a/others/planck.py b/others/planck.py index cb00cc0..c43a3c2 100644 --- a/others/planck.py +++ b/others/planck.py @@ -281,7 +281,10 @@ def allocate(): addr = len(memory) * CELL memory.extend([0]*n) push(addr) +def free(): + pop() # Bootstrap version do nothing add_simple_operator('(allocate)', allocate) +add_simple_operator('(free)', free) start = read(HERE_CELL) comma(find('k'))