46 lines
876 B
Text
46 lines
876 B
Text
include 'std/syscall.fa'
|
|
|
|
|
|
--<
|
|
Get current .data
|
|
|
|
Returns:
|
|
INT: *data
|
|
>--
|
|
macro cdptr
|
|
0 %SYS_brk sys 2
|
|
end
|
|
|
|
|
|
--<
|
|
Allocate n bytes
|
|
WARNING: Don't forgot to %bfree after
|
|
WARNING: This is a very non-portable macro, use
|
|
%malloc and %mfree
|
|
|
|
Takes:
|
|
INT: The buffer size
|
|
|
|
Returns:
|
|
INT: The pointer to the new .data
|
|
INT: The pointer to the old .data
|
|
>--
|
|
fun balloc [ int ] int int eo
|
|
%cdptr add -- Takes the argument on the stack
|
|
%SYS_brk sys 2 --< Extend the .data section
|
|
Also returns the new .data size >--
|
|
end
|
|
|
|
|
|
--<
|
|
Deallocate n bytes
|
|
|
|
Takes:
|
|
INT: The buffer size
|
|
>--
|
|
fun bfree [ int ] eo
|
|
%cdptr sub -- Takes the argument on the stack
|
|
%SYS_brk sys 2 -- Shrink .data
|
|
1 drop -- Drop the current .data
|
|
end
|
|
|