ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.2k stars 142 forks source link

SEXP_USE_MUTABLE_STRINGS 0 is pretty broken #991

Closed ghost closed 2 months ago

ghost commented 2 months ago

Enable the option:

diff --git a/include/chibi/features.h b/include/chibi/features.h
index 9431514f..35d91fed 100644
--- a/include/chibi/features.h
+++ b/include/chibi/features.h
@@ -244,7 +244,7 @@
 /* uncomment this to disable the string-set! opcode */
 /*   By default (non-literal) strings are mutable. */
 /*   Making them immutable allows for packed UTF-8 strings. */
-/* #define SEXP_USE_MUTABLE_STRINGS 0 */
+#define SEXP_USE_MUTABLE_STRINGS 0

 /* uncomment this to enable precomputed index->cursor tables for strings */
 /*   This makes string-ref faster at the expensive of making string */

Get mondo warnings, but it builds:

cc -c  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3  -o main.o main.c
cc -c  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o gc.o gc.c
cc -c  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o sexp.o sexp.c
cc -c  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o bignum.o bignum.c
cc -c  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o gc_heap.o gc_heap.c
cc -c  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o opcodes.o opcodes.c
cc -c  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o vm.o vm.c
cc -c  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o eval.o eval.c
cc -c  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o simplify.o simplify.c
cc  -dynamiclib -install_name /usr/local/lib/libchibi-scheme.0.11.0.dylib -o libchibi-scheme.0.11.0.dylib gc.o sexp.o bignum.o gc_heap.o opcodes.o vm.o eval.o simplify.o    -ldl -lm
ln -sf libchibi-scheme.0.11.0.dylib libchibi-scheme.0.dylib
ln -sf libchibi-scheme.0.dylib libchibi-scheme.dylib
cc  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o chibi-scheme main.o -L.  -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/filesystem.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/filesystem.dylib lib/chibi/filesystem.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/weak.dylib lib/chibi/weak.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/heap-stats.dylib lib/chibi/heap-stats.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/disasm.dylib lib/chibi/disasm.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/ast.dylib lib/chibi/ast.c  -L.  -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/json.dylib lib/chibi/json.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/emscripten.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/emscripten.dylib lib/chibi/emscripten.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/process.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/process.dylib lib/chibi/process.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/time.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/time.dylib lib/chibi/time.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/system.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/system.dylib lib/chibi/system.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/stty.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/stty.dylib lib/chibi/stty.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/pty.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/pty.dylib lib/chibi/pty.c -L.   -lchibi-scheme -lutil
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/net.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/net.dylib lib/chibi/net.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/srfi/18/threads.dylib lib/srfi/18/threads.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/io/io.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/io/io.dylib lib/chibi/io/io.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/optimize/rest.dylib lib/chibi/optimize/rest.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/optimize/profile.dylib lib/chibi/optimize/profile.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/chibi/crypto/crypto.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/chibi/crypto/crypto.dylib lib/chibi/crypto/crypto.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/srfi/27/rand.dylib lib/srfi/27/rand.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/srfi/151/bit.dylib lib/srfi/151/bit.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/srfi/39/param.dylib lib/srfi/39/param.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/srfi/69/hash.dylib lib/srfi/69/hash.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/srfi/95/qsort.dylib lib/srfi/95/qsort.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/srfi/98/env.dylib lib/srfi/98/env.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/srfi/144/math.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/srfi/144/math.dylib lib/srfi/144/math.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/srfi/160/uvprims.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/srfi/160/uvprims.dylib lib/srfi/160/uvprims.c -L.   -lchibi-scheme
LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme -q tools/chibi-ffi lib/scheme/bytevector.stub
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/scheme/bytevector.dylib lib/scheme/bytevector.c -L.   -lchibi-scheme
cc  -dynamiclib  -Iinclude  -DSEXP_USE_NTPGETTIME -DSEXP_USE_INTTYPES -Wall -g -g3 -O3   -o lib/scheme/time.dylib lib/scheme/time.c -L.   -lchibi-scheme
find lib/chibi/ -name \*.sld | \
     LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme tools/generate-install-meta.scm 0.11.0 > lib/.chibi.meta
find lib/srfi/ -name \*.sld | \
     LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme tools/generate-install-meta.scm 0.11.0 > lib/.srfi.meta
find lib/scheme/ -name \*.sld | \
     LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme tools/generate-install-meta.scm 0.11.0 > lib/.scheme.meta

But then it fails rather a lot of the test suite:

