[CM] S7 integrated in TIC-80, and bug reports

David St-Hilaire sthilaire.david at gmail.com
Thu Feb 2 11:36:11 PST 2023


for the first issue, I apologize, I wrote the test example from my cell
phone, and forgot the backquote, it should have been:

(define-macro (test x . args) `(list ,@(map car args)))
(test 10 ('x 1) ('y 2))

which crashes S7, when I load from c string this snippet. The bt from gdb
looks like this:

Thread 1 "tic80" received signal SIGSEGV, Segmentation fault.
0x00005555559bb97d in s7_integer (p=0x0) at
/home/david/hacking/tic80-s7/TIC-80/vendor/s7/s7.c:13462
13462  if (is_t_integer(p)) return(integer(p));
(gdb) bt
#0  0x00005555559bb97d in s7_integer (p=0x0) at
/home/david/hacking/tic80-s7/TIC-80/vendor/s7/s7.c:13462
#1  0x00005555558e136b in scheme_map (sc=0x555556e456a0,
args=0x55555761d9b8)
    at /home/david/hacking/tic80-s7/TIC-80/src/api/scheme.c:313
#2  0x0000555555b27873 in op_c_ss (sc=0x555556e456a0) at
/home/david/hacking/tic80-s7/TIC-80/vendor/s7/s7.c:87854
#3  0x0000555555b340e1 in eval (sc=0x555556e456a0, first_op=420) at
/home/david/hacking/tic80-s7/TIC-80/vendor/s7/s7.c:90383
#4  0x00005555559f8899 in s7_load_c_string_with_environment
(sc=0x555556e456a0,
    content=0x7fffe69dde08 ";; title:   game title\n;; author:  game
developer, email, etc.\n;; desc:    short description\n;; site:    website
link\n;; license: MIT License (change this to your license of choice)\n;;
version: 0.1\n;;"..., bytes=2524,
    e=0x5555570ae610) at
/home/david/hacking/tic80-s7/TIC-80/vendor/s7/s7.c:30466
#5  0x00005555559f89fc in s7_load_c_string (sc=0x555556e456a0,
    content=0x7fffe69dde08 ";; title:   game title\n;; author:  game
developer, email, etc.\n;; desc:    short description\n;; site:    website
link\n;; license: MIT License (change this to your license of choice)\n;;
version: 0.1\n;;"..., bytes=2524)
    at /home/david/hacking/tic80-s7/TIC-80/vendor/s7/s7.c:30482
#6  0x00005555558e3367 in initScheme


For my issue 2, about having a set! only working in some circonstances, I
was expecting the macro to be expanded (thus producing the "(car x)" code
and since car handles the set! call properly I expected to work. Is this a
deviation from the standard or that I have a misconception of how it should
work? I tried it in gsi and it worked well, but guile even fails to eval
"(set! (car x) 3)" so maybe it is to the implementation to decide how this
works?

In my endeavour to use S7 in tic-80, I faced a few roadblocks on some
platforms (windows, rasberry pi and android, mostly). You can see the
details here if you are interested:
https://github.com/nesbox/TIC-80/pull/2113

Windows issues were related to the use of noreturn hints. I didn't know how
to fix it properly so I just removed them for now and it seems fine. I had
less obvious issues on Android which had issues with the cpow and clog
macros being undefined. Finally on rasberry pi, the issue was related to
the type sigjmp_buf being undefined, which I'm still trying to resolve. I
don't know if those changes I'm doing are relevant to you but I thought I
would let you know.

Finally, I mentionned performance issues in my first email, but I was quite
wrong. I optimized my code a bit and also did better measurements and it's
actually running very smoothly ;p Apologies!

Thanks!

--
David

On Thu, Feb 2, 2023 at 1:53 PM <bil at ccrma.stanford.edu> wrote:

> Thanks for the info and bug reports.  Are you catching
> scheme errors or using a repl?  In the repl, I get:
>
>
> (define-macro (test x . args) (list ,@(map car args)))
> (test 10 ('x 1) ('y 2))
>
> ;unquote (',') occurred outside quasiquote: (test 10 ('x 1) ('y 2))
> ;    (test 10 ('x 1) ('y 2))
> ; test: (list (unquote (apply-values (map c... ; args: (('x 1) ('y 2))
>
> In other words, you have ",@(...)" but there's no enclosing
> quasiquote.
>
>
> (define-macro (test x) `(car ,x))
> (let ((x (cons 1 2))) (set! (test x) 3) x)
>
> ;test (a macro) does not have a setter: (set! (test x) 3)
>
> The code (set! (test...)...) only works if the test macro
> has a setter (a function that tells set! how to handle it
> as the target of set!).  Your other case
>
> (let ((x (cons 1 2))) (set! (car x) 3) x)
> ;(3 . 2)
>
> works because car has a built-in setter in s7 (set-car! is
> the standard scheme equivalent).
>
> If you're using s7_eval_c_string or other C-side equivalent,
> you need to catch scheme-side errors.  There's a section in
> s7.html showing one way to do this ("handling scheme errors
> in C" or some such title).
>
>

-- 
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20230202/42857e17/attachment-0001.html>


More information about the Cmdist mailing list