Add continue
This commit is contained in:
Родитель
3352420598
Коммит
2f0a3d52cf
|
@ -39,6 +39,7 @@ module TDev {
|
|||
public ShowProp:IProperty;
|
||||
public ReturnProp:IProperty;
|
||||
public BreakProp:IProperty;
|
||||
public ContinueProp:IProperty;
|
||||
public StringConcatProp:IProperty;
|
||||
public PlaceholderThing:AST.SingletonDef;
|
||||
public AndProp:Property;
|
||||
|
@ -93,6 +94,7 @@ module TDev {
|
|||
this.FunProp = this.Unknown.getProperty("fun");
|
||||
this.ShowProp = this.Unknown.getProperty("show");
|
||||
this.BreakProp = this.Unknown.getProperty("break");
|
||||
this.ContinueProp = this.Unknown.getProperty("continue");
|
||||
this.ReturnProp = this.Unknown.getProperty("return");
|
||||
this.AndProp = <Property>this.Boolean.getProperty("and");
|
||||
this.OrProp = <Property>this.Boolean.getProperty("or");
|
||||
|
@ -227,6 +229,7 @@ module TDev {
|
|||
specProp("return", api.opStmtPriority);
|
||||
specProp("show", api.opStmtPriority);
|
||||
specProp("break", api.opStmtPriority);
|
||||
specProp("continue", api.opStmtPriority);
|
||||
invl.isData = true;
|
||||
|
||||
this.core = new CoreApi(this);
|
||||
|
|
|
@ -132,6 +132,7 @@ module TDev.AST {
|
|||
public tutorialWarning: string;
|
||||
public _hint:string;
|
||||
public _compilerBreakLabel:any;
|
||||
public _compilerContinueLabel:any;
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
|
@ -3501,6 +3502,8 @@ module TDev.AST {
|
|||
return v.visitReturn(this)
|
||||
else if (p == api.core.BreakProp)
|
||||
return v.visitBreak(this)
|
||||
else if (p == api.core.ContinueProp)
|
||||
return v.visitContinue(this)
|
||||
else if (p == api.core.ShowProp)
|
||||
return v.visitShow(this)
|
||||
|
||||
|
@ -3732,6 +3735,7 @@ module TDev.AST {
|
|||
public visitCall(n:Call) { return this.visitExpr(n); }
|
||||
public visitShow(n:Call) { return this.visitCall(n); }
|
||||
public visitBreak(n:Call) { return this.visitCall(n); }
|
||||
public visitContinue(n:Call) { return this.visitCall(n); }
|
||||
public visitReturn(n:Call) { return this.visitCall(n); }
|
||||
public visitAssignment(n:Call) { return this.visitCall(n); }
|
||||
|
||||
|
|
|
@ -885,6 +885,7 @@ module TDev.AST
|
|||
this.updateAnalysisInfo(w.calcNode());
|
||||
this.markLocation(w);
|
||||
var begLabel = this.allocateLabel();
|
||||
w._compilerContinueLabel = begLabel;
|
||||
w._compilerBreakLabel = this.allocateLabel()
|
||||
this.aux.push(begLabel);
|
||||
var cond = this.topExpr(w.condition, w);
|
||||
|
@ -907,6 +908,13 @@ module TDev.AST
|
|||
return this.unit
|
||||
}
|
||||
|
||||
public visitContinue(b:Call)
|
||||
{
|
||||
if (b.topAffectedStmt)
|
||||
this.aux.push(JsGoto.simple(b.topAffectedStmt._compilerContinueLabel))
|
||||
return this.unit
|
||||
}
|
||||
|
||||
public visitReturn(r:Call)
|
||||
{
|
||||
if (r.topRetLocal) {
|
||||
|
@ -1013,6 +1021,7 @@ module TDev.AST
|
|||
|
||||
var idxTmp = this.newTmpVarOK("idx", this.term("0"));
|
||||
var begLabel = this.allocateLabel();
|
||||
f._compilerContinueLabel = begLabel;
|
||||
this.aux.push(begLabel);
|
||||
var lenExpr:JsExpr;
|
||||
if (isArray)
|
||||
|
@ -1069,12 +1078,14 @@ module TDev.AST
|
|||
var idx = this.localVarRef(f.boundLocal);
|
||||
this.aux.push(idx.gets(this.term("0")));
|
||||
var begLabel = this.allocateLabel();
|
||||
f._compilerContinueLabel = this.allocateLabel();
|
||||
f._compilerBreakLabel = this.allocateLabel()
|
||||
var res = this.flushAux();
|
||||
res.push(begLabel);
|
||||
var ifNode = this.allocateIf();
|
||||
ifNode.condition = new JsInfix(idx, "<", bndTmp);
|
||||
ifNode.thenBody = this.dispatch(f.body);
|
||||
ifNode.thenBody.push(f._compilerContinueLabel);
|
||||
ifNode.thenBody.push(new JsExprStmt(new JsInfix(idx, "++", null)));
|
||||
ifNode.thenBody.push(JsGoto.simple(begLabel));
|
||||
ifNode.elseBody = [];
|
||||
|
|
|
@ -2254,6 +2254,10 @@ module TDev.AST {
|
|||
this.nowVisiting.canInline = false;
|
||||
this.visitChildren(n);
|
||||
}
|
||||
visitContinue(n: Call) {
|
||||
this.nowVisiting.canInline = false;
|
||||
this.visitChildren(n);
|
||||
}
|
||||
visitBreak(n: Call) {
|
||||
this.nowVisiting.canInline = false;
|
||||
this.visitChildren(n);
|
||||
|
|
|
@ -633,6 +633,12 @@ module TDev.AST.Json
|
|||
}
|
||||
}
|
||||
|
||||
public visitContinue(n:Call) {
|
||||
return {
|
||||
nodeType: "continue",
|
||||
}
|
||||
}
|
||||
|
||||
public visitBox(n:Box) {
|
||||
return { body: n.body }
|
||||
}
|
||||
|
@ -1225,6 +1231,7 @@ module TDev.AST.Json
|
|||
case "show":
|
||||
case "break":
|
||||
case "return":
|
||||
case "continue":
|
||||
pushOp(e.nodeType)
|
||||
var ee = (<JReturn>e).expr
|
||||
if (ee)
|
||||
|
|
|
@ -191,6 +191,7 @@ module TDev.AST.Json
|
|||
body:JStmt[];
|
||||
}
|
||||
|
||||
export interface JContinue extends JExpr {}
|
||||
export interface JBreak extends JExpr {}
|
||||
export interface JReturn extends JExpr { expr: JExprHolder; }
|
||||
export interface JShow extends JExpr { expr: JExprHolder; }
|
||||
|
|
|
@ -654,17 +654,20 @@ module TDev.AST
|
|||
});
|
||||
}
|
||||
|
||||
public visitBreak(node:Call)
|
||||
public visitBreakContinue(node:Call, tp:string)
|
||||
{
|
||||
node._kind = this.core.Nothing;
|
||||
node.topAffectedStmt = this.currLoop
|
||||
if (!this.currLoop)
|
||||
this.markError(node, lf("TD200: 'break' can be only used inside a loop"))
|
||||
this.markError(node, lf("TD200: '{0}' can be only used inside a loop", tp))
|
||||
if (!node.args[0].isPlaceholder())
|
||||
this.markError(node, lf("TD205: 'break' cannot take arguments"))
|
||||
this.expectExpr(node.args[0], null, "break")
|
||||
this.markError(node, lf("TD205: '{0}' cannot take arguments", tp))
|
||||
this.expectExpr(node.args[0], null, tp)
|
||||
}
|
||||
|
||||
public visitBreak(node:Call) { this.visitBreakContinue(node, "break") }
|
||||
public visitContinue(node:Call) { this.visitBreakContinue(node, "continue") }
|
||||
|
||||
public visitShow(node:Call)
|
||||
{
|
||||
node._kind = this.core.Nothing;
|
||||
|
@ -1140,7 +1143,9 @@ module TDev.AST
|
|||
var prevOut = this.outLocals;
|
||||
var prevRep = this.reportedUnassigned;
|
||||
var prevAct = this.currentAnyAction;
|
||||
var prevLoop = this.currLoop;
|
||||
|
||||
this.currLoop = null;
|
||||
this.writtenLocals = [];
|
||||
|
||||
this.actionSection = ActionSection.Lambda;
|
||||
|
@ -1157,6 +1162,7 @@ module TDev.AST
|
|||
this.outLocals = prevOut;
|
||||
this.currentAnyAction = prevAct;
|
||||
this.reportedUnassigned = prevRep;
|
||||
this.currLoop = prevLoop;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1167,6 +1167,7 @@ module TDev
|
|||
else if (o == "async") tick(Ticks.calcAsync);
|
||||
else if (o == "return") tick(Ticks.codeReturn);
|
||||
else if (o == "break") tick(Ticks.codeBreak);
|
||||
else if (o == "continue") tick(Ticks.codeContinue);
|
||||
else if (o == "show") tick(Ticks.codeShow);
|
||||
else if (o == "true" || o == "false") tick(Ticks.calcTrueFalse);
|
||||
}
|
||||
|
|
|
@ -137,6 +137,7 @@ module TDev.Browser {
|
|||
show: true,
|
||||
"return": true,
|
||||
"break": true,
|
||||
"continue": true,
|
||||
stringConcatProperty: true,
|
||||
// hub
|
||||
scriptAddToChannel: true,
|
||||
|
|
|
@ -699,6 +699,7 @@ module TDev
|
|||
if (this.editor.widgetEnabled("comment"))
|
||||
add({ name: lf("// comment"), desc: lf("insert comment"), node: "//" });
|
||||
addOpStmt("break", lf("stop loop"))
|
||||
addOpStmt("continue", lf("skip iteration"))
|
||||
addOpStmt("return", lf("stop function"))
|
||||
|
||||
return res;
|
||||
|
|
|
@ -55,6 +55,10 @@ module TDev {
|
|||
return env.indent + "break;";
|
||||
}
|
||||
|
||||
public visitContinue(env: EmitterEnv) {
|
||||
return env.indent + "continue;";
|
||||
}
|
||||
|
||||
public visitShow(env: EmitterEnv, expr: J.JExpr) {
|
||||
// TODO hook this up to "post to wall" handling if any
|
||||
return env.indent + "serial.print(" + this.visit(env, expr) + ");";
|
||||
|
|
|
@ -45,6 +45,8 @@ module TDev {
|
|||
return this.visitShow(env, nshow.expr);
|
||||
case "break":
|
||||
return this.visitBreak(env);
|
||||
case "continue":
|
||||
return this.visitContinue(env);
|
||||
case "return":
|
||||
var nret = <J.JReturn> tr;
|
||||
return this.visitReturn(env, nret.expr);
|
||||
|
@ -109,6 +111,7 @@ module TDev {
|
|||
public visitReturn(env: T, expr: J.JExpr): U { throw new Error("Not implemented"); }
|
||||
public visitShow(env: T, expr: J.JExpr): U { throw new Error("Not implemented"); }
|
||||
public visitBreak(env: T): U { throw new Error("Not implemented"); }
|
||||
public visitContinue(env: T): U { throw new Error("Not implemented"); }
|
||||
public visitInlineActions(
|
||||
env: T,
|
||||
expr: J.JExpr,
|
||||
|
|
|
@ -136,6 +136,7 @@ module TDev {
|
|||
codeAddAbove,
|
||||
codeAddBelow,
|
||||
codeShow,
|
||||
codeContinue,
|
||||
codeReturn,
|
||||
codeBreak,
|
||||
codeBoxed,
|
||||
|
|
Загрузка…
Ссылка в новой задаче