Implemented parameters
This commit is contained in:
parent
51a2308179
commit
0d8891d8a7
6 changed files with 76 additions and 27 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"git.akyoto.dev/cli/q/src/build/arch/x64"
|
||||
"git.akyoto.dev/cli/q/src/build/asm"
|
||||
"git.akyoto.dev/cli/q/src/build/cpu"
|
||||
"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"
|
||||
|
@ -100,6 +101,7 @@ func scanFile(path string, functions chan<- *Function) error {
|
|||
blockLevel = 0
|
||||
nameStart = -1
|
||||
paramsStart = -1
|
||||
paramsEnd = -1
|
||||
bodyStart = -1
|
||||
)
|
||||
|
||||
|
@ -128,12 +130,12 @@ func scanFile(path string, functions chan<- *Function) error {
|
|||
for i < len(tokens) {
|
||||
if tokens[i].Kind == token.GroupStart {
|
||||
groupLevel++
|
||||
i++
|
||||
|
||||
if groupLevel == 1 {
|
||||
paramsStart = i
|
||||
}
|
||||
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -144,12 +146,13 @@ func scanFile(path string, functions chan<- *Function) error {
|
|||
return errors.New(errors.MissingGroupStart, file, tokens[i].Position)
|
||||
}
|
||||
|
||||
i++
|
||||
|
||||
if groupLevel == 0 {
|
||||
paramsEnd = i
|
||||
i++
|
||||
break
|
||||
}
|
||||
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -221,17 +224,37 @@ func scanFile(path string, functions chan<- *Function) error {
|
|||
return errors.New(errors.ExpectedFunctionDefinition, file, tokens[i].Position)
|
||||
}
|
||||
|
||||
cpu := cpu.CPU{
|
||||
General: x64.GeneralRegisters,
|
||||
Syscall: x64.SyscallRegisters,
|
||||
Return: x64.ReturnValueRegisters,
|
||||
}
|
||||
|
||||
parameters := tokens[paramsStart:paramsEnd]
|
||||
variables := map[string]*Variable{}
|
||||
|
||||
err := expression.EachParameter(parameters, func(parameter token.List) error {
|
||||
if len(parameter) == 1 {
|
||||
name := parameter[0].Text()
|
||||
register := x64.SyscallRegisters[1+len(variables)]
|
||||
variables[name] = &Variable{Name: name, Register: register}
|
||||
cpu.Use(register)
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New(errors.NotImplemented, file, parameter[0].Position)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
functions <- &Function{
|
||||
Name: tokens[nameStart].Text(),
|
||||
File: file,
|
||||
Head: tokens[paramsStart:bodyStart],
|
||||
Body: tokens[bodyStart:i],
|
||||
Variables: map[string]*Variable{},
|
||||
CPU: cpu.CPU{
|
||||
General: x64.GeneralRegisters,
|
||||
Syscall: x64.SyscallRegisters,
|
||||
Return: x64.ReturnValueRegisters,
|
||||
},
|
||||
Variables: variables,
|
||||
CPU: cpu,
|
||||
Assembler: asm.Assembler{
|
||||
Instructions: make([]asm.Instruction, 0, 32),
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue