P5.6 prereq: port bitwise/shift ops into the comptime VM
`comptime_vm` exec now handles `bit_and`/`bit_or`/`bit_xor`/`bit_not`/`shl`/`shr` (a new `bitwise` helper next to `arith`), mirroring the legacy interp's i64 model exactly: the shift amount clamps to `@min(rhs, 63)` and `shr` is an arithmetic right shift (sign-extending). These were unported and bailed; the `shr` gap surfaced via the iOS-device bundler once P5.5 let it run further (1616). With the port, 1616's strict VM run reaches the real bundler logic and stops only at the genuinely-unavailable iOS runtime on macOS (`_UIApplicationMain` / no linked binary under `sx run`), as expected. New corpus test `examples/0639-comptime-bitwise-shift.sx` folds AND/OR/XOR/NOT/ shl/shr/arith-shr as `::` consts — identical on both evaluators. 704/0 both gates.
This commit is contained in:
20
examples/0639-comptime-bitwise-shift.sx
Normal file
20
examples/0639-comptime-bitwise-shift.sx
Normal file
@@ -0,0 +1,20 @@
|
||||
// Comptime bitwise + shift ops on the VM: AND/OR/XOR/NOT and shl/shr all fold
|
||||
// at compile time. Regression for the VM op port (P5.6) — these were unported in
|
||||
// `comptime_vm` and bailed (`shr` surfaced via the iOS-device bundler). `shr` is
|
||||
// an arithmetic right shift (sign-extending), mirroring the legacy interp's i64
|
||||
// model; the shift amount clamps to 63.
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
AND :: 0b1100 & 0b1010; // 0b1000 = 8
|
||||
OR :: 0b1100 | 0b1010; // 0b1110 = 14
|
||||
XOR :: 0b1100 ^ 0b1010; // 0b0110 = 6
|
||||
NOT :: ~0; // -1
|
||||
SHL :: 1 << 10; // 1024
|
||||
SHR :: 1024 >> 3; // 128
|
||||
ASHR :: (-8) >> 1; // -4 (arithmetic, sign-extending)
|
||||
|
||||
main :: () {
|
||||
print("and={} or={} xor={} not={}\n", AND, OR, XOR, NOT);
|
||||
print("shl={} shr={} ashr={}\n", SHL, SHR, ASHR);
|
||||
}
|
||||
1
examples/expected/0639-comptime-bitwise-shift.exit
Normal file
1
examples/expected/0639-comptime-bitwise-shift.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
1
examples/expected/0639-comptime-bitwise-shift.stderr
Normal file
1
examples/expected/0639-comptime-bitwise-shift.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
2
examples/expected/0639-comptime-bitwise-shift.stdout
Normal file
2
examples/expected/0639-comptime-bitwise-shift.stdout
Normal file
@@ -0,0 +1,2 @@
|
||||
and=8 or=14 xor=6 not=-1
|
||||
shl=1024 shr=128 ashr=-4
|
||||
Reference in New Issue
Block a user