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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if uses == 1 {
|
|
||||||
f.definitions[name] = &Definition{
|
|
||||||
Name: name,
|
|
||||||
Value: value,
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return f.storeVariableInRegister(name, value, uses)
|
return f.storeVariableInRegister(name, value, uses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,12 +74,6 @@ func (f *Function) identifierExists(name string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
_, exists = f.definitions[name]
|
|
||||||
|
|
||||||
if exists {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
_, exists = f.functions[name]
|
_, exists = f.functions[name]
|
||||||
return exists
|
return exists
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,8 @@ func NewFunction(name string, file *fs.File, body token.List) *Function {
|
|||||||
Syscall: x64.SyscallRegisters,
|
Syscall: x64.SyscallRegisters,
|
||||||
Output: x64.ReturnValueRegisters,
|
Output: x64.ReturnValueRegisters,
|
||||||
},
|
},
|
||||||
definitions: map[string]*Definition{},
|
variables: map[string]*Variable{},
|
||||||
variables: map[string]*Variable{},
|
finished: make(chan struct{}),
|
||||||
finished: make(chan struct{}),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,6 @@ func (f *Function) TokenToRegister(t token.Token, register cpu.Register) error {
|
|||||||
switch t.Kind {
|
switch t.Kind {
|
||||||
case token.Identifier:
|
case token.Identifier:
|
||||||
name := t.Text()
|
name := t.Text()
|
||||||
constant, exists := f.definitions[name]
|
|
||||||
|
|
||||||
if exists {
|
|
||||||
return f.ExpressionToRegister(constant.Value, register)
|
|
||||||
}
|
|
||||||
|
|
||||||
variable, exists := f.variables[name]
|
variable, exists := f.variables[name]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
|
@ -12,9 +12,3 @@ type Variable struct {
|
|||||||
Register cpu.Register
|
Register cpu.Register
|
||||||
Alive int
|
Alive int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Definitions are single use expressions that don't reside in a register yet.
|
|
||||||
type Definition struct {
|
|
||||||
Value *expression.Expression
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
@ -10,14 +10,13 @@ import (
|
|||||||
|
|
||||||
// state is the data structure we embed in each function to preserve compilation state.
|
// state is the data structure we embed in each function to preserve compilation state.
|
||||||
type state struct {
|
type state struct {
|
||||||
err error
|
err error
|
||||||
definitions map[string]*Definition
|
variables map[string]*Variable
|
||||||
variables map[string]*Variable
|
functions map[string]*Function
|
||||||
functions map[string]*Function
|
finished chan struct{}
|
||||||
finished chan struct{}
|
assembler asm.Assembler
|
||||||
assembler asm.Assembler
|
cpu cpu.CPU
|
||||||
cpu cpu.CPU
|
count counter
|
||||||
count counter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// counter stores how often a certain statement appeared so we can generate a unique label from it.
|
// counter stores how often a certain statement appeared so we can generate a unique label from it.
|
||||||
|
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},
|
{"chained-calls.q", "", 9},
|
||||||
{"nested-calls.q", "", 4},
|
{"nested-calls.q", "", 4},
|
||||||
{"return.q", "", 6},
|
{"return.q", "", 6},
|
||||||
|
{"reassign.q", "", 2},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrograms(t *testing.T) {
|
func TestPrograms(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user