Skip to content

Commit

Permalink
Extract compilation_error from main loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
acook committed Dec 11, 2016
1 parent dc1f030 commit 8d35695
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions src/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,39 +179,7 @@ func compile(source *Source) ([]byte, error) {
}

default:
bl_byte_offset := source.sourcemap[i]

bl_line := 1
bl_line_col := 1
for ii, rr := range source.code {
if ii >= bl_byte_offset {
// bl_line_col will be at the end of the token at this point
// so subtract the length of the token to get the beginning
// len will be 1 longer than we want, so add 1 to it
bl_line_col = 1 + bl_line_col - len(source.tokens[i])
break
}
bl_line_col = bl_line_col + 1
if rr == rune('\n') {
bl_line = bl_line + 1
bl_line_col = 1
}
}

gofile, goline := GoDebug(-13)

var info sequence
info = new(V)
info = info.App(NewTag("BL_FILE", source.filename))
info = info.App(NewTag("BL_LINE", strconv.Itoa(bl_line)))
info = info.App(NewTag("BL_LINE_COL", strconv.Itoa(bl_line_col)))
info = info.App(NewTag("BL_BYTE_OFFSET", strconv.Itoa(bl_byte_offset)))
info = info.App(NewTag("TOKEN_OFFSET", strconv.Itoa(i)))
info = info.App(NewTag("GO_FILE", gofile))
info = info.App(NewTag("GO_LINE", goline))

err := NewErr("compiler: unrecognized operation: "+t, info)
return nil, err
return nil, compilation_error(source, i, t)
}
}

Expand All @@ -225,6 +193,42 @@ func compile(source *Source) ([]byte, error) {
return bc, nil
}

func compilation_error(source *Source, token_offset int, t string) error {
bl_byte_offset := source.sourcemap[token_offset]

bl_line := 1
bl_line_col := 1
for ii, rr := range source.code {
if ii >= bl_byte_offset {
// bl_line_col will be at the end of the token at this point
// so subtract the length of the token to get the beginning
// len will be 1 longer than we want, so add 1 to it
bl_line_col = 1 + bl_line_col - len(source.tokens[token_offset])
break
}
bl_line_col = bl_line_col + 1
if rr == rune('\n') {
bl_line = bl_line + 1
bl_line_col = 1
}
}

gofile, goline := GoDebug(-13)

var info sequence
info = new(V)
info = info.App(NewTag("BL_FILE", source.filename))
info = info.App(NewTag("BL_LINE", strconv.Itoa(bl_line)))
info = info.App(NewTag("BL_LINE_COL", strconv.Itoa(bl_line_col)))
info = info.App(NewTag("BL_BYTE_OFFSET", strconv.Itoa(bl_byte_offset)))
info = info.App(NewTag("TOKEN_OFFSET", strconv.Itoa(token_offset)))
info = info.App(NewTag("GO_FILE", gofile))
info = info.App(NewTag("GO_LINE", goline))

err := NewErr("compiler: unrecognized operation: "+t, info)
return err
}

var rev_wd_map = make(map[string]uint64)
var wd_map = make(map[uint64][]rune)
var wd_count uint64
Expand Down

0 comments on commit 8d35695

Please sign in to comment.