Simplified file structure
This commit is contained in:
29
src/core/CompileAssert.go
Normal file
29
src/core/CompileAssert.go
Normal file
@ -0,0 +1,29 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/asm"
|
||||
"git.akyoto.dev/cli/q/src/ast"
|
||||
)
|
||||
|
||||
// CompileAssert compiles an assertion.
|
||||
func (f *Function) CompileAssert(assert *ast.Assert) error {
|
||||
f.count.assert++
|
||||
success := fmt.Sprintf("%s_assert_%d_true", f.UniqueName, f.count.assert)
|
||||
fail := fmt.Sprintf("%s_assert_%d_false", f.UniqueName, f.count.assert)
|
||||
err := f.CompileCondition(assert.Condition, success, fail)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.AddLabel(success)
|
||||
|
||||
f.Defer(func() {
|
||||
f.AddLabel(fail)
|
||||
f.Jump(asm.JUMP, "_crash")
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
Reference in New Issue
Block a user