vtereshkov / umka-lang

Umka: a statically typed embeddable scripting language
BSD 2-Clause "Simplified" License
1.07k stars 53 forks source link

Module import paths #136

Open skejeton opened 2 years ago

skejeton commented 2 years ago

Module import paths will allow to specify a path to load modules from. It is similar to -I flag in C. For example, this could be shortened:

import (
        "window.um"; "rect.um"; "th.um"; "canvas.um"; "utf8.um"; "image.um"
        "../../tophat.dat/d_font.um"; "../../tophat.dat/d_util.um"; "../../tophat.dat/d_pfx.um"
)

Into

import (
        "window.um"; "rect.um"; "th.um"; "canvas.um"; "utf8.um"; "image.um"
        "d_font.um"; "d_util.um"; "d_pfx.um"
)

By specifying import path:

umka -I ../../tophat.dat main.um

Specifying import path shall be possible through API. Import paths are prioritized in order they are added. We first check file near "main.um". Then we start checking folders in the import paths, FIFO way, by checking first until last and finding if one matches, or error if no matches.

skejeton commented 8 months ago

Another option I thought of is this:

import ("umbox:tar/tar.um")
import ("src:d_util.um")

Essentially, namespaces for import directories. This case is better since there's a clear distinction, and umbox packages will be disambiguated from sources with same path.