Implemented Value interface
This commit is contained in:
@ -24,7 +24,7 @@ func (f *Function) ArrayElementToRegister(node *expression.Expression, register
|
||||
index := node.Children[1]
|
||||
|
||||
memory := asm.Memory{
|
||||
Base: array.Register,
|
||||
Base: array.Value.Register,
|
||||
Offset: 0,
|
||||
OffsetRegister: math.MaxUint8,
|
||||
Length: byte(1),
|
||||
@ -50,11 +50,11 @@ func (f *Function) ArrayElementToRegister(node *expression.Expression, register
|
||||
|
||||
defer f.UseVariable(indexVariable)
|
||||
|
||||
if !types.Is(indexVariable.Type, types.AnyInt) {
|
||||
return nil, errors.New(&errors.TypeMismatch{Encountered: indexVariable.Type.Name(), Expected: types.AnyInt.Name()}, f.File, index.Token.Position)
|
||||
if !types.Is(indexVariable.Value.Typ, types.AnyInt) {
|
||||
return nil, errors.New(&errors.TypeMismatch{Encountered: indexVariable.Value.Typ.Name(), Expected: types.AnyInt.Name()}, f.File, index.Token.Position)
|
||||
}
|
||||
|
||||
memory.OffsetRegister = indexVariable.Register
|
||||
memory.OffsetRegister = indexVariable.Value.Register
|
||||
|
||||
default:
|
||||
typ, err := f.ExpressionToRegister(index, register)
|
||||
|
@ -21,7 +21,7 @@ func (f *Function) Compare(comparison *expression.Expression) error {
|
||||
}
|
||||
|
||||
defer f.UseVariable(variable)
|
||||
return f.Execute(comparison.Token, variable.Register, right)
|
||||
return f.Execute(comparison.Token, variable.Value.Register, right)
|
||||
}
|
||||
|
||||
if ast.IsFunctionCall(left) && right.IsLeaf() {
|
||||
|
@ -20,7 +20,7 @@ func (f *Function) CompileAssign(node *ast.Assign) error {
|
||||
}
|
||||
|
||||
defer f.UseVariable(variable)
|
||||
return f.Execute(node.Expression.Token, variable.Register, right)
|
||||
return f.Execute(node.Expression.Token, variable.Value.Register, right)
|
||||
}
|
||||
|
||||
if left.Token.Kind == token.Dot {
|
||||
|
@ -25,7 +25,7 @@ func (f *Function) CompileAssignArray(node *ast.Assign) error {
|
||||
defer f.UseVariable(variable)
|
||||
|
||||
memory := asm.Memory{
|
||||
Base: variable.Register,
|
||||
Base: variable.Value.Register,
|
||||
Offset: 0,
|
||||
OffsetRegister: math.MaxUint8,
|
||||
Length: byte(1),
|
||||
@ -38,18 +38,18 @@ func (f *Function) CompileAssignArray(node *ast.Assign) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !types.Is(index.Type, types.AnyInt) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: index.Type.Name(), Expected: types.AnyInt.Name()}, f.File, indexExpr.Token.Position)
|
||||
if !types.Is(index.Type(), types.AnyInt) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: index.Type().Name(), Expected: types.AnyInt.Name()}, f.File, indexExpr.Token.Position)
|
||||
}
|
||||
|
||||
switch index.Kind {
|
||||
switch index := index.(type) {
|
||||
case eval.Number:
|
||||
memory.Offset = int8(index.Number)
|
||||
case eval.Register:
|
||||
memory.OffsetRegister = index.Register
|
||||
defer f.FreeRegister(index.Register)
|
||||
default:
|
||||
panic(fmt.Errorf("%s: not implemented: %d", f.UniqueName, index.Kind))
|
||||
panic(fmt.Errorf("%s: not implemented: %v", f.UniqueName, index))
|
||||
}
|
||||
|
||||
_, err = f.ExpressionToMemory(right, memory)
|
||||
|
@ -36,8 +36,8 @@ func (f *Function) CompileAssignDivision(expr *expression.Expression) error {
|
||||
return err
|
||||
}
|
||||
|
||||
quotientVariable.Type = types.Int
|
||||
remainderVariable.Type = types.Int
|
||||
quotientVariable.Value.Typ = types.Int
|
||||
remainderVariable.Value.Typ = types.Int
|
||||
f.AddVariable(quotientVariable)
|
||||
f.AddVariable(remainderVariable)
|
||||
} else {
|
||||
@ -68,13 +68,13 @@ func (f *Function) CompileAssignDivision(expr *expression.Expression) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !types.Is(dividend.Type, types.AnyInt) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: dividend.Type.Name(), Expected: types.AnyInt.Name()}, f.File, dividendExpr.Token.Position)
|
||||
if !types.Is(dividend.Type(), types.AnyInt) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: dividend.Type().Name(), Expected: types.AnyInt.Name()}, f.File, dividendExpr.Token.Position)
|
||||
}
|
||||
|
||||
divisor := division.Children[1]
|
||||
|
||||
switch dividend.Kind {
|
||||
switch dividend := dividend.(type) {
|
||||
case eval.Number:
|
||||
f.SaveRegister(x86.RAX)
|
||||
f.RegisterNumber(asm.MOVE, x86.RAX, dividend.Number)
|
||||
@ -83,10 +83,10 @@ func (f *Function) CompileAssignDivision(expr *expression.Expression) error {
|
||||
err = f.Execute(division.Token, dividend.Register, divisor)
|
||||
defer f.FreeRegister(dividend.Register)
|
||||
default:
|
||||
panic(fmt.Errorf("%s: not implemented: %d", f.UniqueName, dividend.Kind))
|
||||
panic(fmt.Errorf("%s: not implemented: %v", f.UniqueName, dividend))
|
||||
}
|
||||
|
||||
f.RegisterRegister(asm.MOVE, quotientVariable.Register, x86.RAX)
|
||||
f.RegisterRegister(asm.MOVE, remainderVariable.Register, x86.RDX)
|
||||
f.RegisterRegister(asm.MOVE, quotientVariable.Value.Register, x86.RAX)
|
||||
f.RegisterRegister(asm.MOVE, remainderVariable.Value.Register, x86.RDX)
|
||||
return err
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func (f *Function) CompileAssignField(node *ast.Assign) error {
|
||||
}
|
||||
|
||||
defer f.UseVariable(variable)
|
||||
pointer := variable.Type.(*types.Pointer)
|
||||
pointer := variable.Value.Typ.(*types.Pointer)
|
||||
structure := pointer.To.(*types.Struct)
|
||||
field := structure.FieldByName(fieldName)
|
||||
|
||||
@ -31,7 +31,7 @@ func (f *Function) CompileAssignField(node *ast.Assign) error {
|
||||
}
|
||||
|
||||
memory := asm.Memory{
|
||||
Base: variable.Register,
|
||||
Base: variable.Value.Register,
|
||||
Offset: int8(field.Offset),
|
||||
OffsetRegister: math.MaxUint8,
|
||||
Length: byte(field.Type.Size()),
|
||||
|
@ -75,11 +75,11 @@ func (f *Function) CompileCondition(condition *expression.Expression, successLab
|
||||
return err
|
||||
}
|
||||
|
||||
if !types.Is(value.Type, types.Bool) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: value.Type.Name(), Expected: types.Bool.Name()}, f.File, condition.Token.Position)
|
||||
if !types.Is(value.Type(), types.Bool) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: value.Type().Name(), Expected: types.Bool.Name()}, f.File, condition.Token.Position)
|
||||
}
|
||||
|
||||
switch value.Kind {
|
||||
switch value := value.(type) {
|
||||
case eval.Number:
|
||||
if value.Number == 0 {
|
||||
f.Jump(asm.JUMP, failLabel)
|
||||
@ -89,7 +89,7 @@ func (f *Function) CompileCondition(condition *expression.Expression, successLab
|
||||
f.FreeRegister(value.Register)
|
||||
f.Jump(asm.JE, failLabel)
|
||||
default:
|
||||
panic(fmt.Errorf("%s: not implemented: %d", f.UniqueName, value.Kind))
|
||||
panic(fmt.Errorf("%s: not implemented: %v", f.UniqueName, value))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -21,7 +21,7 @@ func (f *Function) CompileDefinition(node *ast.Define) error {
|
||||
return err
|
||||
}
|
||||
|
||||
typ, err := f.ExpressionToRegister(right, variable.Register)
|
||||
typ, err := f.ExpressionToRegister(right, variable.Value.Register)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -35,7 +35,7 @@ func (f *Function) CompileDefinition(node *ast.Define) error {
|
||||
typ = types.Int
|
||||
}
|
||||
|
||||
variable.Type = typ
|
||||
variable.Value.Typ = typ
|
||||
f.AddVariable(variable)
|
||||
return nil
|
||||
}
|
||||
@ -63,10 +63,10 @@ func (f *Function) CompileDefinition(node *ast.Define) error {
|
||||
}
|
||||
|
||||
if count < len(types) {
|
||||
variable.Type = types[count]
|
||||
variable.Value.Typ = types[count]
|
||||
}
|
||||
|
||||
f.RegisterRegister(asm.MOVE, variable.Register, f.CPU.Output[count])
|
||||
f.RegisterRegister(asm.MOVE, variable.Value.Register, f.CPU.Output[count])
|
||||
f.AddVariable(variable)
|
||||
count++
|
||||
return nil
|
||||
|
@ -20,8 +20,8 @@ func (f *Function) CompileDelete(root *expression.Expression) error {
|
||||
defer f.UseVariable(variable)
|
||||
f.SaveRegister(f.CPU.Input[0])
|
||||
f.SaveRegister(f.CPU.Input[1])
|
||||
f.RegisterRegister(asm.MOVE, f.CPU.Input[0], variable.Register)
|
||||
f.RegisterNumber(asm.MOVE, f.CPU.Input[1], variable.Type.(*types.Pointer).To.Size())
|
||||
f.RegisterRegister(asm.MOVE, f.CPU.Input[0], variable.Value.Register)
|
||||
f.RegisterNumber(asm.MOVE, f.CPU.Input[1], variable.Value.Typ.(*types.Pointer).To.Size())
|
||||
f.CallSafe(f.All.Functions["mem.free"], f.CPU.Input[:2])
|
||||
return nil
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func (f *Function) CompileFor(loop *ast.For) error {
|
||||
return err
|
||||
}
|
||||
|
||||
counter = variable.Register
|
||||
counter = variable.Value.Register
|
||||
from = loop.Head.Children[1].Children[0]
|
||||
to = loop.Head.Children[1].Children[1]
|
||||
f.AddVariable(variable)
|
||||
@ -67,20 +67,20 @@ func (f *Function) CompileFor(loop *ast.For) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !types.Is(value.Type, types.AnyInt) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: value.Type.Name(), Expected: types.AnyInt.Name()}, f.File, to.Token.Position)
|
||||
if !types.Is(value.Type(), types.AnyInt) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: value.Type().Name(), Expected: types.AnyInt.Name()}, f.File, to.Token.Position)
|
||||
}
|
||||
|
||||
f.AddLabel(label)
|
||||
|
||||
switch value.Kind {
|
||||
switch value := value.(type) {
|
||||
case eval.Number:
|
||||
f.RegisterNumber(asm.COMPARE, counter, value.Number)
|
||||
case eval.Register:
|
||||
f.RegisterRegister(asm.COMPARE, counter, value.Register)
|
||||
defer f.FreeRegister(value.Register)
|
||||
default:
|
||||
panic(fmt.Errorf("%s: not implemented: %d", f.UniqueName, value.Kind))
|
||||
panic(fmt.Errorf("%s: not implemented: %v", f.UniqueName, value))
|
||||
}
|
||||
|
||||
f.Jump(asm.JGE, labelEnd)
|
||||
|
@ -21,8 +21,8 @@ func (f *Function) CompileLen(root *expression.Expression) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !types.Is(value.Type, types.AnyArray) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: value.Type.Name(), Expected: types.AnyArray.Name(), ParameterName: "array"}, f.File, root.Children[1].Token.Position)
|
||||
if !types.Is(value.Type(), types.AnyArray) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: value.Type().Name(), Expected: types.AnyArray.Name(), ParameterName: "array"}, f.File, root.Children[1].Token.Position)
|
||||
}
|
||||
|
||||
memory := asm.Memory{
|
||||
@ -34,17 +34,17 @@ func (f *Function) CompileLen(root *expression.Expression) error {
|
||||
output := f.CPU.Output[0]
|
||||
f.SaveRegister(output)
|
||||
|
||||
switch value.Kind {
|
||||
switch value := value.(type) {
|
||||
case eval.Register:
|
||||
memory.Base = value.Register
|
||||
defer f.FreeRegister(value.Register)
|
||||
case eval.Label:
|
||||
f.RegisterLabel(asm.MOVE, output, value.Label)
|
||||
memory.Base = output
|
||||
default:
|
||||
panic(fmt.Errorf("%s: not implemented: %d", f.UniqueName, value.Kind))
|
||||
panic(fmt.Errorf("%s: not implemented: %v", f.UniqueName, value))
|
||||
}
|
||||
|
||||
f.MemoryRegister(asm.LOAD, memory, output)
|
||||
f.FreeRegister(value.Register)
|
||||
return nil
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ func (f *Function) CompileMemoryStore(root *expression.Expression) error {
|
||||
defer f.UseVariable(variable)
|
||||
|
||||
memory := asm.Memory{
|
||||
Base: variable.Register,
|
||||
Base: variable.Value.Register,
|
||||
OffsetRegister: math.MaxUint8,
|
||||
Length: byte(numBytes),
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ func (f *Function) Define(leaf *expression.Expression) (*scope.Variable, error)
|
||||
|
||||
variable = &scope.Variable{
|
||||
Name: name,
|
||||
Value: eval.Value{
|
||||
Kind: eval.Register,
|
||||
Value: eval.Register{
|
||||
Register: f.NewRegister(),
|
||||
Alive: uses,
|
||||
},
|
||||
|
@ -20,10 +20,10 @@ func (f *Function) DotToRegister(node *expression.Expression, register cpu.Regis
|
||||
variable := f.VariableByName(leftText)
|
||||
|
||||
if variable != nil {
|
||||
field := variable.Type.(*types.Pointer).To.(*types.Struct).FieldByName(rightText)
|
||||
field := variable.Value.Typ.(*types.Pointer).To.(*types.Struct).FieldByName(rightText)
|
||||
|
||||
memory := asm.Memory{
|
||||
Base: variable.Register,
|
||||
Base: variable.Value.Register,
|
||||
Offset: int8(field.Offset),
|
||||
OffsetRegister: math.MaxUint8,
|
||||
Length: byte(field.Type.Size()),
|
||||
|
@ -10,9 +10,8 @@ import (
|
||||
// Evaluate evaluates an expression and returns a value.
|
||||
func (f *Function) Evaluate(expr *expression.Expression) (eval.Value, error) {
|
||||
if expr.IsFolded {
|
||||
value := eval.Value{
|
||||
Kind: eval.Number,
|
||||
Type: types.AnyInt,
|
||||
value := eval.Number{
|
||||
Typ: types.AnyInt,
|
||||
Number: expr.Value,
|
||||
}
|
||||
|
||||
@ -37,9 +36,8 @@ func (f *Function) Evaluate(expr *expression.Expression) (eval.Value, error) {
|
||||
tmp := f.NewRegister()
|
||||
typ, err := f.ExpressionToRegister(expr, tmp)
|
||||
|
||||
value := eval.Value{
|
||||
Kind: eval.Register,
|
||||
Type: typ,
|
||||
value := eval.Register{
|
||||
Typ: typ,
|
||||
Register: tmp,
|
||||
}
|
||||
|
||||
|
@ -17,13 +17,13 @@ func (f *Function) EvaluateArray(expr *expression.Expression) (eval.Value, error
|
||||
array := f.VariableByName(name)
|
||||
|
||||
if array == nil {
|
||||
return eval.Value{}, errors.New(&errors.UnknownIdentifier{Name: name}, f.File, expr.Children[0].Token.Position)
|
||||
return nil, errors.New(&errors.UnknownIdentifier{Name: name}, f.File, expr.Children[0].Token.Position)
|
||||
}
|
||||
|
||||
defer f.UseVariable(array)
|
||||
|
||||
memory := asm.Memory{
|
||||
Base: array.Register,
|
||||
Base: array.Value.Register,
|
||||
Offset: 0,
|
||||
OffsetRegister: math.MaxUint8,
|
||||
Length: byte(1),
|
||||
@ -33,26 +33,25 @@ func (f *Function) EvaluateArray(expr *expression.Expression) (eval.Value, error
|
||||
index, err := f.Evaluate(indexExpr)
|
||||
|
||||
if err != nil {
|
||||
return eval.Value{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !types.Is(index.Type, types.AnyInt) {
|
||||
return eval.Value{}, errors.New(&errors.TypeMismatch{Encountered: index.Type.Name(), Expected: types.AnyInt.Name()}, f.File, indexExpr.Token.Position)
|
||||
if !types.Is(index.Type(), types.AnyInt) {
|
||||
return nil, errors.New(&errors.TypeMismatch{Encountered: index.Type().Name(), Expected: types.AnyInt.Name()}, f.File, indexExpr.Token.Position)
|
||||
}
|
||||
|
||||
switch index.Kind {
|
||||
switch index := index.(type) {
|
||||
case eval.Number:
|
||||
memory.Offset = int8(index.Number)
|
||||
case eval.Register:
|
||||
memory.OffsetRegister = index.Register
|
||||
defer f.FreeRegister(index.Register)
|
||||
default:
|
||||
panic(fmt.Errorf("%s: not implemented: %d", f.UniqueName, index.Kind))
|
||||
panic(fmt.Errorf("%s: not implemented: %v", f.UniqueName, index))
|
||||
}
|
||||
|
||||
value := eval.Value{
|
||||
Kind: eval.Memory,
|
||||
Type: array.Type.(*types.Array).Of,
|
||||
value := eval.Memory{
|
||||
Typ: array.Value.Typ.(*types.Array).Of,
|
||||
Memory: memory,
|
||||
}
|
||||
|
||||
|
@ -11,16 +11,15 @@ func (f *Function) EvaluateCall(expr *expression.Expression) (eval.Value, error)
|
||||
types, err := f.CompileCall(expr)
|
||||
|
||||
if err != nil {
|
||||
return eval.Value{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(types) == 0 {
|
||||
return eval.Value{}, errors.New(errors.UntypedExpression, f.File, expr.Token.Position)
|
||||
return nil, errors.New(errors.UntypedExpression, f.File, expr.Token.Position)
|
||||
}
|
||||
|
||||
value := eval.Value{
|
||||
Kind: eval.Register,
|
||||
Type: types[0],
|
||||
value := eval.Register{
|
||||
Typ: types[0],
|
||||
Register: f.CPU.Output[0],
|
||||
}
|
||||
|
||||
|
@ -20,13 +20,12 @@ func (f *Function) EvaluateDot(expr *expression.Expression) (eval.Value, error)
|
||||
variable := f.VariableByName(leftText)
|
||||
|
||||
if variable != nil {
|
||||
field := variable.Type.(*types.Pointer).To.(*types.Struct).FieldByName(rightText)
|
||||
field := variable.Value.Typ.(*types.Pointer).To.(*types.Struct).FieldByName(rightText)
|
||||
|
||||
value := eval.Value{
|
||||
Kind: eval.Memory,
|
||||
Type: field.Type,
|
||||
value := eval.Memory{
|
||||
Typ: field.Type,
|
||||
Memory: asm.Memory{
|
||||
Base: variable.Register,
|
||||
Base: variable.Value.Register,
|
||||
Offset: int8(field.Offset),
|
||||
OffsetRegister: math.MaxUint8,
|
||||
Length: byte(field.Type.Size()),
|
||||
@ -42,12 +41,11 @@ func (f *Function) EvaluateDot(expr *expression.Expression) (eval.Value, error)
|
||||
number, err := ToNumber(constant.Token, constant.File)
|
||||
|
||||
if err != nil {
|
||||
return eval.Value{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
value := eval.Value{
|
||||
Kind: eval.Number,
|
||||
Type: types.AnyInt,
|
||||
value := eval.Number{
|
||||
Typ: types.AnyInt,
|
||||
Number: number,
|
||||
}
|
||||
|
||||
@ -60,14 +58,13 @@ func (f *Function) EvaluateDot(expr *expression.Expression) (eval.Value, error)
|
||||
if exists {
|
||||
f.File.Imports[leftText].Used = true
|
||||
|
||||
value := eval.Value{
|
||||
Kind: eval.Label,
|
||||
Type: types.AnyPointer,
|
||||
value := eval.Label{
|
||||
Typ: types.AnyPointer,
|
||||
Label: function.UniqueName,
|
||||
}
|
||||
|
||||
return value, nil
|
||||
}
|
||||
|
||||
return eval.Value{}, errors.New(&errors.UnknownIdentifier{Name: uniqueName}, f.File, left.Token.Position)
|
||||
return nil, errors.New(&errors.UnknownIdentifier{Name: uniqueName}, f.File, left.Token.Position)
|
||||
}
|
||||
|
@ -18,9 +18,8 @@ func (f *Function) EvaluateLeaf(expr *expression.Expression) (eval.Value, error)
|
||||
name := expr.Token.Text(f.File.Bytes)
|
||||
|
||||
if name == "true" {
|
||||
value := eval.Value{
|
||||
Kind: eval.Number,
|
||||
Type: types.Bool,
|
||||
value := eval.Number{
|
||||
Typ: types.Bool,
|
||||
Number: 1,
|
||||
}
|
||||
|
||||
@ -28,9 +27,8 @@ func (f *Function) EvaluateLeaf(expr *expression.Expression) (eval.Value, error)
|
||||
}
|
||||
|
||||
if name == "false" {
|
||||
value := eval.Value{
|
||||
Kind: eval.Number,
|
||||
Type: types.Bool,
|
||||
value := eval.Number{
|
||||
Typ: types.Bool,
|
||||
Number: 0,
|
||||
}
|
||||
|
||||
@ -42,16 +40,15 @@ func (f *Function) EvaluateLeaf(expr *expression.Expression) (eval.Value, error)
|
||||
if variable != nil {
|
||||
f.UseVariable(variable)
|
||||
|
||||
if variable.Alive == 0 {
|
||||
if variable.Value.Alive == 0 {
|
||||
return variable.Value, nil
|
||||
}
|
||||
|
||||
tmp := f.NewRegister()
|
||||
f.RegisterRegister(asm.MOVE, tmp, variable.Register)
|
||||
f.RegisterRegister(asm.MOVE, tmp, variable.Value.Register)
|
||||
|
||||
value := eval.Value{
|
||||
Kind: eval.Register,
|
||||
Type: variable.Type,
|
||||
value := eval.Register{
|
||||
Typ: variable.Value.Typ,
|
||||
Register: tmp,
|
||||
}
|
||||
|
||||
@ -59,27 +56,25 @@ func (f *Function) EvaluateLeaf(expr *expression.Expression) (eval.Value, error)
|
||||
}
|
||||
|
||||
if function != nil {
|
||||
value := eval.Value{
|
||||
Kind: eval.Label,
|
||||
Type: types.AnyPointer,
|
||||
value := eval.Label{
|
||||
Typ: types.AnyPointer,
|
||||
Label: function.UniqueName,
|
||||
}
|
||||
|
||||
return value, nil
|
||||
}
|
||||
|
||||
return eval.Value{}, errors.New(&errors.UnknownIdentifier{Name: name}, f.File, expr.Token.Position)
|
||||
return nil, errors.New(&errors.UnknownIdentifier{Name: name}, f.File, expr.Token.Position)
|
||||
|
||||
case token.Number, token.Rune:
|
||||
number, err := f.ToNumber(expr.Token)
|
||||
|
||||
if err != nil {
|
||||
return eval.Value{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
value := eval.Value{
|
||||
Kind: eval.Number,
|
||||
Type: types.AnyInt,
|
||||
value := eval.Number{
|
||||
Typ: types.AnyInt,
|
||||
Number: number,
|
||||
}
|
||||
|
||||
@ -94,14 +89,13 @@ func (f *Function) EvaluateLeaf(expr *expression.Expression) (eval.Value, error)
|
||||
copy(slice[8:], data)
|
||||
label := f.AddBytes(slice)
|
||||
|
||||
value := eval.Value{
|
||||
Kind: eval.Label,
|
||||
Type: types.String,
|
||||
value := eval.Label{
|
||||
Typ: types.String,
|
||||
Label: label,
|
||||
}
|
||||
|
||||
return value, nil
|
||||
}
|
||||
|
||||
return eval.Value{}, errors.New(errors.InvalidExpression, f.File, expr.Token.Position)
|
||||
return nil, errors.New(errors.InvalidExpression, f.File, expr.Token.Position)
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ func (f *Function) ExecuteLeaf(operation token.Token, register cpu.Register, ope
|
||||
}
|
||||
|
||||
defer f.UseVariable(variable)
|
||||
return f.ExecuteRegisterRegister(operation, register, variable.Register)
|
||||
return f.ExecuteRegisterRegister(operation, register, variable.Value.Register)
|
||||
|
||||
case token.Number, token.Rune:
|
||||
number, err := f.ToNumber(operand)
|
||||
|
@ -17,7 +17,7 @@ func (f *Function) ExpressionToMemory(node *expression.Expression, memory asm.Me
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch value.Kind {
|
||||
switch value := value.(type) {
|
||||
case eval.Number:
|
||||
f.MemoryNumber(asm.STORE, memory, value.Number)
|
||||
case eval.Register:
|
||||
@ -31,8 +31,8 @@ func (f *Function) ExpressionToMemory(node *expression.Expression, memory asm.Me
|
||||
case eval.Label:
|
||||
f.MemoryLabel(asm.STORE, memory, value.Label)
|
||||
default:
|
||||
panic(fmt.Errorf("%s: not implemented: %d", f.UniqueName, value.Kind))
|
||||
panic(fmt.Errorf("%s: not implemented: %v", f.UniqueName, value))
|
||||
}
|
||||
|
||||
return value.Type, err
|
||||
return value.Type(), err
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func (f *Function) ExpressionToRegister(node *expression.Expression, register cp
|
||||
} else if right.Token.Kind == token.Identifier {
|
||||
rightVariable := f.VariableByName(right.Token.Text(f.File.Bytes))
|
||||
leftPointer, leftIsPointer := typ.(*types.Pointer)
|
||||
rightPointer, rightIsPointer := rightVariable.Type.(*types.Pointer)
|
||||
rightPointer, rightIsPointer := rightVariable.Value.Typ.(*types.Pointer)
|
||||
|
||||
if leftIsPointer && rightIsPointer && leftPointer.To == rightPointer.To {
|
||||
typ = types.Int
|
||||
|
@ -23,7 +23,7 @@ func (f *Function) MultiAssign(left *expression.Expression, right *expression.Ex
|
||||
return errors.New(&errors.UnknownIdentifier{Name: name}, f.File, left.Token.Position)
|
||||
}
|
||||
|
||||
f.RegisterRegister(asm.MOVE, variable.Register, f.CPU.Output[count])
|
||||
f.RegisterRegister(asm.MOVE, variable.Value.Register, f.CPU.Output[count])
|
||||
f.UseVariable(variable)
|
||||
count++
|
||||
return nil
|
||||
|
@ -32,9 +32,8 @@ func (f *Function) ResolveTypes() error {
|
||||
|
||||
f.AddVariable(&scope.Variable{
|
||||
Name: param.name,
|
||||
Value: eval.Value{
|
||||
Kind: eval.Register,
|
||||
Type: param.typ,
|
||||
Value: eval.Register{
|
||||
Typ: param.typ,
|
||||
Register: x86.InputRegisters[i],
|
||||
Alive: uses,
|
||||
},
|
||||
|
@ -32,8 +32,8 @@ func (f *Function) TokenToRegister(t token.Token, register cpu.Register) (types.
|
||||
if variable != nil {
|
||||
f.UseVariable(variable)
|
||||
f.SaveRegister(register)
|
||||
f.RegisterRegister(asm.MOVE, register, variable.Register)
|
||||
return variable.Type, nil
|
||||
f.RegisterRegister(asm.MOVE, register, variable.Value.Register)
|
||||
return variable.Value.Typ, nil
|
||||
}
|
||||
|
||||
if function != nil {
|
||||
|
@ -16,7 +16,7 @@ func (f *Function) UsesRegister(expr *expression.Expression, register cpu.Regist
|
||||
|
||||
variable := f.VariableByName(expr.Token.Text(f.File.Bytes))
|
||||
|
||||
if variable == nil || variable.Register != register {
|
||||
if variable == nil || variable.Value.Register != register {
|
||||
return false
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user