Permalink
Browse files

[bonsai] Generate the module and process UID for variables. Remove Ex…

…ecutable class.
  • Loading branch information...
ptal committed Apr 21, 2017
1 parent 2ae41f9 commit 1207220dab81820473e3fe3a5e9ceab03dfb4a31
View
@@ -63,7 +63,7 @@
<configuration>
<executable>bonsai</executable>
<arguments>
<argument>--main=GolombRuler</argument>
<argument>--main=GolombRuler.execute</argument>
<argument>-o ${project.build.directory}/generated-sources</argument>
<argument>${project.build.sourceDirectory}</argument>
</arguments>
@@ -12,7 +12,7 @@
import bonsai.runtime.choco.*;
import bonsai.runtime.sugarcubes.*;
public class GolombRuler implements Executable
public class GolombRuler
{
world_line VarStore domains = bot;
world_line ConstraintStore constraints = bot;
@@ -12,7 +12,7 @@
import bonsai.runtime.choco.*;
import bonsai.runtime.sugarcubes.*;
public class LatinSquare implements Executable
public class LatinSquare
{
world_line VarStore domains = bot;
world_line ConstraintStore constraints = bot;
@@ -11,7 +11,7 @@
import bonsai.runtime.choco.*;
import bonsai.runtime.sugarcubes.*;
public class NQueens implements Executable
public class NQueens
{
world_line VarStore domains = bot;
world_line ConstraintStore constraints = bot;
@@ -16,9 +16,9 @@
package test;
public class CannotFindModule implements Executable
public class CannotFindModule
{
proc execute() {
proc test() {
module NotFound notFound;
}
}
@@ -16,10 +16,10 @@
package test;
public class DuplicateAttribute implements Executable
public class DuplicateAttribute
{
single_time Dup d;
single_time Dup d;
proc execute() { nothing; }
proc test() { nothing; }
}
@@ -16,9 +16,9 @@
package test;
public class DuplicateVar implements Executable
public class DuplicateVar
{
proc execute() {
proc test() {
single_time Dup d;
single_time Dup d;
}
@@ -16,11 +16,11 @@
package test;
public class DuplicateAttributeVar implements Executable
public class DuplicateAttributeVar
{
single_time Dup d;
proc execute() {
proc test() {
single_time Dup d;
}
}
@@ -17,15 +17,15 @@
package test;
public class TwoDuplicateVar implements Executable
public class TwoDuplicateVar
{
single_time Dup d;
proc execute() {
proc test1() {
single_time Dup d;
}
proc execute2() {
proc test2() {
single_time Dup d;
}
}
@@ -17,12 +17,12 @@
package test;
public class DuplicateProc implements Executable
public class DuplicateProc
{
proc execute() { nothing; }
proc unique1() { nothing; }
proc dup() { nothing; }
proc dup() { nothing; }
proc unique() { nothing; }
proc unique2() { nothing; }
proc dup() { nothing; }
}
@@ -16,13 +16,13 @@
package test;
public class DistinctScope implements Executable
public class DistinctScope
{
proc execute() {
proc test1() {
single_time Dup d;
}
proc execute2() {
proc test2() {
single_time Dup d;
}
}
@@ -69,7 +69,7 @@
<executable>bonsai</executable>
<arguments>
<argument>--debug</argument>
<argument>--main=NQueens</argument>
<argument>--main=NQueens.execute</argument>
<argument>--lib=../../../libstd/src/</argument>
<argument>-o ${project.build.directory}/generated-sources</argument>
<argument>${project.build.sourceDirectory}</argument>
@@ -12,7 +12,7 @@
import bonsai.runtime.sugarcubes.*;
import bonsai.cp.core.*;
public class NQueens implements Executable
public class NQueens
{
private world_line VarStore domains = bot;
private world_line ConstraintStore constraints = bot;
View
@@ -63,8 +63,6 @@
<configuration>
<executable>bonsai</executable>
<arguments>
<argument>--main=NQueens</argument>
<argument>--debug</argument>
<argument>-o ${project.build.directory}/generated-sources</argument>
<argument>${project.build.sourceDirectory}</argument>
</arguments>
@@ -25,7 +25,7 @@
import bonsai.runtime.choco.*;
import bonsai.runtime.sugarcubes.*;
public class Branching implements Executable, Resettable<Branching>
public class Branching implements Resettable<Branching>
{
private ref world_line VarStore domains = bot;
private ref world_line ConstraintStore constraints = bot;
@@ -54,10 +54,6 @@ public void reset(Branching branching) {
this.val = branching.val;
}
public proc execute() {
split();
}
public proc exclude() {
loop {
when consistent |= Consistent.Unknown {
@@ -21,7 +21,7 @@
import bonsai.runtime.choco.*;
import bonsai.runtime.sugarcubes.*;
public class OneSolution implements Executable, Resettable<OneSolution>
public class OneSolution implements Resettable<OneSolution>
{
private ref single_time L<Consistent> consistent = bot;
@@ -22,7 +22,7 @@
import bonsai.runtime.choco.*;
import bonsai.runtime.sugarcubes.*;
public class Propagation implements Executable, Resettable<Propagation>
public class Propagation implements Resettable<Propagation>
{
private ref world_line VarStore domains = bot;
private ref world_line ConstraintStore constraints = bot;
@@ -21,7 +21,7 @@
import bonsai.runtime.choco.*;
import bonsai.runtime.sugarcubes.*;
public class Statistics implements Executable, Resettable<Statistics>
public class Statistics implements Resettable<Statistics>
{
public single_space transient L<BInteger> nodes = bot;
public world_line transient W<BInteger> depth = bot;
@@ -1,25 +0,0 @@
// Copyright 2016 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.runtime.sugarcubes;
import java.util.*;
import bonsai.runtime.core.*;
import inria.meije.rc.sugarcubes.implementation.*;
import inria.meije.rc.sugarcubes.*;
public interface Executable
{
public Program execute();
}
View
@@ -33,6 +33,7 @@ pub fn generate_module<'a>(context: &Context, module: JModule) -> Partial<String
for field in module.fields.clone() {
generate_spacetime_field(&mut fmt, field);
}
generate_object_uid(&mut fmt, &module);
generate_main_method(&context, &mut fmt, module.host.class_name);
for process in module.processes {
generate_process(&mut fmt, context, process);
@@ -128,6 +129,27 @@ fn generate_spacetime_field(fmt: &mut CodeFormatter, field: ModuleField) {
generate_java_field(fmt, jfield);
}
fn generate_object_uid(fmt: &mut CodeFormatter, module: &JModule) {
fmt.push_line("private static int __num_instances = -1;");
fmt.push_line("private int __object_instance;");
fmt.push_line("public String __uid(String var)");
fmt.open_block();
// return "[package]." + "[classname]." + __object_instance + "." + var;
fmt.push_line(&format!(
"return \"{}.\" + \"{}.\" + __object_instance + \".\" + var;",
module.host.package, module.host.class_name));
fmt.close_block();
}
fn generate_proc_uid(fmt: &mut CodeFormatter, process: &Process, proc_instance: String) {
fmt.push_line(&format!("{}++;", proc_instance));
fmt.push_line(&format!("int __proc_instance = {};", proc_instance));
fmt.push_line("java.util.function.Function<String, String> __proc_uid = ");
fmt.push_line(&format!(
" (var) -> __uid(\"{}.\" + __proc_instance + \".\" + var);",
process.name));
}
fn string_from_final(is_final: bool) -> String {
if is_final {
String::from("final ")
@@ -143,9 +165,12 @@ fn string_from_static(is_static: bool) -> String {
}
fn generate_process(fmt: &mut CodeFormatter, context: &Context, process: Process) {
let proc_instance = format!("__proc_{}_instance", process.name);
fmt.push_line(&format!("static int {} = -1;", proc_instance));
fmt.push_line(&format!(
"{} Program {}{}", process.visibility, process.name, process.params));
fmt.open_block();
generate_proc_uid(fmt, &process, proc_instance);
fmt.push_line("return");
fmt.indent();
generate_statement(fmt, context, process.body);
View
@@ -74,10 +74,10 @@ grammar! bonsai {
FQN::new(span, extend_front(first, rest))
}
java_class = PUBLIC CLASS identifier IMPLEMENTS list_java_ty LBRACE item+ RBRACE
java_class = PUBLIC CLASS identifier interfaces_list LBRACE item+ RBRACE
list_java_ty
= java_ty (COMMA java_ty)* > make_list_java_ty
interfaces_list
= IMPLEMENTS java_ty (COMMA java_ty)* > make_list_java_ty
/ "" > empty_java_ty_list
fn make_list_java_ty(first: JType, rest: Vec<JType>) -> Vec<JType> {
@@ -669,7 +669,7 @@ grammar! bonsai {
// fn test_grammar()
// {
// let state = bonsai::recognize_program(r#"
// public class Test implements Executable
// public class Test
// {
// // This is a test grammar.
// /* We can do multi-line comments

0 comments on commit 1207220

Please sign in to comment.