-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to get a basic truffle build going
- Loading branch information
Showing
6 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
truffle/src/main/java/org/bykn/bosatsu/truffle/AdditionNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.bykn.bosatsu.truffle; | ||
import com.oracle.truffle.api.dsl.NodeChild; | ||
|
||
@NodeChild("leftNode") @NodeChild("rightNode") | ||
public abstract class AdditionNode extends BosatsuNode { | ||
protected int addInts(int leftValue, int rightValue) { | ||
return leftValue + rightValue; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
truffle/src/main/java/org/bykn/bosatsu/truffle/BosatsuNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.bykn.bosatsu.truffle; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.Node; | ||
|
||
public abstract class BosatsuNode extends Node { | ||
public abstract int executeInt(VirtualFrame frame); | ||
} |
21 changes: 21 additions & 0 deletions
21
truffle/src/main/java/org/bykn/bosatsu/truffle/BosatsuRootNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.bykn.bosatsu.truffle; | ||
|
||
import com.oracle.truffle.api.nodes.RootNode; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
|
||
class BosatsuRootNode extends RootNode { | ||
@SuppressWarnings("FieldMayBeFinal") | ||
@Child | ||
private BosatsuNode exprNode; | ||
|
||
public BosatsuRootNode(BosatsuNode exprNode) { | ||
super(null); | ||
|
||
this.exprNode = exprNode; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
return this.exprNode.executeInt(frame); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
truffle/src/main/java/org/bykn/bosatsu/truffle/IntNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.bykn.bosatsu.truffle; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
|
||
public class IntNode extends BosatsuNode { | ||
private final int value; | ||
|
||
public IntNode(int value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public int executeInt(VirtualFrame frame) { | ||
return this.value; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
truffle/src/test/scala/org/bykn/bosatsu/truffle/TruffleTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.bykn.bosatsu.truffle | ||
|
||
class TruffleTest extends munit.FunSuite { | ||
test("add 12+32") { | ||
val exprNode = AdditionNodeGen.create( | ||
new IntNode(12), | ||
new IntNode(34)); | ||
val rootNode = new BosatsuRootNode(exprNode) | ||
val callTarget = rootNode.getCallTarget() | ||
|
||
val result = callTarget.call() | ||
|
||
assertEquals(46, result); | ||
} | ||
} |