forked from graalvm/simplelanguage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
608 additions
and
222 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
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
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
27 changes: 27 additions & 0 deletions
27
language/src/main/java/com/banshay/language/WzrdTypeSystem.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,27 @@ | ||
package com.banshay.language; | ||
|
||
import com.banshay.language.types.WzrdNull; | ||
import com.oracle.truffle.api.dsl.ImplicitCast; | ||
import com.oracle.truffle.api.dsl.TypeCast; | ||
import com.oracle.truffle.api.dsl.TypeCheck; | ||
import com.oracle.truffle.api.dsl.TypeSystem; | ||
|
||
@TypeSystem({int.class, double.class, long.class, boolean.class}) | ||
public class WzrdTypeSystem { | ||
|
||
@TypeCheck(WzrdNull.class) | ||
public static boolean isNull(Object value) { | ||
return value == WzrdNull.INSTANCE; | ||
} | ||
|
||
@TypeCast(WzrdNull.class) | ||
public static WzrdNull asWzrdNull(Object value) { | ||
assert isNull(value); | ||
return WzrdNull.INSTANCE; | ||
} | ||
|
||
@ImplicitCast | ||
public static double castInt(int value) { | ||
return value; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
language/src/main/java/com/banshay/language/nodes/WzrdEvalNode.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,74 @@ | ||
package com.banshay.language.nodes; | ||
|
||
import com.banshay.language.WzrdContext; | ||
import com.banshay.language.WzrdLanguage; | ||
import com.banshay.language.types.WzrdNull; | ||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; | ||
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; | ||
import com.oracle.truffle.api.RootCallTarget; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.nodes.DirectCallNode; | ||
import com.oracle.truffle.api.nodes.RootNode; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public final class WzrdEvalNode extends RootNode { | ||
|
||
private final Map<String, RootCallTarget> functions; | ||
|
||
@CompilationFinal private boolean registered; | ||
|
||
@Child private DirectCallNode mainCallNode; | ||
|
||
private WzrdLanguage language; | ||
|
||
public WzrdEvalNode( | ||
WzrdLanguage language, | ||
Map<String, RootCallTarget> functions, | ||
RootCallTarget rootFunction) { | ||
super(language); | ||
this.language = language; | ||
this.functions = Collections.unmodifiableMap(functions); | ||
this.mainCallNode = rootFunction != null ? DirectCallNode.create(rootFunction) : null; | ||
} | ||
|
||
@Override | ||
public boolean isInternal() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected boolean isInstrumentable() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "root eval"; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
if (language.isSingleContext()) { | ||
if (!registered) { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
registerFunctions(); | ||
registered = true; | ||
} | ||
}else{ | ||
registerFunctions(); | ||
} | ||
if (mainCallNode == null) { | ||
return WzrdNull.INSTANCE; | ||
}else{ | ||
var arguments = frame.getArguments(); | ||
return mainCallNode.call(arguments); | ||
} | ||
} | ||
|
||
@TruffleBoundary | ||
private void registerFunctions(){ | ||
WzrdContext.get(this).getFunctionRegistry().register(functions); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
language/src/main/java/com/banshay/language/nodes/expressions/ArgumentNode.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,26 @@ | ||
package com.banshay.language.nodes.expressions; | ||
|
||
import com.banshay.language.nodes.toplevel.WzrdExpressionNode; | ||
import com.banshay.language.types.WzrdNull; | ||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import com.oracle.truffle.api.profiles.BranchProfile; | ||
|
||
public class ArgumentNode extends WzrdExpressionNode { | ||
|
||
private final int index; | ||
private final BranchProfile outOfBoundsToken = BranchProfile.create(); | ||
|
||
public ArgumentNode(int index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public Object executeGeneric(VirtualFrame frame) { | ||
var arguments = frame.getArguments(); | ||
if (index < arguments.length) { | ||
return arguments[index]; | ||
} | ||
outOfBoundsToken.enter(); | ||
return WzrdNull.INSTANCE; | ||
} | ||
} |
Oops, something went wrong.