cardillan / mindcode

A high level language for Mindustry Logic (mlog) and Mindustry Schematics.
http://mindcode.herokuapp.com/
MIT License
87 stars 13 forks source link

Modules #149

Open cardillan opened 2 months ago

cardillan commented 2 months ago

A draft for adding support for modules to Mindcode. To be implemented in 2 phases.

NOTE: parameters in this text aren't function parameters, but global variables declared using the param keyword and used to allow parametrization of the compiled mlog code.

1st phase - Support for loading additional files

2nd phase - Modules, namespaces and a system library

Example:

require standard;

begin
    unit = standard.findUnit(@mega);
    // Do something with unit
end;

Importing two global variables might merge them - do we want to allow this? Might be useful in some situations - e.g. if two modules want to share variables referencing to units.

module foo;
var debug;
...

module bar;
var debug;          // Variables not public - this is different from foo.debug!

require foo, bar;
import foo.debug
import bar.debug;   // Merges foo.debug with bar.debug. Or error. 

Rejected ideas

cardillan commented 1 week ago

The first phase has been more or less completed as of release 2.6.0. On to of that, system libraries were also implemented.

What remains to be done is namespaces and modules.