Commit 0ff4b12c authored by Jeff Smits's avatar Jeff Smits

More example inputs to test out the backtracking semantics of the interpreter,...

More example inputs to test out the backtracking semantics of the interpreter, hybrid interpreter, and compiler. The choice_* are most important, the compiler, interpreter and strs all give something different for them. They're named after what the compiler does.
parent c0864cf0
Specification([Signature([Constructors([])]),Strategies([SDefT("main_0_0",[],[],Scope(["b_0"],Let([SDefT("c_0",[],[],Seq(Match(Var("b_0")),Fail))],GuardedLChoice(CallT(SVar("c_0"),[],[]),Id,Build(Var("b_0"))))))])])
\ No newline at end of file
Specification([Signature([Constructors([ExtOpDecl("Nil",ConstType(Sort("List",[SortVar("a")])))])]),Strategies([SDefT("main_0_0",[],[],Scope(["c_0","d_0"],Seq(Match(Var("c_0")),Seq(Build(Anno(Str("Expected behaviour: failure"),Op("Nil",[]))),Seq(CallT(SVar("debug_0_0"),[],[]),Seq(Build(Var("c_0")),GuardedLChoice(Seq(Match(Var("d_0")),Fail),Id,Seq(Build(Var("d_0")),CallT(SVar("debug_1_0"),[Build(Anno(Str("Well, it succeeded.. b was: "),Op("Nil",[])))],[]))))))))),ExtSDef("debug_0_0",[],[]),ExtSDef("debug_1_0",[VarDec("r_13",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[]))))],[])])])
\ No newline at end of file
......@@ -5,4 +5,4 @@ strategies
// f always fails, but it binds b before that. In a guarded choice, the binding to b needs to be undone. But if you
// compile this program with -O 0 (no optimisations), f stays a separate strategy and becomes a closure inside the
// execution environment. Interaction between closures and backtracking can be trick, hence this "test".
main = where(<debug> "Expected behaviour: failure"); {b: let f = ?b; fail in f <+ !b end }
main = where(<debug> "Expected behaviour: failure"); {b: let f = ?b; fail in f <+ !b; debug(!"Well, it succeeded.. b was: ") end }
Specification([Signature([Constructors([ExtOpDecl("Nil",ConstType(Sort("List",[SortVar("a")])))])]),Strategies([SDefT("main_0_0",[],[],Scope(["c_0","d_0"],Seq(Match(Var("c_0")),Seq(Build(Anno(Str("Expected behaviour: failure"),Op("Nil",[]))),Seq(CallT(SVar("debug_0_0"),[],[]),Seq(Build(Var("c_0")),CallT(SVar("if_3_0"),[Seq(Match(Var("d_0")),Fail),Id,Seq(Build(Var("d_0")),CallT(SVar("debug_1_0"),[Build(Anno(Str("Well, it succeeded.. b was: "),Op("Nil",[])))],[]))],[]))))))),ExtSDef("debug_0_0",[],[]),ExtSDef("debug_1_0",[VarDec("r_13",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[]))))],[]),ExtSDef("if_3_0",[VarDec("c_23",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[])))),VarDec("d_23",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[])))),VarDec("e_23",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[]))))],[])])])
\ No newline at end of file
module bt_if
imports libstratego-lib
strategies
// EXPECTED BEHAVIOUR: program fails at runtime because of unbound b
// f always fails, but it binds b before that. In a guarded choice, the binding to b needs to be undone. But if you
// compile this program with -O 0 (no optimisations), f stays a separate strategy and becomes a closure inside the
// execution environment. Interaction between closures and backtracking can be trick, hence this "test".
main = where(<debug> "Expected behaviour: failure"); {b: let f = ?b; fail in if(f,id,!b;debug(!"Well, it succeeded.. b was: ")) end }
Specification([Signature([Constructors([ExtOpDecl("Nil",ConstType(Sort("List",[SortVar("a")])))])]),Strategies([SDefT("main_0_0",[],[],Scope(["c_0","d_0"],Seq(Match(Var("d_0")),Seq(CallT(SVar("if_3_0"),[Seq(Match(Var("c_0")),Fail),Id,Seq(Build(Var("c_0")),CallT(SVar("debug_1_0"),[Build(Anno(Str("hi"),Op("Nil",[])))],[]))],[]),Build(Var("d_0")))))),ExtSDef("debug_1_0",[VarDec("r_13",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[]))))],[]),ExtSDef("if_3_0",[VarDec("c_23",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[])))),VarDec("d_23",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[])))),VarDec("e_23",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[]))))],[])])])
\ No newline at end of file
module bt_if2
imports libstratego-lib
strategies
main = where(let g = ?b; fail in if(g,id,!b; debug(!"hi")) end)
Specification([Signature([Constructors([ExtOpDecl("Nil",ConstType(Sort("List",[SortVar("a")])))])]),Strategies([SDefT("main_0_0",[],[],Scope(["b_0"],Seq(GuardedLChoice(Seq(Build(Anno(Int("1"),Op("Nil",[]))),Seq(Match(Var("b_0")),Fail)),Id,Id),Seq(Build(Anno(Int("2"),Op("Nil",[]))),Seq(Match(Var("b_0")),CallT(SVar("debug_1_0"),[Build(Anno(Str("success"),Op("Nil",[])))],[])))))),ExtSDef("debug_1_0",[VarDec("o_13",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[]))))],[])])])
\ No newline at end of file
import org.strategoxt.stratego_lib.*;
import org.strategoxt.lang.*;
import org.spoofax.interpreter.terms.*;
import static org.strategoxt.lang.Term.*;
import org.spoofax.interpreter.library.AbstractPrimitive;
import java.util.ArrayList;
import java.lang.ref.WeakReference;
@SuppressWarnings("all") public class choice_failure
{
protected static final boolean TRACES_ENABLED = true;
protected static ITermFactory constantFactory;
private static WeakReference<Context> initedContext;
private static boolean isIniting;
protected static IStrategoTerm const2;
protected static IStrategoTerm const1;
protected static IStrategoTerm const0;
public static IStrategoConstructor _consConc_2;
public static IStrategoConstructor _consNone_0;
public static IStrategoConstructor _consSome_1;
public static Context init(Context context)
{
synchronized(choice_failure.class)
{
if(isIniting)
return null;
try
{
isIniting = true;
ITermFactory termFactory = context.getFactory();
if(constantFactory == null)
{
initConstructors(termFactory);
initConstants(termFactory);
}
if(initedContext == null || initedContext.get() != context)
{
org.strategoxt.stratego_lib.Main.init(context);
context.registerComponent("choice_failure");
}
initedContext = new WeakReference<Context>(context);
constantFactory = termFactory;
}
finally
{
isIniting = false;
}
return context;
}
}
public static Context init()
{
return init(new Context());
}
public static void main(String args[])
{
Context context = init();
context.setStandAlone(true);
try
{
IStrategoTerm result;
try
{
result = context.invokeStrategyCLI(main_0_0.instance, "choice_failure", args);
}
finally
{
context.getIOAgent().closeAllFiles();
}
if(result == null)
{
System.err.println("choice_failure" + (TRACES_ENABLED ? ": rewriting failed, trace:" : ": rewriting failed"));
context.printStackTrace();
context.setStandAlone(false);
System.exit(1);
}
else
{
System.out.println(result);
context.setStandAlone(false);
System.exit(0);
}
}
catch(StrategoErrorExit exit)
{
context.setStandAlone(false);
System.err.println(exit.getLocalizedMessage());
System.exit(exit.getValue());
}
catch(StrategoExit exit)
{
context.setStandAlone(false);
System.exit(exit.getValue());
}
}
public static IStrategoTerm mainNoExit(String ... args) throws StrategoExit
{
return mainNoExit(new Context(), args);
}
public static IStrategoTerm mainNoExit(Context context, String ... args) throws StrategoExit
{
try
{
init(context);
return context.invokeStrategyCLI(main_0_0.instance, "choice_failure", args);
}
finally
{
context.getIOAgent().closeAllFiles();
}
}
public static Strategy getMainStrategy()
{
return main_0_0.instance;
}
public static void initConstructors(ITermFactory termFactory)
{
_consConc_2 = termFactory.makeConstructor("Conc", 2);
_consNone_0 = termFactory.makeConstructor("None", 0);
_consSome_1 = termFactory.makeConstructor("Some", 1);
}
public static void initConstants(ITermFactory termFactory)
{
const0 = termFactory.makeString("success");
const1 = termFactory.makeInt(1);
const2 = termFactory.makeInt(2);
}
@SuppressWarnings("all") public static class main_0_0 extends Strategy
{
public static main_0_0 instance = new main_0_0();
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
{
context.push("main_0_0");
Fail0:
{
IStrategoTerm b_0 = null;
IStrategoTerm term0 = term;
Success0:
{
Fail1:
{
term = choice_failure.const1;
b_0 = choice_failure.const1;
if(true)
break Fail1;
if(true)
break Success0;
}
term = term0;
}
term = choice_failure.const2;
if(b_0 == null)
;
else
if(b_0 != term && !b_0.match(term))
break Fail0;
term = debug_1_0.instance.invoke(context, term, lifted0.instance);
if(term == null)
break Fail0;
context.popOnSuccess();
if(true)
return term;
}
context.popOnFailure();
return null;
}
}
@SuppressWarnings("all") private static final class lifted0 extends Strategy
{
public static final lifted0 instance = new lifted0();
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
{
Fail2:
{
term = choice_failure.const0;
if(true)
return term;
}
return null;
}
}
public static void registerInterop(org.spoofax.interpreter.core.IContext context, Context compiledContext)
{
new InteropRegisterer().registerLazy(context, compiledContext, InteropRegisterer.class.getClassLoader());
}
@SuppressWarnings("unused") public static class InteropRegisterer extends org.strategoxt.lang.InteropRegisterer
{
@Override public void register(org.spoofax.interpreter.core.IContext context, Context compiledContext)
{
register(context, compiledContext, context.getVarScope());
}
@Override public void registerLazy(org.spoofax.interpreter.core.IContext context, Context compiledContext, ClassLoader classLoader)
{
registerLazy(context, compiledContext, classLoader, context.getVarScope());
}
private void register(org.spoofax.interpreter.core.IContext context, Context compiledContext, org.spoofax.interpreter.core.VarScope varScope)
{
compiledContext.registerComponent("choice_failure");
choice_failure.init(compiledContext);
varScope.addSVar("main_0_0", new InteropSDefT(main_0_0.instance, context));
}
private void registerLazy(org.spoofax.interpreter.core.IContext context, Context compiledContext, ClassLoader classLoader, org.spoofax.interpreter.core.VarScope varScope)
{
compiledContext.registerComponent("choice_failure");
choice_failure.init(compiledContext);
varScope.addSVar("main_0_0", new InteropSDefT(classLoader, "choice_failure$main_0_0", context));
}
}
}
\ No newline at end of file
module choice_failure
imports libstratego-lib
strategies
s = where(!"We now expect a to be bound to 1, so the next strategy expressions should fail. If they don't you will see success printed"; debug)
main = (!1; ?a; fail <+ id); s; !2; ?a; debug(!"success") // we expect failure before the debug statement
Specification([Signature([Constructors([ExtOpDecl("Nil",ConstType(Sort("List",[SortVar("a")])))])]),Strategies([SDefT("main_0_0",[],[],Scope(["b_0"],Seq(GuardedLChoice(Seq(Build(Anno(Int("1"),Op("Nil",[]))),Seq(Match(Var("b_0")),Fail)),Id,Seq(Build(Anno(Int("2"),Op("Nil",[]))),Match(Var("b_0")))),CallT(SVar("debug_1_0"),[Build(Anno(Str("success"),Op("Nil",[])))],[])))),ExtSDef("debug_1_0",[VarDec("o_13",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[]))))],[])])])
\ No newline at end of file
import org.strategoxt.stratego_lib.*;
import org.strategoxt.lang.*;
import org.spoofax.interpreter.terms.*;
import static org.strategoxt.lang.Term.*;
import org.spoofax.interpreter.library.AbstractPrimitive;
import java.util.ArrayList;
import java.lang.ref.WeakReference;
@SuppressWarnings("all") public class choice_success
{
protected static final boolean TRACES_ENABLED = true;
protected static ITermFactory constantFactory;
private static WeakReference<Context> initedContext;
private static boolean isIniting;
protected static IStrategoTerm const2;
protected static IStrategoTerm const1;
protected static IStrategoTerm const0;
public static IStrategoConstructor _consConc_2;
public static IStrategoConstructor _consNone_0;
public static IStrategoConstructor _consSome_1;
public static Context init(Context context)
{
synchronized(choice_success.class)
{
if(isIniting)
return null;
try
{
isIniting = true;
ITermFactory termFactory = context.getFactory();
if(constantFactory == null)
{
initConstructors(termFactory);
initConstants(termFactory);
}
if(initedContext == null || initedContext.get() != context)
{
org.strategoxt.stratego_lib.Main.init(context);
context.registerComponent("choice_success");
}
initedContext = new WeakReference<Context>(context);
constantFactory = termFactory;
}
finally
{
isIniting = false;
}
return context;
}
}
public static Context init()
{
return init(new Context());
}
public static void main(String args[])
{
Context context = init();
context.setStandAlone(true);
try
{
IStrategoTerm result;
try
{
result = context.invokeStrategyCLI(main_0_0.instance, "choice_success", args);
}
finally
{
context.getIOAgent().closeAllFiles();
}
if(result == null)
{
System.err.println("choice_success" + (TRACES_ENABLED ? ": rewriting failed, trace:" : ": rewriting failed"));
context.printStackTrace();
context.setStandAlone(false);
System.exit(1);
}
else
{
System.out.println(result);
context.setStandAlone(false);
System.exit(0);
}
}
catch(StrategoErrorExit exit)
{
context.setStandAlone(false);
System.err.println(exit.getLocalizedMessage());
System.exit(exit.getValue());
}
catch(StrategoExit exit)
{
context.setStandAlone(false);
System.exit(exit.getValue());
}
}
public static IStrategoTerm mainNoExit(String ... args) throws StrategoExit
{
return mainNoExit(new Context(), args);
}
public static IStrategoTerm mainNoExit(Context context, String ... args) throws StrategoExit
{
try
{
init(context);
return context.invokeStrategyCLI(main_0_0.instance, "choice_success", args);
}
finally
{
context.getIOAgent().closeAllFiles();
}
}
public static Strategy getMainStrategy()
{
return main_0_0.instance;
}
public static void initConstructors(ITermFactory termFactory)
{
_consConc_2 = termFactory.makeConstructor("Conc", 2);
_consNone_0 = termFactory.makeConstructor("None", 0);
_consSome_1 = termFactory.makeConstructor("Some", 1);
}
public static void initConstants(ITermFactory termFactory)
{
const0 = termFactory.makeString("success. a is now: ");
const1 = termFactory.makeInt(1);
const2 = termFactory.makeInt(2);
}
@SuppressWarnings("all") public static class main_0_0 extends Strategy
{
public static main_0_0 instance = new main_0_0();
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
{
context.push("main_0_0");
Fail0:
{
IStrategoTerm b_0 = null;
Success0:
{
Fail1:
{
term = choice_success.const1;
b_0 = choice_success.const1;
if(true)
break Fail1;
if(true)
break Success0;
}
term = choice_success.const2;
b_0 = choice_success.const2;
}
term = debug_1_0.instance.invoke(context, b_0, lifted0.instance);
if(term == null)
break Fail0;
context.popOnSuccess();
if(true)
return term;
}
context.popOnFailure();
return null;
}
}
@SuppressWarnings("all") private static final class lifted0 extends Strategy
{
public static final lifted0 instance = new lifted0();
@Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
{
Fail2:
{
term = choice_success.const0;
if(true)
return term;
}
return null;
}
}
public static void registerInterop(org.spoofax.interpreter.core.IContext context, Context compiledContext)
{
new InteropRegisterer().registerLazy(context, compiledContext, InteropRegisterer.class.getClassLoader());
}
@SuppressWarnings("unused") public static class InteropRegisterer extends org.strategoxt.lang.InteropRegisterer
{
@Override public void register(org.spoofax.interpreter.core.IContext context, Context compiledContext)
{
register(context, compiledContext, context.getVarScope());
}
@Override public void registerLazy(org.spoofax.interpreter.core.IContext context, Context compiledContext, ClassLoader classLoader)
{
registerLazy(context, compiledContext, classLoader, context.getVarScope());
}
private void register(org.spoofax.interpreter.core.IContext context, Context compiledContext, org.spoofax.interpreter.core.VarScope varScope)
{
compiledContext.registerComponent("choice_success");
choice_success.init(compiledContext);
varScope.addSVar("main_0_0", new InteropSDefT(main_0_0.instance, context));
}
private void registerLazy(org.spoofax.interpreter.core.IContext context, Context compiledContext, ClassLoader classLoader, org.spoofax.interpreter.core.VarScope varScope)
{
compiledContext.registerComponent("choice_success");
choice_success.init(compiledContext);
varScope.addSVar("main_0_0", new InteropSDefT(classLoader, "choice_success$main_0_0", context));
}
}
}
\ No newline at end of file
module choice_success
imports libstratego-lib
strategies
main = (!1; ?a; fail <+ !2; ?a); !a; debug(!"success. a is now: ")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment