xshade-lang / xshade

"cross shade" meta shading language and compiler
MIT License
38 stars 3 forks source link

import, export & modules syntax #7

Open Vengarioth opened 7 years ago

Vengarioth commented 7 years ago

Syntax proposal

We need syntax to make things from other modules accessible. This proposal shows a possible solution.

implementation

import and export are top-level constructs and cannot exist inside of blocks, however they can be placed at any position within a file. There are no syntax for default exports or imports as this leads to issues when IDEs try to refactor code.

Allowed exports and imports are:

example

index.xs

import { Foo, Bar } from other_module;

struct Foobar {
    x: Foo;
    y: Bar;
}

other_module.xs

struct Foo {
    x: f32,
    y: f32,
}

struct Bar {
    x: f32,
    y: f32,
}

fn doFoo(in: Input) -> Output {
    // ...
}

export { Foo, Bar, doFoo };

export syntax

export a single item

export Foo;

export multiple items

export { Foo, Bar };

import syntax

import a single item

import Foo from bar;

import multiple items

import { Foo, Bar } from bar;

import all

import * from bar;

import from submodules

import * from foo/bar;

file resolution

File resolution is a tricky thing for module systems. How do we resolve the standard library? How do we resolve libraries from a potential package manager?

other module systems

BoneCrasher commented 6 years ago

things I'd like to suggest:

Vengarioth commented 6 years ago