Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-20 Thread Ryan Joseph
> On Apr 20, 2017, at 4:06 PM, denisgolovan wrote: > > Another example is network-related code (both client and server code). > Break your huge finite state machines into pipeline stages via coroutines and > it gets pretty modular, extensive and simple to reason about. Nicely encapsulated in t

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-20 Thread Mark Morgan Lloyd
On 20/04/17 09:00, Marco van de Voort wrote: In our previous episode, Mark Morgan Lloyd said:> > I don't know. Such effort should chiefly come from the people interested init I guess.> > Turning it around a little: are there still FPC targets that don't have > threads? Having coroutines would a

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-20 Thread denisgolovan
20.04.2017, 11:43, "Ryan Joseph" : >>  On Apr 20, 2017, at 3:01 PM, Bernd Mueller wrote: >> >>  it would be really nice to have coroutines for the embedded targets like >> AVR and ARM. > > What are people using this for btw? Personally I wanted them to solve some > problems in game programming w

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-20 Thread Mark Morgan Lloyd
On 20/04/17 08:30, Bernd Mueller wrote: On 04/20/2017 09:40 AM, Mark Morgan Lloyd wrote:>> Turning it around a little: are there still FPC targets that don't have> threads? Having coroutines would allow a native thread mechanism to be> implemented, without relying on the underlying OS. it would b

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-20 Thread Ryan Joseph
> On Apr 20, 2017, at 3:01 PM, Bernd Mueller wrote: > > it would be really nice to have coroutines for the embedded targets like AVR > and ARM. What are people using this for btw? Personally I wanted them to solve some problems in game programming where I lots of nested loops that need to be

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-20 Thread Marco van de Voort
In our previous episode, Mark Morgan Lloyd said: > > I don't know. Such effort should chiefly come from the people interested > > init I guess. > > Turning it around a little: are there still FPC targets that don't have > threads? Having coroutines would allow a native thread mechanism to be >

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-20 Thread Mattias Gaertner
On Thu, 20 Apr 2017 07:40:44 + Mark Morgan Lloyd wrote: > Turning it around a little: are there still FPC targets that don't have > threads? Last month Karoly added one: WASM. Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org ht

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-20 Thread Bernd Mueller
On 04/20/2017 09:40 AM, Mark Morgan Lloyd wrote: Turning it around a little: are there still FPC targets that don't have threads? Having coroutines would allow a native thread mechanism to be implemented, without relying on the underlying OS. it would be really nice to have coroutines for the

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-20 Thread Mark Morgan Lloyd
On 19/04/17 20:00, Marco van de Voort wrote: In our previous episode, Daniel Gaspary said:> So..> > Any chance of an Official implementation ? I don't know. Such effort should chiefly come from the people interested init I guess. Turning it around a little: are there still FPC targets that do

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Marco van de Voort
In our previous episode, Daniel Gaspary said: > So.. > > Any chance of an Official implementation ? I don't know. Such effort should chiefly come from the people interested in it I guess. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http:

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Daniel Gaspary
So.. Any chance of an Official implementation ? On Wed, Apr 19, 2017 at 10:50 AM, Marco van de Voort wrote: > In our previous episode, Ryan Joseph said: >> > Your example is simply broken. A few points: >> >> Thanks for the description. Yeah, I assumed the stack would be restored but >> that is

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Marco van de Voort
In our previous episode, Ryan Joseph said: > > Your example is simply broken. A few points: > > Thanks for the description. Yeah, I assumed the stack would be restored but > that isn?t the case apparently. > > I think the coroutine implementation in the link below tries to manage the > stack fr

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Ryan Joseph
> On Apr 19, 2017, at 5:37 PM, Karoly Balogh (Charlie/SGR) > wrote: > > Your example is simply broken. A few points: Thanks for the description. Yeah, I assumed the stack would be restored but that isn’t the case apparently. I think the coroutine implementation in the link below tries to man

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Karoly Balogh (Charlie/SGR)
Hi, On Wed, 19 Apr 2017, Ryan Joseph wrote: > yes, I?d like to see that so I know why my example doesn?t work as I > expected. Everything I?m hearing makes me think ?i? should keep > incrementing after I call SetJmp and then return with JongJmp but > there?s something I?m missing obviously. Your

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Ryan Joseph
> On Apr 19, 2017, at 5:17 PM, Michael Van Canneyt > wrote: > > It's a variable which the compiler does not put on the stack, it exists just > in a register. That kind of defeats the purpose then if you can’t rely on function scoped variables to be restored. Maybe that’s what the code in the

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Michael Van Canneyt
On Wed, 19 Apr 2017, Ryan Joseph wrote: On Apr 19, 2017, at 4:33 PM, Michael Van Canneyt wrote: Your reasoning contains a wrong assumption, namely that I is on the stack. If I is a register variable, then it is not on the stack, and will be reset with each longjmp. I thought all variabl

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Ryan Joseph
> On Apr 19, 2017, at 4:33 PM, Michael Van Canneyt > wrote: > > Your reasoning contains a wrong assumption, namely that I is on the stack. > > If I is a register variable, then it is not on the stack, and will be reset > with each longjmp. I thought all variables declared inside a function (l

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Ryan Joseph
> On Apr 19, 2017, at 4:57 PM, Mark Morgan Lloyd > wrote: > > SetJmp records the current state, LongJmp reverts to it. There's some > common-sense limitations. > > I've got an example program of about 100 lines that would demonstrate what > I've hacked together, I could tack it onto a messag

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Mark Morgan Lloyd
On 19/04/17 09:30, Ryan Joseph wrote: On Apr 19, 2017, at 3:28 PM, Mark Morgan Lloyd wrote:> > It is possible to partially-simulate coroutines with setjmp/longjmp, but you need to store state outside the function. The key thing about coroutines, at least as implemented by Wirth in Modula-2, i

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Michael Van Canneyt
On Wed, 19 Apr 2017, Sven Barth via fpc-pascal wrote: Am 19.04.2017 11:26 schrieb "Ryan Joseph" : On Apr 19, 2017, at 4:14 PM, Sven Barth via fpc-pascal < fpc-pascal@lists.freepascal.org> wrote: Those functions simply store (setjmp) and restore (longjmp) register values (and setjmp als

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Sven Barth via fpc-pascal
Am 19.04.2017 11:26 schrieb "Ryan Joseph" : > > > > On Apr 19, 2017, at 4:14 PM, Sven Barth via fpc-pascal < fpc-pascal@lists.freepascal.org> wrote: > > > > Those functions simply store (setjmp) and restore (longjmp) register values (and setjmp also returns the value passed to longjmp if it had bee

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Michael Van Canneyt
On Wed, 19 Apr 2017, Ryan Joseph wrote: On Apr 19, 2017, at 4:14 PM, Sven Barth via fpc-pascal wrote: Those functions simply store (setjmp) and restore (longjmp) register values (and setjmp also returns the value passed to longjmp if it had been reached by a longjmp). Nothing more, noth

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Ryan Joseph
> On Apr 19, 2017, at 4:14 PM, Sven Barth via fpc-pascal > wrote: > > Those functions simply store (setjmp) and restore (longjmp) register values > (and setjmp also returns the value passed to longjmp if it had been reached > by a longjmp). Nothing more, nothing less. So while the stack regis

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Sven Barth via fpc-pascal
Am 19.04.2017 06:35 schrieb "Ryan Joseph" : > > > > On Apr 19, 2017, at 2:34 AM, Daniel Gaspary wrote: > > > > Using SetJmp and LongJmp? > > > > I believe some months ago it was a discussion on the list on why this > > was not really the way to implement coroutines. > > > > Searching for longjmp/

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Ryan Joseph
> On Apr 19, 2017, at 3:28 PM, Mark Morgan Lloyd > wrote: > > It is possible to partially-simulate coroutines with setjmp/longjmp, but you > need to store state outside the function. The key thing about coroutines, at > least as implemented by Wirth in Modula-2, is that you can transfer > ar

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-19 Thread Mark Morgan Lloyd
On 19/04/17 05:00, Ryan Joseph wrote: On Apr 19, 2017, at 2:34 AM, Daniel Gaspary wrote:> > Using SetJmp and LongJmp?> > I believe some months ago it was a discussion on the list on why this> was not really the way to implement coroutines.> > Searching for longjmp/setjmp you can find the thre

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-18 Thread Ryan Joseph
> On Apr 19, 2017, at 2:34 AM, Daniel Gaspary wrote: > > Using SetJmp and LongJmp? > > I believe some months ago it was a discussion on the list on why this > was not really the way to implement coroutines. > > Searching for longjmp/setjmp you can find the thread, I guess. I never heard of t

Re: [fpc-pascal] Coroutines and VirtualAlloc

2017-04-18 Thread Daniel Gaspary
On Sat, Apr 15, 2017 at 6:20 AM, Ryan Joseph wrote: > I was curious about possible ways coroutines could work in FPC and found this > example that claims to implement just that. It appears to be designed for > Windows though and makes use of a function called VirtualAlloc which I don’t > unders

[fpc-pascal] Coroutines and VirtualAlloc

2017-04-15 Thread Ryan Joseph
I was curious about possible ways coroutines could work in FPC and found this example that claims to implement just that. It appears to be designed for Windows though and makes use of a function called VirtualAlloc which I don’t understand. Is there a non platform specific version of this functi