Permalink
Browse files

[runtime][compiler] Link the compiler and runtime, remove dependency …

…to SugarCubes, first full stack program to compile (Simple).
  • Loading branch information...
ptal committed Nov 9, 2018
1 parent 6588115 commit cf254e18865f5649094ef59247298d9dd7834fa2
@@ -36,7 +36,7 @@ We provide a [manual installation procedure](manual-installation.md) in case the
### Update
Update the compiler and runtime (without updating SugarCubes and Choco libraries):
Update the compiler and runtime (without the external libraries such as Choco):
```sh
.\update.sh
@@ -47,7 +47,6 @@ Update the compiler and runtime (without updating SugarCubes and Choco libraries
```sh
cargo uninstall bonsai
# Remove runtime in the Maven local database
rm ~/.m2/repository/inria
rm ~/.m2/repository/bonsai
```
@@ -0,0 +1,86 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bonsai</groupId>
<artifactId>examples</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Simple</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>bonsai</groupId>
<artifactId>runtime</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<excludes>
<exclude>**/*.bonsai.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>Simple.bonsai.java</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>bonsai</executable>
<arguments>
<argument>--debug</argument>
<argument>--main=Simple.test</argument>
<argument>-o ${project.build.directory}/generated-sources</argument>
<argument>${project.build.sourceDirectory}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<goals>
<goal>add-source</goal>
</goals>
<phase>process-sources</phase>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,5 @@
#!/bin/sh
mvn clean &&
mvn compile &&
mvn exec:java -Dexec.mainClass="bonsai.examples.Simple"
@@ -0,0 +1,22 @@
// Copyright 2018 Pierre Talbot (IRCAM)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package bonsai.examples;
import java.util.*;
public class Simple
{
public proc test() = nothing
}
@@ -26,15 +26,10 @@ cd libstd # (inside the bonsai repository)
## Installing the Bonsai runtime
The Bonsai runtime has two dependencies: [SugarCubes](http://jeanferdysusini.free.fr/index.php?action=SC) for synchronous and reactive programming and [Choco](http://www.choco-solver.org) for constraint programming.
1. Installing SugarCubes in the local Maven database:
```sh
curl http://jeanferdysusini.free.fr/v4.0/SugarCubesv4.0.0a5.jar > /tmp/SugarCubesv4.0.0a5.jar
mvn install:install-file -DgroupId=inria.meije.rc -DartifactId=SugarCubes -Dversion=4.0.0a5 -Dpackaging=jar -Dfile=/tmp/SugarCubesv4.0.0a5.jar
```
2. Installing Bonsai runtime in the local Maven database:
```sh
cd runtime/ # (inside the bonsai repository)
./install.sh
```
The Bonsai runtime has a dependency on [Choco](http://www.choco-solver.org) for constraint programming.
Choco will be downloaded automatically from the Maven central repository.
However, we need to install the Bonsai runtime in the local Maven database:
```sh
cd runtime/ # (inside the bonsai repository)
./install.sh
```
@@ -22,10 +22,5 @@
<artifactId>choco-solver</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>inria.meije.rc</groupId>
<artifactId>SugarCubes</artifactId>
<version>4.0.0a5</version>
</dependency>
</dependencies>
</project>
@@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package bonsai.runtime.synchronous.expressions;
package bonsai.runtime.synchronous;
import java.util.*;
import java.util.function.*;
import bonsai.runtime.core.*;
import bonsai.runtime.synchronous.*;
import bonsai.runtime.synchronous.interfaces.*;
import bonsai.runtime.synchronous.expressions.*;
import bonsai.runtime.synchronous.env.*;
public abstract class NAryCall extends ASTNode
@@ -23,10 +23,12 @@
{
private Program body;
private Environment env;
private boolean debug;
public SpaceMachine(Program body, int numLayers) {
this.body = body;
this.env = new Environment(numLayers);
public SpaceMachine(Program body, int numLayers, boolean debug) {
this.body = new QFUniverse(body);
this.env = new Environment(numLayers+1);
this.debug = debug;
}
// Returns `true` if the program is paused (through a `stop` or `pause up` statement).
@@ -12,12 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package bonsai.runtime.synchronous.expressions;
package bonsai.runtime.synchronous.statements;
import java.util.*;
import java.util.function.*;
import bonsai.runtime.core.*;
import bonsai.runtime.synchronous.*;
import bonsai.runtime.synchronous.expressions.*;
import bonsai.runtime.synchronous.interfaces.*;
import bonsai.runtime.synchronous.env.*;
@@ -15,6 +15,8 @@
package bonsai.runtime.synchronous;
import java.util.*;
import java.util.function.*;
import bonsai.runtime.lattices.*;
import bonsai.runtime.synchronous.*;
import bonsai.runtime.synchronous.statements.*;
import bonsai.runtime.synchronous.interfaces.*;
@@ -34,22 +36,49 @@ public void assertTerminated(SpaceMachine machine) {
}
}
public Program createNestedQFUniverse(int remaining) {
public Program createNestedQFUniverse(Program code, int remaining) {
if (remaining == 0) {
return new Nothing();
return code;
}
else {
return new QFUniverse(createNestedQFUniverse(remaining-1));
return createNestedQFUniverse(new QFUniverse(code), remaining-1);
}
}
@Test
public void testNothingQFUniverse() {
for(int numLayers=1; numLayers < 4; numLayers++) {
for(int numLayers=0; numLayers < 4; numLayers++) {
currentTest = "universe^"+numLayers+" nothing end";
Program process = createNestedQFUniverse(numLayers);
SpaceMachine machine = new SpaceMachine(process, numLayers);
Program process = createNestedQFUniverse(new Nothing(), numLayers);
SpaceMachine machine = new SpaceMachine(process, numLayers, true);
assertTerminated(machine);
}
}
@Test
public void testProcedureQFUniverse() {
for(int numLayers=0; numLayers < 4; numLayers++) {
currentTest = "universe^"+numLayers+" f() end";
LMax numCall = new LMax(0);
Consumer<ArrayList<Object>> f = (args) -> numCall.inc();
ProcedureCall procedure = new ProcedureCall(new ArrayList(), f);
Program process = createNestedQFUniverse(procedure, numLayers);
SpaceMachine machine = new SpaceMachine(process, numLayers, true);
assertTerminated(machine);
assertThat(currentTest, numCall, equalTo(new LMax(1)));
}
}
// @Test throw CausalException
// public void testNonCausalProgram() {
// currentTest = "universe f(read x, write x) end";
// LMax numCall = new LMax(0);
// Consumer<ArrayList<Object>> f = (args) -> fail(currentTest+": function f should not be called");
// List<Access> args = List.of(new ReadAccess("x"), new WriteAccess("x"));
// ProcedureCall procedure = new ProcedureCall(args, f);
// Program process = createNestedQFUniverse(procedure, numLayers);
// SpaceMachine machine = new SpaceMachine(process, numLayers, true);
// assertTerminated(machine);
// assertThat(currentTest, numCall, equalTo(new LMax(1)));
// }
}
@@ -3,26 +3,19 @@
import subprocess
rust_nightly_version = "nightly-2018-08-18"
sugarcubes_jar = "/tmp/SugarCubesv4.0.0a5.jar"
bonsai_runtime_jar = "target/runtime-1.0-SNAPSHOT.jar"
bonsai_runtime_src = "runtime/"
bonsai_libstd_src = "libstd/"
bonsai_libstd_jar = "target/libstd-1.0-SNAPSHOT.jar"
startup_script = "unknown"
lib_path = "unknown"
ending_message = "\nSuccesfully installed bonsai (and its standard library), SugarCubes and bonsai runtime.\n"
ending_message = "\nSuccesfully installed bonsai (and its standard library) and bonsai runtime.\n"
install_rust_cmd = ["rustup", "override", "set", rust_nightly_version]
list_target_rustup_cmd = ["rustup", "target", "list"]
clone_bonsai_cmd = ["git", "clone", "https://github.com/ptal/bonsai.git"]
install_bonsai_cmd = ["cargo", "install"]
install_bonsai_cmd = ["cargo", "install", "--force"]
try_bonsai = ["bonsai", "-h"]
download_sugarcubes_cmd = ["curl",
"http://jeanferdysusini.free.fr/v4.0/SugarCubesv4.0.0a5.jar",
"-o", sugarcubes_jar]
def mvn_install_cmd(groupId, artifactId, version, file):
return ["mvn", "install:install-file",
"-DgroupId={}".format(groupId),
@@ -35,7 +28,6 @@ def mvn_install_cmd(groupId, artifactId, version, file):
mvn_package_cmd = ["mvn", "package", "-quiet", "--fail-fast"]
install_sugarcubes_cmd = mvn_install_cmd("inria.meije.rc", "SugarCubes", "4.0.0a5", sugarcubes_jar)
install_bonsai_runtime_cmd = mvn_install_cmd("bonsai", "runtime", "1.0", bonsai_runtime_jar)
install_bonsai_libstd_cmd = mvn_install_cmd("bonsai", "libstd", "1.0", bonsai_libstd_jar)
@@ -94,17 +86,6 @@ def install_bonsai_libstd():
subprocess.run(install_bonsai_libstd_cmd).check_returncode()
print("`Bonsai libstd` has been installed.")
def install_sugarcubes():
print("Installing SugarCubes Java libary...")
subprocess.run(download_sugarcubes_cmd)
try:
subprocess.run(install_sugarcubes_cmd).check_returncode()
print("`SugarCubes` has been installed.")
except OSError as e:
if e.errno == os.errno.ENOENT:
print("Please install Maven and come back! (see our `README.md` or `http://maven.apache.org`)\n")
exit()
def install_bonsai_runtime():
print("Installing Bonsai runtime Java library...")
with cd(bonsai_runtime_src):
@@ -115,9 +96,8 @@ def install_bonsai_runtime():
def installing_chain():
install_rust()
install_bonsai()
install_sugarcubes()
install_bonsai_runtime()
install_bonsai_libstd()
# install_bonsai_libstd()
print(ending_message)
installing_chain()
@@ -54,6 +54,14 @@ impl<'a> ModuleCompiler<'a>
for import in &jclass.imports {
self.fmt.push_line(&format!("import {};", import));
}
self.runtime_imports();
}
fn runtime_imports(&mut self) {
self.fmt.push_line("import bonsai.runtime.synchronous.*;");
self.fmt.push_line("import bonsai.runtime.synchronous.env.*;");
self.fmt.push_line("import bonsai.runtime.synchronous.statements.*;");
self.fmt.push_line("import bonsai.runtime.synchronous.interfaces.*;");
}
fn class(&mut self, module: JModule) {
@@ -116,11 +124,10 @@ impl<'a> ModuleCompiler<'a>
if let Some(main_expr) = main_expr {
self.fmt.push_line("public static void main(String[] args)");
self.fmt.open_block();
let machine_method = if self.session.config().debug { "createDebug" } else { "create" };
self.fmt.push_block(format!("\
Program program = {};\n\
SpaceMachine machine = SpaceMachine.{}(program);\n\
machine.execute();", main_expr, machine_method));
SpaceMachine machine = new SpaceMachine(program,1,{});\n\
machine.execute();", main_expr, self.session.config().debug));
self.fmt.close_block();
self.fmt.newline();
}
@@ -182,7 +189,7 @@ impl<'a> ModuleCompiler<'a>
}
fn runtime_init_method(&mut self, module: &JModule) {
self.fmt.push_line("public void __init(SpaceEnvironment senv)");
self.fmt.push_line("public void __init(Layer senv)");
self.fmt.open_block();
self.fmt.push_line("__num_instances++;");
self.fmt.push_line("__object_instance = __num_instances;");
@@ -201,7 +208,7 @@ impl<'a> ModuleCompiler<'a>
}
fn runtime_destroy_method(&mut self, module: &JModule) {
self.fmt.push_line("public void __destroy(SpaceEnvironment senv)");
self.fmt.push_line("public void __destroy(Layer senv)");
self.fmt.open_block();
for field in module.fields.clone() {
let binding = field.binding;
Oops, something went wrong.

0 comments on commit cf254e1

Please sign in to comment.