diff --git a/src/common/allocator.odin b/src/common/allocator.odin index 452f729a..a8e23c21 100644 --- a/src/common/allocator.odin +++ b/src/common/allocator.odin @@ -12,17 +12,8 @@ Scratch_Allocator :: struct { leaked_allocations: [dynamic][]byte, } -scratch_allocator_init :: proc( - s: ^Scratch_Allocator, - size: int, - backup_allocator := context.allocator, -) { - s.data, _ = mem.make_aligned( - []byte, - size, - 2 * align_of(rawptr), - backup_allocator, - ) +scratch_allocator_init :: proc(s: ^Scratch_Allocator, size: int, backup_allocator := context.allocator) { + s.data, _ = mem.make_aligned([]byte, size, 2 * align_of(rawptr), backup_allocator) s.curr_offset = 0 s.prev_allocation = nil s.backup_allocator = backup_allocator @@ -57,8 +48,7 @@ scratch_allocator_proc :: proc( if s.data == nil { DEFAULT_BACKING_SIZE :: 1 << 22 - if !(context.allocator.procedure != scratch_allocator_proc && - context.allocator.data != allocator_data) { + if !(context.allocator.procedure != scratch_allocator_proc && context.allocator.data != allocator_data) { panic("cyclic initialization of the scratch allocator with itself") } scratch_allocator_init(s, DEFAULT_BACKING_SIZE) @@ -126,29 +116,13 @@ scratch_allocator_proc :: proc( end := begin + uintptr(len(s.data)) old_ptr := uintptr(old_memory) - data, err := scratch_allocator_proc( - allocator_data, - .Alloc, - size, - alignment, - old_memory, - old_size, - loc, - ) + data, err := scratch_allocator_proc(allocator_data, .Alloc, size, alignment, old_memory, old_size, loc) if err != nil { return data, err } runtime.copy(data, mem.byte_slice(old_memory, old_size)) - _, err = scratch_allocator_proc( - allocator_data, - .Free, - 0, - alignment, - old_memory, - old_size, - loc, - ) + _, err = scratch_allocator_proc(allocator_data, .Free, 0, alignment, old_memory, old_size, loc) return data, err case .Query_Features: diff --git a/src/common/ast.odin b/src/common/ast.odin index 3fde3040..af3c812c 100644 --- a/src/common/ast.odin +++ b/src/common/ast.odin @@ -253,7 +253,7 @@ collect_value_decl :: proc( return } - global_expr := GlobalExpr{ + global_expr := GlobalExpr { mutable = value_decl.is_mutable, docs = value_decl.docs, attributes = value_decl.attributes[:], diff --git a/src/common/config.odin b/src/common/config.odin index 27bc1ac1..2c40e4ad 100644 --- a/src/common/config.odin +++ b/src/common/config.odin @@ -4,6 +4,7 @@ ConfigProfile :: struct { os: string, name: string, checker_path: [dynamic]string, + defines: map[string]string, } Config :: struct { diff --git a/src/common/fuzzy.odin b/src/common/fuzzy.odin index 822f37f9..fdb04df6 100644 --- a/src/common/fuzzy.odin +++ b/src/common/fuzzy.odin @@ -1,19 +1,19 @@ package common -import "core:strings" import "core:fmt" +import "core:strings" /* Ported from https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clangd/FuzzyMatch.cpp */ max_pattern :: 63 -max_word :: 256 +max_word :: 256 awful_score: int = -(1 << 13) perfect_bonus :: 4 -miss :: 0 -match :: 1 +miss :: 0 +match :: 1 FuzzyCharTypeSet :: u8 @@ -84,19 +84,19 @@ make_fuzzy_matcher :: proc(pattern: string, allocator := context.temp_allocator) matcher := new(FuzzyMatcher, allocator) matcher.pattern_count = min(len(pattern), max_pattern) - matcher.score_scale = matcher.pattern_count > 0 ? 1 / cast(f32)(perfect_bonus * matcher.pattern_count) : 0 - matcher.pattern = pattern[0:matcher.pattern_count] + matcher.score_scale = matcher.pattern_count > 0 ? 1 / cast(f32)(perfect_bonus * matcher.pattern_count) : 0 + matcher.pattern = pattern[0:matcher.pattern_count] matcher.lower_pattern = strings.to_lower(matcher.pattern, context.temp_allocator) score_info_miss: FuzzyScoreInfo score_info_miss.score = 0 - score_info_miss.prev = miss + score_info_miss.prev = miss matcher.scores[0][0][miss] = score_info_miss score_info_match: FuzzyScoreInfo score_info_match.score = awful_score - score_info_match.prev = match + score_info_match.prev = match matcher.scores[0][0][match] = score_info_match @@ -106,8 +106,8 @@ make_fuzzy_matcher :: proc(pattern: string, allocator := context.temp_allocator) for a := 0; a < 2; a += 1 { score_info: FuzzyScoreInfo - score_info.score = awful_score - score_info.prev = miss + score_info.score = awful_score + score_info.prev = miss matcher.scores[p][w][a] = score_info ref := matcher.pattern_role[:matcher.pattern_count] matcher.pattern_type_set = fuzzy_calculate_roles(matcher.pattern, &ref) @@ -125,7 +125,7 @@ fuzzy_to_acronym :: proc(word: string) -> (string, bool) { return "", false } - i := 1 + i := 1 last_char := word[0] strings.write_byte(&builder, last_char) @@ -151,7 +151,7 @@ fuzzy_to_acronym :: proc(word: string) -> (string, bool) { } //changed from bool to int because of a linux bug - 10.05.2021 fuzzy_match :: proc(matcher: ^FuzzyMatcher, word: string) -> (f32, int) { - + if !fuzzy_init(matcher, word) { return 0, 0 } @@ -168,8 +168,10 @@ fuzzy_match :: proc(matcher: ^FuzzyMatcher, word: string) -> (f32, int) { fuzzy_build_graph(matcher) - best := max(cast(int)matcher.scores[matcher.pattern_count][matcher.word_count][miss].score, - cast(int)matcher.scores[matcher.pattern_count][matcher.word_count][match].score) + best := max( + cast(int)matcher.scores[matcher.pattern_count][matcher.word_count][miss].score, + cast(int)matcher.scores[matcher.pattern_count][matcher.word_count][match].score, + ) if fuzzy_is_awful(best) { return 0.0, 0 @@ -228,7 +230,7 @@ fuzzy_packed_lookup :: proc(data: $A/[]$T, i: uint) -> T { } fuzzy_init :: proc(matcher: ^FuzzyMatcher, word: string) -> bool { - matcher.word = word + matcher.word = word matcher.word_count = min(max_word, len(matcher.word)) if matcher.pattern_count > matcher.word_count { @@ -261,11 +263,11 @@ fuzzy_init :: proc(matcher: ^FuzzyMatcher, word: string) -> bool { } fuzzy_skip_penalty :: proc(matcher: ^FuzzyMatcher, w: int) -> int { - if w == 0 { // Skipping the first character. + if w == 0 { // Skipping the first character. return 3 } - if matcher.word_role[w] == .Head { // Skipping a segment. + if matcher.word_role[w] == .Head { // Skipping a segment. return 1 } @@ -277,61 +279,63 @@ fuzzy_build_graph :: proc(matcher: ^FuzzyMatcher) { s: FuzzyScoreInfo - score := cast(int)matcher.scores[0][w][miss].score + score := cast(int)matcher.scores[0][w][miss].score penalty := fuzzy_skip_penalty(matcher, w) - sum := score - penalty + sum := score - penalty s.score = sum - s.prev = miss + s.prev = miss matcher.scores[0][w + 1][miss] = s s.score = awful_score - s.prev = miss + s.prev = miss matcher.scores[0][w + 1][match] = s } for p := 0; p < matcher.pattern_count; p += 1 { for w := p; w < matcher.word_count; w += 1 { - score := &matcher.scores[p + 1][w + 1] + score := &matcher.scores[p + 1][w + 1] pre_miss := &matcher.scores[p + 1][w] match_miss_score := pre_miss[match].score - miss_miss_score := pre_miss[miss].score + miss_miss_score := pre_miss[miss].score if p < matcher.pattern_count - 1 { match_miss_score -= fuzzy_skip_penalty(matcher, w) - miss_miss_score -= fuzzy_skip_penalty(matcher, w) + miss_miss_score -= fuzzy_skip_penalty(matcher, w) } if match_miss_score > miss_miss_score { s: FuzzyScoreInfo - s.score = match_miss_score - s.prev = match + s.score = match_miss_score + s.prev = match score[miss] = s } else { s: FuzzyScoreInfo - s.score = miss_miss_score - s.prev = miss + s.score = miss_miss_score + s.prev = miss score[miss] = s } pre_match := &matcher.scores[p][w] - match_match_score := fuzzy_allow_match(matcher, p, w, match) ? cast(int)pre_match[match].score + fuzzy_match_bonus(matcher, p, w, match) : awful_score + match_match_score := + fuzzy_allow_match(matcher, p, w, match) ? cast(int)pre_match[match].score + fuzzy_match_bonus(matcher, p, w, match) : awful_score - miss_match_score := fuzzy_allow_match(matcher, p, w, miss) ? cast(int)pre_match[miss].score + fuzzy_match_bonus(matcher, p, w, miss) : awful_score + miss_match_score := + fuzzy_allow_match(matcher, p, w, miss) ? cast(int)pre_match[miss].score + fuzzy_match_bonus(matcher, p, w, miss) : awful_score if match_match_score > miss_match_score { s: FuzzyScoreInfo - s.score = match_match_score - s.prev = match + s.score = match_match_score + s.prev = match score[match] = s } else { s: FuzzyScoreInfo - s.score = miss_match_score - s.prev = miss + s.score = miss_match_score + s.prev = miss score[match] = s } } @@ -350,8 +354,8 @@ fuzzy_match_bonus :: proc(matcher: ^FuzzyMatcher, p: int, w: int, last: int) -> // Single-case patterns lack segmentation signals and we assume any character // can be a head of a segment. if matcher.pattern[p] == matcher.word[w] || - (matcher.word_role[w] == FuzzyCharRole.Head && - (is_pattern_single_case || matcher.pattern_role[p] == FuzzyCharRole.Head)) { + (matcher.word_role[w] == FuzzyCharRole.Head && + (is_pattern_single_case || matcher.pattern_role[p] == FuzzyCharRole.Head)) { s += 1 //fmt.println("match 1"); } @@ -393,8 +397,9 @@ fuzzy_allow_match :: proc(matcher: ^FuzzyMatcher, p: int, w: int, last: int) -> if last == miss { - if matcher.word_role[w] == FuzzyCharRole.Tail && (matcher.word[w] == matcher.lower_word[w] || - 0 >= (cast(uint)matcher.word_type_set & 1 << cast(uint)FuzzyCharType.Lower)) { + if matcher.word_role[w] == FuzzyCharRole.Tail && + (matcher.word[w] == matcher.lower_word[w] || + 0 >= (cast(uint)matcher.word_type_set & 1 << cast(uint)FuzzyCharType.Lower)) { return false } } diff --git a/src/common/position.odin b/src/common/position.odin index 739f3aa8..fca82b03 100644 --- a/src/common/position.odin +++ b/src/common/position.odin @@ -1,10 +1,10 @@ package common -import "core:strings" -import "core:unicode/utf8" import "core:fmt" -import "core:odin/ast" import "core:log" +import "core:odin/ast" +import "core:strings" +import "core:unicode/utf8" /* This file handles the conversion between utf-16 and utf-8 offsets in the text document @@ -34,13 +34,7 @@ AbsoluteRange :: struct { AbsolutePosition :: int -get_absolute_position :: proc( - position: Position, - document_text: []u8, -) -> ( - AbsolutePosition, - bool, -) { +get_absolute_position :: proc(position: Position, document_text: []u8) -> (AbsolutePosition, bool) { absolute: AbsolutePosition if len(document_text) == 0 { @@ -52,31 +46,16 @@ get_absolute_position :: proc( index := 1 last := document_text[0] - if !get_index_at_line( - &index, - &line_count, - &last, - document_text, - position.line, - ) { + if !get_index_at_line(&index, &line_count, &last, document_text, position.line) { return absolute, false } - absolute = - index + - get_character_offset_u16_to_u8( - position.character, - document_text[index:], - ) + absolute = index + get_character_offset_u16_to_u8(position.character, document_text[index:]) return absolute, true } -get_relative_token_position :: proc( - offset: int, - document_text: []u8, - current_start: int, -) -> Position { +get_relative_token_position :: proc(offset: int, document_text: []u8, current_start: int) -> Position { start_index := current_start data := document_text[start_index:] @@ -111,9 +90,7 @@ get_relative_token_position :: proc( go_backwards_to_endline :: proc(offset: int, document_text: []u8) -> int { index := offset - for index > 0 && - document_text[index] != '\n' && - document_text[index] != '\r' { + for index > 0 && document_text[index] != '\n' && document_text[index] != '\r' { index -= 1 } @@ -141,32 +118,17 @@ get_token_range :: proc(node: ast.Node, document_text: string) -> Range { } range.start.line = node.pos.line - 1 - range.start.character = get_character_offset_u8_to_u16( - node.pos.column - 1, - transmute([]u8)document_text[offset:], - ) + range.start.character = get_character_offset_u8_to_u16(node.pos.column - 1, transmute([]u8)document_text[offset:]) - offset = go_backwards_to_endline( - end_offset - 1, - transmute([]u8)document_text, - ) + offset = go_backwards_to_endline(end_offset - 1, transmute([]u8)document_text) range.end.line = node.end.line - 1 - range.end.character = get_character_offset_u8_to_u16( - node.end.column - 1, - transmute([]u8)document_text[offset:], - ) + range.end.character = get_character_offset_u8_to_u16(node.end.column - 1, transmute([]u8)document_text[offset:]) return range } -get_absolute_range :: proc( - range: Range, - document_text: []u8, -) -> ( - AbsoluteRange, - bool, -) { +get_absolute_range :: proc(range: Range, document_text: []u8) -> (AbsoluteRange, bool) { absolute: AbsoluteRange if len(document_text) == 0 { @@ -179,22 +141,11 @@ get_absolute_range :: proc( index := 1 last := document_text[0] - if !get_index_at_line( - &index, - &line_count, - &last, - document_text, - range.start.line, - ) { + if !get_index_at_line(&index, &line_count, &last, document_text, range.start.line) { return absolute, false } - absolute.start = - index + - get_character_offset_u16_to_u8( - range.start.character, - document_text[index:], - ) + absolute.start = index + get_character_offset_u16_to_u8(range.start.character, document_text[index:]) //if the last line was indexed at zero we have to move it back to index 1. //This happens when line = 0 @@ -202,22 +153,11 @@ get_absolute_range :: proc( index = 1 } - if !get_index_at_line( - &index, - &line_count, - &last, - document_text, - range.end.line, - ) { + if !get_index_at_line(&index, &line_count, &last, document_text, range.end.line) { return absolute, false } - absolute.end = - index + - get_character_offset_u16_to_u8( - range.end.character, - document_text[index:], - ) + absolute.end = index + get_character_offset_u16_to_u8(range.end.character, document_text[index:]) return absolute, true } @@ -265,10 +205,7 @@ get_index_at_line :: proc( return false } -get_character_offset_u16_to_u8 :: proc( - character_offset: int, - document_text: []u8, -) -> int { +get_character_offset_u16_to_u8 :: proc(character_offset: int, document_text: []u8) -> int { utf8_idx := 0 utf16_idx := 0 @@ -291,10 +228,7 @@ get_character_offset_u16_to_u8 :: proc( return utf8_idx } -get_character_offset_u8_to_u16 :: proc( - character_offset: int, - document_text: []u8, -) -> int { +get_character_offset_u8_to_u16 :: proc(character_offset: int, document_text: []u8) -> int { utf8_idx := 0 utf16_idx := 0 diff --git a/src/common/util_linux.odin b/src/common/util_linux.odin index 4fa7d383..805d0c79 100644 --- a/src/common/util_linux.odin +++ b/src/common/util_linux.odin @@ -1 +1 @@ -package common +package common diff --git a/src/common/util_windows.odin b/src/common/util_windows.odin index 71fe3e2e..db280ad1 100644 --- a/src/common/util_windows.odin +++ b/src/common/util_windows.odin @@ -37,11 +37,7 @@ get_case_sensitive_path :: proc( if (file == win32.INVALID_HANDLE) { when !ODIN_TEST { - log.errorf( - "Failed on get_case_sensitive_path(%v) at %v", - path, - location, - ) + log.errorf("Failed on get_case_sensitive_path(%v) at %v", path, location) log_last_error() } return path @@ -49,12 +45,7 @@ get_case_sensitive_path :: proc( buffer := make([]u16, 512, context.temp_allocator) - ret := win32.GetFinalPathNameByHandleW( - file, - &buffer[0], - cast(u32)len(buffer), - 0, - ) + ret := win32.GetFinalPathNameByHandleW(file, &buffer[0], cast(u32)len(buffer), 0) res, _ := win32.utf16_to_utf8(buffer[4:], allocator) @@ -85,14 +76,7 @@ log_last_error :: proc() { } -run_executable :: proc( - command: string, - stdout: ^[]byte, -) -> ( - u32, - bool, - []byte, -) { +run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) { stdout_read: win32.HANDLE stdout_write: win32.HANDLE @@ -143,13 +127,7 @@ run_executable :: proc( success: win32.BOOL = true for success { - success = win32.ReadFile( - stdout_read, - &read_buffer[0], - len(read_buffer), - &read, - nil, - ) + success = win32.ReadFile(stdout_read, &read_buffer[0], len(read_buffer), &read, nil) if read > 0 && index + cast(int)read <= len(stdout) { mem.copy(&stdout[index], &read_buffer[0], cast(int)read) diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin index 74f5853c..2258466d 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -151,7 +151,7 @@ build_disabled_lines_info :: proc(p: ^Printer) { empty = empty, } - for line in disable_position.line..=comment.pos.line { + for line in disable_position.line ..= comment.pos.line { p.disabled_lines[line] = disabled_info } diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 869a4acf..c2971dfa 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -821,8 +821,16 @@ visit_attributes :: proc(p: ^Printer, attributes: ^[dynamic]^ast.Attribute, pos: //Ensure static is not forced newline, but until if the width is full if len(attributes) == 1 && len(attributes[0].elems) == 1 { - if ident, ok := attributes[0].elems[0].derived.(^ast.Ident); ok && (ident.name == "static" || ident.name == "require") { - document = cons(document, text("@"), text("("), visit_expr(p, attributes[0].elems[0]), text(")"), break_with_no_newline()) + if ident, ok := attributes[0].elems[0].derived.(^ast.Ident); + ok && (ident.name == "static" || ident.name == "require") { + document = cons( + document, + text("@"), + text("("), + visit_expr(p, attributes[0].elems[0]), + text(")"), + break_with_no_newline(), + ) set_source_position(p, pos) return document } diff --git a/src/server/when.odin b/src/server/when.odin new file mode 100644 index 00000000..f1407fee --- /dev/null +++ b/src/server/when.odin @@ -0,0 +1,7 @@ +package server + +import "core:odin/ast" + +resolve_when_stmt :: proc(ast_context: ^AstContext, when_stmt: ^ast.When_Stmt) -> bool { + return false +}