Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pkg/runtime/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (g *Generator) generateValue(value any) string {
case *lang.MultiFn:
return g.generateMultiFn(v)
case lang.Keyword:
if ns := v.Namespace(); ns != "" {
if ns := v.Namespace(); ns != nil {
return g.allocKWVar(fmt.Sprintf("%s/%s", ns, v.Name()))
} else {
return g.allocKWVar(v.Name())
Expand Down Expand Up @@ -1213,11 +1213,11 @@ func (g *Generator) generateCase(node *ast.Node) string {
// if a test matches, we evaluate the corresponding body and assign to resultVar
// Generate code based on test type
testType := caseNode.TestType.(lang.Keyword)

// Calculate the lookup key based on test type
lookupVar := g.allocateTempVar()
g.writef("var %s int64\n", lookupVar)

switch testType {
case lang.KWInt:
// For integers, convert directly to int64 and apply shift/mask
Expand All @@ -1234,7 +1234,7 @@ func (g *Generator) generateCase(node *ast.Node) string {
g.writef("%s = int64(uint32(%s >> %d) & uint32(%d))\n",
lookupVar, lookupVar, caseNode.Shift, caseNode.Mask)
}

case lang.KWHashIdentity:
// Use identity hash
if caseNode.Mask == 0 {
Expand All @@ -1243,7 +1243,7 @@ func (g *Generator) generateCase(node *ast.Node) string {
g.writef("%s = int64(uint32(lang.IdentityHash(%s) >> %d) & uint32(%d))\n",
lookupVar, testExpr, caseNode.Shift, caseNode.Mask)
}

case lang.KWHashEquiv:
// Use hash
if caseNode.Mask == 0 {
Expand All @@ -1253,19 +1253,19 @@ func (g *Generator) generateCase(node *ast.Node) string {
lookupVar, testExpr, caseNode.Shift, caseNode.Mask)
}
}

// Generate switch statement for the entries
first := true
for i, entry := range caseNode.Entries {
g.writef("// case entry %d (key=%d, collision=%v)\n", i, entry.Key, entry.HasCollision)

if first {
g.writef("if %s == %d {\n", lookupVar, entry.Key)
first = false
} else {
g.writef("} else if %s == %d {\n", lookupVar, entry.Key)
}

if entry.HasCollision {
// For collision cases, evaluate the condp expression
condpExpr := g.generateASTNode(entry.ResultExpr)
Expand Down