dschmenk/PLASMA

Allow including a module's header in the module's own source code

ZornsLemma opened this issue · 3 comments

Hi Dave, I hope you're well!

I hope this makes sense...

In C you'd often have a foo.h header which declares the functions and associated constants for code in foo.c, and then other code (in say quux.c) would do "#include "foo.h" to pick up those declarations. foo.c itself would normally #include "foo.h" as well, to avoid duplicating constant definitions and to consistency check the prototypes in the header with the actual code.

In PLASMA this technique doesn't seem to work. The attached zip file has a foo module with foo.pla and foo.plh files and a quux module which uses the foo module. When I compile this, the "foo" module ends up with a dependency on itself and the VM gets upset when trying to load it. (I have only tested the Acorn VM, to be scrupulously honest, but I can see from examining the "foo" module on disk that it does have a dependency on itself.)

I don't know how hard it would be to make this work. A necessary step would probably be to stop the compiler emitting a dependency when processing an import statement if the dependency is the module currently being compiled, but I don't know whether that would be sufficient or not.

I appreciate you may not have the time or inclination to look into making any code changes (although if you do that would be fantastic) but I'd appreciate your thoughts on this. Is it a reasonable thing to want, at least? Is it something you can already do if you just arrange things a little differently in the source code?

Thanks.

Steve

include-header-from-own-module.zip

Steve-

Took a pass at being able to import self module. I've tried it out for three modules: conio, fileio, and inet. Available with the cross compiler for now. Let me know what you think.

Thanks Dave! I've just given this a go with the include-header-from-own-module.zip test case and it works really nicely.

I'll see if I can finish tidying up the merge and post to stardot with the new version for some user feedback, but it looks good to me.