Skip to content

Commit 19b7638

Browse files
committed
refactor tasks WIP
tasks scheduler wip unbrick tasks scheduler update func lowering tests run goroutine lowering when optimizations are disabled avr/arduino fixup clean up tasks scheduler by seperating stack from state test coroutines lowering pass fix return buffer allocation and return pointer store typing reschedule tasks instead of immediately resuming them to avoid stack overflow in loops add -scheduler none for avr support pin the fake function on the coroutines scheduler to work around gba support pin the fake function on the coroutines scheduler to work around gba support allow synchronous main functions to be called directly on the tasks scheduler fix type of task state eliminate lowering for tasks scheduler
1 parent 4c0ebb5 commit 19b7638

39 files changed

+1852
-1462
lines changed

compiler/compiler.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,21 @@ var functionsUsedInTransforms = []string{
4242
"runtime.free",
4343
"runtime.scheduler",
4444
"runtime.nilPanic",
45+
"internal/task.start",
46+
"internal/task.Pause",
4547
}
4648

47-
var taskFunctionsUsedInTransforms = []string{
48-
"runtime.startGoroutine",
49-
}
49+
var taskFunctionsUsedInTransforms = []string{}
5050

5151
var coroFunctionsUsedInTransforms = []string{
52-
"runtime.avrSleep",
53-
"runtime.getFakeCoroutine",
54-
"runtime.setTaskStatePtr",
55-
"runtime.getTaskStatePtr",
56-
"runtime.activateTask",
57-
"runtime.noret",
58-
"runtime.getParentHandle",
59-
"runtime.getCoroutine",
60-
"runtime.llvmCoroRefHolder",
52+
"internal/task.fake",
53+
"internal/task.Current",
54+
"internal/task.createTask",
55+
"(*internal/task.Task).setState",
56+
"(*internal/task.Task).returnTo",
57+
"(*internal/task.Task).returnCurrent",
58+
"(*internal/task.Task).setReturnPtr",
59+
"(*internal/task.Task).getReturnPtr",
6160
}
6261

6362
type Compiler struct {
@@ -161,6 +160,7 @@ func (c *Compiler) Module() llvm.Module {
161160
func (c *Compiler) getFunctionsUsedInTransforms() []string {
162161
fnused := functionsUsedInTransforms
163162
switch c.Scheduler() {
163+
case "none":
164164
case "coroutines":
165165
fnused = append(append([]string{}, fnused...), coroFunctionsUsedInTransforms...)
166166
case "tasks":
@@ -217,7 +217,7 @@ func (c *Compiler) Compile(mainPath string) []error {
217217
path = path[len(tinygoPath+"/src/"):]
218218
}
219219
switch path {
220-
case "machine", "os", "reflect", "runtime", "runtime/interrupt", "runtime/volatile", "sync", "testing", "internal/reflectlite":
220+
case "machine", "os", "reflect", "runtime", "runtime/interrupt", "runtime/volatile", "sync", "testing", "internal/reflectlite", "internal/task":
221221
return path
222222
default:
223223
if strings.HasPrefix(path, "device/") || strings.HasPrefix(path, "examples/") {
@@ -1035,7 +1035,7 @@ func (c *Compiler) parseInstr(frame *Frame, instr ssa.Instruction) {
10351035
funcPtr, context := c.decodeFuncValue(c.getValue(frame, instr.Call.Value), instr.Call.Value.Type().(*types.Signature))
10361036
params = append(params, context) // context parameter
10371037
switch c.Scheduler() {
1038-
case "coroutines":
1038+
case "none", "coroutines":
10391039
// There are no additional parameters needed for the goroutine start operation.
10401040
case "tasks":
10411041
// Add the function pointer as a parameter to start the goroutine.

compiler/func.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (c *Compiler) funcImplementation() funcValueImplementation {
3535
// Always pick the switch implementation, as it allows the use of blocking
3636
// inside a function that is used as a func value.
3737
switch c.Scheduler() {
38-
case "coroutines":
38+
case "none", "coroutines":
3939
return funcValueSwitch
4040
case "tasks":
4141
return funcValueDoubleword

0 commit comments

Comments
 (0)