9942 commits 0 issues 0 pull requests 439 contributors 0 branches 0 releases
Additions: 73 Deletions: 28
vlib/v/ast/ast.v
1 pub struct AsmIO {
2 pub:
3 alias string // [alias_a]
4- constraint string // '=r'
5+ constraint string // '=r' TODO: allow all backends to easily use this with a struct
6 expr Expr // (a)
7 comments []Comment // // this is a comment
8 typ Type
9
vlib/v/fmt/fmt.v
1 }
2 f.indent--
3 f.writeln('}')
4+ if stmt.is_top_level {
5+ f.writeln('')
6+ }
7 }
8
9 fn (mut f Fmt) asm_arg(arg ast.AsmArg) {
10
vlib/v/parser/parser.v
1 if constraint != '' {
2 p.next()
3 }
4- if p.tok.kind == .assign {
5- constraint += '='
6- p.next()
7- } else if p.tok.kind == .plus {
8- constraint += '+'
9+ constraint += p.tok.lit
10+ if p.tok.kind == .at {
11 p.next()
12+ } else {
13+ p.check(.name)
14 }
15- constraint += p.tok.lit
16- p.check(.name)
17 }
18 mut expr := p.expr(0)
19 if mut expr is ast.ParExpr {
20
vlib/v/scanner/scanner.v
1 return s.new_token(.name, '@' + name, name.len + 1)
2 }
3 // @FN, @STRUCT, @MOD etc. See full list in token.valid_at_tokens
4- if '@' + name in token.valid_at_tokens {
5+ if '@' + name in token.valid_at_tokens || name.starts_with('cc') { // `[email protected]` in inline assembly
6 return s.new_token(.at, '@' + name, name.len + 1)
7 }
8 if !token.is_key(name) {
9
vlib/v/tests/assembly/asm_test.amd64.v
1 ; =r (a)
2 }
3 assert a == 48321074923
4-
5- mut b := i64(4)
6- asm amd64 {
7- mov b, one_two_three // see below
8- ; =r (b)
9- }
10- assert b == 48321074923
11 }
12
13 asm amd64 {
14 one_two_three:
15 .quad 48321074923
16 }
17+
18+fn test_flag_output() {
19+ a, b := 4, 9
20+ mut out := false
21+ asm amd64 {
22+ cmp a, b
23+ ; [email protected] (out)
24+ ; r (a)
25+ r (b)
26+ }
27+ assert out
28+ asm amd64 {
29+ cmp b, a
30+ ; [email protected] (out)
31+ ; r (a)
32+ r (b)
33+ }
34+ assert !out
35+
36+ zero := 0
37+ asm amd64 {
38+ cmp zero, zero
39+ ; [email protected] (out)
40+ ; r (zero)
41+ }
42+ assert out
43+}
44
vlib/v/tests/assembly/asm_test.i386.v
1 }
2 }
3 }
4+
5+fn test_flag_output() {
6+ a, b := 4, 9
7+ mut out := false
8+ asm amd64 {
9+ cmp a, b
10+ ; [email protected] (out)
11+ ; r (a)
12+ r (b)
13+ }
14+ assert out
15+ asm amd64 {
16+ cmp b, a
17+ ; [email protected] (out)
18+ ; r (a)
19+ r (b)
20+ }
21+ assert !out
22+
23+ zero := 0
24+ asm amd64 {
25+ cmp zero, zero
26+ ; [email protected] (out)
27+ ; r (zero)
28+ }
29+ assert out
30+}
31
vlib/v/tests/break_in_lock_test.v
1 )
2
3 fn test_return_lock() {
4+ start := time.now()
5 shared s := AA{'3'}
6- go printer(shared s)
7- go fn (shared s AA) {
8- start := time.now()
9+ go printer(shared s, start)
10+ go fn (shared s AA, start time.Time) {
11 for {
12 reader(shared s)
13 if time.now() - start > sleep_time {
14 exit(0)
15 }
16 }
17- }(shared s)
18+ }(shared s, start)
19 time.sleep(sleep_time * 2)
20 assert false
21 }
22
23-fn printer(shared s AA) {
24- start := time.now()
25+fn printer(shared s AA, start time.Time) {
26 for {
27 lock s {
28 assert s.b in ['0', '1', '2', '3', '4', '5']
29
vlib/v/tests/return_in_lock_test.v
1 )
2
3 fn test_return_lock() {
4+ start := time.now()
5 shared s := AA{'3'}
6- go printer(shared s)
7- go fn (shared s AA) {
8- start := time.now()
9+ go printer(shared s, start)
10+ go fn (shared s AA, start time.Time) {
11 for {
12 reader(shared s)
13 if time.now() - start > sleep_time {
14 exit(0)
15 }
16 }
17- }(shared s)
18+ }(shared s, start)
19 time.sleep(sleep_time * 2)
20 assert false
21 }
22
23-fn printer(shared s AA) {
24- start := time.now()
25+fn printer(shared s AA, start time.Time) {
26 for {
27 lock s {
28 assert s.b in ['0', '1', '2', '3', '4', '5']
29