Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[truffle] Implement nqp::getcurhllsym, nqp::bindcurhllsym, nqp::gethl…
…lsym, nqp::bindhllsym
- Loading branch information
Showing
11 changed files
with
283 additions
and
1 deletion.
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
15 changes: 15 additions & 0 deletions
15
src/vm/jvm/runtime/org/perl6/nqp/truffle/GlobalContext.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,15 @@ | ||
package org.perl6.nqp.truffle; | ||
|
||
import org.perl6.nqp.truffle.runtime.HLL; | ||
import java.util.HashMap; | ||
|
||
public class GlobalContext { | ||
static GlobalContext SINGLETON = new GlobalContext(); | ||
|
||
public HashMap<String, HLL> hlls; | ||
|
||
public GlobalContext() { | ||
hlls = new HashMap<String, HLL>(); | ||
} | ||
} | ||
|
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
55 changes: 55 additions & 0 deletions
55
src/vm/jvm/runtime/org/perl6/nqp/truffle/NQPCompUnitScope.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,55 @@ | ||
package org.perl6.nqp.truffle; | ||
|
||
import org.perl6.nqp.truffle.runtime.HLL; | ||
import java.util.HashMap; | ||
|
||
import com.oracle.truffle.api.frame.FrameSlot; | ||
|
||
import java.util.HashMap; | ||
|
||
public class NQPCompUnitScope extends NQPScope { | ||
NQPScope outer; | ||
HLL currentHLL; | ||
HashMap<String, HLL> hlls; | ||
|
||
public NQPCompUnitScope(NQPScope outer, HashMap<String, HLL> hlls, String hll) { | ||
this.outer = outer; | ||
this.hlls = hlls; | ||
|
||
if (!this.hlls.containsKey(hll)) { | ||
hlls.put(hll, new HLL()); | ||
} | ||
|
||
this.currentHLL = hlls.get(hll); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pmurias
Author
Contributor
|
||
} | ||
|
||
@Override | ||
public HashMap<String, HLL> getHLLs() { | ||
return hlls; | ||
} | ||
|
||
@Override | ||
public HLL getCurrentHLL() { | ||
return currentHLL; | ||
} | ||
|
||
@Override | ||
public FrameSlot addLexical(String name) { | ||
return outer.addLexical(name); | ||
} | ||
|
||
@Override | ||
public FoundLexical findLexical(String name, int depth) { | ||
return outer.findLexical(name, depth); | ||
} | ||
|
||
@Override | ||
public FrameSlot addLocal(String name) { | ||
return outer.addLocal(name); | ||
} | ||
|
||
@Override | ||
public FrameSlot findLocal(String name) { | ||
return outer.findLocal(name); | ||
} | ||
} |
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
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
31 changes: 31 additions & 0 deletions
31
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPBindcurhllsymNode.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,31 @@ | ||
package org.perl6.nqp.truffle.nodes.expression; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.NodeInfo; | ||
import org.perl6.nqp.truffle.nodes.NQPNode; | ||
import org.perl6.nqp.truffle.nodes.NQPObjNode; | ||
import org.perl6.nqp.truffle.runtime.HLL; | ||
import org.perl6.nqp.truffle.NQPScope; | ||
import org.perl6.nqp.dsl.Deserializer; | ||
|
||
@NodeInfo(shortName = "bindcurhllsym") | ||
public final class NQPBindcurhllsymNode extends NQPObjNode { | ||
private final HLL currentHLL; | ||
@Child private NQPNode symbolNode; | ||
@Child private NQPNode valueNode; | ||
|
||
public NQPBindcurhllsymNode(HLL currentHLL, NQPNode symbolNode, NQPNode valueNode) { | ||
this.currentHLL = currentHLL; | ||
this.symbolNode = symbolNode; | ||
this.valueNode = valueNode; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
return currentHLL.bindSymbol(symbolNode.executeStr(frame), valueNode.execute(frame)); | ||
} | ||
|
||
@Deserializer("bindcurhllsym") | ||
public static NQPBindcurhllsymNode deserialize(NQPScope scope, NQPNode symbolNode, NQPNode valueNode) { | ||
return new NQPBindcurhllsymNode(scope.getCurrentHLL(), symbolNode, valueNode); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPBindhllsymNode.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,43 @@ | ||
package org.perl6.nqp.truffle.nodes.expression; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.NodeInfo; | ||
import java.util.HashMap; | ||
import org.perl6.nqp.truffle.nodes.NQPNode; | ||
import org.perl6.nqp.truffle.nodes.NQPObjNode; | ||
import org.perl6.nqp.truffle.NQPScope; | ||
import org.perl6.nqp.truffle.runtime.HLL; | ||
import org.perl6.nqp.dsl.Deserializer; | ||
|
||
@NodeInfo(shortName = "bindhllsym") | ||
public final class NQPBindhllsymNode extends NQPObjNode { | ||
public final HashMap<String, HLL> hlls; | ||
@Child private NQPNode hllNameNode; | ||
@Child private NQPNode symbolNode; | ||
@Child private NQPNode valueNode; | ||
|
||
public NQPBindhllsymNode(HashMap<String, HLL> hlls, NQPNode hllNameNode, NQPNode symbolNode, NQPNode valueNode) { | ||
this.hlls = hlls; | ||
this.hllNameNode = hllNameNode; | ||
this.symbolNode = symbolNode; | ||
this.valueNode = valueNode; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
String hllName = hllNameNode.executeStr(frame); | ||
String symbol = symbolNode.executeStr(frame); | ||
Object value = valueNode.execute(frame); | ||
|
||
if (!hlls.containsKey(hllName)) { | ||
hlls.put(hllName, new HLL()); | ||
} | ||
|
||
return hlls.get(hllName).bindSymbol(symbol, value); | ||
} | ||
|
||
@Deserializer("bindhllsym") | ||
public static NQPBindhllsymNode deserialize(NQPScope scope, NQPNode hllNameNode, NQPNode symbolNode, NQPNode valueNode) { | ||
return new NQPBindhllsymNode(scope.getHLLs(), hllNameNode, symbolNode, valueNode); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPGetcurhllsymNode.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,29 @@ | ||
package org.perl6.nqp.truffle.nodes.expression; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.NodeInfo; | ||
import org.perl6.nqp.truffle.nodes.NQPNode; | ||
import org.perl6.nqp.truffle.nodes.NQPObjNode; | ||
import org.perl6.nqp.truffle.runtime.HLL; | ||
import org.perl6.nqp.truffle.NQPScope; | ||
import org.perl6.nqp.dsl.Deserializer; | ||
|
||
@NodeInfo(shortName = "getcurhllsym") | ||
public final class NQPGetcurhllsymNode extends NQPObjNode { | ||
private final HLL currentHLL; | ||
@Child private NQPNode symNode; | ||
|
||
public NQPGetcurhllsymNode(HLL currentHLL, NQPNode symNode) { | ||
this.currentHLL = currentHLL; | ||
this.symNode = symNode; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
return currentHLL.getSymbol(symNode.executeStr(frame)); | ||
} | ||
|
||
@Deserializer("getcurhllsym") | ||
public static NQPGetcurhllsymNode deserialize(NQPScope scope, NQPNode symbolNode) { | ||
return new NQPGetcurhllsymNode(scope.getCurrentHLL(), symbolNode); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/expression/NQPGethllsymNode.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,40 @@ | ||
package org.perl6.nqp.truffle.nodes.expression; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.NodeInfo; | ||
import java.util.HashMap; | ||
import org.perl6.nqp.truffle.NQPScope; | ||
import org.perl6.nqp.truffle.nodes.NQPNode; | ||
import org.perl6.nqp.truffle.nodes.NQPObjNode; | ||
import org.perl6.nqp.truffle.runtime.HLL; | ||
import org.perl6.nqp.truffle.runtime.NQPNull; | ||
import org.perl6.nqp.dsl.Deserializer; | ||
|
||
@NodeInfo(shortName = "gethllsym") | ||
public final class NQPGethllsymNode extends NQPObjNode { | ||
public final HashMap<String, HLL> hlls; | ||
@Child private NQPNode hllNameNode; | ||
@Child private NQPNode symbolNode; | ||
|
||
public NQPGethllsymNode(HashMap<String, HLL> hlls, NQPNode hllNameNode, NQPNode symbolNode) { | ||
this.hlls = hlls; | ||
this.hllNameNode = hllNameNode; | ||
this.symbolNode = symbolNode; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
String hllName = hllNameNode.executeStr(frame); | ||
String symbolName = symbolNode.executeStr(frame); | ||
|
||
if (!hlls.containsKey(hllName)) { | ||
return NQPNull.SINGLETON; | ||
} | ||
|
||
return hlls.get(hllName).getSymbol(symbolName); | ||
} | ||
|
||
@Deserializer("gethllsym") | ||
public static NQPGethllsymNode deserialize(NQPScope scope, NQPNode hllNameNode, NQPNode symbolNode) { | ||
return new NQPGethllsymNode(scope.getHLLs(), hllNameNode, symbolNode); | ||
} | ||
} |
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,26 @@ | ||
package org.perl6.nqp.truffle.runtime; | ||
|
||
import org.perl6.nqp.truffle.runtime.NQPNull; | ||
import java.util.HashMap; | ||
|
||
public final class HLL { | ||
HashMap<String, Object> symbols; | ||
|
||
public HLL() { | ||
symbols = new HashMap<String, Object>(); | ||
} | ||
|
||
public Object getSymbol(String key) { | ||
Object value = symbols.get(key); | ||
if (value == null) { | ||
return NQPNull.SINGLETON; | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
public Object bindSymbol(String key, Object value) { | ||
symbols.put(key, value); | ||
return value; | ||
} | ||
} |
how performance-sensitive is this? wouldn't it make more sense to assign it to the
new HLL()
in the!containsKey
case?