Compiling R7RS code to executable #1383

Open
opened 2025-11-29 15:49:46 +00:00 by Retropikzel · 7 comments
Retropikzel commented 2025-11-29 15:49:46 +00:00 (Migrated from github.com)

I noticed that on the website the --r7rs flag is only for running scripts with interpreter, is there something similar for compiling R7RS code?

Assuming files.
main.scm

(import (scheme base)
        (foo bar))
(hello)

foo/bar.sld

(define-library
  (foo bar)
  (import (scheme base)
          (scheme write))
  (export hello)
  (include "bar.scm"))

foo/bar.scm

(define (hello)
  (display "Hello world")
  (newline))

You can compile it with different R7RS supporting implementations like so:

  • Loko
    • loko -std=r7rs --compile main.scm
  • Cyclone
    • cyclone main.scm
  • Chicken
    • csc -R r7rs -X r7rs -c -J -static -unit foo.bar -o foo.bar.a foo/bar.sld
    • csc -R r7rs -X r7rs -static -uses foo.bar main.scm

They all produce main executable which can then be just run with ./main

I noticed that on the website the --r7rs flag is only for running scripts with interpreter, is there something similar for compiling R7RS code? Assuming files. main.scm ``` (import (scheme base) (foo bar)) (hello) ``` foo/bar.sld ``` (define-library (foo bar) (import (scheme base) (scheme write)) (export hello) (include "bar.scm")) ``` foo/bar.scm ``` (define (hello) (display "Hello world") (newline)) ``` You can compile it with different R7RS supporting implementations like so: - Loko - `loko -std=r7rs --compile main.scm` - Cyclone - `cyclone main.scm` - Chicken - `csc -R r7rs -X r7rs -c -J -static -unit foo.bar -o foo.bar.a foo/bar.sld` - `csc -R r7rs -X r7rs -static -uses foo.bar main.scm` They all produce `main` executable which can then be just run with `./main`
vyzo commented 2025-11-29 15:59:15 +00:00 (Migrated from github.com)

This is an oversight, the compiler should support both --r7rs and general custom preludes.

I will make sure this is implemented before release, hopefully sooner.

This is an oversight, the compiler should support both --r7rs and general custom preludes. I will make sure this is implemented before release, hopefully sooner.
vyzo commented 2025-11-29 16:01:27 +00:00 (Migrated from github.com)

We should also add support for recognizing .sld files as r7rs by default, maybe for the .scm files too so that you don't even have to specify the prelude flag and it just works out of the box.

We should also add support for recognizing .sld files as r7rs by default, maybe for the .scm files too so that you don't even have to specify the prelude flag and it just works out of the box.
vyzo commented 2025-11-29 16:03:49 +00:00 (Migrated from github.com)

another UX improvement detail should be automatic main (or not requiring a main at all) for r7rs.

Since you are well versed with multiple r7rs implementations, what other flags are common?

another UX improvement detail should be automatic main (or not requiring a main at all) for r7rs. Since you are well versed with multiple r7rs implementations, what other flags are common?
Retropikzel commented 2025-11-29 16:34:23 +00:00 (Migrated from github.com)

Most implementations also have flags for adding directories into the beginning of load path and at the end of load path. Imagine your foo directory was in ~/libraries. Then you could run something like:
gxc --r7rs -I ~/libraries -o main main.scm

If the flags -I and -A are free then I recommend them. They are used often in new implementations and they come from https://srfi.schemers.org/srfi-138/srfi-138.html

Edit: I noticed that there is GERBIL_LOADPATH, but sometimes it can be handy to have the option to put the library path in front of the list, or at the end of the list. For example an SRFI library in the directory can break things if it is loaded first.

Most implementations also have flags for adding directories into the beginning of load path and at the end of load path. Imagine your foo directory was in ~/libraries. Then you could run something like: `gxc --r7rs -I ~/libraries -o main main.scm` If the flags -I and -A are free then I recommend them. They are used often in new implementations and they come from https://srfi.schemers.org/srfi-138/srfi-138.html Edit: I noticed that there is GERBIL_LOADPATH, but sometimes it can be handy to have the option to put the library path in front of the list, or at the end of the list. For example an SRFI library in the directory can break things if it is loaded first.
vyzo commented 2025-11-29 18:21:10 +00:00 (Migrated from github.com)

yeah, both -I and -A are free. -I is easy to add and makes sense, we should also add it to gxi.

What does -A do? like -I but append instead of prepend?

yeah, both `-I` and `-A` are free. `-I` is easy to add and makes sense, we should also add it to `gxi`. What does `-A` do? like `-I` but append instead of prepend?
vyzo commented 2025-11-29 18:21:51 +00:00 (Migrated from github.com)

ok i see, prepend and append indeed. I will add them.

ok i see, prepend and append indeed. I will add them.
vyzo commented 2025-11-29 18:23:04 +00:00 (Migrated from github.com)

I will also add -D, we already use it in gxtest.

I will also add `-D`, we already use it in gxtest.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mighty-gerbils/gerbil#1383
No description provided.