-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
Truffle rbx integration #2414
Truffle rbx integration #2414
Conversation
# raise PrimitiveFailure, "Time.now primitive failed" | ||
#end | ||
def self.now | ||
Rubinius.primitive :time_s_now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Primitive call here. Note the unusual semantics - fall through for cases not handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I wasn't following how this works.
And as a general comment: This looks like awesome progress and the absolute right direction (i.e., implementing large parts of the standard library in Ruby itself). This gives a couple of hundreds passing specs in just one go :)! |
@@ -192,7 +192,7 @@ public RubyBignum pow(RubyBignum a, RubyBignum b) { | |||
|
|||
} | |||
|
|||
@CoreMethod(names = "/", required = 1) | |||
@CoreMethod(names = {"/", "__slash__"}, required = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the addition of __slash__
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubinius calls it from here https://github.com/jruby/jruby/pull/2414/files#diff-1eabf0e4bde8dc8dce596aa4d27d7042R41. I didn't do the digging yet to figure out if it's supposed to mean something special - such as never monkey patched.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably their way to not be polluted by mathn
which redefines /
.
I wonder why div
or quo
is not sufficient though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__slash__
is used to define div
.
This looks great. I had a few small comments, but otherwise thumbs up from me to merge. |
@CompilerDirectives.TruffleBoundary | ||
@Specialization | ||
public boolean even(RubyBignum value) { | ||
return value.bigIntegerValue().getLowestSetBit() != 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's got to be a better way for this, but it seems even BigInteger.intValue()
goes to crazy lengths ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BigInteger is not highly optimised, so this is probably the least of our concerns with the performance of Bignum. It is cached, however, as it's used internally for many other operations.
* Node which wraps a {@link RubiniusPrimitiveNode}, providing the implicit control flow that you get with calls to | ||
* Rubinius primitives. | ||
*/ | ||
public class CallRubiniusPrimitiveNode extends RubyNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for not having a boolean flag all around!
Looks good to me for compatibility! |
Yeah, I'll remove those. If we're going to worry about performance we need a good benchmark first! |
Conflicts: core/src/main/java/org/jruby/truffle/nodes/core/TimeNodes.java core/src/main/java/org/jruby/truffle/runtime/RubyContext.java core/src/main/java/org/jruby/truffle/runtime/core/RubyTime.java
This is the first big push towards implementing the Rubinius primitive system. Before we were using the standard library
Struct
from Rubinius, which was pure Ruby code. Here I've pulled inRational
andTime
, which is tightly integrated into the Rubinius primitive system (they're like native calls).Doing this we've got the majority of the specs passing for both of these classes in about a day. The work we're doing here will also apply for some standard library classes which also uses these primitives.
This is quite a lot of code here, but you can skip most of the Ruby files. To help you understand what's going on, I've added one comment where Ruby code calls a primitive, and another where that's implemented in Java.
@eregon, @nirvdrum, @thomaswue please review
@headius, @enebo, if you want to keep up with what we're doing, this might be a good commit to cast an eye over, but don't feel obliged to spend your time reviewing our code