Implemented switch statements

This commit is contained in:
Eduard Urbach 2024-08-03 22:24:40 +02:00
parent 09ec8d8446
commit 52d1de042c
Signed by: eduard
GPG key ID: 49226B848C78F6C8
10 changed files with 170 additions and 27 deletions

View file

@ -20,11 +20,6 @@ func Count(body AST, buffer []byte, kind token.Kind, name string) uint8 {
case *Define:
count += node.Expression.Count(buffer, kind, name)
case *Return:
if node.Value != nil {
count += node.Value.Count(buffer, kind, name)
}
case *If:
count += node.Condition.Count(buffer, kind, name)
count += Count(node.Body, buffer, kind, name)
@ -33,6 +28,20 @@ func Count(body AST, buffer []byte, kind token.Kind, name string) uint8 {
case *Loop:
count += Count(node.Body, buffer, kind, name)
case *Return:
if node.Value != nil {
count += node.Value.Count(buffer, kind, name)
}
case *Switch:
for _, c := range node.Cases {
if c.Condition != nil {
count += c.Condition.Count(buffer, kind, name)
}
count += Count(c.Body, buffer, kind, name)
}
default:
panic("unknown AST type")
}