From kennethflak at protonmail.com Mon Dec 23 11:20:07 2024 From: kennethflak at protonmail.com (Kenneth Flak) Date: Mon, 23 Dec 2024 19:20:07 +0000 Subject: [CM] Using clm in common lisp? Message-ID: <87seqedx5p.fsf@protonmail.com> Hi everybody, I'm currently in the process of transitioning my SuperCollider life over to common lisp and the excellent cl-collider and cl-patterns libraries. I am curious if it is possible to work with CLM within common lisp as well? Or is the only reasonable way to work with it these days within the framework of snd? Best, Kenneth -- Roosna & Flak - Contemporary Dance & Music Web: roosnaflak.com Code: {github,gitlab,codeberg}.com/kflak Mastodon: @kf at sonomu.club From bil at ccrma.Stanford.EDU Mon Dec 23 11:56:37 2024 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Mon, 23 Dec 2024 11:56:37 -0800 Subject: [CM] =?utf-8?q?Using_clm_in_common_lisp=3F?= In-Reply-To: <87seqedx5p.fsf@protonmail.com> References: <87seqedx5p.fsf@protonmail.com> Message-ID: <6f8eb882bf90f578650a9d07a7994caa@ccrma.stanford.edu> You can use clm5 available at ccrma-ftp ftp://ccrma-ftp.stanford.edu/pub/Lisp/clm5.tar.gz. I haven't worked on it in about 30 years, but I always make sure it still runs in sbcl. It's less convenient than CLM in Snd/s7, but basically the same functionality. Its major drawback is that it's nearly impossible to debug -- it writes an arcane .c file, compiles and loads it, etc like Chicken scheme. From kennethflak at protonmail.com Mon Dec 23 22:03:37 2024 From: kennethflak at protonmail.com (Kenneth Flak) Date: Tue, 24 Dec 2024 06:03:37 +0000 Subject: [CM] Using clm in common lisp? In-Reply-To: <6f8eb882bf90f578650a9d07a7994caa@ccrma.stanford.edu> References: <87seqedx5p.fsf@protonmail.com> <6f8eb882bf90f578650a9d07a7994caa@ccrma.stanford.edu> Message-ID: <87zfkld3d6.fsf@protonmail.com> Thanks! I'm trying to get it to work now, and the first hurdle was easy enough to clear: csh was not installed on my system. After that was done, I ran into this one: ; Compiling "/home/kf/quicklisp/local-projects/clm-5/xen.c" ; Compiling "/home/kf/quicklisp/local-projects/clm-5/io.c" ; Compiling "/home/kf/quicklisp/local-projects/clm-5/headers.c" ; Compiling "/home/kf/quicklisp/local-projects/clm-5/audio.c" ; Compiling "/home/kf/quicklisp/local-projects/clm-5/sound.c" ; Compiling "/home/kf/quicklisp/local-projects/clm-5/clm.c" ; Compiling "/home/kf/quicklisp/local-projects/clm-5/vct.c" ; Compiling "/home/kf/quicklisp/local-projects/clm-5/cmus.c" ; Creating "/home/kf/quicklisp/local-projects/clm-5/libclm.so" ;;gcc -shared -fPIC -o /home/kf/quicklisp/local-projects/clm-5/libclm.so /home/kf/quicklisp/local-projects/clm-5/xen.o /home/kf/quicklisp/local-projects/clm-5/headers.o /home/kf/quicklisp/local-projects/clm-5/audio.o /home/kf/quicklisp/local-projects/clm-5/io.o /home/kf/quicklisp/local-projects/clm-5/sound.o /home/kf/quicklisp/local-projects/clm-5/clm.o /home/kf/quicklisp/local-projects/clm-5/vct.o /home/kf/quicklisp/local-projects/clm-5/cmus.o -lasound "/home/kf/quicklisp/local-projects/clm-5/libclm.so" was not created? Perhaps there was a C compiler or loader error. You might try the following command in a terminal to see what happened: "gcc -shared -fPIC -o /home/kf/quicklisp/local-projects/clm-5/libclm.so /home/kf/quicklisp/local-projects/clm-5/xen.o /home/kf/quicklisp/local-projects/clm-5/headers.o /home/kf/quicklisp/local-projects/clm-5/audio.o /home/kf/quicklisp/local-projects/clm-5/io.o /home/kf/quicklisp/local-projects/clm-5/sound.o /home/kf/quicklisp/local-projects/clm-5/clm.o /home/kf/quicklisp/local-projects/clm-5/vct.o /home/kf/quicklisp/local-projects/clm-5/cmus.o -lasound " ;compiling /home/kf/quicklisp/local-projects/clm-5/clm-package.lisp[package clm] ;loading /home/kf/quicklisp/local-projects/clm-5/clm-package.fasl ;compiling /home/kf/quicklisp/local-projects/clm-5/initmus.lisp.. ;loading /home/kf/quicklisp/local-projects/clm-5/initmus.fasl While evaluating the form starting at line 558, column 0 of #P"/home/kf/quicklisp/local-projects/clm-5/all.lisp": Output from running the suggested command: /usr/bin/ld: cannot find /home/kf/quicklisp/local-projects/clm-5/xen.o: No such file or directory /usr/bin/ld: cannot find /home/kf/quicklisp/local-projects/clm-5/headers.o: No such file or directory /usr/bin/ld: cannot find /home/kf/quicklisp/local-projects/clm-5/audio.o: No such file or directory /usr/bin/ld: cannot find /home/kf/quicklisp/local-projects/clm-5/io.o: No such file or directory /usr/bin/ld: cannot find /home/kf/quicklisp/local-projects/clm-5/sound.o: No such file or directory /usr/bin/ld: cannot find /home/kf/quicklisp/local-projects/clm-5/clm.o: No such file or directory /usr/bin/ld: cannot find /home/kf/quicklisp/local-projects/clm-5/vct.o: No such file or directory /usr/bin/ld: cannot find /home/kf/quicklisp/local-projects/clm-5/cmus.o: No such file or directory collect2: error: ld returned 1 exit status I symlinked all the .o files from an existing snd build I had on my hard-drive, but couldn't find cmus.o there. Re-running the command gave me this: /usr/bin/ld: /home/kf/quicklisp/local-projects/clm-5/vct.o: warning: relocation against `s7' in read-only section `.text' /usr/bin/ld: /home/kf/quicklisp/local-projects/clm-5/sound.o: relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: bad value collect2: error: ld returned 1 exit status Which I guess means that I can't use those object files... Any help much appreciated! Best, Kenneth writes: > You can use clm5 available at ccrma-ftp > ftp://ccrma-ftp.stanford.edu/pub/Lisp/clm5.tar.gz. > I haven't worked on it in about 30 years, but > I always make sure it still runs in sbcl. It's > less convenient than CLM in Snd/s7, but basically > the same functionality. Its major drawback is > that it's nearly impossible to debug -- it writes > an arcane .c file, compiles and loads it, etc like > Chicken scheme. -- Roosna & Flak - Contemporary Dance & Music Web: roosnaflak.com Code: {github,gitlab,codeberg}.com/kflak Mastodon: @kf at sonomu.club From bil at ccrma.Stanford.EDU Tue Dec 24 06:39:19 2024 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 24 Dec 2024 06:39:19 -0800 Subject: [CM] =?utf-8?q?Using_clm_in_common_lisp=3F?= In-Reply-To: <87zfkld3d6.fsf@protonmail.com> References: <87seqedx5p.fsf@protonmail.com> <6f8eb882bf90f578650a9d07a7994caa@ccrma.stanford.edu> <87zfkld3d6.fsf@protonmail.com> Message-ID: I don't know what the problem is. Whenever I build CLM, I go to an empty directory, tar xf the clm5 tarball, start sbcl (in that directory), and load "all.lisp". From orm.finnendahl at selma.hfmdk-frankfurt.de Tue Dec 24 07:19:41 2024 From: orm.finnendahl at selma.hfmdk-frankfurt.de (Orm Finnendahl) Date: Tue, 24 Dec 2024 16:19:41 +0100 Subject: [CM] Using clm in common lisp? In-Reply-To: <87seqedx5p.fsf@protonmail.com> References: <87seqedx5p.fsf@protonmail.com> Message-ID: Hi Kenneth, I can confirm CLM works here (Linux, sbcl). Maybe you also want to consider using Incudine. It comines concepts of CLM, csound and SuperCollider, but does all the work in the LISP process itself rather than compiling to C or relying on precompiled C++ UGens. I'm in the process to release a new package, integrating CM, incudine, ATS and CLOG with some additional backends for CM and you can just load CLM into it. The documentation is about 90% done and the code is somewhere between alpha and beta. I expect to release it next spring. In case you want a sneak preview you can contact me off-list. Happy Holidays to everybody! Best, Orm ---------------------------------------------------------------------- Prof. Orm Finnendahl Komposition Hochschule f?r Musik und Darstellende Kunst Eschersheimer Landstr. 29-39 60322 Frankfurt am Main https://www.youtube.com/watch?v=2rWha1HTfFE&list=PLiGfneJSWmNw6dTUvcTHbTkCYOOTiB_N6 Am Montag, den 23. Dezember 2024 um 19:20:07 Uhr (+0000) schrieb Kenneth Flak: > Hi everybody, > > I'm currently in the process of transitioning my SuperCollider life over to common lisp and the excellent cl-collider and cl-patterns libraries. I am curious if it is possible to work with CLM within common lisp as well? Or is the only reasonable way to work with it these days within the framework of snd? > > Best, > Kenneth > > -- > Roosna & Flak - Contemporary Dance & Music > Web: roosnaflak.com > Code: {github,gitlab,codeberg}.com/kflak > Mastodon: @kf at sonomu.club > > > _______________________________________________ > Cmdist mailing list > Cmdist at ccrma.stanford.edu > https://cm-mail.stanford.edu/mailman/listinfo/cmdist From kennethflak at protonmail.com Tue Dec 24 07:40:43 2024 From: kennethflak at protonmail.com (Kenneth Flak) Date: Tue, 24 Dec 2024 15:40:43 +0000 Subject: [CM] Using clm in common lisp? In-Reply-To: References: <87seqedx5p.fsf@protonmail.com> <6f8eb882bf90f578650a9d07a7994caa@ccrma.stanford.edu> <87zfkld3d6.fsf@protonmail.com> Message-ID: <87ed1xm6mg.fsf@protonmail.com> Ah, that was the way to go about it... I tried the (ql:quickload :clm) approach, which failed miserably. It builds! Now I just need to check if it actually works on my machine :-) Best, Kenneth writes: > I don't know what the problem is. Whenever I build CLM, > I go to an empty directory, tar xf the clm5 tarball, > start sbcl (in that directory), and load "all.lisp". -- Roosna & Flak - Contemporary Dance & Music Web: roosnaflak.com Code: {github,gitlab,codeberg}.com/kflak Mastodon: @kf at sonomu.club From kennethflak at protonmail.com Tue Dec 24 07:43:06 2024 From: kennethflak at protonmail.com (Kenneth Flak) Date: Tue, 24 Dec 2024 15:43:06 +0000 Subject: [CM] Using clm in common lisp? In-Reply-To: References: <87seqedx5p.fsf@protonmail.com> Message-ID: <875xn9m6if.fsf@protonmail.com> Hi Orm, Funny, I was just looking into Incudine yesterday... It looks like a very interesting project. Will probably not have much time to dig into it until the summer, by which time I am _very_ much looking forward to giving your package a go. All the best, and happy holidays to all of you! Now off to eat unhealthy amounts of food... Kenneth "Orm Finnendahl" writes: > Hi Kenneth, > > I can confirm CLM works here (Linux, sbcl). > > Maybe you also want to consider using Incudine. It comines concepts of > CLM, csound and SuperCollider, but does all the work in the LISP > process itself rather than compiling to C or relying on precompiled > C++ UGens. > > I'm in the process to release a new package, integrating CM, incudine, > ATS and CLOG with some additional backends for CM and you can just > load CLM into it. > > The documentation is about 90% done and the code is somewhere between > alpha and beta. I expect to release it next spring. In case you want a > sneak preview you can contact me off-list. > > Happy Holidays to everybody! > > Best, > Orm > ---------------------------------------------------------------------- > Prof. Orm Finnendahl > Komposition > Hochschule f?r Musik und Darstellende Kunst > Eschersheimer Landstr. 29-39 > 60322 Frankfurt am Main > > https://www.youtube.com/watch?v=2rWha1HTfFE&list=PLiGfneJSWmNw6dTUvcTHbTkCYOOTiB_N6 > > > Am Montag, den 23. Dezember 2024 um 19:20:07 Uhr (+0000) schrieb > Kenneth Flak: >> Hi everybody, >> >> I'm currently in the process of transitioning my SuperCollider life >> over to common lisp and the excellent cl-collider and cl-patterns >> libraries. I am curious if it is possible to work with CLM within >> common lisp as well? Or is the only reasonable way to work with it >> these days within the framework of snd? >> >> Best, >> Kenneth >> >> -- >> Roosna & Flak - Contemporary Dance & Music >> Web: roosnaflak.com >> Code: {github,gitlab,codeberg}.com/kflak >> Mastodon: @kf at sonomu.club >> >> >> _______________________________________________ >> Cmdist mailing list >> Cmdist at ccrma.stanford.edu >> https://cm-mail.stanford.edu/mailman/listinfo/cmdist > > _______________________________________________ > Cmdist mailing list > Cmdist at ccrma.stanford.edu > https://cm-mail.stanford.edu/mailman/listinfo/cmdist -- Roosna & Flak - Contemporary Dance & Music Web: roosnaflak.com Code: {github,gitlab,codeberg}.com/kflak Mastodon: @kf at sonomu.club From chrghrc at protonmail.com Sun Dec 29 14:40:23 2024 From: chrghrc at protonmail.com (chrg) Date: Sun, 29 Dec 2024 22:40:23 +0000 Subject: [CM] s7 C functions and environments Message-ID: <9GBhyzUUx4TmGLdi5HKlVQ3Bq2VLxZRxR6hOYitb_vcw_Qh-fGdwyQDW105ahEt96bzcyKHD6weJofmmgNEuGHwgOVLS0ve6HjoMMb_oLgw=@protonmail.com> Hello, This might be a bit of a newbie question, but I'd like to clear this doubt. The problem I'm facing is: I want to define a function in C, and I want to pass some data to it at definition time. I thought I'd use environments for it: create a new environment to keep the data, then access it inside the function. Basically, what I'd like to do is similar to this Scheme setup: (define (make-f) (let ((x 1)) (lambda (y) (+ x y)))) (define f (make-f)) (display (f 2)) Except f here should be a C function. Unfortunately, it seems C-defined functions work differently from Scheme functions. I've tried using both s7_set_curlet and s7_make_typed_function_with_environment, but no matter what I do, using s7_curlet I always get back the rootlet. So please tell me: is this actually possible? If it's not how should I rethink this problem? (As for why I need this: I was trying to write a small C++ wrapper for s7 and one feature I'd like to have is to be able to automatically define functions that aren't necessarily s7_function's, by doing the necessary conversions and then calling the original function. I tried doing that by declaring a template function that would take a function pointer, but then I can't figure out how to pass the function pointer to the s7_function I'm defining. You can see the work I've done here: https://github.com/chrg127/s7-tests/blob/52fdeb4692ac21e2be4e899c6c80db184f1d17c5/s7.hpp#L346) -------------- next part -------------- An HTML attachment was scrubbed... URL: From bil at ccrma.Stanford.EDU Sun Dec 29 17:05:08 2024 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Sun, 29 Dec 2024 17:05:08 -0800 Subject: [CM] s7 C functions and environments In-Reply-To: <9GBhyzUUx4TmGLdi5HKlVQ3Bq2VLxZRxR6hOYitb_vcw_Qh-fGdwyQDW105ahEt96bzcyKHD6weJofmmgNEuGHwgOVLS0ve6HjoMMb_oLgw=@protonmail.com> References: <9GBhyzUUx4TmGLdi5HKlVQ3Bq2VLxZRxR6hOYitb_vcw_Qh-fGdwyQDW105ahEt96bzcyKHD6weJofmmgNEuGHwgOVLS0ve6HjoMMb_oLgw=@protonmail.com> Message-ID: <1f3bbcbe5cf6ff8c94ffe2c3c0d6b885@ccrma.stanford.edu> I hope I understand your question!: the first example using "+" could be: static s7_pointer make_f(s7_scheme *sc, s7_pointer args) { s7_pointer x = s7_car(args); char buf[256]; snprintf(buf, 256, "(let ((x %ld)) (lambda (y) (+ x y)))", s7_integer(x)); return(s7_eval_c_string(sc, buf)); } The same idea using a C function in place of "+": static int64_t fadd(int64_t x, int64_t y) {return(x + y);} static s7_pointer g_fadd(s7_scheme *sc, s7_pointer args) { return(s7_make_integer(sc, fadd(s7_integer(s7_car(args)), s7_integer(s7_cadr(args))))); } static s7_pointer make_fadd(s7_scheme *sc, s7_pointer args) { s7_pointer x = s7_car(args); char buf[256]; snprintf(buf, 256, "(let ((x %ld)) (lambda (y) (fadd x y)))", s7_integer(x)); return(s7_eval_c_string(sc, buf)); } s7_scheme *s7 = s7_init(); s7_define_function(s7, "make-f", make_f, 1, 0, false, NULL); s7_define_function(s7, "make-fadd", make_fadd, 1, 0, false, NULL); s7_define_function(s7, "fadd", g_fadd, 2, 0, false, NULL); ... I haven't brought out to s7.h the lambda call above (as s7_lambda or something), and need to think about whether there's currently a reasonable way to do it with the existing s7.h functions -- will mull it over. From da at liii.pro Mon Dec 30 05:29:45 2024 From: da at liii.pro (Da Shen) Date: Mon, 30 Dec 2024 21:29:45 +0800 Subject: [CM] =?utf-8?q?Failed_to_build_S7_Scheme_using_MSVC_when_HAVE=5FO?= =?utf-8?q?VERFLOW=5FCHECKS_is_enabled?= Message-ID: It is because of the missing impl of the following routines: s7.lib(s7.c.obj) : error LNK2001: unresolved external symbol multiply_overflow s7.lib(s7.c.obj) : error LNK2001: unresolved external symbol add_overflow s7.lib(s7.c.obj) : error LNK2001: unresolved external symbol int32_multiply_overflow s7.lib(s7.c.obj) : error LNK2001: unresolved external symbol int32_add_overflow s7.lib(s7.c.obj) : error LNK2001: unresolved external symbol subtract_overflow Just found the nice feature of S7 Scheme on Linux and macOS without GMP enabled: (+ #x7fffffffffffffff 1) => 9223372036854776000.0 And unfortunately, it does not work on Windows: (+ #x7fffffffffffffff 1) => -9223372036854775808 Could you help implement the missing routines on MSVC? It seems the routines generated by Deepseek or Claude is trustworthy to use. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bil at ccrma.Stanford.EDU Mon Dec 30 10:47:52 2024 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Mon, 30 Dec 2024 10:47:52 -0800 Subject: [CM] =?utf-8?q?Failed_to_build_S7_Scheme_using_MSVC_when_HAVE=5FO?= =?utf-8?q?VERFLOW=5FCHECKS_is_enabled?= In-Reply-To: References: Message-ID: <922bda10cddea99a509a2408acd55e7d@ccrma.stanford.edu> To implement those functions I need the equivalent of gcc's __builtin_add_overflow and friends. The MSVC versions appear to be restricted to unsigned ints, and only work on the x86 chips. I'm very leery of any code Claude or its competitors turns out. What do they suggest? From da at liii.pro Tue Dec 31 00:26:52 2024 From: da at liii.pro (Da Shen) Date: Tue, 31 Dec 2024 16:26:52 +0800 Subject: [CM] =?utf-8?q?Failed_to_build_S7_Scheme_using_MSVC_when_HAVE=5FO?= =?utf-8?q?VERFLOW=5FCHECKS_is_enabled?= In-Reply-To: <922bda10cddea99a509a2408acd55e7d@ccrma.stanford.edu> References: , <922bda10cddea99a509a2408acd55e7d@ccrma.stanford.edu> Message-ID: <0676a193-ebbe-44c0-9341-b9bb06bec77d.da@liii.pro> The impl by Deepseek of add_overflow, subtract_overflow and multiply_overflow is list below. I have not generated the code for the two int32 routines, because I'm a bit confused on its meaning. Here is the impl by Deepseek of add_overflow ---------------------------------------------------------------------------------------------------------- #include #include #include #include typedef int64_t s7_int; // Assume s7_int is int64_t // Generic overflow check for addition (for s7_int type) static bool add_overflow(s7_int A, s7_int B, s7_int *C) { *C = A + B; // Overflow condition: If A and B have the same sign, and the result has a different sign than A and B, overflow occurs return ((A ^ B) >= 0) && ((A ^ *C) < 0); } // Test cases int main() { s7_int A, B, C; bool overflow; // Test case 1: Positive overflow A = INT64_MAX; B = 1; overflow = add_overflow(A, B, &C); printf("Test 1: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 2: Negative overflow A = INT64_MIN; B = -1; overflow = add_overflow(A, B, &C); printf("Test 2: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 3: No overflow (positive numbers) A = 100; B = 200; overflow = add_overflow(A, B, &C); printf("Test 3: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 4: No overflow (different signs) A = 100; B = -50; overflow = add_overflow(A, B, &C); printf("Test 4: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 5: Edge case (zero) A = 0; B = 0; overflow = add_overflow(A, B, &C); printf("Test 5: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 6: Edge case (maximum positive number plus zero) A = INT64_MAX; B = 0; overflow = add_overflow(A, B, &C); printf("Test 6: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 7: Edge case (minimum negative number plus zero) A = INT64_MIN; B = 0; overflow = add_overflow(A, B, &C); printf("Test 7: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); return 0; } Here is the impl of subtract_overflow by deepseek: ---------------------------------------------------------------------------------------------------------- #include #include #include #include typedef int64_t s7_int; // Assume s7_int is int64_t // Generic overflow check for addition (for s7_int type) static bool add_overflow(s7_int A, s7_int B, s7_int *C) { *C = A + B; // Overflow condition: If A and B have the same sign, and the result has a different sign than A and B, overflow occurs return ((A ^ B) >= 0) && ((A ^ *C) < 0); } // Test cases int main() { s7_int A, B, C; bool overflow; // Test case 1: Positive overflow A = INT64_MAX; B = 1; overflow = add_overflow(A, B, &C); printf("Test 1: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 2: Negative overflow A = INT64_MIN; B = -1; overflow = add_overflow(A, B, &C); printf("Test 2: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 3: No overflow (positive numbers) A = 100; B = 200; overflow = add_overflow(A, B, &C); printf("Test 3: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 4: No overflow (different signs) A = 100; B = -50; overflow = add_overflow(A, B, &C); printf("Test 4: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 5: Edge case (zero) A = 0; B = 0; overflow = add_overflow(A, B, &C); printf("Test 5: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 6: Edge case (maximum positive number plus zero) A = INT64_MAX; B = 0; overflow = add_overflow(A, B, &C); printf("Test 6: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); // Test case 7: Edge case (minimum negative number plus zero) A = INT64_MIN; B = 0; overflow = add_overflow(A, B, &C); printf("Test 7: A = %lld, B = %lld\n", A, B); printf("Result: C = %lld, Overflow: %s\n\n", C, overflow ? "true" : "false"); return 0; } Here is the impl of multiply_overflow by deepseek: ---------------------------------------------------------------------------------------------------------- #include #include #include // Function to check for overflow during multiplication of two int64_t values static bool multiply_overflow(int64_t a, int64_t b, int64_t *result) { // Perform the multiplication *result = a * b; // Check for overflow if (a > 0 && b > 0) { // If both numbers are positive, the result should be positive return *result < 0; } else if (a < 0 && b < 0) { // If both numbers are negative, the result should be positive return *result < 0; } else if (a > 0 && b < 0) { // If one is positive and the other is negative, the result should be negative return *result > 0; } else if (a < 0 && b > 0) { // If one is negative and the other is positive, the result should be negative return *result > 0; } else { // If one of the numbers is zero, no overflow can occur return false; } } int main() { int64_t result; bool overflow; // Test case 1: No overflow overflow = multiply_overflow(100, 200, &result); printf("100 * 200 = %ld, Overflow: %s\n", result, overflow ? "true" : "false"); // Test case 2: Overflow (positive numbers) overflow = multiply_overflow(INT64_MAX, 2, &result); printf("INT64_MAX * 2 = %ld, Overflow: %s\n", result, overflow ? "true" : "false"); // Test case 3: Overflow (negative numbers) overflow = multiply_overflow(INT64_MIN, 2, &result); printf("INT64_MIN * 2 = %ld, Overflow: %s\n", result, overflow ? "true" : "false"); // Test case 4: No overflow (one positive, one negative) overflow = multiply_overflow(100, -200, &result); printf("100 * -200 = %ld, Overflow: %s\n", result, overflow ? "true" : "false"); // Test case 5: No overflow (one zero) overflow = multiply_overflow(0, 200, &result); printf("0 * 200 = %ld, Overflow: %s\n", result, overflow ? "true" : "false"); return 0; } ------------------------------------------------------------------ From:bil Send Time:2024 Dec. 31 (Tue.) 02:47 To:"??" Cc:cmdist Subject:Re: [CM] Failed to build S7 Scheme using MSVC when HAVE_OVERFLOW_CHECKS is enabled To implement those functions I need the equivalent of gcc's __builtin_add_overflow and friends. The MSVC versions appear to be restricted to unsigned ints, and only work on the x86 chips. I'm very leery of any code Claude or its competitors turns out. What do they suggest? -------------- next part -------------- An HTML attachment was scrubbed... URL: From bil at ccrma.Stanford.EDU Tue Dec 31 06:05:06 2024 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 31 Dec 2024 06:05:06 -0800 Subject: [CM] =?utf-8?q?Failed_to_build_S7_Scheme_using_MSVC_when_HAVE=5FO?= =?utf-8?q?VERFLOW=5FCHECKS_is_enabled?= In-Reply-To: <0676a193-ebbe-44c0-9341-b9bb06bec77d.da@liii.pro> References: , <922bda10cddea99a509a2408acd55e7d@ccrma.stanford.edu> <0676a193-ebbe-44c0-9341-b9bb06bec77d.da@liii.pro> Message-ID: <6f5162bd67da8ecabfa8298d8ed31742@ccrma.stanford.edu> Thanks very much for that code! I think there's a small bug in the subtract case. They reuse the add_overflow code, apparently assuming I'll pass -B, but B might be the most negative integer which can't be negated. Also the multiply code is going to be very slow. The idea behind the gcc/clang __builtins is that they can often use hardware support -- "conditional jump on overflow" -- and the check will not affect the speed of the multiply very much. I haven't re-run the timing tests in a long time, but my recollection is that the slowdown was not noticeable in s7's context. I'll try those tests again both with and without the checks (and with these laborious MSVC checks) and see how bad it is. My preference would be to omit the tests if they affect the timings too much -- anyone using ints in the 2^63 range (or 2^32 for *) ought to have some idea of what they are doing. From bil at ccrma.Stanford.EDU Tue Dec 31 11:42:07 2024 From: bil at ccrma.Stanford.EDU (bil at ccrma.Stanford.EDU) Date: Tue, 31 Dec 2024 11:42:07 -0800 Subject: [CM] s7 C functions and environments In-Reply-To: <9GBhyzUUx4TmGLdi5HKlVQ3Bq2VLxZRxR6hOYitb_vcw_Qh-fGdwyQDW105ahEt96bzcyKHD6weJofmmgNEuGHwgOVLS0ve6HjoMMb_oLgw=@protonmail.com> References: <9GBhyzUUx4TmGLdi5HKlVQ3Bq2VLxZRxR6hOYitb_vcw_Qh-fGdwyQDW105ahEt96bzcyKHD6weJofmmgNEuGHwgOVLS0ve6HjoMMb_oLgw=@protonmail.com> Message-ID: Here's an idea: /* tfunc.c */ #include #include #include #include "s7.h" s7_pointer g_f(s7_scheme *sc, s7_pointer args) /* (f f 12) */ { s7_pointer let = s7_function_let(sc, s7_car(args)); s7_pointer x = s7_symbol_local_value(sc, s7_make_symbol(sc, "x"), let); return(s7_make_integer(sc, s7_integer(x) + s7_integer(s7_cadr(args)))); } s7_pointer make_f(s7_scheme *sc, s7_pointer args) /* (make-f 1) */ { s7_pointer let = s7_sublet(sc, s7_curlet(sc), s7_nil(sc)); s7_pointer old_curlet = s7_set_curlet(sc, let); s7_define(sc, let, s7_make_symbol(sc, "x"), s7_car(args)); s7_pointer f = s7_make_typed_function_with_environment(sc, NULL, g_f, 2, 0, false, "f", NULL, let); s7_set_curlet(sc, old_curlet); return(f); } int main(int argc, char **argv) { char buffer[512]; char response[1024]; s7_scheme *s7 = s7_init(); s7_define_function(s7, "make-f", make_f, 1, 0, false, NULL); while (1) { fprintf(stdout, "\n> "); fgets(buffer, 512, stdin); if ((buffer[0] != '\n') || (strlen(buffer) > 1)) { sprintf(response, "(write %s)", buffer); s7_eval_c_string(s7, response); }} } /* The "g_f" function called in C has no idea which value returned by make-f is calling it. So we can get around that by passing it as an argument ("self"?): gcc tfunc.c -o tfunc -I. -g3 s7.o -ldl -lm -Wl,-export-dynamic tfunc > (define f1 (make-f 1)) # ; NULL as name above = anonymous function > (define f2 (make-f 2)) # > (f1 f1 3) 4 > (f2 f2 3) 5 */