diff --git a/src/codegen/count.go b/src/codegen/count.go index f2c7ffd..360ae3d 100644 --- a/src/codegen/count.go +++ b/src/codegen/count.go @@ -6,9 +6,9 @@ type counter uint16 // count stores how often a certain statement appeared so we can generate a unique label from it. type count struct { Assert counter - Data counter Branch counter + Data counter Loop counter - Switch counter SubBranch counter + Switch counter } \ No newline at end of file diff --git a/src/codegen/execute.go b/src/codegen/execute.go index 147e6bd..12f903e 100644 --- a/src/codegen/execute.go +++ b/src/codegen/execute.go @@ -21,12 +21,12 @@ func (f *Function) execute(step *Step) { f.executeCallExtern(step, instr) case *ssa.Copy: f.executeCopy(step, instr) - case *ssa.Data: - f.executeData(step, instr) - case *ssa.FromTuple: - f.executeFromTuple(step, instr) + case *ssa.Field: + f.executeField(step, instr) case *ssa.Function: f.executeFunction(step, instr) + case *ssa.Global: + f.executeGlobal(step, instr) case *ssa.Int: f.executeInt(step, instr) case *ssa.Jump: diff --git a/src/codegen/executeFromTuple.go b/src/codegen/executeField.go similarity index 78% rename from src/codegen/executeFromTuple.go rename to src/codegen/executeField.go index d0626c1..50641c0 100644 --- a/src/codegen/executeFromTuple.go +++ b/src/codegen/executeField.go @@ -5,7 +5,7 @@ import ( "git.urbach.dev/cli/q/src/ssa" ) -func (f *Function) executeFromTuple(step *Step, instr *ssa.FromTuple) { +func (f *Function) executeField(step *Step, instr *ssa.Field) { source := f.CPU.Call.Out[instr.Index] if step.Register == source { diff --git a/src/codegen/executeData.go b/src/codegen/executeGlobal.go similarity index 74% rename from src/codegen/executeData.go rename to src/codegen/executeGlobal.go index f897168..e65fc7d 100644 --- a/src/codegen/executeData.go +++ b/src/codegen/executeGlobal.go @@ -5,7 +5,7 @@ import ( "git.urbach.dev/cli/q/src/ssa" ) -func (f *Function) executeData(step *Step, instr *ssa.Data) { +func (f *Function) executeGlobal(step *Step, instr *ssa.Global) { f.Assembler.Append(&asm.MoveLabel{ Destination: step.Register, Label: instr.Label, diff --git a/src/codegen/findFreeRegister.go b/src/codegen/findFreeRegister.go index 944f679..745013b 100644 --- a/src/codegen/findFreeRegister.go +++ b/src/codegen/findFreeRegister.go @@ -105,7 +105,7 @@ func (f *Function) findFreeRegister(step *Step) cpu.Register { // Mark input and output registers as used. switch instr := current.Value.(type) { - case *ssa.FromTuple: + case *ssa.Field: usedRegisters |= (1 << f.CPU.Call.Out[instr.Index]) case *ssa.Parameter: usedRegisters |= (1 << f.CPU.Call.In[instr.Index]) diff --git a/src/codegen/hintABI.go b/src/codegen/hintABI.go index 4c54b7e..36bbc09 100644 --- a/src/codegen/hintABI.go +++ b/src/codegen/hintABI.go @@ -25,7 +25,7 @@ func (f *Function) hintABI(step *Step) { f.ValueToStep[param].hint(f.CPU.ExternCall.In[r]) } - case *ssa.FromTuple: + case *ssa.Field: if step.Register == -1 { step.Register = f.CPU.Call.Out[instr.Index] } diff --git a/src/core/decomposeTuple.go b/src/core/decomposeTuple.go index 6228aff..a12537d 100644 --- a/src/core/decomposeTuple.go +++ b/src/core/decomposeTuple.go @@ -22,7 +22,7 @@ func (f *Function) decomposeTuple(value ssa.Value, tuple *types.Tuple, typeCheck return nil, errors.New(typeMismatch, f.File, source) } - v := f.Append(&ssa.FromTuple{ + v := f.Append(&ssa.Field{ Tuple: value, Index: i, Source: source, diff --git a/src/core/define.go b/src/core/define.go index 2b395c1..17573b4 100644 --- a/src/core/define.go +++ b/src/core/define.go @@ -28,17 +28,17 @@ func (f *Function) define(left *expression.Expression, right *expression.Express return err } - data, isData := leftValue.(*ssa.Data) + global, isGlobal := leftValue.(*ssa.Global) - if isData { + if isGlobal { zero := f.Append(&ssa.Int{Int: 0}) f.Append(&ssa.Store{ Memory: &ssa.Memory{ - Typ: data.Typ.(*types.Pointer).To, - Address: data, + Typ: global.Typ.(*types.Pointer).To, + Address: global, Index: zero, - Source: data.Source, + Source: global.Source, }, Value: rightValue, }) diff --git a/src/core/defineMulti.go b/src/core/defineMulti.go index fb1f907..af10d4b 100644 --- a/src/core/defineMulti.go +++ b/src/core/defineMulti.go @@ -51,7 +51,7 @@ func (f *Function) defineMulti(left *expression.Expression, right *expression.Ex structure, isStructType := types.Unwrap(fn.Typ.Output[i]).(*types.Struct) if !isStructType { - value := &ssa.FromTuple{ + value := &ssa.Field{ Tuple: rightValue, Index: count, Source: identifier.Source(), @@ -74,7 +74,7 @@ func (f *Function) defineMulti(left *expression.Expression, right *expression.Ex composite := f.makeStructFromTuple(rightValue, fn.Typ.Output[i], structure, name, identifier.Source()) for _, element := range composite.Arguments { - element.(*ssa.FromTuple).Index += count + element.(*ssa.Field).Index += count protected = append(protected, element) } diff --git a/src/core/dereference.go b/src/core/dereference.go index 1d1399d..c71f458 100644 --- a/src/core/dereference.go +++ b/src/core/dereference.go @@ -8,7 +8,7 @@ import ( // dereference loads from memory if the value was a memory address, otherwise returns the raw value. func (f *Function) dereference(value ssa.Value) ssa.Value { switch value := value.(type) { - case *ssa.Data: + case *ssa.Global: zero := f.Append(&ssa.Int{Int: 0}) load := f.Append(&ssa.Load{ diff --git a/src/core/evaluatePackageMember.go b/src/core/evaluatePackageMember.go index 94a39ea..c163a70 100644 --- a/src/core/evaluatePackageMember.go +++ b/src/core/evaluatePackageMember.go @@ -32,7 +32,7 @@ func (f *Function) evaluatePackageMember(pkg *Package, rightText string, expr *e global, exists := pkg.Globals[rightText] if exists { - v := f.Append(&ssa.Data{ + v := f.Append(&ssa.Global{ Label: pkg.Name + "." + global.Name, Typ: f.Env.Pointer(global.Typ), Source: expr.Source(), diff --git a/src/core/fieldFromCall.go b/src/core/fieldFromCall.go index 33dbe4d..49a9535 100644 --- a/src/core/fieldFromCall.go +++ b/src/core/fieldFromCall.go @@ -20,7 +20,7 @@ func (f *Function) fieldFromCall(call *ssa.Call, left *expression.Expression, ri return nil, errors.New(&UnknownStructField{StructName: structure.Name(), FieldName: fieldName}, f.File, right.Source()) } - value := f.Append(&ssa.FromTuple{ + value := f.Append(&ssa.Field{ Tuple: call, Index: int(field.Index), Source: expr.Source(), diff --git a/src/core/makeStructFromTuple.go b/src/core/makeStructFromTuple.go index 6f33299..1e5b859 100644 --- a/src/core/makeStructFromTuple.go +++ b/src/core/makeStructFromTuple.go @@ -10,7 +10,7 @@ func (f *Function) makeStructFromTuple(tuple ssa.Value, typ types.Type, structTy fields := make([]ssa.Value, len(structType.Fields)) for i, field := range structType.Fields { - fieldValue := &ssa.FromTuple{ + fieldValue := &ssa.Field{ Tuple: tuple, Index: i, Source: source, diff --git a/src/core/store.go b/src/core/store.go index b0f8a31..78eddbb 100644 --- a/src/core/store.go +++ b/src/core/store.go @@ -34,7 +34,7 @@ func (f *Function) store(memory *ssa.Memory, value ssa.Value) error { fieldValues := make([]ssa.Value, len(structure.Fields)) for i := range structure.Fields { - fieldValue := &ssa.FromTuple{ + fieldValue := &ssa.Field{ Tuple: value, Index: i, Source: token.NewSource(value.(errors.Source).Start(), value.(errors.Source).End()), diff --git a/src/core/validateLeft.go b/src/core/validateLeft.go index f6702cb..70db723 100644 --- a/src/core/validateLeft.go +++ b/src/core/validateLeft.go @@ -20,7 +20,7 @@ func (f *Function) validateLeft(left *expression.Expression, right *expression.E global, isGlobal := pkg.Globals[name] if isGlobal { - v := f.Append(&ssa.Data{ + v := f.Append(&ssa.Global{ Label: f.File.Package + "." + global.Name, Typ: f.Env.Pointer(global.Typ), Source: left.Source(), diff --git a/src/optimizer/Reorder.go b/src/optimizer/Reorder.go index 559e27d..1d477f6 100644 --- a/src/optimizer/Reorder.go +++ b/src/optimizer/Reorder.go @@ -12,7 +12,7 @@ func Reorder(ir ssa.IR) { for _, block := range ir.Blocks { for start, instr := range slices.Backward(block.Instructions) { switch instr.(type) { - case *ssa.Bytes, *ssa.Data, *ssa.Int: + case *ssa.Bytes, *ssa.Global, *ssa.Int: default: continue } diff --git a/src/ssa/FromTuple.go b/src/ssa/Field.go similarity index 63% rename from src/ssa/FromTuple.go rename to src/ssa/Field.go index db181b6..42fae9c 100644 --- a/src/ssa/FromTuple.go +++ b/src/ssa/Field.go @@ -6,8 +6,8 @@ import ( "git.urbach.dev/cli/q/src/types" ) -// FromTuple is a value inside of a struct or tuple. -type FromTuple struct { +// Field is a value inside of a struct or tuple. +type Field struct { Tuple Value Liveness Index int @@ -15,8 +15,8 @@ type FromTuple struct { } // Equals returns true if the tuple accesses are equal. -func (a *FromTuple) Equals(v Value) bool { - b, sameType := v.(*FromTuple) +func (a *Field) Equals(v Value) bool { + b, sameType := v.(*Field) if !sameType { return false @@ -26,23 +26,23 @@ func (a *FromTuple) Equals(v Value) bool { } // Inputs returns the tuple. -func (f *FromTuple) Inputs() []Value { return []Value{f.Tuple} } +func (f *Field) Inputs() []Value { return []Value{f.Tuple} } // IsPure returns true because accessing the same element will always have the same value. -func (f *FromTuple) IsPure() bool { return true } +func (f *Field) IsPure() bool { return true } // Replace replaces the tuple if it matches. -func (f *FromTuple) Replace(old Value, new Value) { +func (f *Field) Replace(old Value, new Value) { if f.Tuple == old { f.Tuple = new } } // String returns a human-readable representation of the tuple access. -func (f *FromTuple) String() string { return fmt.Sprintf("field(%p, %d)", f.Tuple, f.Index) } +func (f *Field) String() string { return fmt.Sprintf("field(%p, %d)", f.Tuple, f.Index) } // Type returns the type of the tuple element. -func (f *FromTuple) Type() types.Type { +func (f *Field) Type() types.Type { switch typ := types.Unwrap(f.Tuple.Type()).(type) { case *types.Struct: return typ.Fields[f.Index].Type diff --git a/src/ssa/Data.go b/src/ssa/Global.go similarity index 58% rename from src/ssa/Data.go rename to src/ssa/Global.go index dc968c8..0d25a5c 100644 --- a/src/ssa/Data.go +++ b/src/ssa/Global.go @@ -4,8 +4,8 @@ import ( "git.urbach.dev/cli/q/src/types" ) -// Data is a memory location identified by a label. -type Data struct { +// Global is a memory location identified by a label. +type Global struct { Label string Typ types.Type Liveness @@ -13,8 +13,8 @@ type Data struct { } // Equals returns true if the data labels are equal. -func (a *Data) Equals(v Value) bool { - b, sameType := v.(*Data) +func (a *Global) Equals(v Value) bool { + b, sameType := v.(*Global) if !sameType { return false @@ -24,16 +24,16 @@ func (a *Data) Equals(v Value) bool { } // Inputs returns nil because a data label has no inputs. -func (d *Data) Inputs() []Value { return nil } +func (d *Global) Inputs() []Value { return nil } // IsPure returns true because a data label is always constant. -func (d *Data) IsPure() bool { return true } +func (d *Global) IsPure() bool { return true } // Replace does nothing because a data label has no inputs. -func (d *Data) Replace(Value, Value) {} +func (d *Global) Replace(Value, Value) {} // String returns a human-readable representation of the data label. -func (d *Data) String() string { return d.Label } +func (d *Global) String() string { return d.Label } // Type returns the type of the memory it references. -func (d *Data) Type() types.Type { return d.Typ } \ No newline at end of file +func (d *Global) Type() types.Type { return d.Typ } \ No newline at end of file