PistonDevelopers / PistonDevelopers/dyon
Global objects
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.9k
- Forks
- 56
- Avg merge
- 1m
- Merged PRs (30d)
- 6
Description
A global object is declared at module level with some fields:
~ foo { a: f64 }
fn bar() foo {
println(foo.a)
}
fn baz() mut foo {
foo.a = 42
}
The global object is created automatically if it doesn't exist already.
A global object outlives any other lifetime.
The globals function returns a list of all global objects:
fn main() {
println(globals())
}
A global can be destroyed, but it will recreated when calling some function accessing it or using it:
fn main() {
foo() // Creates global object `foo_object`
destroy("foo")
foo() // Recreates global object `foo_object`
}
~ foo_object {}
fn foo() foo_object {}
A global object can inherit from another global object:
~ rect { pos: [vec4], size: [vec4] }
~ button: rect { label: [str] }
When a global object only contains arrays as members, one can use the for-in syntax:
fn foo() mut button {
for b in button {
b.label = "click me!"
}
}
Methods can be declared on global objects that can be used inside for-in syntax:
~ rect {
pos: [vec4],
size: [vec4],
min() = pos
max() = pos + size
}
fn foo() rect {
for r in rect {
println(r.max())
}
}
Methods can also combine lists and scalar fields:
~ foo {
a: f64,
b: [f64],
bar() = a + b
}
To insert a new item in a global object, one uses push syntax:
~ rect { pos: vec4, size: vec4 }
fn main() {
foo()
}
fn foo() mut rect {
push rect { pos: (0, 0), size: (0, 0) }
}
The super function returns the inherited global object of a global object:
fn super(global: str) -> opt[str] { ... }
The methods function returns a list of methods and their types:
fn methods(global: str) -> [{}] { ... }
The glob function converts a global into an ordinary object (read-only):
fn glob(global: str) -> opt[{}] { ... }
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides no file, test, or entry point. First map how Dyon parses declarations, resolves names, manages lifetimes, inheritance, and built-ins, then define tests for the listed global-object behaviors; done means the examples and destruction/recreation semantics work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100