diff --git a/src/build/core/CompileDefinition.go b/src/build/core/CompileDefinition.go index 13b361f..d9daf58 100644 --- a/src/build/core/CompileDefinition.go +++ b/src/build/core/CompileDefinition.go @@ -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 } diff --git a/src/build/core/Function.go b/src/build/core/Function.go index a80e7d1..be45db3 100644 --- a/src/build/core/Function.go +++ b/src/build/core/Function.go @@ -36,9 +36,8 @@ 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{}), + variables: map[string]*Variable{}, + finished: make(chan struct{}), }, } } diff --git a/src/build/core/TokenToRegister.go b/src/build/core/TokenToRegister.go index bdce4d6..7a9c428 100644 --- a/src/build/core/TokenToRegister.go +++ b/src/build/core/TokenToRegister.go @@ -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 { diff --git a/src/build/core/Variable.go b/src/build/core/Variable.go index 8667b35..4557945 100644 --- a/src/build/core/Variable.go +++ b/src/build/core/Variable.go @@ -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 -} diff --git a/src/build/core/state.go b/src/build/core/state.go index 2bca805..31313d0 100644 --- a/src/build/core/state.go +++ b/src/build/core/state.go @@ -10,14 +10,13 @@ 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{} - assembler asm.Assembler - cpu cpu.CPU - count counter + err error + variables map[string]*Variable + functions map[string]*Function + finished chan struct{} + assembler asm.Assembler + cpu cpu.CPU + count counter } // counter stores how often a certain statement appeared so we can generate a unique label from it. diff --git a/tests/programs/reassign.q b/tests/programs/reassign.q new file mode 100644 index 0000000..df940d8 --- /dev/null +++ b/tests/programs/reassign.q @@ -0,0 +1,6 @@ +main() { + x := 1 + y := x + 1 + x = 2 + syscall(60, y) +} \ No newline at end of file diff --git a/tests/programs_test.go b/tests/programs_test.go index bcd947a..feba797 100644 --- a/tests/programs_test.go +++ b/tests/programs_test.go @@ -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) {