Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #1492

Re: OS_GBPB 12 in a Wimp task

Date 2012-03-11 18:25 +0000
From Gavin Wraith <gavin@wra1th.plus.com>
Newsgroups comp.sys.acorn.programmer
Subject Re: OS_GBPB 12 in a Wimp task
Message-ID <d670e66e52.wra1th@wra1th.plus.com> (permalink)
References (3 earlier) <dea93483-8f06-4b66-8cd0-91b1968f3694@em9g2000vbb.googlegroups.com> <dc26716e52.Matthew@sinenomine.freeserve.co.uk> <almarsoft.5374763469681712868@news.orange.fr> <8299b36e52.Matthew@sinenomine.freeserve.co.uk> <almarsoft.6587021169203963779@news.orange.fr>
Organization Home

Show all headers | View raw


In message <almarsoft.6587021169203963779@news.orange.fr>
          Rick Murray <heyrickmail-usenet@yahoo.co.uk> 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/

Back to comp.sys.acorn.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

OS_GBPB 12 in a Wimp task Christopher Bazley <cs99cjb@gmail.com> - 2012-03-06 14:33 -0800
  Re: OS_GBPB 12 in a Wimp task jeff <jeffrey.a.doggett@gmail.com> - 2012-03-07 00:02 -0800
    Re: OS_GBPB 12 in a Wimp task Matthew Phillips <spam2011m@yahoo.co.uk> - 2012-03-08 22:33 +0000
      Re: OS_GBPB 12 in a Wimp task Christopher Bazley <cs99cjb@gmail.com> - 2012-03-10 10:22 -0800
        Re: OS_GBPB 12 in a Wimp task Matthew Phillips <spam2011m@yahoo.co.uk> - 2012-03-10 21:04 +0000
          Re: OS_GBPB 12 in a Wimp task Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2012-03-10 23:11 +0100
            Re: OS_GBPB 12 in a Wimp task Matthew Phillips <spam2011m@yahoo.co.uk> - 2012-03-11 09:10 +0000
              Re: OS_GBPB 12 in a Wimp task Chris Johnson <chrisjohnson+news@spamcop.net> - 2012-03-11 10:41 +0000
              Re: OS_GBPB 12 in a Wimp task Steve Fryatt <news@stevefryatt.org.uk> - 2012-03-11 11:06 +0000
              Re: OS_GBPB 12 in a Wimp task Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2012-03-11 17:56 +0100
                Re: OS_GBPB 12 in a Wimp task Gavin Wraith <gavin@wra1th.plus.com> - 2012-03-11 18:25 +0000
                Re: OS_GBPB 12 in a Wimp task Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2012-03-12 00:33 +0100
                Re: OS_GBPB 12 in a Wimp task Gavin Wraith <gavin@wra1th.plus.com> - 2012-03-12 11:56 +0000
                Re: OS_GBPB 12 in a Wimp task Martin Wuerthner <spamtrap@mw-software.com> - 2012-03-12 16:44 +0100
                Re: OS_GBPB 12 in a Wimp task druck <news@druck.org.uk> - 2012-03-12 20:57 +0000
                Re: OS_GBPB 12 in a Wimp task Martin Wuerthner <spamtrap@mw-software.com> - 2012-03-12 22:26 +0100
                Re: OS_GBPB 12 in a Wimp task Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2012-03-13 17:50 +0100
                Re: OS_GBPB 12 in a Wimp task jgharston <jgh@arcade.demon.co.uk> - 2012-03-13 10:15 -0700
                Re: OS_GBPB 12 in a Wimp task Matthew Phillips <spam2011m@yahoo.co.uk> - 2012-03-13 07:34 +0000
                Re: OS_GBPB 12 in a Wimp task Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2012-03-14 06:00 +0100
                Re: OS_GBPB 12 in a Wimp task Christopher Bazley <cs99cjb@gmail.com> - 2012-03-15 02:40 -0700
                Re: OS_GBPB 12 in a Wimp task Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2012-03-15 14:55 +0100
                Re: OS_GBPB 12 in a Wimp task "Ste (news)" <steve@revi11.plus.com> - 2012-03-15 14:46 +0000
                Re: OS_GBPB 12 in a Wimp task Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2012-03-15 18:44 +0100
                Re: OS_GBPB 12 in a Wimp task Jeremy Nicoll - news posts <jn.nntp.scrap007@wingsandbeaks.org.uk> - 2012-03-15 19:44 +0000
                Re: OS_GBPB 12 in a Wimp task Alan Adams <alan@adamshome.org.uk> - 2012-03-15 20:36 +0000
                Re: OS_GBPB 12 in a Wimp task Chris Johnson <chrisjohnson+news@spamcop.net> - 2012-03-15 20:26 +0000
                Re: OS_GBPB 12 in a Wimp task Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2012-03-16 06:12 +0100
                Re: OS_GBPB 12 in a Wimp task Matthew Phillips <spam2011m@yahoo.co.uk> - 2012-03-15 20:34 +0000
                Re: OS_GBPB 12 in a Wimp task Alan Adams <alan@adamshome.org.uk> - 2012-03-15 21:04 +0000
                Re: OS_GBPB 12 in a Wimp task Matthew Phillips <spam2011m@yahoo.co.uk> - 2012-03-16 00:17 +0000
        Re: OS_GBPB 12 in a Wimp task Chris Johnson <chrisjohnson+news@spamcop.net> - 2012-03-10 23:58 +0000
          Re: OS_GBPB 12 in a Wimp task Chris Johnson <chrisjohnson+news@spamcop.net> - 2012-03-11 10:43 +0000
          Re: OS_GBPB 12 in a Wimp task jeff <jeffrey.a.doggett@gmail.com> - 2012-03-12 03:03 -0700
            Re: OS_GBPB 12 in a Wimp task Chris Johnson <chrisjohnson+news@spamcop.net> - 2012-03-12 10:44 +0000
            Re: OS_GBPB 12 in a Wimp task Matthew Phillips <spam2011m@yahoo.co.uk> - 2012-03-13 07:44 +0000
              Re: OS_GBPB 12 in a Wimp task jeff <jeffrey.a.doggett@gmail.com> - 2012-03-13 03:06 -0700
  Re: OS_GBPB 12 in a Wimp task druck <news@druck.org.uk> - 2012-03-07 10:08 +0000

csiph-web