Reorganized functions
This commit is contained in:
parent
ef7deb30b7
commit
3b29d4cdee
5 changed files with 99 additions and 86 deletions
|
@ -7,7 +7,6 @@ import (
|
|||
"git.akyoto.dev/cli/q/src/build/expression"
|
||||
"git.akyoto.dev/cli/q/src/build/fs"
|
||||
"git.akyoto.dev/cli/q/src/build/token"
|
||||
"git.akyoto.dev/cli/q/src/errors"
|
||||
)
|
||||
|
||||
// Function represents a function.
|
||||
|
@ -82,39 +81,6 @@ func (f *Function) CompileTokens(body token.List) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// CompileInstruction compiles a single instruction.
|
||||
func (f *Function) CompileInstruction(line token.List) error {
|
||||
if len(line) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if line[0].Kind == token.Keyword {
|
||||
return f.CompileKeyword(line)
|
||||
}
|
||||
|
||||
expr := expression.Parse(line)
|
||||
|
||||
if expr == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
defer expr.Close()
|
||||
|
||||
switch true {
|
||||
case isVariableDefinition(expr):
|
||||
return f.CompileVariableDefinition(expr)
|
||||
|
||||
case isAssignment(expr):
|
||||
return f.CompileAssignment(expr)
|
||||
|
||||
case isFunctionCall(expr):
|
||||
return f.CompileFunctionCall(expr)
|
||||
|
||||
default:
|
||||
return errors.New(&errors.InvalidInstruction{Instruction: expr.Token.Text()}, f.File, expr.Token.Position)
|
||||
}
|
||||
}
|
||||
|
||||
// Logf formats a message for verbose output.
|
||||
func (f *Function) Logf(format string, data ...any) {
|
||||
fmt.Printf("[%s @ %d] %s\n", f, len(f.assembler.Instructions), fmt.Sprintf(format, data...))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue