Skip to content

Commit

Permalink
build: #3893 do not return LLVM structs from Build
Browse files Browse the repository at this point in the history
  • Loading branch information
kenbell committed Sep 12, 2023
1 parent c4de195 commit 86eede9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
8 changes: 4 additions & 4 deletions interp/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func isRecoverableError(err error) bool {
// ErrorLine is one line in a traceback. The position may be missing.
type ErrorLine struct {
Pos token.Position
Inst llvm.Value
Inst string
}

// Error encapsulates compile-time interpretation errors with an associated
// import path. The errors may not have a precise location attached.
type Error struct {
ImportPath string
Inst llvm.Value
Inst string
Pos token.Position
Err error
Traceback []ErrorLine
Expand All @@ -60,10 +60,10 @@ func (r *runner) errorAt(inst instruction, err error) *Error {
pos := getPosition(inst.llvmInst)
return &Error{
ImportPath: r.pkgName,
Inst: inst.llvmInst,
Inst: inst.String(),
Pos: pos,
Err: err,
Traceback: []ErrorLine{{pos, inst.llvmInst}},
Traceback: []ErrorLine{{pos, inst.String()}},
}
}

Expand Down
8 changes: 3 additions & 5 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ func runTest(t *testing.T, pathPrefix string) {
if err != nil {
if err, match := err.(*Error); match {
println(err.Error())
if !err.Inst.IsNil() {
err.Inst.Dump()
println()
if len(err.Inst) != 0 {
println(err.Inst)
}
if len(err.Traceback) > 0 {
println("\ntraceback:")
for _, line := range err.Traceback {
println(line.Pos.String() + ":")
line.Inst.Dump()
println()
println(line.Inst)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion interp/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
// how this function got called.
callErr.Traceback = append(callErr.Traceback, ErrorLine{
Pos: getPosition(inst.llvmInst),
Inst: inst.llvmInst,
Inst: inst.String(),
})
return nil, mem, callErr
}
Expand Down
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,16 +1289,14 @@ func printCompilerError(logln func(...interface{}), err error) {
case *interp.Error:
logln("#", err.ImportPath)
logln(err.Error())
if !err.Inst.IsNil() {
err.Inst.Dump()
logln()
if len(err.Inst) != 0 {
logln(err.Inst)
}
if len(err.Traceback) > 0 {
logln("\ntraceback:")
for _, line := range err.Traceback {
logln(line.Pos.String() + ":")
line.Inst.Dump()
logln()
logln(line.Inst)
}
}
case loader.Errors:
Expand Down

0 comments on commit 86eede9

Please sign in to comment.