Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849package core
import ( "git.urbach.dev/cli/q/src/errors" "git.urbach.dev/cli/q/src/expression" "git.urbach.dev/cli/q/src/ssa" "git.urbach.dev/cli/q/src/types")
// fieldFromMemory extracts a field from memory.func (f *Function) fieldFromMemory(leftValue ssa.Value, left *expression.Expression, right *expression.Expression, expr *expression.Expression) (ssa.Value, error) { fieldName := right.Token.StringFrom(f.File.Bytes) leftUnwrapped := types.Unwrap(leftValue.Type()) pointer, isPointer := leftUnwrapped.(*types.Pointer)
if isPointer { leftUnwrapped = pointer.To }
structure, isStructPointer := leftUnwrapped.(*types.Struct)
if !isStructPointer { return nil, errors.New(&NotDataStruct{TypeName: leftUnwrapped.Name()}, f.File, left.Source()) }
if structure.IsArray() && fieldName == "len" { return f.Append(&ssa.Int{Int: len(structure.Fields), Source: right.Source()}), nil }
field := structure.FieldByName(fieldName)
if field == nil { return nil, errors.New(&UnknownStructField{StructName: structure.Name(), FieldName: fieldName}, f.File, right.Source()) }
memory := f.structField(leftValue, field) _, memoryIsStruct := memory.Typ.(*types.Struct)
if !memoryIsStruct { load := f.Append(&ssa.Load{ Memory: memory, Source: expr.Source(), })
return load, nil }
return memory, nil}