Skip to content

Commit c4a42aa

Browse files
committed
v2: lots of cleanc fixes; v self works now!
1 parent edbec73 commit c4a42aa

15 files changed

Lines changed: 3500 additions & 353 deletions

File tree

‎vlib/v2/ast/ast.v‎

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,54 @@ pub fn (expr Expr) name() string {
187187

188188
pub fn (expr Expr) pos() token.Pos {
189189
return match expr {
190+
AsCastExpr {
191+
expr.pos
192+
}
193+
ArrayInitExpr {
194+
expr.pos
195+
}
196+
CallExpr {
197+
expr.pos
198+
}
199+
CallOrCastExpr {
200+
expr.pos
201+
}
202+
CastExpr {
203+
expr.pos
204+
}
205+
ComptimeExpr {
206+
expr.pos
207+
}
190208
Ident {
191209
expr.pos
192210
}
211+
InfixExpr {
212+
expr.pos
213+
}
214+
MapInitExpr {
215+
expr.pos
216+
}
217+
MatchExpr {
218+
expr.pos
219+
}
220+
OrExpr {
221+
expr.pos
222+
}
223+
PrefixExpr {
224+
expr.pos
225+
}
226+
SelectExpr {
227+
expr.pos
228+
}
193229
SelectorExpr {
194230
expr.pos
195231
// NOTE: should we remove `pos` from `SelectorExpr` and use `expr.lhs.pos()` instead?
196232
// which would always get the position of the left most part of the `SelectorExpr`
197233
// expr.lhs.pos()
198234
}
199235
else {
200-
panic('Expr.pos(): TODO: add ${expr.type_name()}')
236+
// Default for expressions without pos field
237+
0
201238
}
202239
}
203240
}
@@ -853,9 +890,9 @@ pub:
853890
pub fn (ft &FnType) str() string {
854891
mut s := 'fn('
855892
for param in ft.params {
856-
s += param.name + param.typ.str()
893+
s += param.name + param.typ.name()
857894
}
858-
s += ') ' + ft.return_type.str()
895+
s += ') ' + ft.return_type.name()
859896
return s
860897
}
861898

‎vlib/v2/builder/builder.v‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,30 @@ pub fn new_builder(prefs &pref.Preferences) &Builder {
3737
pub fn (mut b Builder) build(files []string) {
3838
b.user_files = files
3939
mut sw := time.new_stopwatch()
40-
b.files = if b.pref.no_parallel {
41-
b.parse_files(files)
42-
} else {
43-
b.parse_files_parallel(files)
40+
$if parallel ? {
41+
b.files = if b.pref.no_parallel {
42+
b.parse_files(files)
43+
} else {
44+
b.parse_files_parallel(files)
45+
}
46+
} $else {
47+
b.files = b.parse_files(files)
4448
}
4549
parse_time := sw.elapsed()
4650
print_time('Scan & Parse', parse_time)
4751

48-
b.env = if b.pref.skip_type_check {
49-
types.Environment.new()
50-
} else if b.pref.no_parallel {
51-
b.type_check_files()
52+
if b.pref.skip_type_check {
53+
b.env = types.Environment.new()
5254
} else {
53-
b.type_check_files_parallel()
55+
$if parallel ? {
56+
b.env = if b.pref.no_parallel {
57+
b.type_check_files()
58+
} else {
59+
b.type_check_files_parallel()
60+
}
61+
} $else {
62+
b.env = b.type_check_files()
63+
}
5464
}
5565
type_check_time := time.Duration(sw.elapsed() - parse_time)
5666
print_time('Type Check', type_check_time)

‎vlib/v2/builder/util.v‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ pub fn get_v_files_from_dir(dir string) []string {
2020
// skip OS-specific files for other platforms
2121
// Note: _nix files are for Unix-like systems including macOS and Linux
2222
$if macos {
23-
if file.contains('_windows.') || file.contains('_linux.') {
23+
if file.contains('_windows.') || file.contains('_linux.') || file.contains('_android') {
2424
continue
2525
}
2626
} $else $if linux {
27-
if file.contains('_windows.') || file.contains('_macos.') {
27+
if file.contains('_windows.') || file.contains('_macos.') || file.contains('_android') {
2828
continue
2929
}
3030
} $else $if windows {
31-
if file.contains('_linux.') || file.contains('_macos.') || file.contains('_nix.') {
31+
if file.contains('_linux.') || file.contains('_macos.') || file.contains('_nix.')
32+
|| file.contains('_android') {
3233
continue
3334
}
3435
}

‎vlib/v2/gen/cleanc/cleanc.v‎

Lines changed: 3319 additions & 278 deletions
Large diffs are not rendered by default.

‎vlib/v2/parser/parser.v‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,41 @@ fn (mut p Parser) expr(min_bp token.BindingPower) ast.Expr {
769769
}
770770
}
771771
}
772+
// (`[n]type{}` | `[n]type`) - single-dimensional fixed array with one size expr
773+
else if exprs.len == 1 && p.tok in [.amp, .name] {
774+
lhs = ast.Type(ast.ArrayFixedType{
775+
elem_type: p.expect_type()
776+
len: exprs[0]
777+
})
778+
// `[n]type{}`
779+
if p.tok == .lcbr && !p.exp_lcbr {
780+
p.next()
781+
mut init := ast.empty_expr
782+
if p.tok != .rcbr {
783+
key := p.expect_name()
784+
p.expect(.colon)
785+
match key {
786+
'init' { init = p.expr(.lowest) }
787+
else { p.error('expecting `init`, got `${key}`') }
788+
}
789+
}
790+
p.next()
791+
lhs = ast.ArrayInitExpr{
792+
typ: lhs
793+
init: init
794+
pos: pos
795+
}
796+
}
797+
// `[n]type`
798+
// casts are completed in expr loop
799+
else if p.tok != .lpar {
800+
if !p.exp_pt {
801+
p.error('unexpected type')
802+
}
803+
// no need to chain here
804+
return lhs
805+
}
806+
}
772807
// (`[]type{}` | `[][]type{}` | `[]&type{len: 2}`) | `[]type`
773808
else if p.tok in [.amp, .lsbr, .name] {
774809
lhs = ast.Type(ast.ArrayType{

‎vlib/v2/pref/pref.v‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ pub fn new_preferences_from_args(args []string) Preferences {
8484
backend: backend
8585
arch: arch
8686
output_file: output_file
87+
// Explicitly set defaults since cleanc doesn't handle struct default values
88+
vroot: os.dir(@VEXE)
89+
vmodules_path: os.vmodules_dir()
8790
}
8891
}
8992

‎vlib/v2/ssa/builder.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3308,7 +3308,7 @@ fn (mut b Builder) expr_call_or_cast(node ast.CallOrCastExpr) ValueID {
33083308
])
33093309

33103310
// Get field index - look up the struct type by name
3311-
struct_typ_id := b.struct_types[struct_type_name] or { 0 }
3311+
struct_typ_id := b.struct_types[struct_type_name] or { TypeID(0) }
33123312
struct_type := b.mod.type_store.types[struct_typ_id]
33133313
mut field_idx := -1
33143314
for i, fname in struct_type.field_names {

‎vlib/v2/token/position.v‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// that can be found in the LICENSE file.
44
module token
55

6-
import sync
7-
86
// TODO: finish fileset / file / base pos etc
97

108
// compact encoding of a source position within a file set
@@ -36,7 +34,6 @@ mut:
3634
base int = 1 // reserve 0 for no position
3735
// files shared []&File
3836
files []&File
39-
mu &sync.Mutex = sync.new_mutex()
4037
}
4138

4239
pub fn FileSet.new() &FileSet {
@@ -46,10 +43,6 @@ pub fn FileSet.new() &FileSet {
4643
// TODO:
4744
pub fn (mut fs FileSet) add_file(filename string, base_ int, size int) &File {
4845
// eprintln('>>> add_file fs: ${voidptr(fs)} | filename: $filename | base_: $base_ | size: $size')
49-
fs.mu.lock()
50-
defer {
51-
fs.mu.unlock()
52-
}
5346
mut base := if base_ < 0 { fs.base } else { base_ }
5447

5548
// eprintln('>>> add_file fs: ${voidptr(fs)} | base: ${base:10} | fs.base: $fs.base | base_: ${base_:10} | size: ${size:10} | filename: $filename')
@@ -109,10 +102,6 @@ fn search_files(files []&File, x int) int {
109102

110103
pub fn (mut fs FileSet) file(pos Pos) &File {
111104
// eprintln('>>>>>>>>> file fs: ${voidptr(fs)} | pos: $pos')
112-
fs.mu.lock()
113-
defer {
114-
fs.mu.unlock()
115-
}
116105

117106
// lock fs.files
118107
// last file

0 commit comments

Comments
 (0)