all: atomic int fixes
							parent
							
								
									82ac39eca6
								
							
						
					
					
						commit
						7dbfa86f25
					
				|  | @ -578,3 +578,8 @@ pub fn (b u8) repeat(count int) string { | |||
| 	} | ||||
| 	return unsafe { ret.vstring_with_len(new_len) } | ||||
| } | ||||
| 
 | ||||
| // for atomic ints, internal
 | ||||
| fn _Atomic__int_str(x int) string { | ||||
| 	return x.str() | ||||
| } | ||||
|  |  | |||
|  | @ -127,7 +127,7 @@ pub fn (t Type) atomic_typename() string { | |||
| 	idx := t.idx() | ||||
| 	match idx { | ||||
| 		ast.u32_type_idx { return 'atomic_uint' } | ||||
| 		ast.int_type_idx { return 'atomic_int' } | ||||
| 		ast.int_type_idx { return '_Atomic int' } | ||||
| 		ast.u64_type_idx { return 'atomic_ullong' } | ||||
| 		ast.i64_type_idx { return 'atomic_llong' } | ||||
| 		else { return 'unknown_atomic' } | ||||
|  | @ -1161,6 +1161,10 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string] | |||
| 		nr_muls-- | ||||
| 		res = 'shared ' + res | ||||
| 	} | ||||
| 	if typ.has_flag(.atomic_f) { | ||||
| 		nr_muls-- | ||||
| 		res = 'atomic ' + res | ||||
| 	} | ||||
| 	if nr_muls > 0 && !typ.has_flag(.variadic) { | ||||
| 		res = strings.repeat(`&`, nr_muls) + res | ||||
| 	} | ||||
|  |  | |||
|  | @ -35,7 +35,8 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) { | |||
| 	if node.is_range { | ||||
| 		high_type := c.expr(node.high) | ||||
| 		high_type_idx := high_type.idx() | ||||
| 		if typ_idx in ast.integer_type_idxs && high_type_idx !in ast.integer_type_idxs { | ||||
| 		if typ_idx in ast.integer_type_idxs && high_type_idx !in ast.integer_type_idxs | ||||
| 			&& high_type_idx != ast.void_type_idx { | ||||
| 			c.error('range types do not match', node.cond.pos()) | ||||
| 		} else if typ_idx in ast.float_type_idxs || high_type_idx in ast.float_type_idxs { | ||||
| 			c.error('range type can not be float', node.cond.pos()) | ||||
|  |  | |||
|  | @ -401,10 +401,13 @@ pub fn (mut p Parser) parse_type() ast.Type { | |||
| 			p.error_with_pos('cannot use `mut` on struct field type', p.tok.pos()) | ||||
| 		} | ||||
| 	} | ||||
| 	if p.tok.kind == .key_mut || is_shared || is_atomic { | ||||
| 	if p.tok.kind == .key_mut || is_shared { // || is_atomic {
 | ||||
| 		nr_muls++ | ||||
| 		p.next() | ||||
| 	} | ||||
| 	if is_atomic { | ||||
| 		p.next() | ||||
| 	} | ||||
| 	if p.tok.kind == .mul { | ||||
| 		p.error('use `&Type` instead of `*Type` when declaring references') | ||||
| 		return 0 | ||||
|  |  | |||
|  | @ -0,0 +1,23 @@ | |||
| import term | ||||
| import os | ||||
| import runtime | ||||
| import time | ||||
| 
 | ||||
| struct App { | ||||
| mut: | ||||
| 	idx atomic int | ||||
| } | ||||
| 
 | ||||
| fn test_atomic() { | ||||
| 	mut app := &App{} | ||||
| 	for i in 0 .. 10 { | ||||
| 		go app.run() | ||||
| 	} | ||||
| 	time.sleep(2 * time.second) | ||||
| 	println('idx=$app.idx') | ||||
| 	assert app.idx == 10 | ||||
| } | ||||
| 
 | ||||
| fn (mut app App) run() { | ||||
| 	app.idx++ | ||||
| } | ||||
		Loading…
	
		Reference in New Issue