eignnx / rellog

0 stars 0 forks source link

Module System #40

Open eignnx opened 8 months ago

eignnx commented 8 months ago

Works toward #23.

Basically copy-paste Rust's module system into Rellog.

Goal

Get this example working:

# in shapes.rellog
[[imports
    - circle::[circle_radius][circle_area]
    - quads::
        - self
        - rectangle::[rect_width][rect_height][rect_area]
        - square::[square_width][square_area]
]]

[[submodules
    - circle
    - quads
]]

[[exports
    - [shape][area]
    - circle
    - quads
]]

[shape {square Width}][Area]
    - quads::square::[SquareWidth][square_area Area]

[shape {rect RectWidth RectHeight}][Area]
    - quads::[RectWidth][RectHeight][rect_area Area]

[shape {circle CircleRadius}][Area]
    - [CircleRadius][circle_area Area]
# in quads.rellog
[[exports
    - square::'*'
    - rectangle::'*'
]]

[[submodules
    - square
    - rectangle
]]

See full example here

eignnx commented 8 months ago

Subgoal

Get the greetings.rellog example working:

# greetings.rellog
[[imports
    - hello::[hello_world]
    - goodbye
]]

[[submodules
    - hello
    - goodbye
]]

[main]
    - [hello_world]
    - goodbye::[goodbye_world]
# hello.rellog
[[exports [HelloWorld]]]

[hello_world]
    - [io_writeln "Hello, world!"][stream stdout]

[hidden]
    - [io_writeln "Uh-oh! This should be private to module `hello`!"][stream stdout]
# goodbye.rellog
[[exports [GoodbyeWorld]]]

[goodbye_world]
    - [io_writeln "Goodbye, world!"][stream stdout]