Skip to content

Commit

Permalink
final set of REPL changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontatton committed Jan 16, 2020
1 parent ad52003 commit 11b5433
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/tools/com/concurnas/conc/ConcWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private static String createJVMArgs(Path dir, boolean modules) throws IOExceptio
sb.append("--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED\n");

sb.append("--add-opens=java.base/java.nio=ALL-UNNAMED\n");
sb.append("--add-opens=java.base/java.time=ALL-UNNAMED\n");
sb.append("--add-opens=java.base/com.concurnas.bootstrap.lang=ALL-UNNAMED");

return sb.toString().trim();
Expand Down
13 changes: 12 additions & 1 deletion src/tools/com/concurnas/repl/REPL.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private static List<ErrorHolder> remoteSupressedErrors(HashSet<ErrorHolder> ers)
REPLTopLevelComponent replCtxt = er.getHeadContext();
if(null != replCtxt) {
String prefix = formatTopLevelElement(replCtxt);
if(!prefix.contains("$")) {
if(null != prefix && !prefix.contains("$")) {
er = er.copyWithErPrefix(prefix);
}
}
Expand Down Expand Up @@ -743,6 +743,17 @@ public String processInput(String input){

private void tidyScopeFrameDirtyVars(REPLTopLevelComponent tla) {
if(tla.getErrors()) {

if(tla instanceof AssignExisting) {
if(!((AssignExisting)tla).isReallyNew) {
return;//skip if not new, dont remove previous var
}
}else if(tla instanceof AssignNew) {
if(!((AssignNew)tla).isReallyNew) {
return;//skip if not new, dont remove previous var
}
}

if(null != this.moduleCompiler.moduleLevelFrame) {
this.moduleCompiler.moduleLevelFrame.removeVariable(tla.getName());
}
Expand Down
8 changes: 4 additions & 4 deletions src/tools/com/concurnas/repl/REPLCodeRepointStateHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ public void boxIfPrimative(String desc) {
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
if(owner.equals(classNameToRedirect)) {
if(opcode == PUTSTATIC) {
mv.visitFieldInsn(GETSTATIC, "com/concurnas/repl/REPLRuntimeState", "vars", "Ljava/util/concurrent/ConcurrentHashMap;");
mv.visitFieldInsn(GETSTATIC, "com/concurnas/repl/REPLRuntimeState", "vars", "Ljava/util/Map;");
genericSswap(desc);
mv.visitLdcInsn(name);
genericSswap(desc);
//thing to object type
boxIfPrimative(desc);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/ConcurrentHashMap", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true);
mv.visitInsn(POP);
return;
}else if(opcode == GETSTATIC) {
mv.visitFieldInsn(GETSTATIC, "com/concurnas/repl/REPLRuntimeState", "vars", "Ljava/util/concurrent/ConcurrentHashMap;");
mv.visitFieldInsn(GETSTATIC, "com/concurnas/repl/REPLRuntimeState", "vars", "Ljava/util/Map;");
mv.visitLdcInsn(name);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/ConcurrentHashMap", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
//object type to thing
unboxToRequiredType(desc);
return;
Expand Down
8 changes: 5 additions & 3 deletions src/tools/com/concurnas/repl/REPLRuntimeState.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.concurnas.repl;

import java.util.concurrent.ConcurrentHashMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.concurnas.lang.Shared;

public class REPLRuntimeState {
@Shared
public static ConcurrentHashMap<String, Object> vars = new ConcurrentHashMap<String, Object>();
public static Map<String, Object> vars = Collections.synchronizedMap(new HashMap<String, Object>());

public static void reset() {
vars = new ConcurrentHashMap<String, Object>();
vars = Collections.synchronizedMap(new HashMap<String, Object>());
}
}
8 changes: 4 additions & 4 deletions src/tools/com/concurnas/repl/REPLTaskMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ protected void makeApply(ClassWriter cw) {
String var = itr.next();

mv.visitLabel(new Label());
mv.visitFieldInsn(GETSTATIC, "com/concurnas/repl/REPLRuntimeState", "vars", "Ljava/util/concurrent/ConcurrentHashMap;");
mv.visitFieldInsn(GETSTATIC, "com/concurnas/repl/REPLRuntimeState", "vars", "Ljava/util/Map;");
mv.visitLdcInsn(var);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/ConcurrentHashMap", "containsKey", "(Ljava/lang/Object;)Z", false);
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "containsKey", "(Ljava/lang/Object;)Z", true);
Label onmissing = new Label();
mv.visitJumpInsn(IFEQ, onmissing);
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
mv.visitInsn(DUP);
mv.visitLdcInsn(var + " ==> ");
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
mv.visitFieldInsn(GETSTATIC, "com/concurnas/repl/REPLRuntimeState", "vars", "Ljava/util/concurrent/ConcurrentHashMap;");
mv.visitFieldInsn(GETSTATIC, "com/concurnas/repl/REPLRuntimeState", "vars", "Ljava/util/Map;");
mv.visitLdcInsn(var);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/ConcurrentHashMap", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
mv.visitMethodInsn(INVOKESTATIC, "com/concurnas/bootstrap/lang/Stringifier", "stringify", "(Ljava/lang/Object;)Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
//if(n++ < sz) {
Expand Down
13 changes: 13 additions & 0 deletions tests/com/concurnas/repl/REPLTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void after() {

//////////////////////////////////////////////////////////


@Test
public void createVar() {
assertEquals("x ==> 10", repl.processInput("x = 10"));
Expand Down Expand Up @@ -1243,6 +1244,18 @@ public void gpukernel() throws Exception {
}


@Test
public void nullableTypes() throws Exception {
assertEquals("v ==> hi", repl.processInput("v String? = 'hi'"));
assertEquals("v ==> null", repl.processInput("v=null"));
}

@Test
public void dontremovePrevOKVarDuetoFaultyAssign() throws Exception {
assertEquals("v ==> hi", repl.processInput("v String = 'hi'"));
assertEquals("| ERROR 1:0 in v - Assingment can be null, but assignment type is not nullable", repl.processInput("v=null"));
assertEquals("v ==> hi", repl.processInput("v"));
}


}
1 change: 1 addition & 0 deletions tools/eclipse/vmArguments-Java9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@
--add-exports java.base/com.concurnas.bootstrap.runtime.transactions=ALL-UNNAMED
--add-exports java.base/jdk.internal.ref=ALL-UNNAMED
--add-opens java.base/java.nio=ALL-UNNAMED
--add-opens java.base/java.time=ALL-UNNAMED
--add-opens java.base/com.concurnas.bootstrap.lang=ALL-UNNAMED
-Djava.io.tmpdir=./tmp

0 comments on commit 11b5433

Please sign in to comment.