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.
12345678910111213141516171819202122232425262728293031323334353637383940414243package core
import ( "git.urbach.dev/cli/q/src/ast" "git.urbach.dev/cli/q/src/ssa" "git.urbach.dev/cli/q/src/token")
// compileStoreArray compiles an assignment to an element in an array.func (f *Function) compileStoreArray(node *ast.Assign) error { right := node.Expression.Children[1] rightValue, err := f.evaluateRight(right)
if err != nil { return err }
left := node.Expression.Children[0] leftValue, err := f.evaluateArray(left)
if err != nil { return err }
memory, isMemory := leftValue.(*ssa.Memory)
if !isMemory { panic("not a memory address") }
if node.Expression.Token.Kind != token.Assign { leftValue = f.dereference(memory)
rightValue = f.Append(&ssa.BinaryOp{ Op: removeAssign(node.Expression.Token.Kind), Left: leftValue, Right: rightValue, Source: node.Expression.Source(), }) }
return f.store(memory, rightValue)}