Cleaned up function type
This commit is contained in:
parent
f870a5f1f8
commit
67b3a3d820
14 changed files with 310 additions and 294 deletions
|
@ -1,46 +1,20 @@
|
|||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/build/expression"
|
||||
"git.akyoto.dev/cli/q/src/build/token"
|
||||
"git.akyoto.dev/cli/q/src/errors"
|
||||
)
|
||||
|
||||
// CompileKeyword compiles an instruction that starts with a keyword.
|
||||
func (f *Function) CompileKeyword(line token.List) error {
|
||||
switch line[0].Text() {
|
||||
func (f *Function) CompileKeyword(tokens token.List) error {
|
||||
switch tokens[0].Text() {
|
||||
case "return":
|
||||
if len(line) > 1 {
|
||||
value := expression.Parse(line[1:])
|
||||
defer value.Close()
|
||||
// TODO: Set the return value
|
||||
}
|
||||
|
||||
f.Assembler.Return()
|
||||
return f.CompileReturn(tokens)
|
||||
|
||||
case "loop":
|
||||
blockStart := line.IndexKind(token.BlockStart) + 1
|
||||
blockEnd := line.LastIndexKind(token.BlockEnd)
|
||||
|
||||
if blockStart == -1 {
|
||||
return errors.New(errors.MissingBlockStart, f.File, line[0].End())
|
||||
}
|
||||
|
||||
if blockEnd == -1 {
|
||||
return errors.New(errors.MissingBlockEnd, f.File, line[len(line)-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(line[blockStart:blockEnd])
|
||||
return f.CompileLoop(tokens)
|
||||
|
||||
default:
|
||||
return errors.New(&errors.KeywordNotImplemented{Keyword: line[0].Text()}, f.File, line[0].Position)
|
||||
return errors.New(&errors.KeywordNotImplemented{Keyword: tokens[0].Text()}, f.File, tokens[0].Position)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue