| OLD | NEW |
| 1 var DeltaBlue; | 1 var DeltaBlue; |
| 2 (function(exports) { | 2 (function(exports) { |
| 3 'use strict'; | 3 'use strict'; |
| 4 // Function main: () → dynamic | 4 // Function main: () → dynamic |
| 5 function main() { | 5 function main() { |
| 6 new DeltaBlue().report(); | 6 new DeltaBlue().report(); |
| 7 } | 7 } |
| 8 class DeltaBlue extends BenchmarkBase.BenchmarkBase { | 8 class DeltaBlue extends BenchmarkBase.BenchmarkBase { |
| 9 DeltaBlue() { | 9 DeltaBlue() { |
| 10 super.BenchmarkBase("DeltaBlue"); | 10 super.BenchmarkBase("DeltaBlue"); |
| 11 } | 11 } |
| 12 run() { | 12 run() { |
| 13 chainTest(100); | 13 chainTest(100); |
| 14 projectionTest(100); | 14 projectionTest(100); |
| 15 } | 15 } |
| 16 } | 16 } |
| 17 class Strength extends core.Object { | 17 class Strength extends core.Object { |
| 18 Strength(value, name) { | 18 Strength(value, name) { |
| 19 this.value = value; | 19 this.value = value; |
| 20 this.name = name; | 20 this.name = name; |
| 21 } | 21 } |
| 22 nextWeaker() { | 22 nextWeaker() { |
| 23 return /* Unimplemented const */new List.from([STRONG_PREFERRED, PREFERRED
, STRONG_DEFAULT, NORMAL, WEAK_DEFAULT, WEAKEST]).get(this.value); | 23 return /* Unimplemented const */new core.List$(Strength).from([STRONG_PREF
ERRED, PREFERRED, STRONG_DEFAULT, NORMAL, WEAK_DEFAULT, WEAKEST]).get(this.value
); |
| 24 } | 24 } |
| 25 static stronger(s1, s2) { | 25 static stronger(s1, s2) { |
| 26 return dart.notNull(s1.value) < dart.notNull(s2.value); | 26 return dart.notNull(s1.value) < dart.notNull(s2.value); |
| 27 } | 27 } |
| 28 static weaker(s1, s2) { | 28 static weaker(s1, s2) { |
| 29 return dart.notNull(s1.value) > dart.notNull(s2.value); | 29 return dart.notNull(s1.value) > dart.notNull(s2.value); |
| 30 } | 30 } |
| 31 static weakest(s1, s2) { | 31 static weakest(s1, s2) { |
| 32 return weaker(s1, s2) ? s1 : s2; | 32 return weaker(s1, s2) ? s1 : s2; |
| 33 } | 33 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 class EqualityConstraint extends BinaryConstraint { | 235 class EqualityConstraint extends BinaryConstraint { |
| 236 EqualityConstraint(v1, v2, strength) { | 236 EqualityConstraint(v1, v2, strength) { |
| 237 super.BinaryConstraint(v1, v2, strength); | 237 super.BinaryConstraint(v1, v2, strength); |
| 238 } | 238 } |
| 239 execute() { | 239 execute() { |
| 240 this.output().value = this.input().value; | 240 this.output().value = this.input().value; |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 class Variable extends core.Object { | 243 class Variable extends core.Object { |
| 244 Variable(name, value) { | 244 Variable(name, value) { |
| 245 this.constraints = new List.from([]); | 245 this.constraints = new core.List$(Constraint).from([]); |
| 246 this.name = name; | 246 this.name = name; |
| 247 this.value = value; | 247 this.value = value; |
| 248 this.determinedBy = null; | 248 this.determinedBy = null; |
| 249 this.mark = 0; | 249 this.mark = 0; |
| 250 this.walkStrength = WEAKEST; | 250 this.walkStrength = WEAKEST; |
| 251 this.stay = true; | 251 this.stay = true; |
| 252 } | 252 } |
| 253 addConstraint(c) { | 253 addConstraint(c) { |
| 254 this.constraints.add(c); | 254 this.constraints.add(c); |
| 255 } | 255 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 let c = todo.removeLast(); | 294 let c = todo.removeLast(); |
| 295 if (c.output().mark !== mark && dart.notNull(c.inputsKnown(mark))) { | 295 if (c.output().mark !== mark && dart.notNull(c.inputsKnown(mark))) { |
| 296 plan.addConstraint(c); | 296 plan.addConstraint(c); |
| 297 c.output().mark = mark; | 297 c.output().mark = mark; |
| 298 this.addConstraintsConsumingTo(c.output(), todo); | 298 this.addConstraintsConsumingTo(c.output(), todo); |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 return plan; | 301 return plan; |
| 302 } | 302 } |
| 303 extractPlanFromConstraints(constraints) { | 303 extractPlanFromConstraints(constraints) { |
| 304 let sources = new List.from([]); | 304 let sources = new core.List$(Constraint).from([]); |
| 305 for (let i = 0; dart.notNull(i) < dart.notNull(constraints.length); i = da
rt.notNull(i) + 1) { | 305 for (let i = 0; dart.notNull(i) < dart.notNull(constraints.length); i = da
rt.notNull(i) + 1) { |
| 306 let c = constraints.get(i); | 306 let c = constraints.get(i); |
| 307 if (dart.notNull(c.isInput()) && dart.notNull(c.isSatisfied())) | 307 if (dart.notNull(c.isInput()) && dart.notNull(c.isSatisfied())) |
| 308 sources.add(c); | 308 sources.add(c); |
| 309 } | 309 } |
| 310 return this.makePlan(sources); | 310 return this.makePlan(sources); |
| 311 } | 311 } |
| 312 addPropagate(c, mark) { | 312 addPropagate(c, mark) { |
| 313 let todo = new List.from([c]); | 313 let todo = new core.List$(Constraint).from([c]); |
| 314 while (dart.notNull(todo.length) > 0) { | 314 while (dart.notNull(todo.length) > 0) { |
| 315 let d = todo.removeLast(); | 315 let d = todo.removeLast(); |
| 316 if (d.output().mark === mark) { | 316 if (d.output().mark === mark) { |
| 317 this.incrementalRemove(c); | 317 this.incrementalRemove(c); |
| 318 return false; | 318 return false; |
| 319 } | 319 } |
| 320 d.recalculate(); | 320 d.recalculate(); |
| 321 this.addConstraintsConsumingTo(d.output(), todo); | 321 this.addConstraintsConsumingTo(d.output(), todo); |
| 322 } | 322 } |
| 323 return true; | 323 return true; |
| 324 } | 324 } |
| 325 removePropagateFrom(out) { | 325 removePropagateFrom(out) { |
| 326 out.determinedBy = null; | 326 out.determinedBy = null; |
| 327 out.walkStrength = WEAKEST; | 327 out.walkStrength = WEAKEST; |
| 328 out.stay = true; | 328 out.stay = true; |
| 329 let unsatisfied = new List.from([]); | 329 let unsatisfied = new core.List$(Constraint).from([]); |
| 330 let todo = new List.from([out]); | 330 let todo = new core.List$(Variable).from([out]); |
| 331 while (dart.notNull(todo.length) > 0) { | 331 while (dart.notNull(todo.length) > 0) { |
| 332 let v = todo.removeLast(); | 332 let v = todo.removeLast(); |
| 333 for (let i = 0; dart.notNull(i) < dart.notNull(v.constraints.length); i
= dart.notNull(i) + 1) { | 333 for (let i = 0; dart.notNull(i) < dart.notNull(v.constraints.length); i
= dart.notNull(i) + 1) { |
| 334 let c = v.constraints.get(i); | 334 let c = v.constraints.get(i); |
| 335 if (!dart.notNull(c.isSatisfied())) | 335 if (!dart.notNull(c.isSatisfied())) |
| 336 unsatisfied.add(c); | 336 unsatisfied.add(c); |
| 337 } | 337 } |
| 338 let determining = v.determinedBy; | 338 let determining = v.determinedBy; |
| 339 for (let i = 0; dart.notNull(i) < dart.notNull(v.constraints.length); i
= dart.notNull(i) + 1) { | 339 for (let i = 0; dart.notNull(i) < dart.notNull(v.constraints.length); i
= dart.notNull(i) + 1) { |
| 340 let next = v.constraints.get(i); | 340 let next = v.constraints.get(i); |
| 341 if (dart.notNull(!dart.equals(next, determining)) && dart.notNull(next
.isSatisfied())) { | 341 if (dart.notNull(!dart.equals(next, determining)) && dart.notNull(next
.isSatisfied())) { |
| 342 next.recalculate(); | 342 next.recalculate(); |
| 343 todo.add(next.output()); | 343 todo.add(next.output()); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 return unsatisfied; | 347 return unsatisfied; |
| 348 } | 348 } |
| 349 addConstraintsConsumingTo(v, coll) { | 349 addConstraintsConsumingTo(v, coll) { |
| 350 let determining = v.determinedBy; | 350 let determining = v.determinedBy; |
| 351 for (let i = 0; dart.notNull(i) < dart.notNull(v.constraints.length); i =
dart.notNull(i) + 1) { | 351 for (let i = 0; dart.notNull(i) < dart.notNull(v.constraints.length); i =
dart.notNull(i) + 1) { |
| 352 let c = v.constraints.get(i); | 352 let c = v.constraints.get(i); |
| 353 if (dart.notNull(!dart.equals(c, determining)) && dart.notNull(c.isSatis
fied())) | 353 if (dart.notNull(!dart.equals(c, determining)) && dart.notNull(c.isSatis
fied())) |
| 354 coll.add(c); | 354 coll.add(c); |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 class Plan extends core.Object { | 358 class Plan extends core.Object { |
| 359 Plan() { | 359 Plan() { |
| 360 this.list = new List.from([]); | 360 this.list = new core.List$(Constraint).from([]); |
| 361 } | 361 } |
| 362 addConstraint(c) { | 362 addConstraint(c) { |
| 363 this.list.add(c); | 363 this.list.add(c); |
| 364 } | 364 } |
| 365 size() { | 365 size() { |
| 366 return this.list.length; | 366 return this.list.length; |
| 367 } | 367 } |
| 368 execute() { | 368 execute() { |
| 369 for (let i = 0; dart.notNull(i) < dart.notNull(this.list.length); i = dart
.notNull(i) + 1) { | 369 for (let i = 0; dart.notNull(i) < dart.notNull(this.list.length); i = dart
.notNull(i) + 1) { |
| 370 this.list.get(i).execute(); | 370 this.list.get(i).execute(); |
| 371 } | 371 } |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 // Function chainTest: (int) → void | 374 // Function chainTest: (int) → void |
| 375 function chainTest(n) { | 375 function chainTest(n) { |
| 376 exports.planner = new Planner(); | 376 exports.planner = new Planner(); |
| 377 let prev = null, first = null, last = null; | 377 let prev = null, first = null, last = null; |
| 378 for (let i = 0; dart.notNull(i) <= dart.notNull(n); i = dart.notNull(i) + 1)
{ | 378 for (let i = 0; dart.notNull(i) <= dart.notNull(n); i = dart.notNull(i) + 1)
{ |
| 379 let v = new Variable("v", 0); | 379 let v = new Variable("v", 0); |
| 380 if (prev !== null) | 380 if (prev !== null) |
| 381 new EqualityConstraint(prev, v, REQUIRED); | 381 new EqualityConstraint(prev, v, REQUIRED); |
| 382 if (i === 0) | 382 if (i === 0) |
| 383 first = v; | 383 first = v; |
| 384 if (i === n) | 384 if (i === n) |
| 385 last = v; | 385 last = v; |
| 386 prev = v; | 386 prev = v; |
| 387 } | 387 } |
| 388 new StayConstraint(last, STRONG_DEFAULT); | 388 new StayConstraint(last, STRONG_DEFAULT); |
| 389 let edit = new EditConstraint(first, PREFERRED); | 389 let edit = new EditConstraint(first, PREFERRED); |
| 390 let plan = exports.planner.extractPlanFromConstraints(new List.from([edit]))
; | 390 let plan = exports.planner.extractPlanFromConstraints(new core.List$(Constra
int).from([edit])); |
| 391 for (let i = 0; dart.notNull(i) < 100; i = dart.notNull(i) + 1) { | 391 for (let i = 0; dart.notNull(i) < 100; i = dart.notNull(i) + 1) { |
| 392 first.value = i; | 392 first.value = i; |
| 393 plan.execute(); | 393 plan.execute(); |
| 394 if (last.value !== i) { | 394 if (last.value !== i) { |
| 395 core.print("Chain test failed:"); | 395 core.print("Chain test failed:"); |
| 396 core.print(`Expected last value to be ${i} but it was ${last.value}.`); | 396 core.print(`Expected last value to be ${i} but it was ${last.value}.`); |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 // Function projectionTest: (int) → void | 400 // Function projectionTest: (int) → void |
| 401 function projectionTest(n) { | 401 function projectionTest(n) { |
| 402 exports.planner = new Planner(); | 402 exports.planner = new Planner(); |
| 403 let scale = new Variable("scale", 10); | 403 let scale = new Variable("scale", 10); |
| 404 let offset = new Variable("offset", 1000); | 404 let offset = new Variable("offset", 1000); |
| 405 let src = null, dst = null; | 405 let src = null, dst = null; |
| 406 let dests = new List.from([]); | 406 let dests = new core.List$(Variable).from([]); |
| 407 for (let i = 0; dart.notNull(i) < dart.notNull(n); i = dart.notNull(i) + 1)
{ | 407 for (let i = 0; dart.notNull(i) < dart.notNull(n); i = dart.notNull(i) + 1)
{ |
| 408 src = new Variable("src", i); | 408 src = new Variable("src", i); |
| 409 dst = new Variable("dst", i); | 409 dst = new Variable("dst", i); |
| 410 dests.add(dst); | 410 dests.add(dst); |
| 411 new StayConstraint(src, NORMAL); | 411 new StayConstraint(src, NORMAL); |
| 412 new ScaleConstraint(src, scale, offset, dst, REQUIRED); | 412 new ScaleConstraint(src, scale, offset, dst, REQUIRED); |
| 413 } | 413 } |
| 414 change(src, 17); | 414 change(src, 17); |
| 415 if (dst.value !== 1170) | 415 if (dst.value !== 1170) |
| 416 core.print("Projection 1 failed"); | 416 core.print("Projection 1 failed"); |
| 417 change(dst, 1050); | 417 change(dst, 1050); |
| 418 if (src.value !== 5) | 418 if (src.value !== 5) |
| 419 core.print("Projection 2 failed"); | 419 core.print("Projection 2 failed"); |
| 420 change(scale, 5); | 420 change(scale, 5); |
| 421 for (let i = 0; dart.notNull(i) < dart.notNull(n) - 1; i = dart.notNull(i) +
1) { | 421 for (let i = 0; dart.notNull(i) < dart.notNull(n) - 1; i = dart.notNull(i) +
1) { |
| 422 if (dests.get(i).value !== dart.notNull(i) * 5 + 1000) | 422 if (dests.get(i).value !== dart.notNull(i) * 5 + 1000) |
| 423 core.print("Projection 3 failed"); | 423 core.print("Projection 3 failed"); |
| 424 } | 424 } |
| 425 change(offset, 2000); | 425 change(offset, 2000); |
| 426 for (let i = 0; dart.notNull(i) < dart.notNull(n) - 1; i = dart.notNull(i) +
1) { | 426 for (let i = 0; dart.notNull(i) < dart.notNull(n) - 1; i = dart.notNull(i) +
1) { |
| 427 if (dests.get(i).value !== dart.notNull(i) * 5 + 2000) | 427 if (dests.get(i).value !== dart.notNull(i) * 5 + 2000) |
| 428 core.print("Projection 4 failed"); | 428 core.print("Projection 4 failed"); |
| 429 } | 429 } |
| 430 } | 430 } |
| 431 // Function change: (Variable, int) → void | 431 // Function change: (Variable, int) → void |
| 432 function change(v, newValue) { | 432 function change(v, newValue) { |
| 433 let edit = new EditConstraint(v, PREFERRED); | 433 let edit = new EditConstraint(v, PREFERRED); |
| 434 let plan = exports.planner.extractPlanFromConstraints(new List.from([edit]))
; | 434 let plan = exports.planner.extractPlanFromConstraints(new core.List$(EditCon
straint).from([edit])); |
| 435 for (let i = 0; dart.notNull(i) < 10; i = dart.notNull(i) + 1) { | 435 for (let i = 0; dart.notNull(i) < 10; i = dart.notNull(i) + 1) { |
| 436 v.value = newValue; | 436 v.value = newValue; |
| 437 plan.execute(); | 437 plan.execute(); |
| 438 } | 438 } |
| 439 edit.destroyConstraint(); | 439 edit.destroyConstraint(); |
| 440 } | 440 } |
| 441 exports.planner = null; | 441 exports.planner = null; |
| 442 // Exports: | 442 // Exports: |
| 443 exports.main = main; | 443 exports.main = main; |
| 444 exports.DeltaBlue = DeltaBlue; | 444 exports.DeltaBlue = DeltaBlue; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 460 exports.BinaryConstraint = BinaryConstraint; | 460 exports.BinaryConstraint = BinaryConstraint; |
| 461 exports.ScaleConstraint = ScaleConstraint; | 461 exports.ScaleConstraint = ScaleConstraint; |
| 462 exports.EqualityConstraint = EqualityConstraint; | 462 exports.EqualityConstraint = EqualityConstraint; |
| 463 exports.Variable = Variable; | 463 exports.Variable = Variable; |
| 464 exports.Planner = Planner; | 464 exports.Planner = Planner; |
| 465 exports.Plan = Plan; | 465 exports.Plan = Plan; |
| 466 exports.chainTest = chainTest; | 466 exports.chainTest = chainTest; |
| 467 exports.projectionTest = projectionTest; | 467 exports.projectionTest = projectionTest; |
| 468 exports.change = change; | 468 exports.change = change; |
| 469 })(DeltaBlue || (DeltaBlue = {})); | 469 })(DeltaBlue || (DeltaBlue = {})); |
| OLD | NEW |