Modified:
trunk/static/logo.js
trunk/static/turtle.js
Log:
adding recursion depth limit
Modified: trunk/static/logo.js
==============================================================================
--- trunk/static/logo.js (original)
+++ trunk/static/logo.js Sat Feb 14 13:15:02 2009
@@ -29,6 +29,8 @@
this.repcount = -1;
this.setup();
+ this.depth = 0;
+ this.maxdepth = 200;
}
Logo.prototype.random = function () {
@@ -577,19 +579,32 @@
newvalues.set(name,value);
}
+ // running function
+ if (this.depth > this.maxdepth) {
+ return new Token('error', 'too much recursion');
+ }
+
if (last.type == "wrd" && last.data == code.data) {
var par = this.values;
var tail = f.code.pop();
+ rec_depth = this.depth;
while (1) { // revursive
+ if (this.depth > this.maxdepth) {
+ this.depth = rec_depth;
+ return new Token('error', 'too much recursion');
+ }
+ this.depth++;
+
this.values = newvalues;
var result = this.eval_list(f.code);
if (result && (result.type == "stop" || result.type
== "error")) {
this.values = par; // restore the original stack
f.code.push(tail); // restore the original tail.
+ this.depth=rec_depth;
return result.data;
};
@@ -603,16 +618,15 @@
//alert("rec: "+code.data+" setting: "+name +":"
+value);
newvalues.set(name,value);
-
}
}
} else {
this.values = newvalues;
-
+ this.depth++;
var result = this.eval_list(f.code);
//alert(result);
-
+ this.depth--;
if (result && result.type == "stop") { result =
result.data };
this.values = this.values.par;
Modified: trunk/static/turtle.js
==============================================================================
--- trunk/static/turtle.js (original)
+++ trunk/static/turtle.js Sat Feb 14 13:15:02 2009
@@ -192,6 +192,8 @@
this.pen = true;
}
+Turtle.prototype.paint = function () {}
+
function DelayCommand (that,fun,args) {
this.that = that;
this.fun = fun;