OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Copyright 1996 John Maloney and Mario Wolczko. | 2 // Copyright 1996 John Maloney and Mario Wolczko. |
3 | 3 |
4 // This program is free software; you can redistribute it and/or modify | 4 // This program is free software; you can redistribute it and/or modify |
5 // it under the terms of the GNU General Public License as published by | 5 // it under the terms of the GNU General Public License as published by |
6 // the Free Software Foundation; either version 2 of the License, or | 6 // the Free Software Foundation; either version 2 of the License, or |
7 // (at your option) any later version. | 7 // (at your option) any later version. |
8 // | 8 // |
9 // This program is distributed in the hope that it will be useful, | 9 // This program is distributed in the hope that it will be useful, |
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 28 matching lines...) Expand all Loading... |
39 * | 39 * |
40 * Beware: this benchmark is written in a grotesque style where | 40 * Beware: this benchmark is written in a grotesque style where |
41 * the constraint model is built by side-effects from constructors. | 41 * the constraint model is built by side-effects from constructors. |
42 * I've kept it this way to avoid deviating too much from the original | 42 * I've kept it this way to avoid deviating too much from the original |
43 * implementation. | 43 * implementation. |
44 */ | 44 */ |
45 | 45 |
46 | 46 |
47 /* --- O b j e c t M o d e l --- */ | 47 /* --- O b j e c t M o d e l --- */ |
48 | 48 |
49 Object.prototype.inherits = function (shuper) { | 49 Object.prototype.inheritsFrom = function (shuper) { |
50 function Inheriter() { } | 50 function Inheriter() { } |
51 Inheriter.prototype = shuper.prototype; | 51 Inheriter.prototype = shuper.prototype; |
52 this.prototype = new Inheriter(); | 52 this.prototype = new Inheriter(); |
53 this.superConstructor = shuper; | 53 this.superConstructor = shuper; |
54 } | 54 } |
55 | 55 |
56 function OrderedCollection() { | 56 function OrderedCollection() { |
57 this.elms = new Array(); | 57 this.elms = new Array(); |
58 } | 58 } |
59 | 59 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 * Abstract superclass for constraints having a single possible output | 209 * Abstract superclass for constraints having a single possible output |
210 * variable. | 210 * variable. |
211 */ | 211 */ |
212 function UnaryConstraint(v, strength) { | 212 function UnaryConstraint(v, strength) { |
213 UnaryConstraint.superConstructor.call(this, strength); | 213 UnaryConstraint.superConstructor.call(this, strength); |
214 this.myOutput = v; | 214 this.myOutput = v; |
215 this.satisfied = false; | 215 this.satisfied = false; |
216 this.addConstraint(); | 216 this.addConstraint(); |
217 } | 217 } |
218 | 218 |
219 UnaryConstraint.inherits(Constraint); | 219 UnaryConstraint.inheritsFrom(Constraint); |
220 | 220 |
221 /** | 221 /** |
222 * Adds this constraint to the constraint graph | 222 * Adds this constraint to the constraint graph |
223 */ | 223 */ |
224 UnaryConstraint.prototype.addToGraph = function () { | 224 UnaryConstraint.prototype.addToGraph = function () { |
225 this.myOutput.addConstraint(this); | 225 this.myOutput.addConstraint(this); |
226 this.satisfied = false; | 226 this.satisfied = false; |
227 } | 227 } |
228 | 228 |
229 /** | 229 /** |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 /** | 287 /** |
288 * Variables that should, with some level of preference, stay the same. | 288 * Variables that should, with some level of preference, stay the same. |
289 * Planners may exploit the fact that instances, if satisfied, will not | 289 * Planners may exploit the fact that instances, if satisfied, will not |
290 * change their output during plan execution. This is called "stay | 290 * change their output during plan execution. This is called "stay |
291 * optimization". | 291 * optimization". |
292 */ | 292 */ |
293 function StayConstraint(v, str) { | 293 function StayConstraint(v, str) { |
294 StayConstraint.superConstructor.call(this, v, str); | 294 StayConstraint.superConstructor.call(this, v, str); |
295 } | 295 } |
296 | 296 |
297 StayConstraint.inherits(UnaryConstraint); | 297 StayConstraint.inheritsFrom(UnaryConstraint); |
298 | 298 |
299 StayConstraint.prototype.execute = function () { | 299 StayConstraint.prototype.execute = function () { |
300 // Stay constraints do nothing | 300 // Stay constraints do nothing |
301 } | 301 } |
302 | 302 |
303 /* --- * | 303 /* --- * |
304 * E d i t C o n s t r a i n t | 304 * E d i t C o n s t r a i n t |
305 * --- */ | 305 * --- */ |
306 | 306 |
307 /** | 307 /** |
308 * A unary input constraint used to mark a variable that the client | 308 * A unary input constraint used to mark a variable that the client |
309 * wishes to change. | 309 * wishes to change. |
310 */ | 310 */ |
311 function EditConstraint(v, str) { | 311 function EditConstraint(v, str) { |
312 EditConstraint.superConstructor.call(this, v, str); | 312 EditConstraint.superConstructor.call(this, v, str); |
313 } | 313 } |
314 | 314 |
315 EditConstraint.inherits(UnaryConstraint); | 315 EditConstraint.inheritsFrom(UnaryConstraint); |
316 | 316 |
317 /** | 317 /** |
318 * Edits indicate that a variable is to be changed by imperative code. | 318 * Edits indicate that a variable is to be changed by imperative code. |
319 */ | 319 */ |
320 EditConstraint.prototype.isInput = function () { | 320 EditConstraint.prototype.isInput = function () { |
321 return true; | 321 return true; |
322 } | 322 } |
323 | 323 |
324 EditConstraint.prototype.execute = function () { | 324 EditConstraint.prototype.execute = function () { |
325 // Edit constraints do nothing | 325 // Edit constraints do nothing |
(...skipping 13 matching lines...) Expand all Loading... |
339 * variables. | 339 * variables. |
340 */ | 340 */ |
341 function BinaryConstraint(var1, var2, strength) { | 341 function BinaryConstraint(var1, var2, strength) { |
342 BinaryConstraint.superConstructor.call(this, strength); | 342 BinaryConstraint.superConstructor.call(this, strength); |
343 this.v1 = var1; | 343 this.v1 = var1; |
344 this.v2 = var2; | 344 this.v2 = var2; |
345 this.direction = Direction.NONE; | 345 this.direction = Direction.NONE; |
346 this.addConstraint(); | 346 this.addConstraint(); |
347 } | 347 } |
348 | 348 |
349 BinaryConstraint.inherits(Constraint); | 349 BinaryConstraint.inheritsFrom(Constraint); |
350 | 350 |
351 /** | 351 /** |
352 * Decides if this constratint can be satisfied and which way it | 352 * Decides if this constratint can be satisfied and which way it |
353 * should flow based on the relative strength of the variables related, | 353 * should flow based on the relative strength of the variables related, |
354 * and record that decision. | 354 * and record that decision. |
355 */ | 355 */ |
356 BinaryConstraint.prototype.chooseMethod = function (mark) { | 356 BinaryConstraint.prototype.chooseMethod = function (mark) { |
357 if (this.v1.mark == mark) { | 357 if (this.v1.mark == mark) { |
358 this.direction = (this.v1.mark != mark && Strength.stronger(this.strength, t
his.v2.walkStrength)) | 358 this.direction = (this.v1.mark != mark && Strength.stronger(this.strength, t
his.v2.walkStrength)) |
359 ? Direction.FORWARD | 359 ? Direction.FORWARD |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 * this relationship but the scale factor and offset are considered | 452 * this relationship but the scale factor and offset are considered |
453 * read-only. | 453 * read-only. |
454 */ | 454 */ |
455 function ScaleConstraint(src, scale, offset, dest, strength) { | 455 function ScaleConstraint(src, scale, offset, dest, strength) { |
456 this.direction = Direction.NONE; | 456 this.direction = Direction.NONE; |
457 this.scale = scale; | 457 this.scale = scale; |
458 this.offset = offset; | 458 this.offset = offset; |
459 ScaleConstraint.superConstructor.call(this, src, dest, strength); | 459 ScaleConstraint.superConstructor.call(this, src, dest, strength); |
460 } | 460 } |
461 | 461 |
462 ScaleConstraint.inherits(BinaryConstraint); | 462 ScaleConstraint.inheritsFrom(BinaryConstraint); |
463 | 463 |
464 /** | 464 /** |
465 * Adds this constraint to the constraint graph. | 465 * Adds this constraint to the constraint graph. |
466 */ | 466 */ |
467 ScaleConstraint.prototype.addToGraph = function () { | 467 ScaleConstraint.prototype.addToGraph = function () { |
468 ScaleConstraint.superConstructor.prototype.addToGraph.call(this); | 468 ScaleConstraint.superConstructor.prototype.addToGraph.call(this); |
469 this.scale.addConstraint(this); | 469 this.scale.addConstraint(this); |
470 this.offset.addConstraint(this); | 470 this.offset.addConstraint(this); |
471 } | 471 } |
472 | 472 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 * E q u a l i t y C o n s t r a i n t | 508 * E q u a l i t y C o n s t r a i n t |
509 * --- */ | 509 * --- */ |
510 | 510 |
511 /** | 511 /** |
512 * Constrains two variables to have the same value. | 512 * Constrains two variables to have the same value. |
513 */ | 513 */ |
514 function EqualityConstraint(var1, var2, strength) { | 514 function EqualityConstraint(var1, var2, strength) { |
515 EqualityConstraint.superConstructor.call(this, var1, var2, strength); | 515 EqualityConstraint.superConstructor.call(this, var1, var2, strength); |
516 } | 516 } |
517 | 517 |
518 EqualityConstraint.inherits(BinaryConstraint); | 518 EqualityConstraint.inheritsFrom(BinaryConstraint); |
519 | 519 |
520 /** | 520 /** |
521 * Enforce this constraint. Assume that it is satisfied. | 521 * Enforce this constraint. Assume that it is satisfied. |
522 */ | 522 */ |
523 EqualityConstraint.prototype.execute = function () { | 523 EqualityConstraint.prototype.execute = function () { |
524 this.output().value = this.input().value; | 524 this.output().value = this.input().value; |
525 } | 525 } |
526 | 526 |
527 /* --- * | 527 /* --- * |
528 * V a r i a b l e | 528 * V a r i a b l e |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 edit.destroyConstraint(); | 871 edit.destroyConstraint(); |
872 } | 872 } |
873 | 873 |
874 // Global variable holding the current planner. | 874 // Global variable holding the current planner. |
875 var planner = null; | 875 var planner = null; |
876 | 876 |
877 function deltaBlue() { | 877 function deltaBlue() { |
878 chainTest(100); | 878 chainTest(100); |
879 projectionTest(100); | 879 projectionTest(100); |
880 } | 880 } |
OLD | NEW |