ashinn / chibi-scheme

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

Can't make an image file that includes SRFI 193. #916

Closed shawnw closed 1 year ago

shawnw commented 1 year ago

Demonstration:

$ chibi-scheme -m srfi.193 -d foo.img
ERROR: importing unknown binding
    raw-script-file
    (*this-module* *this-path* make-module %module-exports module-env module-env-set! module-meta-data module-meta-data-set! module-exports module-name->strings module-name->file module-name-prefix load-module-definition find-module *modules* add-module! delete-module! symbol-append symbol-drop warn to-id from-id id-filter %resolve-import auto-generate-bindings *chibi-env* *auto-env* resolve-import resolve-module-imports load-module eval-module mutable-environment environment meta-begin meta-define define-library-transformer define-library module pop-this-path include-library-declarations define-meta-primitive import import-immutable export export-all include include-ci include-shared include-shared-optionally body begin repl-import)

I think it's probably because the image dump processing happens before raw-script-file is defined in main.c.

ghost commented 1 year ago

I confirm that this bug behaves the same on my machine.

lassik commented 1 year ago

This code:

    tmp = SEXP_FALSE;
    if ((i < argc) && !main_symbol)
      tmp = sexp_c_string(ctx,argv[i],-1);
    sexp_env_define(
      ctx, sexp_meta_env(ctx),
      sym=sexp_intern(ctx, sexp_raw_script_file_symbol, -1), tmp);

both defines the variable and sets the right value at once.

We probably should define it as #f first, and set! it later.

lassik commented 1 year ago

I can't find anything like sexp_env_set. But reading the code of sexp_env_define, it looks like you can call it more than once. When it meets an existing variable, it will re-use the same "location" (in RnRS parlance).

lassik commented 1 year ago

@ashinn Should we add the raw-script-file symbol to the globals table? See sexp_init_context_globals() in sexp.c. That's where all the "usual suspects" are listed (current-input-port and so on).