Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add APIs on class::Spec and module::Spec for defining constants #27

Closed
lopopolo opened this issue Jul 7, 2019 · 1 comment · Fixed by #526
Closed

Add APIs on class::Spec and module::Spec for defining constants #27

lopopolo opened this issue Jul 7, 2019 · 1 comment · Fixed by #526
Labels
A-core Area: Core traits and interpreter-agnostic Ruby Core and Ruby stdlib implementations. A-ruby-core Area: Ruby Core types. A-ruby-stdlib Area: Ruby Standard Library packages. B-mruby Backend: Implementation of artichoke-core using mruby.

Comments

@lopopolo
Copy link
Member

lopopolo commented Jul 7, 2019

Currently, regexp::init defines constants with eval and format!.

Add an API that allows defining a constant that takes anything that implements FromMrb<Value> in the same way that you add a method to these specs.

@lopopolo lopopolo transferred this issue from artichoke/ferrocarril Jul 28, 2019
@lopopolo lopopolo added this to the VM milestone Jul 28, 2019
@lopopolo lopopolo added A-core Area: Core traits and interpreter-agnostic Ruby Core and Ruby stdlib implementations. A-ruby-core Area: Ruby Core types. A-ruby-stdlib Area: Ruby Standard Library packages. labels Aug 5, 2019
@lopopolo lopopolo removed this from the VM milestone Aug 6, 2019
lopopolo added a commit that referenced this issue Dec 1, 2019
The specs consisted of two parts:

- Class definition and metadata, capable of interfacing with the murby
  VM for `*mut RClass` and FQ name retrieval.
- A builder pattern for defining methods (and one day constants).

This commit turns `class::Spec` and `module::Spec` into read only
containers. `class::Builder` and `module::Builder` are introduced to
allow defining items on a spec and loading them into the mruby VM.

The addition of the builder structs makes it clear where to implement
new functionality like defining constants, see GH-27. The builders also
operate on spec references which means foreign core types and modules
can define items on any other type.

Because the specs are read only, they can be cloned freely.
@lopopolo
Copy link
Member Author

Closed by GH-526.

lopopolo added a commit that referenced this issue Feb 22, 2020
`Float` and `Regexp` both define constants by string formatting `i64`s
and `f64`s  into a code string with `format!` and evaling it on the
interpreter. This is not ideal.

GH-526 added constant definition APIs to `artichoke-core` and
implemented them for `artichoke-backend`. This commit wires it up in
`extn`. The resulting code has more localized failures - errors are
reported on the granularity of defining a single constant. The constant
values are converted into proper `Value`s directly from their native
Rust form.

See also GH-27, the issue referenced by both of the TODOs (the TODO in
`float.rs` refers to the issue number from lopopolo/ferrocarril before
it was migrated to the artichoke/artichoke repo).
lopopolo added a commit that referenced this issue Feb 22, 2020
Use constant definition APIs from artichoke-core in extn
@lopopolo lopopolo added the B-mruby Backend: Implementation of artichoke-core using mruby. label Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core traits and interpreter-agnostic Ruby Core and Ruby stdlib implementations. A-ruby-core Area: Ruby Core types. A-ruby-stdlib Area: Ruby Standard Library packages. B-mruby Backend: Implementation of artichoke-core using mruby.
Development

Successfully merging a pull request may close this issue.

1 participant