diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-03-04 19:22:33 +0100 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-03-04 19:22:33 +0100 |
| commit | 2d9f5709d74992e0cd485099a5a8cdf12178e80d (patch) | |
| tree | aebd707471ee0d6a62334bfd69f5681299f692cb | |
| parent | 75ab88b2c81c164b851c4e064f4da1c11b2a5679 (diff) | |
Add support for builtin symbols.
| -rw-r--r-- | builtin/builtin.odin | 75 | ||||
| -rw-r--r-- | src/analysis/analysis.odin | 3 | ||||
| -rw-r--r-- | src/common/ast.odin | 10 | ||||
| -rw-r--r-- | src/index/build.odin | 1 | ||||
| -rw-r--r-- | src/index/collector.odin | 6 | ||||
| -rw-r--r-- | src/index/memory_index.odin | 3 | ||||
| -rw-r--r-- | src/server/completion.odin | 1 |
7 files changed, 80 insertions, 19 deletions
diff --git a/builtin/builtin.odin b/builtin/builtin.odin index 009a7eb..b1cabed 100644 --- a/builtin/builtin.odin +++ b/builtin/builtin.odin @@ -1,17 +1,17 @@ package ols_builtin // Procedures -len :: proc(array: Array_Type) -> int --- -cap :: proc(array: Array_Type) -> int --- +@builtin len :: proc(array: Array_Type) -> int --- +@builtin cap :: proc(array: Array_Type) -> int --- size_of :: proc($T: typeid) -> int --- -align_of :: proc($T: typeid) -> int --- -offset_of :: proc($T: typeid) -> uintptr --- -type_of :: proc(x: expr) -> type --- -type_info_of :: proc($T: typeid) -> ^runtime.Type_Info --- -typeid_of :: proc($T: typeid) -> typeid --- +@builtin align_of :: proc($T: typeid) -> int --- +@builtin offset_of :: proc($T: typeid) -> uintptr --- +@builtin type_of :: proc(x: expr) -> type --- +@builtin type_info_of :: proc($T: typeid) -> ^runtime.Type_Info --- +@builtin typeid_of :: proc($T: typeid) -> typeid --- -swizzle :: proc(x: [N]T, indices: ..int) -> [len(indices)]T --- +@builtin swizzle :: proc(x: [N]T, indices: ..int) -> [len(indices)]T --- complex :: proc(real, imag: Float) -> Complex_Type --- quaternion :: proc(real, imag, jmag, kmag: Float) -> Quaternion_Type --- @@ -21,7 +21,58 @@ jmag :: proc(value: Quaternion) -> Float --- kmag :: proc(value: Quaternion) -> Float --- conj :: proc(value: Complex_Or_Quaternion) -> Complex_Or_Quaternion --- -min :: proc(values: ..T) -> T --- -max :: proc(values: ..T) -> T --- -abs :: proc(value: T) -> T --- -clamp :: proc(value, minimum, maximum: T) -> T ---
\ No newline at end of file +@builtin min :: proc(values: ..T) -> T --- +@builtin max :: proc(values: ..T) -> T --- +@builtin abs :: proc(value: T) -> T --- +@builtin clamp :: proc(value, minimum, maximum: T) -> T --- + +/* + This is interally from the compiler +*/ + +Odin_OS_Type :: enum int { + Unknown, + Windows, + Darwin, + Linux, + Essence, + FreeBSD, + WASI, + JS, + Freestanding, +} + +@builtin +ODIN_OS: Odin_OS_Type + +Odin_Arch_Type :: enum int { + Unknown, + amd64, + i386, + arm64, + wasm32, + wasm64, +} + +@builtin +ODIN_ARCH: Odin_Arch_Type + +Odin_Build_Mode_Type :: enum int { + Executable, + Dynamic, + Object, + Assembly, + LLVM_IR, +} + +@builtin +ODIN_BUILD_MODE: Odin_Build_Mode_Type + +Odin_Endian_Type :: enum int { + Unknown, + Little, + Big, +} + +@builtin +ODIN_ENDIAN: Odin_Endian_Type
\ No newline at end of file diff --git a/src/analysis/analysis.odin b/src/analysis/analysis.odin index 400bde6..b7be73c 100644 --- a/src/analysis/analysis.odin +++ b/src/analysis/analysis.odin @@ -1346,6 +1346,9 @@ resolve_type_identifier :: proc(ast_context: ^AstContext, node: ast.Ident) -> (i //If we are resolving a symbol that is in the document package, then we'll check the builtin packages. if ast_context.current_package == ast_context.document_package { + if symbol, ok := index.lookup(node.name, "$builtin"); ok { + return resolve_symbol_return(ast_context, symbol) + } for built in index.indexer.builtin_packages { if symbol, ok := index.lookup(node.name, built); ok { return resolve_symbol_return(ast_context, symbol) diff --git a/src/common/ast.odin b/src/common/ast.odin index 669b44a..7a32cde 100644 --- a/src/common/ast.odin +++ b/src/common/ast.odin @@ -73,9 +73,9 @@ GlobalExpr :: struct { deprecated: bool, file_private: bool, package_private: bool, + builtin: bool, } - unwrap_pointer :: proc(expr: ^ast.Expr) -> (ast.Ident, bool) { expr := expr for expr != nil { @@ -99,10 +99,10 @@ unwrap_pointer :: proc(expr: ^ast.Expr) -> (ast.Ident, bool) { collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^ast.Node, skip_private: bool) { if value_decl, ok := stmt.derived.(^ast.Value_Decl); ok { - is_deprecated := false is_private_file := false is_package_file := false + is_builtin := false for attribute in value_decl.attributes { for elem in attribute.elems { @@ -118,14 +118,14 @@ collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^a is_package_file = true } } - case "deprecated": - is_deprecated = true } } } else if ident, ok := elem.derived.(^ast.Ident); ok { switch ident.name { case "deprecated": is_deprecated = true + case "builtin": + is_builtin = true } } } @@ -146,6 +146,7 @@ collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^a docs = value_decl.docs, attributes = value_decl.attributes[:], deprecated = is_deprecated, + builtin = is_builtin, }) } else { if len(value_decl.values) > i { @@ -156,6 +157,7 @@ collect_value_decl :: proc(exprs: ^[dynamic]GlobalExpr, file: ast.File, stmt: ^a docs = value_decl.docs, attributes = value_decl.attributes[:], deprecated = is_deprecated, + builtin = is_builtin, }) } } diff --git a/src/index/build.odin b/src/index/build.odin index a7944f0..8acb052 100644 --- a/src/index/build.odin +++ b/src/index/build.odin @@ -113,6 +113,7 @@ build_static_index :: proc(allocator := context.allocator, config: ^common.Confi p := parser.Parser { err = log_error_handler, warn = log_warning_handler, + flags = {.Optional_Semicolons}, } //have to cheat the parser since it really wants to parse an entire package with the new changes... diff --git a/src/index/collector.odin b/src/index/collector.odin index 495e2a3..c527873 100644 --- a/src/index/collector.odin +++ b/src/index/collector.odin @@ -359,6 +359,12 @@ collect_symbols :: proc(collection: ^SymbolCollection, file: ast.File, uri: stri symbol.type = token_type symbol.doc = common.get_doc(expr.docs, collection.allocator) + if expr.builtin { + symbol.pkg = "$builtin" + } else { + symbol.pkg = get_index_unique_string(collection, directory) + } + if expr.deprecated { symbol.flags |= {.Deprecated} } diff --git a/src/index/memory_index.odin b/src/index/memory_index.odin index d4e7e6e..5146bf8 100644 --- a/src/index/memory_index.odin +++ b/src/index/memory_index.odin @@ -19,7 +19,6 @@ MemoryIndex :: struct { } make_memory_index :: proc(collection: SymbolCollection) -> MemoryIndex { - return MemoryIndex { collection = collection, } @@ -31,7 +30,6 @@ memory_index_lookup :: proc(index: ^MemoryIndex, name: string, pkg: string) -> ( } memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, pkgs: []string) -> ([]FuzzyResult, bool) { - symbols := make([dynamic]FuzzyResult, 0, context.temp_allocator) fuzzy_matcher := common.make_fuzzy_matcher(name) @@ -64,7 +62,6 @@ memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, pkgs: []str } exists_in_scope :: proc(symbol_scope: string, scope: []string) -> bool { - for s in scope { if strings.compare(symbol_scope, s) == 0 { return true diff --git a/src/server/completion.odin b/src/server/completion.odin index 78697ac..ca731c6 100644 --- a/src/server/completion.odin +++ b/src/server/completion.odin @@ -834,6 +834,7 @@ get_identifier_completion :: proc(ast_context: ^analysis.AstContext, position_co } append(&pkgs, ast_context.document_package) + append(&pkgs, "$builtin") if results, ok := index.fuzzy_search(lookup, pkgs[:]); ok { for r in results { |