runtime: add MemAvail function
This commit is contained in:
parent
95cc02ffcb
commit
165517a9c8
2 changed files with 28 additions and 0 deletions
|
|
@ -1764,6 +1764,33 @@ MEM_DUMP_L0:
|
||||||
DROP
|
DROP
|
||||||
RET
|
RET
|
||||||
|
|
||||||
|
; calculate total free heap space
|
||||||
|
; args: none
|
||||||
|
; returns: cumulative size of all free chunks in bytes
|
||||||
|
MEMAVAIL:
|
||||||
|
FPADJ -4
|
||||||
|
LOADC 0
|
||||||
|
STORE 0 ; start with zero as result
|
||||||
|
|
||||||
|
LOADCP _HEAP_ANCHOR
|
||||||
|
MAV_L:
|
||||||
|
DUP ; dup chunk ptr for later
|
||||||
|
INC 4 ; move to size field
|
||||||
|
LOADI ; load chunk size
|
||||||
|
LOAD 0 ; add to current result value
|
||||||
|
ADD
|
||||||
|
STORE 0
|
||||||
|
|
||||||
|
LOADI ; load next ptr
|
||||||
|
DUP
|
||||||
|
LOADCP _HEAP_ANCHOR ; compare with anchor
|
||||||
|
CMPU NE
|
||||||
|
CBRANCH MAV_L ; if not equal, loop
|
||||||
|
MAX_XT:
|
||||||
|
LOAD 0 ; put result value on stack
|
||||||
|
FPADJ 4
|
||||||
|
RET
|
||||||
|
|
||||||
; check if a pointer is part of the free list
|
; check if a pointer is part of the free list
|
||||||
; args: pointer returned by MEM_ALLOC
|
; args: pointer returned by MEM_ALLOC
|
||||||
; throws runtime error if the pointer is found
|
; throws runtime error if the pointer is found
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,7 @@ procedure appendchar(var s:string; aChar:char); external;
|
||||||
procedure strmoveup(var s:string;index,length,delta:integer); external;
|
procedure strmoveup(var s:string;index,length,delta:integer); external;
|
||||||
procedure strmovedown(var s:string;index,length,delta:integer); external;
|
procedure strmovedown(var s:string;index,length,delta:integer); external;
|
||||||
procedure RuntimeError(var s:string); external;
|
procedure RuntimeError(var s:string); external;
|
||||||
|
function MemAvail:integer; external;
|
||||||
|
|
||||||
(* from stdlib *)
|
(* from stdlib *)
|
||||||
function copy(s:string[256];index,count:integer):string[256]; external;
|
function copy(s:string[256];index,count:integer):string[256]; external;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue