Cleaned up function type
This commit is contained in:
parent
f870a5f1f8
commit
67b3a3d820
14 changed files with 310 additions and 294 deletions
28
src/build/Loop.go
Normal file
28
src/build/Loop.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/build/token"
|
||||
"git.akyoto.dev/cli/q/src/errors"
|
||||
)
|
||||
|
||||
// CompileLoop compiles a loop instruction.
|
||||
func (f *Function) CompileLoop(tokens token.List) error {
|
||||
blockStart := tokens.IndexKind(token.BlockStart) + 1
|
||||
blockEnd := tokens.LastIndexKind(token.BlockEnd)
|
||||
|
||||
if blockStart == -1 {
|
||||
return errors.New(errors.MissingBlockStart, f.File, tokens[0].End())
|
||||
}
|
||||
|
||||
if blockEnd == -1 {
|
||||
return errors.New(errors.MissingBlockEnd, f.File, tokens[len(tokens)-1].End())
|
||||
}
|
||||
|
||||
loop := fmt.Sprintf("%s_loop_%d", f.Name, f.count.loop)
|
||||
f.assembler.Label(loop)
|
||||
defer f.assembler.Jump(loop)
|
||||
f.count.loop++
|
||||
return f.CompileTokens(tokens[blockStart:blockEnd])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue