Skip to content

Commit 64d96ad

Browse files
authored
Merge pull request #873 from zig-lang/self-hosted-parser
Self hosted parser completion
2 parents ee3e279 + 405a239 commit 64d96ad

File tree

4 files changed

+5291
-644
lines changed

4 files changed

+5291
-644
lines changed

std/special/builtin.zig

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,43 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn
1414
}
1515
}
1616

17-
// Note that memset does not return `dest`, like the libc API.
18-
// The semantics of memset is dictated by the corresponding
19-
// LLVM intrinsics, not by the libc API.
20-
export fn memset(dest: ?&u8, c: u8, n: usize) void {
17+
export fn memset(dest: ?&u8, c: u8, n: usize) ?&u8 {
2118
@setRuntimeSafety(false);
2219

2320
var index: usize = 0;
2421
while (index != n) : (index += 1)
2522
(??dest)[index] = c;
23+
24+
return dest;
2625
}
2726

28-
// Note that memcpy does not return `dest`, like the libc API.
29-
// The semantics of memcpy is dictated by the corresponding
30-
// LLVM intrinsics, not by the libc API.
31-
export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) void {
27+
export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) ?&u8 {
3228
@setRuntimeSafety(false);
3329

3430
var index: usize = 0;
3531
while (index != n) : (index += 1)
3632
(??dest)[index] = (??src)[index];
33+
34+
return dest;
35+
}
36+
37+
export fn memmove(dest: ?&u8, src: ?&const u8, n: usize) ?&u8 {
38+
@setRuntimeSafety(false);
39+
40+
if (@ptrToInt(dest) < @ptrToInt(src)) {
41+
var index: usize = 0;
42+
while (index != n) : (index += 1) {
43+
(??dest)[index] = (??src)[index];
44+
}
45+
} else {
46+
var index = n;
47+
while (index != 0) {
48+
index -= 1;
49+
(??dest)[index] = (??src)[index];
50+
}
51+
}
52+
53+
return dest;
3754
}
3855

3956
comptime {

0 commit comments

Comments
 (0)