|
|
| Author |
Message |
pjc30943
Joined: 02 Dec 2005
Posts: 220
|
|
Posted: 28 September 2006, 5:08 AM Post subject: Passing parameters to a task |
|
|
| Why are task parameters prohibited by the compiler? It's nice to use the same task for several events, with its variations caused by parameters. A global would work of course, but... |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 28 September 2006, 5:22 AM Post subject: |
|
|
ZBasic was originally designed to be compatible with BasicX and in the latter, task main routines must be defined with no parameters.
We are currently testing a new version of the compiler that allows an arbitrary number of parameters. The VM also had to be updated to support this. |
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX
|
|
Posted: 28 September 2006, 5:53 AM Post subject: |
|
|
| dkinzer wrote: | | We are currently testing a new version of the compiler that allows an arbitrary number of parameters. The VM also had to be updated to support this. |
That is good.
I haven't tried this myself but it would good to be able to also pass in dynamically allocated memory for the task stack. Then I can create as many tasks as I like without going through the overhead of allocating static arrays at compile time. |
|
| Back to top |
|
 |
stevech
Joined: 23 Feb 2006
Posts: 657
|
|
Posted: 28 September 2006, 6:09 AM Post subject: |
|
|
I suspect that dynamically allocated task stacks will also be forthcoming.
I have a ZBasic program that does quasi-dynamic task stack allocation until ZBasic has this as intrinsic. The scheme I use is for a state machine, where each state is a particular ZBasic task/sub(). I could elaborate if there's interest.
I also have a working example of a task to handle the AVR's INT0 and INT1 with the same code. I just callTask() twice to the same code with different stacks. Parameter for each instance of the task is passed in a gobal for now. The task instances copy it to a local variable, freeing up the global. |
|
| Back to top |
|
 |
|