Skip to content

Commit

Permalink
Fixed client/server to refer to io not IO type
Browse files Browse the repository at this point in the history
Looking at the source of stdlib’s io.wyv - whoever wrote it made the
type “io” not “IO” which seems weird. So I rewrote client and server to
use io until you decide which one you want as otherwise var io and type
IO conflict:

import io
val ioobj = io(java)

// Open a connection to a server at port 1254
val s1 = ioobj.makeSocket("localhost", 1254)

PS I suspect the stdlib should have IO though!
  • Loading branch information
potanin committed Jan 16, 2018
1 parent 7ae0567 commit 088f486
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions examples/io-lib/client.wyv
Expand Up @@ -5,15 +5,15 @@

require java
require stdout
import IO
val io = IO(java)
import io
val ioobj = io(java)

// Open a connection to a server at port 1254
val s1 = io.makeSocket("localhost", 1254)
val s1 = ioobj.makeSocket("localhost", 1254)

// Get an input file handle from the socket and read input
val s1in = s1.getInputStream()
val dis = io.makeDataInputStream(s1in)
val dis = ioobj.makeDataInputStream(s1in)

// Read in from server
val str = dis.readUTF()
Expand Down
8 changes: 4 additions & 4 deletions examples/io-lib/server.wyv
Expand Up @@ -5,12 +5,12 @@

require java
require stdout
import IO
val io = IO(java)
import io
val ioobj = io(java)


// Make a ServerSocket on port 1254
val serverSocket = io.makeServerSocket(1254)
val serverSocket = ioobj.makeServerSocket(1254)

// Wait and accept a connection
stdout.print("Waiting for a client connection...\n")
Expand All @@ -20,7 +20,7 @@ stdout.print("Accepted a connection.\n")
// Get a communication stream associated with the socket
val s1out = s1.getOutputStream()

val dos = io.makeDataOutputStream(s1out)
val dos = ioobj.makeDataOutputStream(s1out)

dos.writeUTF("This is a server message\n")
stdout.print("Wrote to DataOutputStream\n")
Expand Down
8 changes: 4 additions & 4 deletions tools/src/wyvern/tools/Interpreter.java
Expand Up @@ -55,14 +55,14 @@ public static void main(String[] args) {
// sanity check: is the wyvernPath a valid directory?
if (!Files.isDirectory(Paths.get(wyvernPath))) {
System.err.println("Error: WYVERN_HOME is not set to a valid Wyvern project directory");
return;
return;
}
final InterpreterState state = new InterpreterState(InterpreterState.PLATFORM_JAVA, rootDir, new File(wyvernPath));
Module m = state.getResolver().load("unknown", filepath.toFile(), true);
IExpr program = m.getExpression();
program = state.getResolver().wrap(program, m.getDependencies());
program = (IExpr)PlatformSpecializationVisitor.specializeAST((ASTNode)program, "java", Globals.getGenContext(state));
program = (IExpr)PlatformSpecializationVisitor.specializeAST((ASTNode)program, "java", Globals.getGenContext(state));

/*ExpressionAST ast = (ExpressionAST) TestUtil.getNewAST(filepath.toFile());
GenContext genCtx = Globals.getGenContext(state);
Expression program = ast.generateIL(genCtx, null);*/
Expand All @@ -79,7 +79,7 @@ public static void main(String[] args) {

// used to set WYVERN_HOME when called programatically
public static final ThreadLocal<String> wyvernHome = new ThreadLocal<String>();

// used to set WYVERN_ROOT when called programatically
public static final ThreadLocal<String> wyvernRoot = new ThreadLocal<String>();
}
50 changes: 25 additions & 25 deletions tools/src/wyvern/tools/tests/ExampleTests.java
Expand Up @@ -22,7 +22,7 @@
import wyvern.tools.tests.suites.RegressionTests;

/** Runs the Wyvern compiler on the example source code in the wyvern/examples directory tree
*
*
* @author aldrich
*
*/
Expand All @@ -39,12 +39,12 @@ public class ExampleTests {
public void testHello() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "rosetta.hello", Util.unitType(), Util.unitValue());
}

