Removed incorrect optimization
This commit is contained in:
parent
8f9481c548
commit
a9f305dec2
@ -38,15 +38,6 @@ func (f *Function) CompileDefinition(node *ast.Define) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if uses == 1 {
|
||||
f.definitions[name] = &Definition{
|
||||
Name: name,
|
||||
Value: value,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return f.storeVariableInRegister(name, value, uses)
|
||||
}
|
||||
|
||||
@ -83,12 +74,6 @@ func (f *Function) identifierExists(name string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
_, exists = f.definitions[name]
|
||||
|
||||
if exists {
|
||||
return true
|
||||
}
|
||||
|
||||
_, exists = f.functions[name]
|
||||
return exists
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ func NewFunction(name string, file *fs.File, body token.List) *Function {
|
||||
Syscall: x64.SyscallRegisters,
|
||||
Output: x64.ReturnValueRegisters,
|
||||
},
|
||||
definitions: map[string]*Definition{},
|
||||
variables: map[string]*Variable{},
|
||||
finished: make(chan struct{}),
|
||||
},
|
||||
|
@ -15,12 +15,6 @@ func (f *Function) TokenToRegister(t token.Token, register cpu.Register) error {
|
||||
switch t.Kind {
|
||||
case token.Identifier:
|
||||
name := t.Text()
|
||||
constant, exists := f.definitions[name]
|
||||
|
||||
if exists {
|
||||
return f.ExpressionToRegister(constant.Value, register)
|
||||
}
|
||||
|
||||
variable, exists := f.variables[name]
|
||||
|
||||
if !exists {
|
||||
|
@ -12,9 +12,3 @@ type Variable struct {
|
||||
Register cpu.Register
|
||||
Alive int
|
||||
}
|
||||
|
||||
// Definitions are single use expressions that don't reside in a register yet.
|
||||
type Definition struct {
|
||||
Value *expression.Expression
|
||||
Name string
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
// state is the data structure we embed in each function to preserve compilation state.
|
||||
type state struct {
|
||||
err error
|
||||
definitions map[string]*Definition
|
||||
variables map[string]*Variable
|
||||
functions map[string]*Function
|
||||
finished chan struct{}
|
||||
|
6
tests/programs/reassign.q
Normal file
6
tests/programs/reassign.q
Normal file
@ -0,0 +1,6 @@
|
||||
main() {
|
||||
x := 1
|
||||
y := x + 1
|
||||
x = 2
|
||||
syscall(60, y)
|
||||
}
|
@ -22,6 +22,7 @@ var programs = []struct {
|
||||
{"chained-calls.q", "", 9},
|
||||
{"nested-calls.q", "", 4},
|
||||
{"return.q", "", 6},
|
||||
{"reassign.q", "", 2},
|
||||
}
|
||||
|
||||
func TestPrograms(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user