Commit Graph

98 Commits

Author SHA1 Message Date
Peter Wagenet ca60150948
Revert "Allow calling init seperately" 2019-07-29 13:12:56 -07:00
Yehuda Katz 73e0534a17
Merge pull request #148 from konstin/split_out_init
Allow calling init seperately
2019-07-29 11:17:25 -07:00
Godfrey Chan 750be7995d [BREAKING] Allow arbitrary attributes for classes
We no longer automatically derive Clone and Debug on the structs.

Fixes #143
2018-06-16 09:24:04 -04:00
Godfrey Chan a8e1f37362 Allow arbitrary attributes for methods 2018-06-16 09:23:54 -04:00
Godfrey Chan af2042154e give better error messages
Fixes #144 (somewhat)
2018-06-16 09:00:35 -04:00
konstin f5840040ef Fixes for the the examples 2018-06-14 17:43:32 +02:00
konstin 6733f74b0d Use cargo metadata to determine the target directory
The command otherwise failed when used with cargo workspaces
2018-06-14 17:43:32 +02:00
konstin f148ac0d62 Move class intialization to method
This allows generating the init function from class names alone
2018-06-14 17:43:32 +02:00
Terence Lee 088a636192 allow private constructor. also add docopt example
You can do this by setting:

```
def initialize(helix, ...) {
}
```

Right now this only works on the constructor and only unexported is
supported.
2018-06-14 00:09:09 -07:00
Terence Lee 7dbc5cf3e9 refactor parser to support more method attributes 2018-06-14 00:01:46 -07:00
Godfrey Chan 16eb12ca98 Add missing coercions for `usize` and `isize` 2018-06-03 10:32:52 +09:00
Godfrey Chan b6a3e5acc9
Merge pull request #150 from tildeio/safer-strings
Safer string coercions
2018-06-01 17:13:19 -07:00
Godfrey Chan faaa6b1b26 Safer string coercions
Previously, we blindly assume Ruby strings are UTF-8 and turn them
into Rust Strings (which *are* assumed to be UTF-8). This is clearly
unsafe so this commit adds some checks to cofirm that and generate
type errors appropiately.
2018-06-02 08:42:12 +09:00
Godfrey Chan fca1620cf8 Add coercions for tuples 2018-04-26 17:57:56 -07:00
Godfrey Chan 7e2ca2f418 Ensure classes with a struct implements initialize 2018-04-25 13:45:04 -07:00
Delton Ding b00d9ad0d4 Fix typo 2018-01-01 00:22:53 +08:00
Godfrey Chan c485529059 Merge pull request #128 from tildeio/consume-self
Allow consuming self in methods
2017-10-09 22:18:30 -07:00
Godfrey Chan 3adc5fd5b7 Allow consuming self in methods
Using the object (calling Rust methods from Ruby) after consuming
would raise a RuntimeError.

Also fixes some parser bugs that previously allowed invalid syntax
through in the arguments position.
2017-10-09 11:20:42 -07:00
Godfrey Chan 0cdd075c22 Add Symbol coercion
The main use case for symbols is to use them as a HashMap key. However,
this introduces a GC problem – we cannot store Ruby values in the heap
without properly marking/registering them, otherwise they might get
GC'ed by Ruby unexpectedly. (In fact, this is already a problem if you
have a `Vec<VALUE>`.)

I tried to avoid introducing additional problems by pinning down any
symbols that goes thought the coercion protocol. This is probably
overly aggressive, as it would cause any dynamic symbols (e.g.
`String#to_sym`) to become un-GC-able. We can revisit this once we
have a more general-purpose system to encode pinning semantics in
the type system.
2017-10-07 19:29:33 -07:00
Godfrey Chan 5ce16e9550 Add hash <-> HashMap coercion 2017-10-06 14:54:11 -07:00
Godfrey Chan ff2a9d2a59 Add slice -> Ruby array 2017-10-05 10:47:42 -07:00
Godfrey Chan f584a08f5b Some coercion house-keeping 2017-10-05 09:58:42 -07:00
Godfrey Chan 259b556943 Improve error message 2017-10-05 09:44:48 -07:00
Godfrey Chan dac16373ae Rename to match Rust types 2017-10-05 09:37:45 -07:00
Peter Wagenet ce8f4430bc
Add Array coercions 2017-10-05 00:12:42 -05:00
Terence Lee aec4d726e1
implement fmt::Display for Error 2017-10-05 00:11:19 -05:00
Godfrey Chan d0a4460dbb Don't panic! 2017-09-26 21:42:02 -04:00
Godfrey Chan cfdf0ce1ea Refactor `FromRuby`
- Make `Checked` an associated type. This allows `from_ruby` to carry
  over additional information (useful for `Option` etc)

