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

Closes #165. Use native types for primitives. #166

Merged
merged 2 commits into from
Feb 25, 2018

Conversation

faultyserver
Copy link
Member

Integer, Float, Boolean, and String are now all implemented directly by Crystal's native Int64, Float64, Bool, and String types.

#165 covers most of what went into the implementation changes, so I won't bother repeating it here. The only difference is that instead of changing how type lookup works, the native types have been re-opened to add the needed type_name, truthy?, and ivars properties on them. For these types, referring to ivars will raise an exception.

In the past, collision between the Myst-level type `Value` and Crystal's native `Value` class has been cumbersome (requiring namespacing as `Myst::Value`). Renaming to `MTValue` clears that confusion, and makes it more obvious where we're talking about Myst values.
…d `MutableValue`s.

Instead of using wrapper classes for the primitive types of `TInteger`, `TFloat`, `TString`, and `TBoolean`, these values are now implemented directly as the underlying Crystal types: `Int64`, `Float64`, `String`, and `Bool` respectively. `TList` and `TMap` may also be converted over to use `Array` and `Hash` directly in the near future.

`TNil` and `TSymbol` will remain non-native types. `TNil` will remain because it would conflict in many cases with Crystal's standard library returning `nil` in many cases (this is already enough of an issue with `false`). `TSymbol` needs to remain to be able to retain the name of the Symbol at run time.

There are two main reasons for implementing this change:
- **Performance improvements.** While not overly substantial (~0.1% speed-wise in a super-quick test benchmark), the interpreter no longer needs to allocate a whole object on the heap to represent integers, floats, or booleans (strings will still be allocated on the heap). In the long run, this will help with both speed and memory.
- **Cleaner native library work.** Native library methods no longer need to wrap and unwrap values to work with them. Since these values are literally the Crystal objects themselves, they can be manipulated directly.
@faultyserver faultyserver added this to the Next milestone Feb 25, 2018
@faultyserver faultyserver merged commit 3ec71d3 into myst-lang:master Feb 25, 2018
@faultyserver faultyserver deleted the native_primitives branch February 25, 2018 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant