Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637package 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}