Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] Truffle#graal? #substate? and #version
  • Loading branch information
chrisseaton committed Jan 26, 2015
1 parent 8ddcf61 commit dafa4cc
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Expand Up @@ -101,6 +101,7 @@ public void init() {
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, MethodNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, UnboundMethodNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, ByteArrayNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TruffleNodesFactory.getFactories());

// Give the core library manager a chance to tweak some of those methods

Expand Down
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyString;

@CoreClass(name = "Truffle")
public abstract class TruffleNodes {

@CoreMethod(names = "graal?", onSingleton = true)
public abstract static class GraalNode extends CoreMethodNode {

public GraalNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public GraalNode(GraalNode prev) {
super(prev);
}

@Specialization
public boolean graal() {
return Truffle.getRuntime().getName().toLowerCase().contains("graal");
}

}

@CoreMethod(names = "substrate?", onSingleton = true)
public abstract static class SubstrateNode extends CoreMethodNode {

public SubstrateNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public SubstrateNode(SubstrateNode prev) {
super(prev);
}

@Specialization
public boolean substrate() {
return false;
}

}

@CoreMethod(names = "version", onSingleton = true)
public abstract static class VersionNode extends CoreMethodNode {

public VersionNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public VersionNode(VersionNode prev) {
super(prev);
}

@Specialization
public RubyString version() {
return getContext().makeString(System.getProperty("graal.version", "unknown"));
}

}

}

0 comments on commit dafa4cc

Please sign in to comment.