Added more tests
This commit is contained in:
parent
e6ae755e60
commit
5cedb516c5
4 changed files with 29 additions and 3 deletions
|
@ -131,13 +131,21 @@ func (f *Function) CompileInstruction(line token.List) error {
|
|||
return errors.New(errors.MissingAssignValue, f.File, expr.LastChild().Token.After())
|
||||
}
|
||||
|
||||
name := expr.Children[0]
|
||||
name := expr.Children[0].Token.Text()
|
||||
_, exists := f.Variables[name]
|
||||
|
||||
if exists {
|
||||
return errors.New(&errors.VariableAlreadyExists{Name: name}, f.File, expr.Children[0].Token.Position)
|
||||
}
|
||||
|
||||
value := expr.Children[1]
|
||||
|
||||
// All expressions are returned to the memory pool.
|
||||
// To avoid losing variable values, we will remove it from the expression.
|
||||
expr.RemoveChild(value)
|
||||
|
||||
f.Variables[name.Token.Text()] = &Variable{
|
||||
Name: name.Token.Text(),
|
||||
f.Variables[name] = &Variable{
|
||||
Name: name,
|
||||
Value: value,
|
||||
IsConst: true,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue