This should have been way more commits

This commit is contained in:
Sasha Koshka 2023-11-26 04:02:22 -05:00
parent 3a751666ba
commit aa107072d8
10 changed files with 649 additions and 156 deletions

49
generator/assignment.go Normal file
View File

@ -0,0 +1,49 @@
package generator
import "git.tebibyte.media/sashakoshka/fspl/llvm"
import "git.tebibyte.media/sashakoshka/fspl/entity"
import "git.tebibyte.media/sashakoshka/fspl/analyzer"
func (this *generator) generateAssignment (assignment *entity.Assignment) (llvm.Value, error) {
source, err := this.generateAssignmentSource (
assignment.Value,
assignment.Location.Type())
if err != nil { return nil, err }
destination, err := this.generateExpressionLoc(assignment.Location)
if err != nil { return nil, err }
this.blockManager.NewStore(source, destination)
return nil, nil
}
// generateAssignmentSource performs type coercions if necessary, mainly
// interface assignment. this should be called instead of generateExpression
// when the type to assign to is known.
func (this *generator) generateAssignmentSource (
from entity.Expression,
to entity.Type,
) (
llvm.Value,
error,
) {
source, err := this.generateExpression(from)
if err != nil { return nil, err }
ty := analyzer.ReduceToBase(to)
switch ty := ty.(type) {
// case *entity.TypeInterface:
// TODO
// sourceTy := analyzer.ReduceToBase(from.Type())
// irSourceTy, err := this,generateType(sourceTy)
// if err != nil { return nil, err }
//
// if
//
// irType, err := this.generateType(to)
// if err != nil { return nil, err }
// pointer := this.
default:
ty = ty
return source, nil
}
}

View File

@ -1,13 +1,23 @@
package generator package generator
import "fmt"
import "errors"
import "git.tebibyte.media/sashakoshka/fspl/llvm" import "git.tebibyte.media/sashakoshka/fspl/llvm"
import "git.tebibyte.media/sashakoshka/fspl/entity" import "git.tebibyte.media/sashakoshka/fspl/entity"
type loopEntry struct {
value llvm.Value
stub *llvm.Block
wantLocation bool
}
type blockManager struct { type blockManager struct {
*llvm.Block *llvm.Block
generator *generator generator *generator
function *llvm.Function function *llvm.Function
declarations map[*entity.Declaration] llvm.Value declarations map[*entity.Declaration] llvm.Value
loops []*loopEntry
} }
func (this *generator) pushBlockManager (function *llvm.Function) *blockManager { func (this *generator) pushBlockManager (function *llvm.Function) *blockManager {