Analyze for loops

This commit is contained in:
Sasha Koshka 2024-03-16 13:25:53 -04:00
parent bb1886ab9c
commit c0476f14ae
2 changed files with 37 additions and 1 deletions

View File

@ -816,7 +816,42 @@ func (this *Tree) analyzeFor (
entity.Expression,
error,
) {
// TODO
loop.Ty = into
this.pushScope(loop)
defer this.popScope()
// index
if loop.Index != nil {
index, err := this.analyzeDeclaration (
builtinType("Index"),
strict, loop.Index)
if err != nil { return nil, err }
loop.Index = index.(*entity.Declaration)
}
// element
element, err := this.analyzeDeclaration(nil, strict, loop.Element)
if err != nil { return nil, err }
loop.Element = element.(*entity.Declaration)
// over
over, err := this.analyzeExpression (
&entity.TypeSlice {
Pos: loop.Position(),
Element: element.Type(),
}, weak, loop.Over)
if err != nil { return nil, err }
loop.Over = over
this.pushLoop(loop)
defer this.popLoop()
body, err := this.analyzeExpression(nil, strict, loop.Body)
if err != nil { return nil, err }
loop.Body = body
return loop, nil
}
func (this *Tree) analyzeBreak (

View File

@ -493,6 +493,7 @@ type For struct {
// Semantics
Ty Type
Scope
}
func (*For) expression(){}
func (*For) breakable(){}