Adding allocate and free.

This commit is contained in:
Brad Nelson
2021-01-03 00:32:58 -08:00
parent 952a7d9d07
commit 0ccb9ea026
3 changed files with 19 additions and 1 deletions

View File

@ -35,8 +35,10 @@ typedef uint64_t udcell_t;
X("OVER", OP_OVER, DUP; tos = sp[-1]) \ X("OVER", OP_OVER, DUP; tos = sp[-1]) \
X("DROP", OP_DROP, DROP) \ X("DROP", OP_DROP, DROP) \
X("@", OP_AT, tos = *(cell_t *) tos) \ X("@", OP_AT, tos = *(cell_t *) tos) \
X("L@", OP_LAT, tos = *(int32_t *) tos) \
X("C@", OP_CAT, tos = *(uint8_t *) tos) \ X("C@", OP_CAT, tos = *(uint8_t *) tos) \
X("!", OP_STORE, *(cell_t *) tos = *sp; --sp; DROP) \ X("!", OP_STORE, *(cell_t *) tos = *sp; --sp; DROP) \
X("L!", OP_LSTORE, *(int32_t *) tos = *sp; --sp; DROP) \
X("C!", OP_CSTORE, *(uint8_t *) tos = *sp; --sp; DROP) \ X("C!", OP_CSTORE, *(uint8_t *) tos = *sp; --sp; DROP) \
X("FILL", OP_FILL, memset((void *) sp[-1], tos, *sp); sp -= 2; DROP) \ X("FILL", OP_FILL, memset((void *) sp[-1], tos, *sp); sp -= 2; DROP) \
X("MOVE", OP_MOVE, memmove((void *) sp[-1], (void *) *sp, tos); sp -= 2; DROP) \ X("MOVE", OP_MOVE, memmove((void *) sp[-1], (void *) *sp, tos); sp -= 2; DROP) \

View File

@ -47,7 +47,7 @@ CORE
0= 0< + UM/MOD */MOD 0= 0< + UM/MOD */MOD
AND OR XOR AND OR XOR
DUP SWAP OVER DROP DUP SWAP OVER DROP
@ C@ ! C! FILL MOVE @ L@ C@ ! L! C! FILL MOVE
SP@ SP! RP@ RP! >R R> R@ SP@ SP! RP@ RP! >R R> R@
EXECUTE BRANCH 0BRANCH DONEXT DOLIT EXECUTE BRANCH 0BRANCH DONEXT DOLIT
ALITERAL CELL ALITERAL CELL

View File

@ -21,6 +21,12 @@ z" write" 3 sysfunc write
z" lseek" 3 sysfunc lseek z" lseek" 3 sysfunc lseek
z" exit" 1 sysfunc sysexit z" exit" 1 sysfunc sysexit
z" fork" 0 sysfunc fork z" fork" 0 sysfunc fork
z" mmap" 6 sysfunc mmap
z" munmap" 2 sysfunc munmap
( Errno )
z" __errno_location" 0 sysfunc __errno_location
: errno ( -- n ) __errno_location l@ ;
( Default Pipes ) ( Default Pipes )
0 constant stdin 0 constant stdin
@ -56,3 +62,13 @@ z" fork" 0 sysfunc fork
: posix-bye 0 sysexit ; : posix-bye 0 sysexit ;
' posix-bye is bye ' posix-bye is bye
( I/O Error Helpers )
: 0ior ( n -- n ior ) dup 0= if errno else 0 then ;
( Words with OS assist )
z" malloc" 1 sysfunc malloc
z" free" 1 sysfunc sysfree
z" realloc" 2 sysfunc realloc
: allocate ( n -- a ior ) malloc 0ior ;
: free ( a -- ior ) sysfree 0 ;
: resize ( a n -- a ior ) realloc 0ior ;