This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathbuiltin.v
169 lines (149 loc) · 3.69 KB
/
builtin.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
module analyzer
import os
const numeric_types = ['u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'int', 'i64', 'f32', 'f64']
const numeric_types_with_any_type = ['u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'int', 'i64', 'f32',
'f64', 'int_literal', 'float_literal']
pub fn setup_builtin(mut store Store, builtin_path string) {
mut importer := Importer{
context: store.default_context()
}
mut builtin_import, builtin_idx, _ := store.add_import('',
resolved: true
module_name: 'builtin'
path: builtin_path
)
store.register_auto_import(builtin_import, '')
register_builtin_symbols(mut store, builtin_import)
importer.import_modules(mut store.imports[importer.context.file_dir], [
builtin_idx,
])
register_none(mut store, builtin_import)
}
fn register_none(mut ss Store, builtin_import &Import) {
registered_none_sym := ss.symbols[builtin_import.path].get('None__') or { return }
mut none_sym := Symbol{
name: 'none'
kind: .typedef
access: .public
parent_sym: &Symbol{
name: '&' + registered_none_sym.name
is_top_level: true
file_path: registered_none_sym.file_path
parent_sym: registered_none_sym
kind: .ref
file_version: 0
}
is_top_level: true
file_path: registered_none_sym.file_path
file_version: 0
}
ss.register_symbol(mut none_sym) or { eprintln('none registration is skipped. Reason: $err') }
}
fn register_builtin_symbols(mut ss Store, builtin_import &Import) {
builtin_path := builtin_import.path
placeholder_file_path := os.join_path(builtin_path, 'placeholder.vv')
// defer {
// unsafe { placeholder_file_path.free() }
// }
builtin_types := [
'voidptr',
'byteptr',
'charptr',
'i8',
'i16',
'int',
'i64',
'byte',
'u8',
'u16',
'u32',
'u64',
'f32',
'f64',
'char',
'bool',
'string',
'rune',
'array',
'map',
'chan',
'size_t',
'float_literal',
'int_literal',
'thread',
'IError',
]
should_be_placeholders := ['IError', 'string', 'array', 'map']
for type_name in builtin_types {
mut builtin_sym := Symbol{
name: type_name
kind: .placeholder
access: .public
is_top_level: true
file_path: placeholder_file_path
file_version: if type_name in should_be_placeholders { -1 } else { 0 }
}
ss.register_symbol(mut builtin_sym) or {
eprintln('$type_name registration is skipped. Reason: $err')
continue
}
}
for type_name in builtin_types {
mut returned_sym := ss.symbols[builtin_path].get(type_name) or { continue }
if type_name == 'string' {
// register []string
mut array_sym := Symbol{
name: '[]' + type_name
kind: .array_
access: .public
is_top_level: true
children_syms: [returned_sym]
file_path: os.join_path(builtin_path, 'array.vv')
file_version: 0
}
ss.register_symbol(mut array_sym) or {
eprintln('$array_sym.name registration is skipped. Reason: $err')
continue
}
}
if returned_sym.name !in should_be_placeholders {
returned_sym.kind = .typedef
}
match returned_sym.name {
'array' {
ss.base_symbol_locations << BaseSymbolLocation{
module_name: ''
symbol_name: returned_sym.name
for_kind: .array_
}
ss.base_symbol_locations << BaseSymbolLocation{
module_name: ''
symbol_name: returned_sym.name
for_kind: .variadic
}
}
'map' {
ss.base_symbol_locations << BaseSymbolLocation{
module_name: ''
symbol_name: returned_sym.name
for_kind: .map_
}
}
'chan' {
ss.base_symbol_locations << BaseSymbolLocation{
module_name: ''
symbol_name: returned_sym.name
for_kind: .chan_
}
}
'IError' {
ss.base_symbol_locations << BaseSymbolLocation{
module_name: ''
symbol_name: returned_sym.name
for_kind: .optional
}
}
else {}
}
}
}