Skip to content

Commit

Permalink
refactor: clean up compiler code
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Dec 19, 2024
1 parent 02b47f3 commit ec1f432
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 7 additions & 0 deletions go/vt/vtgate/evalengine/compiler_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5146,3 +5146,10 @@ func (asm *assembler) Fn_LAST_INSERT_ID() {
return 1
}, "FN LAST_INSERT_ID UINT64(SP-1)")
}

func (asm *assembler) Fn_LAST_INSERT_ID_NULL() {
asm.emit(func(env *ExpressionEnv) int {
env.VCursor().SetLastInsertID(0)
return 1
}, "FN LAST_INSERT_ID NULL")
}
12 changes: 4 additions & 8 deletions go/vt/vtgate/evalengine/fn_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,13 @@ func (call *builtinLastInsertID) compile(c *compiler) (ctype, error) {

setZero := c.compileNullCheck1(arg)
c.compileToUint64(arg, 1)
setLastInsertID := c.asm.jumpFrom()
c.asm.Fn_LAST_INSERT_ID()
end := c.asm.jumpFrom()

c.asm.jumpDestination(setZero)
c.asm.emit(func(env *ExpressionEnv) int {
env.vm.stack[env.vm.sp] = env.vm.arena.newEvalUint64(0)
env.vm.sp++
return 1
}, "PUSH UINT64(0)")
c.asm.Fn_LAST_INSERT_ID_NULL()

c.asm.jumpDestination(setLastInsertID)
c.asm.Fn_LAST_INSERT_ID()
c.asm.jumpDestination(end)

return ctype{Type: sqltypes.Uint64, Flag: flagNullable, Col: collationNumeric}, nil
}
Expand Down

0 comments on commit ec1f432

Please sign in to comment.