-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Labels
onlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week
Description
The lack of recursion in goboscript (only tail recursion) reduces the flexibility and power of functions/procs in gs. This is because local vars do not belong to a specific 'frame' or 'level' of the function.
This post provides a simple concept for how local variables could work (efficiently) in gs.
Note
Recursive local vars should only be allowed with warped (not nowarp) procs and funcs, because otherwise there could be memory conflicts
Syntax
example syntax (each local var is explicitly made into a recursive local var):
func foo(a) {
rloc c = ...;
...
}
or (function is assigned as recursive, so all local variables are also recursive):
recur func foo(a) {
local c = ...;
...
}
concept
- For each recursive local variable, make a list (it also has to be local to the function.)
e.g. In this case,rloc c
could generate a list called:foo: c
(note this would conflict with local lists but that is a rejected feature) -
At the start of the func or proc, add an empty item to each list
Note that this *could* be optimised to only add to the list when the variable is first assigned, but then checks for recursion and possibilities of not being initialised (e.g. in an if statement). But this does not matter because if you are using recursive local vars, one shouldn't expect it to be that micro-optimised anyway - access the rloc variables using the 'last' item of list (using 'last' instead of item[length list] would reduce block count and improve efficiency in vanilla scratch):

- At the end of the proc, delete the last item of each of the rloc lists. This may happen just before a
stop_this_script
block, or just before thestop_this_script
block in thereturn
keyword's codegen, or just when a proc ends naturally

things that would have to be handled differently (kind of obvious)
Metadata
Metadata
Assignees
Labels
onlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week