Graphviz code: fslist.pal

From PROSE Programming Language - Wiki
Revision as of 09:52, 22 June 2018 by Cambridge (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% fslist.pal
% Author: Mark R. Bannister
% Date: 05/Oct/2016
% Modified 20/Apr/2017 for graphviz demo
%
% Creates the system function tools.fslist() for listing all files
% underneath a filesystem object
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

~Module
EQUS {[sys.tools]}

._init
func/def	[fslist], &[.list], NULL, [psPointer], [start_node]
local/rtn

.list
stack/lock
var/addr        PUSH, [start_node]
attr/addr       PUSH, PULL, [psPointer]
reg/jmpeq       &[.invalid], PEEK, NULL
class/test      PEEK, [psFileHook], [psFile]
reg/jmpeq       &[.notfs], SFLG, #0
reg/load        P14, ![.prose.sys.io]
attr/load       P15, [psStreamOut], P13, [psFilePath]

% -------------------------------------------
%attr/direct     P14, P15, PEEK, P13
%attr/add        P14, P15, [\n]

%obj/dump	PEEK

func/bcall	NULL, [tools.gv_add_node], PEEK
% -------------------------------------------

reg/load        PUSH, (PULL)
reg/jmpeq       &[.rtn], PEEK, NULL

.loop
reg/load	P0, (PEEK)
reg/jmpeq	&[.loop_next], P0, NULL

% -------------------------------------------
%attr/direct     P14, P15, P0, P13
%attr/add        P14, P15, [\n]

%obj/dump	P0

func/bcall	NULL, [tools.gv_add_node], P0
% -------------------------------------------

reg/load	P1, (P0)
reg/jmpeq	&[.loop], P1, NULL

stack/push	P1
local/jmp	&[.loop]

.loop_next
reg/clr		PULL
reg/jmpne	&[.loop], PEEK, LOCK
stack/unlock

.rtn
func/rtn

.invalid
error/now       ![.prose.error.sys.BadAddress],
                    [Pointer argument contained invalid object address]

.notfs
error/now       ![.prose.error.sys.InvalidArgument],
                    [Pointer argument did not point to a filesystem object]