- Move `ToRust` into `FromRuby` to ensure both get implemented together
2017-09-26 21:36:28 -04:00
Godfrey Chan d9ace88cc9 Remove unused UncheckedValue 2017-09-26 16:40:13 -04:00
Terence Lee 6d3675c0f8 change UncheckedValue::to_checked to FromRuby::from_ruby
This allows helix gems to create type coercions
2017-09-26 16:35:02 -04:00
Godfrey Chan b9f090ed28 Cleanup downcast code 2017-09-26 14:27:39 -04:00
Godfrey Chan 9b638ac151 Test new error macros 2017-09-26 12:52:26 -04:00
Godfrey Chan 144157c064 [WIP] Exceptions cleanup 2017-09-26 11:03:39 -04:00
Godfrey Chan ab7ba71b6a Allow `to_ruby` to fail
This switches the `to_ruby` trait method to return a `Result`, which
allows the coercion to fail.

The most obvious use case for this is to implement coercion for the
`Result` type in Rust (included in this PR), but there could be other
reasons why a coercion might fail. For example, if we were to implement
a coercion between a Rust and Ruby regular expression, the coercion
could fail if the Rust regular expression uses some Rust-specific
features that are not supported by the Ruby regular expression
implementation.
2017-09-20 18:50:09 +09:00
Godfrey Chan 58d8da10f2 Use `compile_errors!` to report parse errors
Unfortunately, we will lose the span for these errors.

(See rust-lang/rust#44535)
2017-09-13 02:50:56 -07:00
Godfrey Chan f64727dbea Support #[ruby_name] remapping for classes 2017-09-11 02:01:02 -07:00
Godfrey Chan eeb4d56b08 Remove outdated/incorrect expansion rule in parser
Class names are not passed as meta in the AST, so this rule
wouldn't have matched anything.
2017-09-11 01:39:26 -07:00
Godfrey Chan 856244698f Use cstr-macro crate 2017-09-11 00:57:44 -07:00
Yehuda Katz 68b217c16a Improve "implicit coercion" language
Closes #85
2017-05-18 08:53:52 -07:00
Yehuda Katz cd495e44f2 Merge pull request #96 from tildeio/unwind-safe
Allow any closure to be used with catch_panic
2017-05-15 21:48:29 -07:00
Yehuda Katz ea64284443 Fix compat with serde_json
The previous code was relying on the accidental fact that only a single
impl of PartialEq<usize> existed. serde_json defines another impl of
PartialEq<usize>, which causes the constraint to be insufficient, which
results in a compile error when serde_json is added to a project with
Helix.

This commit forces the VALUE into a usize eagerly, avoiding this
inference issue.

Fixes #93

h/t @alyssais

Thanks to @nikomatsakis for helping me figure out the root cause.
2017-05-15 18:08:16 -07:00
Yehuda Katz 27d4a7458b Allow any closure to be used with catch_panic
Asserting unwind safe is supposed to mean that we poison mutable object
involved in the panic (to prevent objects that were involved in panics
from triggering errors over and over again) and we should do that in the
future.
2017-05-15 16:22:48 -07:00
Corey Farwell aa53e47dd8 Prefer `Option` combinator over `match`. 2017-05-04 21:30:46 -04:00
Corey Farwell a6bca6a8a6 Simplify conditional expression. 2017-05-04 21:30:46 -04:00
Corey Farwell d1e869853a Replace nested matching with `Option` combinators. 2017-05-04 21:30:46 -04:00
Corey Farwell 03adf88e22 Fewer allocations by making function signatures take `&CStr`s.
As discussed in https://github.com/tildeio/helix/pull/76.

[breaking-change]
2017-05-02 22:32:44 -04:00
Peter Wagenet 8d67226300 Raise TypeError on bad initialize 2017-04-27 12:58:43 -07:00
Yehuda Katz d668a31150 Rename declare_types! to ruby! 2017-04-21 17:54:52 -07:00
Yehuda Katz b72c306cd4 Support #[ruby_name = "blank?"]
Support using attributes to specify the Ruby name for a method.

At the same time, refactor the macro.
2017-04-21 17:53:10 -07:00
Yehuda Katz ea51eeb654 Refactor codegen into more pieces 2017-04-21 16:22:01 -07:00