implemented realloc as well as a bunch of fixes and some small changes like changing the order of arguments for !, making alloc drop etc.

This commit is contained in:
IgorCielniak
2026-02-02 15:51:58 +01:00
parent ec826c31b2
commit 5ea020100e
9 changed files with 100 additions and 46 deletions

View File

@@ -8,6 +8,7 @@ word alloc
-1 # fd
0 # offset
mmap
swap drop
end
word free
@@ -21,7 +22,6 @@ word memcpy #(dst_addr src_addr len -- dst_addr len)
dup c@
3 pick swap
c!
drop
swap
for
1 + dup
@@ -33,10 +33,30 @@ word memcpy #(dst_addr src_addr len -- dst_addr len)
dup
rot
c!
drop
swap
end
swap
nip
r> dup -rot - swap
end
word memset #( value len addr -- )
swap
0 swap for
-rot swap 2 pick + 2dup swap ! 1 + -rot swap
end
2drop drop
end
word memdump #( len addr -- addr )
for
dup c@ puti cr 1 +
end
end
word realloc #( addr old_len new_len -- new_addr )
2 pick swap alloc
rot rot swap
memcpy
swap -rot free
end