Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Sun, 11 Mar 2012 13:26:06 -0500 Date: Sun, 11 Mar 2012 18:25:41 GMT From: Gavin Wraith Newsgroups: comp.sys.acorn.programmer Subject: Re: OS_GBPB 12 in a Wimp task Message-ID: References: <4cf7edf6-12e6-45c9-95b2-700fe371192f@b18g2000vbz.googlegroups.com> <9fa95124-990a-43e2-a561-b4c03bff439c@p7g2000yqk.googlegroups.com> <8299b36e52.Matthew@sinenomine.freeserve.co.uk> Organization: Home User-Agent: Messenger-Pro/1.00c (MsgServe/1.00a) (RISC-OS/5.18) NewsHound/v1.50-32 Lines: 83 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-ZssgoMI/cH41GxVNWke0TB+S94sMm4Plr8KdhVsJ1y1TNCe+aGQbNIhNJAXhw6FZ0dTzriqTVP0Ovol!JtxOGDka9sLQOWoc16INHJcAZT4F9ppi70fhn9Md/qh9oKqwI1WehFv1kCY0EbQJ1aXxQZ+cZqQV!7eQK X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4171 Xref: csiph.com comp.sys.acorn.programmer:1492 In message Rick Murray wrote: > The big problem I see is that the file system does not have a > mechanism to preserve state across polls. Surely that should be up to the application that is doing the polling, or have I misconstrued what you are saying? The heart of RiscLua's directory iteration has prototype: extern int rdir(const char *dir, char *buf, int buflen, int offset); realized by this assembler code: rdir STMFD sp!,{R1-R6,R14} MOV R6,#0 MOV R5,R2 MOV R4,R3 MOV R3,#1 MOV R2,R1 MOV R1,R0 MOV R0,#12 SWI &2000C ; XOS_GBPB MOVVS R3,#0 CMP R3,#1 MOVEQ R0,R4 MVNNE R0,#0 LDMFD sp!,{R1-R6,pc} So the value of the unknown "offset" is returned to be tested and possibly stored for the next call by the wrapper code that realizes the iterator. This (in c.riscoslib in the RiscLua sources) is static int rdir_iter (lua_State *L); #define RDIR_BUFLEN 256 static char rdir_buf[RDIR_BUFLEN]; static int rdir_read (lua_State *L) { /* the iterator */ lua_pushinteger(L,0); lua_pushstring(L,lua_tostring(L,1)); lua_pushcclosure(L,&rdir_iter,2); return 1; } static int rdir_iter (lua_State *L) { int *ft = (int *)rdir_buf; int offset = (int) lua_tointeger(L,lua_upvalueindex(1)); const char * dir = lua_tostring(L,lua_upvalueindex(2)); int n = rdir(dir,rdir_buf,RDIR_BUFLEN,offset); /* new offset */ if (n == -1) { /* finished */ lua_pushnil(L); return 1; } else { lua_pushinteger(L, n); lua_replace(L,lua_upvalueindex(1)); /* modify iterator state */ lua_pushstring(L,rdir_buf+24); /* return leaf name */ lua_pushinteger(L,ft[5]); /* return filetype */ return 2; } } The returned offset is the value of "n", which, if it does not indicate completion ( n == -1 ), updates ( see the line lua_replace(L,lua_upvalueindex(1)); ) an "upvalue" of the iterator - that is to say a slot in the function's environment table. Such slots are not directly readable by the user. Environments for functions are not features of every programming language (e.g. C no, Pascal yes). My point is that the mechanisms available for preserving state (in this case the "offset" in R4) rather depend on the kind of high level language that one is using. In this case state is preserved across co-routine yields, but across Wimp_Polls (an external coroutine, sort of?) - how could it be? Especially as another task could have deleted the directory in question before the Wimp_Poll returns. Note that rdir just returns the termination value, -1, when XOS_GBPB returns an error. -- Gavin Wraith (gavin@wra1th.plus.com) Home page: http://www.wra1th.plus.com/