@Test
public void testHelloExplicit() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "rosetta.hello-explicit", Util.unitType(), Util.unitValue());
}

@Test
public void testFib() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "rosetta.fibonacci", Util.unitType(), Util.unitValue());
Expand All @@ -54,57 +54,57 @@ public void testFib() throws ParseException {
public void testFactorial() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "rosetta.factorial", Util.unitType(), Util.unitValue());
}

@Test
public void testTSL() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "tsls.postfixClient", Util.intType(), new IntegerLiteral(7));
}

@Test
public void testBox() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "introductory.box", Util.intType(), new IntegerLiteral(15));
}

@Test
public void testFunctions() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "introductory.functions", Util.intType(), new IntegerLiteral(6));
}

@Test
public void testObjects() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "introductory.objects", Util.intType(), new IntegerLiteral(7));
}

@Test
public void testTailCalls() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "introductory.tailcalls", Util.intType(), new IntegerLiteral(10000));
}

@Test
public void testStrings() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "introductory.strings", Util.booleanType(), new BooleanLiteral(true));
}

@Test
public void testCell() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "introductory.cell", Util.intType(), new IntegerLiteral(3));
}

@Test
public void testCellClient() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "modules.cellClient", Util.intType(), new IntegerLiteral(7));
}

@Test
public void testCellModuleClient() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "modules.cellModuleClient", Util.intType(), new IntegerLiteral(2));
}

@Test
public void testCellClientMain() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "modules.cellClientMain", Util.intType(), new IntegerLiteral(1));
}

@Test
public void testOptionParameterized() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "introductory.optionP", Util.intType(), new IntegerLiteral(15));
Expand All @@ -114,53 +114,53 @@ public void testOptionParameterized() throws ParseException {
public void testPalindromeChecker() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "rosetta/check-palindrome", Util.unitType(), Util.unitValue());
}

@Test
@Category(CurrentlyBroken.class)
public void testListParameterized() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "introductory.listP", Util.intType(), new IntegerLiteral(15));
}

@Test
public void testJavaFFI() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "ffi.callFromJava", Util.unitType(), Util.unitValue());
}

@Test
public void testCrossPlatformHello() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "xplatform.hello-via-writer", Util.unitType(), Util.unitValue());
}

@Test
public void testExplicitCrossPlatformHello() throws ParseException {
TestUtil.doTestScriptModularly(PATH, "xplatform.hello-explicit-writer", Util.unitType(), Util.unitValue());
}

@Test
public void testPythonCompilerOnScript() {
String[] args = new String[] { TestUtil.EXAMPLES_PATH + "pong/pong.wyv" };
PythonCompiler.wyvernHome.set("..");
PythonCompiler.wyvernRoot.set(TestUtil.EXAMPLES_PATH + "pong/");
PythonCompiler.main(args);
}

@Test
public void testIOLibServerClient() throws ParseException {
ExecutorService executor = Executors.newFixedThreadPool(2);

Future<?> futureServer = executor.submit(() -> {
try {
TestUtil.doTestScriptModularly(PATH, "io-lib.server", Util.unitType(), Util.unitValue());
} catch (Exception e) {
throw new RuntimeException(e);
}
});

// We need to let the server start and get to waiting/blocking on a socket with accept before we start client.
// Thus I wait 3 seconds. The following code will also catch any ToolError that might have happened in the test.

try {
futureServer.get(10, TimeUnit.SECONDS);
futureServer.get(3, TimeUnit.SECONDS);
} catch (InterruptedException e) {
// This one is OK.
} catch (TimeoutException e) {
Expand All @@ -184,7 +184,7 @@ public void testIOLibServerClient() throws ParseException {
try {
if (!executor.awaitTermination(3, TimeUnit.SECONDS)) {
executor.shutdownNow();
}
}
} catch (InterruptedException e) {
} finally {
executor.shutdownNow();
Expand Down

0 comments on commit 088f486

Please sign in to comment.