Added eval package
This commit is contained in:
parent
891b4d9f90
commit
3d294eb35c
16 changed files with 274 additions and 148 deletions
31
src/core/MultiAssign.go
Normal file
31
src/core/MultiAssign.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"git.urbach.dev/cli/q/src/asm"
|
||||
"git.urbach.dev/cli/q/src/errors"
|
||||
"git.urbach.dev/cli/q/src/expression"
|
||||
)
|
||||
|
||||
// MultiAssign assigns multiple return values to local variables.
|
||||
func (f *Function) MultiAssign(left *expression.Expression, right *expression.Expression) error {
|
||||
count := 0
|
||||
_, err := f.CompileCall(right)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return left.EachLeaf(func(leaf *expression.Expression) error {
|
||||
name := leaf.Token.Text(f.File.Bytes)
|
||||
variable := f.VariableByName(name)
|
||||
|
||||
if variable == nil {
|
||||
return errors.New(&errors.UnknownIdentifier{Name: name}, f.File, left.Token.Position)
|
||||
}
|
||||
|
||||
f.RegisterRegister(asm.MOVE, variable.Register, f.CPU.Output[count])
|
||||
f.UseVariable(variable)
|
||||
count++
|
||||
return nil
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue