mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add Volatile type.
This commit is contained in:
@@ -968,3 +968,18 @@ fn void* __memcpy(void* dst, void* src, usz n) @weak @export("memcpy")
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
module std::core::mem::volatile { Type };
|
||||
|
||||
typedef Volatile @structlike = Type;
|
||||
|
||||
macro Type Volatile.get(&self)
|
||||
{
|
||||
return @volatile_load(*(Type*)self);
|
||||
}
|
||||
|
||||
macro Type Volatile.set(&self, Type val)
|
||||
{
|
||||
return @volatile_store(*(Type*)self, val);
|
||||
}
|
||||
@@ -85,6 +85,7 @@
|
||||
- Add `ConditionVariable.wait_until` and `ConditionVariable.wait_for`
|
||||
- Added readline_to_stream that takes a stream.
|
||||
- Added `Ref` and `RefCounted` experimental functionality.
|
||||
- Add `Volatile` generic type.
|
||||
|
||||
## 0.7.3 Change list
|
||||
|
||||
|
||||
24
test/test_suite/stdlib/volatile.c3t
Normal file
24
test/test_suite/stdlib/volatile.c3t
Normal file
@@ -0,0 +1,24 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
import std;
|
||||
fn void main()
|
||||
{
|
||||
Volatile{int} y;
|
||||
y.set(20);
|
||||
y.get();
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define void @test.main() #0 {
|
||||
entry:
|
||||
%y = alloca i32, align 4
|
||||
store i32 0, ptr %y, align 4
|
||||
%neq = icmp ne ptr %y, null
|
||||
call void @llvm.assume(i1 %neq)
|
||||
store volatile i32 20, ptr %y, align 4
|
||||
%neq1 = icmp ne ptr %y, null
|
||||
call void @llvm.assume(i1 %neq1)
|
||||
%0 = load volatile i32, ptr %y, align 4
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user