Add Volatile type.

This commit is contained in:
Christoffer Lerno
2025-07-22 14:13:48 +02:00
parent 53051e04a3
commit 428165590e
3 changed files with 40 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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

View 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
}