Skip to content

Commit 8dfb496

Browse files
committed
Got non-lambda method body tests passing
1 parent 897529c commit 8dfb496

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

Lang/src/main/java/chipmunk/vm/BytecodeInterpreter.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public static void dispatch(Fiber fiber, CMethod method, int ip){
9797
fiber.push(method.module.constants[fetchInt(code, ip + 1)]);
9898
ip += 5;
9999
}
100+
case EQ -> {
101+
var t = (Boolean) fiber.invokeValue(method, ip, "equals", 1, true);
102+
fiber.push(t);
103+
ip++;
104+
//ip = testJump(v.intValue() < 0, fiber, ip, fetchInt(code, ip + 1), 5);
105+
}
100106
case LT -> {
101107
var v = (Number) fiber.invokeValue(method, ip, "compare", 1, true);
102108
fiber.push(v.intValue() < 0);
@@ -121,6 +127,11 @@ public static void dispatch(Fiber fiber, CMethod method, int ip){
121127
ip += 6;
122128
fiber.invoke(method, ip - 6, name, pCount, false);
123129
}
130+
case RANGE -> {
131+
fiber.push(fetchByte(code, ip + 1) != 0);
132+
fiber.push(fiber.invokeValue(method, ip, "range", 2, true));
133+
ip += 2;
134+
}
124135
case LIST -> {
125136
fiber.push(new CList(fetchInt(code, ip + 1)));
126137
ip += 5;
@@ -129,6 +140,10 @@ public static void dispatch(Fiber fiber, CMethod method, int ip){
129140
fiber.push(new CMap(fetchInt(code, ip + 1)));
130141
ip += 5;
131142
}
143+
case ITER -> {
144+
fiber.invoke(method, ip, "iterator", 0, false);
145+
ip++;
146+
}
132147
case GETAT -> {
133148
fiber.invoke(method, ip, "getAt", 1, false);
134149
ip++;

Lang/src/main/java/chipmunk/vm/ChipmunkScript.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import chipmunk.vm.invoke.ChipmunkLibraries;
3131
import chipmunk.vm.invoke.security.LinkingPolicy;
3232
import chipmunk.vm.invoke.security.SecurityMode;
33-
import chipmunk.vm.jvm.JvmCompiler;
3433

3534
import java.io.IOException;
3635
import java.util.*;
@@ -190,15 +189,16 @@ public CModule getCModule(String name) throws ModuleLoadException {
190189
return module;
191190
}
192191

193-
public void createEntryFiber(Object... args){
192+
public void initEntryFiber(Object... args){
194193
var module = getCModule(entryPoint.getModule());
195194
var fiber = newFiber();
196195
fiber.initialize(module.cls.getInstanceMethod(entryPoint.getMethod()), args);
196+
setCurrentFiber(fiber);
197197
}
198198

199199
// TODO - run from suspended state
200200

201-
public Object run(Object[] args){
201+
public Object run(Object... args){
202202

203203
try {
204204
getCModule(entryPoint.getModule());
@@ -225,10 +225,6 @@ public void setCurrentFiber(Fiber f){
225225
currentFiber.set(f);
226226
}
227227

228-
public Object run(){
229-
return run(new Object[]{});
230-
}
231-
232228
public void interrupt(){
233229
currentFiber.getAndUpdate(f -> {
234230
if(f != null){

Lang/src/main/java/chipmunk/vm/ChipmunkVM.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public ChipmunkScript compileScript(CompilationUnit unit) {
121121

122122
ChipmunkScript script = new ChipmunkScript(this);
123123
script.getModuleLoader().setDelegate(unit.getModuleLoader());
124+
script.setEntryPoint(new EntryPoint(unit.getEntryModule(), unit.getEntryMethodName()));
124125
script.setId(scriptIds.incrementAndGet());
125126
script.setLinkPolicy(defaultLinkPolicy);
126127
script.setLibs(defaultLibraries);
@@ -207,7 +208,7 @@ public CLinker createLinker(){
207208
}
208209

209210
public CompletableFuture<Object> runAsync(ChipmunkScript script) {
210-
return invokeAsync(script, script, "main");
211+
return runInScriptPool(script, () -> script.run());
211212
}
212213

213214
public CompletableFuture<Object> runAsync(ChipmunkScript script, Object[] params) {

Lang/src/main/java/chipmunk/vm/Fiber.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public void invoke(CMethod method, int ip, String name, int count, boolean opera
146146
args[i] = pop();
147147
}
148148

149+
// TODO - throw a Chipmunk-specific NPE with a Chipmunk stack trace
149150
var targetType = target.getClass();
150151
var argTypes = CallUtil.types(args);
151152

Lang/src/main/java/chipmunk/vm/invoke/ChipmunkLibraries.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ private List<LibraryMethod> getLibraryMethodsForType(Class<?> receiverType){
5454
}
5555

5656
public Method getMethod(Class<?> returnType, String name, Class<?>[] argTypes){
57+
// TODO - ideally we'd be able to link against zero-argument library overrides
58+
if(argTypes.length == 0){
59+
return null;
60+
}
5761
Class<?> receiverType = argTypes[0];
5862
if(receiverType == null){
5963
receiverType = Object.class;

0 commit comments

Comments
 (0)