Added simple variable lifetimes
This commit is contained in:
parent
9e3112ad52
commit
6b5bc22ec6
6 changed files with 107 additions and 39 deletions
|
@ -224,43 +224,41 @@ func scanFile(path string, functions chan<- *Function) error {
|
|||
return errors.New(errors.ExpectedFunctionDefinition, file, tokens[i].Position)
|
||||
}
|
||||
|
||||
cpu := cpu.CPU{
|
||||
Call: x64.CallRegisters,
|
||||
General: x64.GeneralRegisters,
|
||||
Syscall: x64.SyscallRegisters,
|
||||
Return: x64.ReturnValueRegisters,
|
||||
function := &Function{
|
||||
Name: tokens[nameStart].Text(),
|
||||
File: file,
|
||||
Body: tokens[bodyStart:i],
|
||||
Variables: map[string]*Variable{},
|
||||
CPU: cpu.CPU{
|
||||
Call: x64.CallRegisters,
|
||||
General: x64.GeneralRegisters,
|
||||
Syscall: x64.SyscallRegisters,
|
||||
Return: x64.ReturnValueRegisters,
|
||||
},
|
||||
Assembler: asm.Assembler{
|
||||
Instructions: make([]asm.Instruction, 0, 32),
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
err := expression.EachParameter(parameters, func(tokens token.List) error {
|
||||
if len(tokens) == 1 {
|
||||
name := tokens[0].Text()
|
||||
register := x64.CallRegisters[len(function.Variables)]
|
||||
variable := &Variable{Name: name, Register: register}
|
||||
function.addVariable(variable)
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New(errors.NotImplemented, file, parameter[0].Position)
|
||||
return errors.New(errors.NotImplemented, file, tokens[0].Position)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
functions <- &Function{
|
||||
Name: tokens[nameStart].Text(),
|
||||
File: file,
|
||||
Body: tokens[bodyStart:i],
|
||||
Variables: variables,
|
||||
CPU: cpu,
|
||||
Assembler: asm.Assembler{
|
||||
Instructions: make([]asm.Instruction, 0, 32),
|
||||
},
|
||||
}
|
||||
|
||||
functions <- function
|
||||
nameStart = -1
|
||||
paramsStart = -1
|
||||
bodyStart = -1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue