package core import ( "git.urbach.dev/cli/q/src/ast" "git.urbach.dev/cli/q/src/ssa" ) // compileAssert compiles an assertion. func (f *Function) compileAssert(assert *ast.Assert) error { f.Count.Assert++ thenLabel := f.CreateLabel("assert.then", f.Count.Assert) elseLabel := f.CreateLabel("assert.else", f.Count.Assert) thenBlock := ssa.NewBlock(thenLabel) elseBlock := ssa.NewBlock(elseLabel) err := f.compileCondition(assert.Condition, thenBlock, elseBlock) if err != nil { return err } f.AddBlock(elseBlock) crash := f.Env.Function("run", "crash") fn := &ssa.Function{ FunctionRef: crash, Typ: crash.Type, } source := assert.Condition.Source() data := []byte(assert.Condition.SourceString(f.File.Bytes)) pointer := f.Append(&ssa.Bytes{Bytes: data, Source: source}) length := f.Append(&ssa.Int{Int: len(data), Source: source}) f.call(fn, []ssa.Value{pointer, length}, source) f.Calls.Add(crash) f.AddBlock(thenBlock) return nil }