Commit 647ed7f2 authored by Jeff Smits's avatar Jeff Smits

Removed uninitialised variable error

parent 5877382e
Specification([Signature([Constructors([ExtOpDecl("Nil",ConstType(Sort("List",[SortVar("a")]))),ExtOpDecl("Cons",FunType([ConstType(SortVar("a")),ConstType(Sort("List",[SortVar("a")]))],ConstType(Sort("List",[SortVar("a")])))),ExtOpDecl("",FunType([ConstType(SortVar("a")),ConstType(SortVar("b"))],ConstType(Sort("Tuple",[Sort("Cons",[SortVar("a"),Sort("Cons",[SortVar("b"),Sort("Nil",[])])])])))),OpDecl("Add",FunType([ConstType(Sort("String",[]))],ConstType(Sort("Term",[]))))])]),Strategies([SDefT("main_0_0",[],[],Scope(["c_0"],GuardedLChoice(Scope(["d_0","e_0","f_0","g_0"],Seq(CallT(SVar("try_1_0"),[Match(Anno(Op("Add",[Var("c_0")]),Wld))],[]),Seq(Build(Anno(Op("Cons",[Anno(Int("1"),Op("Nil",[])),Anno(Op("Cons",[Anno(Int("2"),Op("Nil",[])),Anno(Op("Cons",[Anno(Int("3"),Op("Nil",[])),Anno(Op("Nil",[]),Op("Nil",[]))]),Op("Nil",[]))]),Op("Nil",[]))]),Op("Nil",[]))),Seq(Match(Var("e_0")),Seq(Match(Var("g_0")),Seq(Build(Var("c_0")),Seq(CallT(SVar("cify_0_0"),[],[]),Seq(Match(Var("f_0")),Seq(Build(Var("g_0")),Seq(Build(Anno(Op("",[Var("f_0"),Anno(Str("_1_0"),Op("Nil",[]))]),Op("Nil",[]))),Seq(CallT(SVar("conc_strings_0_0"),[],[]),Seq(Match(Var("d_0")),Seq(Build(Var("e_0")),CallDynamic(Var("d_0"),[Build(Anno(Int("1"),Op("Nil",[])))],[])))))))))))))),Id,Build(Anno(Str("recovering from unintialised variable in dynamic call"),Op("Nil",[])))))),ExtSDef("conc_strings_0_0",[],[]),ExtSDef("cify_0_0",[],[]),ExtSDef("try_1_0",[VarDec("c_23",FunType([ConstType(Sort("ATerm",[]))],ConstType(Sort("ATerm",[]))))],[])])])
\ No newline at end of file
module call-dynamic-fail
imports libstratego-lib
signature
constructors
Add : String -> Term
strategies
main = try(?Add(x));![1,2,3];call(x|!1|) <+ !"recovering from unintialised variable in dynamic call"
Specification([Signature([Constructors([ExtOpDecl("Nil",ConstType(Sort("List",[SortVar("a")]))),ExtOpDecl("Cons",FunType([ConstType(SortVar("a")),ConstType(Sort("List",[SortVar("a")]))],ConstType(Sort("List",[SortVar("a")])))),ExtOpDecl("",FunType([ConstType(SortVar("a")),ConstType(SortVar("b"))],ConstType(Sort("Tuple",[Sort("Cons",[SortVar("a"),Sort("Cons",[SortVar("b"),Sort("Nil",[])])])]))))])]),Strategies([SDefT("main_0_0",[],[],Scope(["b_0","c_0","d_0","e_0"],Seq(Build(Anno(Op("Cons",[Anno(Int("1"),Op("Nil",[])),Anno(Op("Cons",[Anno(Int("2"),Op("Nil",[])),Anno(Op("Cons",[Anno(Int("3"),Op("Nil",[])),Anno(Op("Nil",[]),Op("Nil",[]))]),Op("Nil",[]))]),Op("Nil",[]))]),Op("Nil",[]))),Seq(Match(Var("c_0")),Seq(Match(Var("e_0")),Seq(Build(Anno(Str("map"),Op("Nil",[]))),Seq(CallT(SVar("cify_0_0"),[],[]),Seq(Match(Var("d_0")),Seq(Build(Var("e_0")),Seq(Build(Anno(Op("",[Var("d_0"),Anno(Str("_1_0"),Op("Nil",[]))]),Op("Nil",[]))),Seq(CallT(SVar("conc_strings_0_0"),[],[]),Seq(Match(Var("b_0")),Seq(Build(Var("c_0")),CallDynamic(Var("b_0"),[Build(Anno(Int("1"),Op("Nil",[])))],[])))))))))))))),ExtSDef("conc_strings_0_0",[],[]),ExtSDef("cify_0_0",[],[])])])
\ No newline at end of file
module call-dynamic
imports libstratego-lib
strategies
main = ![1,2,3];call("map"|!1|)
...@@ -84,7 +84,7 @@ impl<'a> MutContext<'a> { ...@@ -84,7 +84,7 @@ impl<'a> MutContext<'a> {
pub fn get_term(&self, term_name: &str) -> Result<ATermRef> { pub fn get_term(&self, term_name: &str) -> Result<ATermRef> {
self.get_term_option(term_name) self.get_term_option(term_name)
.and_then(|o| o.ok_or(Error::UninitializedVariable(String::from(term_name)))) .and_then(|o| o.ok_or(Error::StrategyFailed))
} }
pub fn match_term(&self, term_name: &str, current: &ATermRef) -> Result<()> { pub fn match_term(&self, term_name: &str, current: &ATermRef) -> Result<()> {
......
...@@ -16,7 +16,6 @@ pub enum Error { ...@@ -16,7 +16,6 @@ pub enum Error {
UndefinedStrategy(String), UndefinedStrategy(String),
UndefinedVariable(String), UndefinedVariable(String),
UndefinedPrimitive(String), UndefinedPrimitive(String),
UninitializedVariable(String),
StrategyFailed, StrategyFailed,
UnknownBehaviour(&'static str), UnknownBehaviour(&'static str),
InterpreterExit(i32), InterpreterExit(i32),
...@@ -32,7 +31,6 @@ impl<'t> error::Error for Error { ...@@ -32,7 +31,6 @@ impl<'t> error::Error for Error {
Error::UndefinedStrategy(_) => "couldn't find strategy", Error::UndefinedStrategy(_) => "couldn't find strategy",
Error::UndefinedVariable(_) => "couldn't find variable", Error::UndefinedVariable(_) => "couldn't find variable",
Error::UndefinedPrimitive(_) => "couldn't find primitive", Error::UndefinedPrimitive(_) => "couldn't find primitive",
Error::UninitializedVariable(_) => "variable was used but not bound",
Error::StrategyFailed => "strategy failed", Error::StrategyFailed => "strategy failed",
Error::UnknownBehaviour(_) => "unknown behaviour", Error::UnknownBehaviour(_) => "unknown behaviour",
Error::InterpreterExit(_) => "interpreter exit", Error::InterpreterExit(_) => "interpreter exit",
...@@ -48,7 +46,6 @@ impl<'t> error::Error for Error { ...@@ -48,7 +46,6 @@ impl<'t> error::Error for Error {
Error::UndefinedStrategy(_) | Error::UndefinedStrategy(_) |
Error::UndefinedVariable(_) | Error::UndefinedVariable(_) |
Error::UndefinedPrimitive(_) | Error::UndefinedPrimitive(_) |
Error::UninitializedVariable(_) |
Error::StrategyFailed | Error::StrategyFailed |
Error::UnknownBehaviour(_) | Error::UnknownBehaviour(_) |
Error::InterpreterExit(_) => None, Error::InterpreterExit(_) => None,
...@@ -66,7 +63,6 @@ impl<'t> fmt::Display for Error { ...@@ -66,7 +63,6 @@ impl<'t> fmt::Display for Error {
Error::UndefinedStrategy(ref s) => write!(f, "UndefinedStrategyError: {}", s), Error::UndefinedStrategy(ref s) => write!(f, "UndefinedStrategyError: {}", s),
Error::UndefinedVariable(ref s) => write!(f, "UndefinedVariableError: {}", s), Error::UndefinedVariable(ref s) => write!(f, "UndefinedVariableError: {}", s),
Error::UndefinedPrimitive(ref s) => write!(f, "UndefinedPrimitiveError: {}", s), Error::UndefinedPrimitive(ref s) => write!(f, "UndefinedPrimitiveError: {}", s),
Error::UninitializedVariable(ref s) => write!(f, "Uninitialized variable: {}", s),
Error::StrategyFailed => write!(f, "Strategy failed"), Error::StrategyFailed => write!(f, "Strategy failed"),
Error::UnknownBehaviour(s) => write!(f, "Unknown behaviour for {}", s), Error::UnknownBehaviour(s) => write!(f, "Unknown behaviour for {}", s),
Error::InterpreterExit(i) => write!(f, "Interpreter exited with code {}", i), Error::InterpreterExit(i) => write!(f, "Interpreter exited with code {}", i),
......
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