4 + 2 = 6

This commit is contained in:
2026-05-16 03:02:25 -06:00
parent 0bb66acae0
commit 466e2a38a9
10 changed files with 113 additions and 35 deletions
+23
View File
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <libguile/scm.h>
#define BLAH (-1 >> 2 == -1) && (-4 >> 2 == -1) && (-5 >> 2 == -2) && (-8 >> 2 == -2)
#if BLAH
# define SCM_SRS(x, y) ((x) >> (y))
#else
# define SCM_SRS(x, y) \
((x) < 0 \
? -1 - (scm_t_signed_bits) (~(scm_t_bits)(x) >> (y)) \
: ((x) >> (y)))
#endif
int main () {
unsigned long mask = 0xfffffffffffffffe;
unsigned long x = (4 << 2) + 2;
unsigned long y = (2 << 2) + 2;
unsigned long z = ((x + y) >> 2) + 2;
printf ("BLAH: %d\n", BLAH);
printf ("%ld\n", sizeof(long));
printf ("%lx\n", (long) z >> 2);
}
Executable
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -1,4 +1,4 @@
;;; -*- mode:scheme -*-
(let ((x0 (prim:+ 2 4)) (x1 (prim:write x0))) x1)
(let ((x0 (prim:cons 4 2)) (x2 (prim:write x1)) (x1 (prim:car x0))) x2)
+5 -1
View File
@@ -3,7 +3,11 @@
main:
pushq %rbp
movq %rsp, %rbp
movl $30, %edi
movl $16, %edi
callq GC_malloc
movq $18, (%rax)
movq $10, 8(%rax)
movl $18, %edi
callq scm_write
leave
ret
+3 -1
View File
@@ -1 +1,3 @@
(prim:write (prim:+ 2 4))
(let ((pair (prim:cons 4 2)))
(begin (prim:write (prim:car pair))
(prim:write (prim:cdr pair))))
+7 -5
View File
@@ -1,9 +1,11 @@
export
function w $main () {
@start
%.2 =l add 10, 18
%.3 =l and %.2, 18446744073709551613
%x0 =l or %.3, 2
%x1 =l call $scm_write (l %x0)
ret %x1
%x0 =l call $GC_malloc (l 16)
%.3 =l add %x0, 8
storel 18, %x0
storel 10, %.3
%x1 =l loadl %x0
%x2 =l call $scm_write (l %x1)
ret %x2
}