LD_LIBRARY_PATH=".:" DYLD_LIBRARY_PATH=".:" CHIBI_IGNORE_SYSTEM_PATH=1 CHIBI_MODULE_PATH=lib ./chibi-scheme tests/r7rs-tests.scm
R7RS: 

    4.1 Primitive expression types: 
     ...........................
    27 out of 27 (100.0%) tests passed in 0.007436990737915039 seconds.
    4.2 Derived expression types: 
     ..........................................................................

    74 out of 74 (100.0%) tests passed in 0.035043954849243164 seconds.
    4.3 Macros: 
     .........................
    25 out of 25 (100.0%) tests passed in 0.023190975189208984 seconds.
    5 Program structure: 
     ...............
    15 out of 15 (100.0%) tests passed in 0.007798910140991211 seconds.
    6.1 Equivalence Predicates: 
     .........................
    25 out of 25 (100.0%) tests passed in 0.00926518440246582 seconds.
    6.2 Numbers: 
     ..........................................................................
     ..........................................................................
     ...............................................................
    211 out of 211 (100.0%) tests passed in 0.059996843338012695 seconds.
    6.3 Booleans: 
     ..................
    18 out of 18 (100.0%) tests passed in 0.0037419795989990234 seconds.
    6.4 Lists: 
     .................................................................
    65 out of 65 (100.0%) tests passed in 0.02360391616821289 seconds.
    6.5 Symbols: 
     .................
    17 out of 17 (100.0%) tests passed in 0.00618290901184082 seconds.
    6.6 Characters: 
     ..........................................................................
     .....
    79 out of 79 (100.0%) tests passed in 0.02087998390197754 seconds.
    6.7 Strings: 
     ...............!!.........................................................
     ..............................................!!!!!!!!!!
    118 out of 130 (90.8%) tests passed in 0.039335012435913086 seconds.
    12 errors (9.2%).
    ERROR: (let ((str (string #\a #\b #\c))) (string-set! str 1 #\-) str)
        Exception: undefined variable: string-set!
        on line 1320 of file "tests/r7rs-tests.scm"
    ERROR: (let ((s (string #\a #\b #\c))) (string-set! s 1 #\🜀) s)
        Exception: undefined variable: string-set!
        on line 1323 of file "tests/r7rs-tests.scm"
    ERROR: (let ((str (make-string 5 #\x))) (string-fill! str #\-) str)
        Exception: undefined variable: string-set!
        on line 1457 of file "tests/r7rs-tests.scm"
    ERROR: (let ((str (make-string 5 #\x))) (string-fill! str #\- 2) str)
        Exception: undefined variable: string-set!
        on line 1459 of file "tests/r7rs-tests.scm"
    ERROR: (let ((str (make-string 5 #\x))) (string-fill! str #\- 2 3) str)
        Exception: undefined variable: string-set!
        on line 1461 of file "tests/r7rs-tests.scm"
    ERROR: ...str
        Exception: undefined variable: string-set!
        on line 1464 of file "tests/r7rs-tests.scm"
    ERROR: (let ((str (make-string 5 #\x))) (string-copy! str 0 "-----") str)
        Exception: undefined variable: string-set!
        on line 1466 of file "tests/r7rs-tests.scm"
    ERROR: ...str
        Exception: undefined variable: string-set!
        on line 1468 of file "tests/r7rs-tests.scm"
    ERROR: ...str
        Exception: undefined variable: string-set!
        on line 1470 of file "tests/r7rs-tests.scm"
    ERROR: ...str
        Exception: undefined variable: string-set!
        on line 1472 of file "tests/r7rs-tests.scm"
    ERROR: ...str
        Exception: undefined variable: string-set!
        on line 1476 of file "tests/r7rs-tests.scm"
    ERROR: ...str
        Exception: undefined variable: string-set!
        on line 1478 of file "tests/r7rs-tests.scm"
    6.8 Vectors: 
     ...........................................
    43 out of 43 (100.0%) tests passed in 0.017297983169555664 seconds.
    6.9 Bytevectors: 
     ................................xxx....
    36 out of 39 (92.3%) tests passed in 0.012196063995361328 seconds.
    3 failures (7.7%).
    FAIL: (utf8->string #u8(0 #x41 #x42 #x43) 1)
        expected "ABC" but got "ABC\x00;"
        on line 1627 of file "tests/r7rs-tests.scm"
    FAIL: (utf8->string #u8(0 #x41 #x42 #x43 0) 1 4)
        expected "ABC" but got "ABC\x00;"
        on line 1628 of file "tests/r7rs-tests.scm"
    FAIL: (utf8->string #u8(0 #xCE #xBB 0) 1 3)
        expected "λ" but got "λ\x00;"
        on line 1629 of file "tests/r7rs-tests.scm"
    6.10 Control Features: 
     ..................................
    34 out of 34 (100.0%) tests passed in 0.016185998916625977 seconds.
    6.11 Exceptions: 
     ..............................
    30 out of 30 (100.0%) tests passed in 0.015750885009765625 seconds.
    6.12 Environments and evaluation: 
     ....
    4 out of 4 (100.0%) tests passed in 0.0019350051879882812 seconds.
    6.13 Input and output: 
     ...............................................................
        Read syntax: 
         ......................................................................
         .......................
        93 out of 93 (100.0%) tests passed in 0.030590057373046875 seconds.
        Numeric syntax: 
         ......................................................................
         ......................................................................
         ......................................................................
         ..........
        220 out of 220 (100.0%) tests passed in 0.09760308265686035 seconds.
    376 out of 376 (100.0%) tests passed in 0.15198516845703125 seconds.
    2 out of 2 (100.0%) subgroups passed.
    6.14 System interface: 
     .............
    13 out of 13 (100.0%) tests passed in 0.005388975143432617 seconds.
1210 out of 1225 (98.8%) tests passed in 0.46364307403564453 seconds.
3 failures (0.2%).
12 errors (1.0%).
16 out of 18 (88.9%) subgroups passed.

And every REPL prompt and invocation of any kind, it spits out WARNING: reference to undefined variable string-set!

I think the failing tests and the warning should be disabled in case SEXP_USE_MUTABLE STRINGS 0.

ashinn commented 2 months ago

Chibi is built in layers, and states this in the documentation.

To get the full Chibi and R7RS support you need most of the default compiler options. Toggling these options is intended only for custom builds, in most cases to strip the size down for embedded executables or extension language use. Given that, SEXP_USE_MUTABLE STRINGS 0 works surprisingly well here.