dylan-hackers / mindy

Mindy - minimal compiler-interpreter for Dylan
Other
21 stars 9 forks source link

can't import module format-out from library io #35

Closed dram closed 8 years ago

dram commented 8 years ago

When trying to use format-out module from io library with following code:

define library main
  use dylan;

  use io, import: { format-out };
end;

define module main
  use dylan;
  use extensions;

  use format-out;
end;

Mindy refused to run with following error:

error: library main can't import module format-out from library io because it isn't exported.

What becomes interesting is that when I specifing io-lib.dbc explicitly, it runs correctly:

mindy -f /path/to/io-lib.dbc -f main.dbc
waywardmonkeys commented 8 years ago

What if you just do this in the library:

define library main
  use dylan;
  use io;
end;
dram commented 8 years ago

Then will be another error:

error: Unknown module format-out in library main
dram commented 8 years ago

The problem is that there is no module defined in io library, after adding an empty module, the problem disappeared.

The deeper cause is that for every library, for first time complete_library is called, it will call load_library, and then define_module. In define_module library will be checked again for its completeness, then complete_library will be call again.

If there is no module in library, define_module will not be called, and library will be leave as uncompleted.

waywardmonkeys commented 8 years ago

Great work!

It looks like many things currently call complete_library and it isn't clear to me if that's the nature of the design and intentional or whether the design is moderately clumsy and so it needs to be called from lots of places. :)

But either way, since it is called many times, perhaps this current behavior is just an oversight and can be fixed by finding the right place to insert a new check to see if the library is completed, and if not, then to complete it?

complete_library already calls complete_library on each of the libraries that it uses. Maybe there's an error in the logic there?

dram commented 8 years ago

Yes, I think complete_library is quite confusing.

I made a possible fix, calling complete_library and also complete_module in fop_done, which I think is more reasonable, doing completion at end of definition, instead of before using it. see here: https://github.com/dram/mindy/commit/f721f579ff055150458e1150eaebdf83b7453920

Have not read through Mindy's interpreter code yet, not sure if it will cause other problems, and I also not satisfied with that patch, so do not send pull request yet.

dram commented 8 years ago

Although code reading is not finished yet, I'm kind of satisfied with this new fix, so I send a pull request for review.