Skip to content

Various improper results from fresh compiled repl-min.scm #7

@apg

Description

@apg

Have been exploring ribbit a bit lately, and working on a Zig implementation (which will probably diverge a lot from this as I explore additions to the RVM). Anyway, in the midst of trying to understand the RVM decoding, I encountered the following on a fresh git clone:

~/tmp/ribbit/src $ csi -q rsc.scm -t c -l min -m repl-min.scm 
~/tmp/ribbit/src $ gcc -o rvm.min repl-min.scm.c
~/tmp/ribbit/src $ ./rvm.min
> (string-length "hello")
()
> (string-ref "hello" 1)
Segmentation fault (core dumped)
apg@hc-apg:~/tmp/ribbit/src $ grep fer-gnirts repl-min.scm.c
    "Detouq,htgnel-gnirts,fer-gnirts,fi,!rdc-tes,tsil>-rotcev,!tes-gnirts,"
char *input = "E!rdc-tes,rddc,=,htgnel-gnirts,fer-gnirts,!tes-gnirts,gnirts-ekam,?rotcev,tsil>-
    ***SNIP***

As you can see, string-ref is in there, so the segfault is not occurring due to an unknown procedure or something (it would seem). Loading gdb:

~/tmp/ribbit/src $ gcc -g -o rvm.min.g repl-min.scm.c 
~/tmp/ribbit/src $ ./rvm.min.g 
> (string-ref "hello" 1)
Segmentation fault (core dumped)
~/tmp/ribbit/src $ gdb ./rvm.min.g 
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./rvm.min.g...
(gdb) run
Starting program: /home/apg/tmp/ribbit/src/rvm.min.g 
> (string-ref "hello" 1)

Program received signal SIGSEGV, Segmentation fault.
prim (no=6) at repl-min.scm.c:440
440         push2(CAR(x), PAIR_TAG);

I'd try this with min-tc, which I suspect might provide more clues, but that doesn't exist.

I did test the min defintions of list-ref and list-tail in chicken "just to be sure":

#;1> (define (list-ref lst i)
   (car (list-tail lst i)))

Note: assignment to imported value binding: list-ref
#;2> (define (list-tail lst i)
     (if (< 0 i) (list-tail (cdr lst) (- i 1)) lst))

Note: assignment to imported value binding: list-tail
#;3> (list-ref (string->list "hello") 1)
#\e

Finally, doing the same thing with the repl-max, I get correct results:

~/tmp/ribbit/src $ csi -q rsc.scm -t c -l max -m repl-max.scm 
~/tmp/ribbit/src $ ls
host  minify.scm    repl-max.scm.c  repl-min.scm.c  rvm.min
lib   repl-max.scm  repl-min.scm    rsc.scm         tests
~/tmp/ribbit/src $ gcc -o rvm.max repl-max.scm.c 
~/tmp/ribbit/src $ ./rvm.max
> (string-length "hello")
5
> (string-ref "hello" 1)
101
> 

In the min.scm, library string-length is an alias to field1 which makes this pretty interesting. I would say that field1 is somehow not linked properly, but it's of course a primitive. Also, car and cdr work just fine.

Also of note that using -l max and compiling repl-min works just fine. I guess it's possible that I should have no expectation that this works, but figured I'd raise it anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions