Skip to content

Commit

Permalink
if component state boolean is not declared, switch to the block0, dec…
Browse files Browse the repository at this point in the history
…lare it and assign it a false state to start
  • Loading branch information
mbellotti committed Oct 13, 2023
1 parent 5417e05 commit 84a96c0
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions llvm/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Compiler struct {
instanceChildren map[string]string
structPropOrder map[string][]string

block0 *ir.Block
contextBlock *ir.Block
contextFunc *ir.Func
contextFuncName string
Expand Down Expand Up @@ -547,25 +548,7 @@ func (c *Compiler) compileComponent(node *ast.ComponentLiteral) {
//These functions are treated as booleans too
//initialize them as false first
rawid := v.RawId()
c.componentBool(rawid, false)

// b := &ast.Boolean{Value: false, ProcessedName: v.ProcessedName}
// val := c.compileValue(b)

// if val != nil {
// rawid := b.RawId()
// s := c.specs[rawid[0]]
// if s.GetSpecVar(rawid) != nil {
// vname := strings.Join(rawid, "_")
// pointer := s.GetSpecVarPointer(rawid)
// ty := s.GetSpecType(vname)
// c.contextBlock.NewLoad(ty, pointer)
// } else {
// s.DefineSpecType(rawid, val.Type())
// s.DefineSpecVar(rawid, val)
// c.allocVariable(rawid, val, []int{0, 0, 0, 0})
// }
// }
c.componentBool(rawid)

parentID := node.IdString()
c.structPropOrder[childId] = c.structPropOrder[parentID]
Expand Down Expand Up @@ -612,23 +595,26 @@ func (c *Compiler) compileComponent(node *ast.ComponentLiteral) {
}
}

func (c *Compiler) componentBool(rawid []string, placeholder bool) value.Value {
func (c *Compiler) componentBool(rawid []string) value.Value {
oldBlock := c.contextBlock
c.contextBlock = c.block0
s := c.specs[rawid[0]]
if s.GetSpecVar(rawid) != nil {
vname := strings.Join(rawid, "_")
pointer := s.GetSpecVarPointer(rawid)
ty := s.GetSpecType(vname)
c.contextBlock.NewLoad(ty, pointer)
return c.contextBlock.NewLoad(ty, pointer)
}

b := &ast.Boolean{Value: false, ProcessedName: rawid}
val := c.compileValue(b)

if val != nil && !placeholder {
if val != nil {
s.DefineSpecType(rawid, val.Type())
s.DefineSpecVar(rawid, val)
c.allocVariable(rawid, val, []int{0, 0, 0, 0})
}
c.contextBlock = oldBlock
return val
}

Expand Down Expand Up @@ -1065,7 +1051,7 @@ func (c *Compiler) compileInfixNode(node ast.Node) value.Value {
// Otherwise is this a component state?
if c.isComponent(v.RawId()) {
//Return a boolean as a placeholder
return c.componentBool(v.RawId(), true)
return c.componentBool(v.RawId())
}
panic(fmt.Sprintf("infix node %s is invalid", v.String()))
case *ast.This:
Expand Down Expand Up @@ -1798,6 +1784,7 @@ func (c *Compiler) setup() {
mainBlock := c.contextFunc.NewBlock(name.Block())
mainBlock.NewRet(nil)
c.contextBlock = mainBlock
c.block0 = mainBlock
}

type Panic string

0 comments on commit 84a96c0

Please sign in to comment.