Implemented echo example
This commit is contained in:
parent
fcc4f8d2d9
commit
86175d7a53
9 changed files with 70 additions and 58 deletions
|
@ -22,21 +22,7 @@ func (f *Function) CompileDefinition(node *ast.Define) error {
|
|||
return errors.New(&errors.UnusedVariable{Name: name}, f.File, node.Name.Position)
|
||||
}
|
||||
|
||||
value := node.Value
|
||||
|
||||
err := value.EachLeaf(func(leaf *expression.Expression) error {
|
||||
if leaf.Token.Kind == token.Identifier && !f.identifierExists(leaf.Token.Text()) {
|
||||
return errors.New(&errors.UnknownIdentifier{Name: leaf.Token.Text()}, f.File, leaf.Token.Position)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return f.storeVariableInRegister(name, value, uses)
|
||||
return f.storeVariableInRegister(name, node.Value, uses)
|
||||
}
|
||||
|
||||
func (f *Function) AddVariable(variable *Variable) {
|
||||
|
@ -94,12 +80,7 @@ func (f *Function) identifierExists(name string) bool {
|
|||
}
|
||||
|
||||
func (f *Function) storeVariableInRegister(name string, value *expression.Expression, uses int) error {
|
||||
reg, exists := f.Scope().FindFree(f.cpu.General)
|
||||
|
||||
if !exists {
|
||||
panic("no free registers")
|
||||
}
|
||||
|
||||
reg := f.Scope().MustFindFree(f.cpu.General)
|
||||
f.Scope().Reserve(reg)
|
||||
err := f.ExpressionToRegister(value, reg)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue