Simplified type system
This commit is contained in:
@ -27,14 +27,14 @@ func (f *Function) CompileAssignField(node *ast.Assign) error {
|
||||
field := structure.FieldByName(fieldName)
|
||||
|
||||
if field == nil {
|
||||
return errors.New(&errors.UnknownStructField{StructName: structure.Name, FieldName: fieldName}, f.File, destination.Children[1].Token.Position)
|
||||
return errors.New(&errors.UnknownStructField{StructName: structure.Name(), FieldName: fieldName}, f.File, destination.Children[1].Token.Position)
|
||||
}
|
||||
|
||||
memory := asm.Memory{
|
||||
Base: variable.Register,
|
||||
Offset: field.Offset,
|
||||
Offset: byte(field.Offset),
|
||||
OffsetRegister: math.MaxUint8,
|
||||
Length: field.Type.TotalSize(),
|
||||
Length: byte(field.Type.Size()),
|
||||
}
|
||||
|
||||
_, err := f.ExpressionToMemory(value, memory)
|
||||
|
@ -92,10 +92,10 @@ func (f *Function) CompileCall(root *expression.Expression) (*Function, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !types.Check(typ, fn.Parameters[i].Type) {
|
||||
if !types.Is(typ, fn.Parameters[i].Type) {
|
||||
return nil, errors.New(&errors.TypeMismatch{
|
||||
Encountered: typ.UniqueName(),
|
||||
Expected: fn.Parameters[i].Type.UniqueName(),
|
||||
Encountered: typ.Name(),
|
||||
Expected: fn.Parameters[i].Type.Name(),
|
||||
ParameterName: fn.Parameters[i].Name,
|
||||
}, f.File, parameters[i].Token.Position)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ func (f *Function) CompileDelete(root *expression.Expression) error {
|
||||
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], int(variable.Type.(*types.Pointer).To.TotalSize()))
|
||||
f.RegisterNumber(asm.MOVE, f.CPU.Input[1], int(variable.Type.(*types.Pointer).To.Size()))
|
||||
|
||||
for _, register := range f.CPU.General {
|
||||
if f.RegisterIsUsed(register) {
|
||||
|
@ -11,7 +11,7 @@ func (f *Function) CompileNew(root *expression.Expression) error {
|
||||
structName := parameters[0].Token.Text(f.File.Bytes)
|
||||
typ := f.Types[structName]
|
||||
f.SaveRegister(f.CPU.Input[0])
|
||||
f.RegisterNumber(asm.MOVE, f.CPU.Input[0], int(typ.TotalSize()))
|
||||
f.RegisterNumber(asm.MOVE, f.CPU.Input[0], typ.Size())
|
||||
|
||||
for _, register := range f.CPU.General {
|
||||
if f.RegisterIsUsed(register) {
|
||||
|
@ -25,10 +25,10 @@ func (f *Function) CompileReturn(node *ast.Return) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !types.Check(typ, f.ReturnTypes[i]) {
|
||||
if !types.Is(typ, f.ReturnTypes[i]) {
|
||||
return errors.New(&errors.TypeMismatch{
|
||||
Encountered: typ.UniqueName(),
|
||||
Expected: f.ReturnTypes[i].UniqueName(),
|
||||
Encountered: typ.Name(),
|
||||
Expected: f.ReturnTypes[i].Name(),
|
||||
ParameterName: "",
|
||||
IsReturn: true,
|
||||
}, f.File, node.Values[i].Token.Position)
|
||||
|
@ -51,7 +51,7 @@ func (f *Function) ExpressionToRegister(node *expression.Expression, register cp
|
||||
right := node.Children[1]
|
||||
name = right.Token.Text(f.File.Bytes)
|
||||
field := variable.Type.(*types.Pointer).To.(*types.Struct).FieldByName(name)
|
||||
f.MemoryRegister(asm.LOAD, asm.Memory{Base: variable.Register, Offset: field.Offset, Length: field.Type.TotalSize()}, register)
|
||||
f.MemoryRegister(asm.LOAD, asm.Memory{Base: variable.Register, Offset: byte(field.Offset), Length: byte(field.Type.Size())}, register)
|
||||
return field.Type, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user