private GSCore execWhile(GSCoreCollection args) { GSCoreCollection commands = args.getSublist(1); GSCore r = null; while (ExecuteElement(args.getSafe(0)).getBooleanValue()) { foreach (GSCore cmd in commands) { r = ExecuteElement(cmd); if (r is GSReturn) { break; } } if (r is GSReturn) { GSReturn ret = r as GSReturn; if (ret.Type == GSReturn.TYPE_BREAK) { break; } if (ret.Type == GSReturn.TYPE_RETURN) { return(ret); } } } return(GSCore.Void); }
private GSCore execForeach(GSCoreCollection args) { if (args.Count < 4) { Debugger.Log(0, "", "Insufficient arguments for (FOREACH varName : list commands ) "); return(null); } GSCore t1 = args.getSafe(0); GSCore l1 = ExecuteElement(args.getSafe(2)); if (!(t1 is GSToken)) { Debugger.Log(0, "", "Token shoudl be second argument in FOREACH "); return(null); } if (!(l1 is GSList)) { Debugger.Log(0, "", "List should be fourth argument in FOREACH "); return(null); } GSToken tk = (GSToken)t1; GSList lst = (GSList)l1; GSCore r = null; int ik = 0; foreach (GSCore item in lst.Parts) { SetVariable(tk.Token, item); for (int i = 3; i < args.Count; i++) { r = ExecuteElement(args.getSafe(i)); if (r is GSReturn) { break; } } ik++; if (r is GSReturn) { GSReturn ret = r as GSReturn; if (ret.Type == GSReturn.TYPE_BREAK) { break; } if (ret.Type == GSReturn.TYPE_RETURN) { return(ret); } } } return(new GSNumber(ik)); }
public override GSCore ExecuteMessage(string token, GSCoreCollection args) { GSCore result = null; if (token.Equals("add") || token.Equals("+")) { result = execAdd(getNativeValues(args)); } else if (token.Equals("sub") || token.Equals("-")) { result = execSub(getNativeValues(args)); } else if (token.Equals("mul") || token.Equals("*")) { result = execMul(getNativeValues(args)); } else if (token.Equals("div") || token.Equals("/")) { result = execDiv(getNativeValues(args)); } else if (token.Equals("and") || token.Equals("&")) { result = execAnd(getNativeValues(args)); } else if (token.Equals("or") || token.Equals("|")) { result = execOr(getNativeValues(args)); } else if (token.Equals("not") || token.Equals("!")) { result = execNot(args); } else if (token.Equals("set") && args.Count > 1) { result = execSet(args[0], args[1]); } else if ((token.Equals("gt") || token.Equals(">")) && args.Count > 1) { result = execGt(getNativeValues(args)); } else if ((token.Equals("ge") || token.Equals(">=")) && args.Count > 1) { result = execGe(getNativeValues(args)); } else if ((token.Equals("eq") || token.Equals("==")) && args.Count > 1) { result = execEq(getNativeValues(args)); } else if ((token.Equals("ne") || token.Equals("!=")) && args.Count > 1) { result = execNe(getNativeValues(args)); } else if ((token.Equals("le") || token.Equals("<=")) && args.Count > 1) { result = execLe(getNativeValues(args)); } else if ((token.Equals("lt") || token.Equals("<")) && args.Count > 1) { result = execLt(getNativeValues(args)); } else if (token.Equals("print")) { result = execPrint(args, false); } else if (token.Equals("println")) { result = execPrint(args, true); } else if (token.Equals("if")) { result = execIf(args); } else if (token.Equals("while")) { result = execWhile(args); } else if (token.Equals("foreach")) { result = execForeach(args); } else if (token.Equals("x")) { result = execMessage(args); } else if (token.Equals("do")) { result = execDo(args); } else if (token.Equals("return")) { result = new GSReturn(args.getSafe(0)); } else if (token.Equals("break")) { result = new GSReturn(GSReturn.TYPE_BREAK); } else if (token.Equals("continue")) { result = new GSReturn(GSReturn.TYPE_CONTINUE); } else { Debugger.Log(0, "", "UNKNOWN MESSAGE: " + token + " "); } return(result); }