Guest User

Untitled

a guest
Feb 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. diff --git a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts
  2. index f6f6486..bcbc891 100644
  3. --- a/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts
  4. +++ b/packages/@glimmer/runtime/lib/compiled/opcodes/component.ts
  5. @@ -353,6 +353,7 @@ APPEND_OPCODES.add(Op.GetComponentSelf, (vm, { op1: _state }) => {
  6. let { definition, state } = check(vm.fetchValue(_state), CheckComponentInstance);
  7. let { manager } = definition;
  8.  
  9. + console.log(manager, state, manager.getSelf(state));
  10. vm.stack.push(manager.getSelf(state));
  11. });
  12.  
  13. diff --git a/packages/@glimmer/runtime/lib/vm/gbox.ts b/packages/@glimmer/runtime/lib/vm/gbox.ts
  14. index 8f5b288..b559282 100644
  15. --- a/packages/@glimmer/runtime/lib/vm/gbox.ts
  16. +++ b/packages/@glimmer/runtime/lib/vm/gbox.ts
  17. @@ -10,7 +10,7 @@
  18. import { assert } from '@glimmer/util';
  19. import { DEBUG } from '@glimmer/local-debug-flags';
  20. import { WasmLowLevelVM } from '@glimmer/low-level';
  21. -import { isConst } from '@glimmer/reference';
  22. +import { isConst, ConstReference } from '@glimmer/reference';
  23. import { ComponentInstance } from "../compiled/opcodes/component";
  24. import {
  25. ComponentDefinition,
  26. @@ -72,6 +72,14 @@ export class Context {
  27. }
  28.  
  29. encode(a: any): number {
  30. + if (a instanceof ConstReference) {
  31. + console.log('encode', a);
  32. + return this.encodeRaw(a.value()) | Flag.CONST_REF;
  33. + }
  34. + return this.encodeRaw(a);
  35. + }
  36. +
  37. + private encodeRaw(a: any): number {
  38. switch (typeof a) {
  39. case 'number':
  40. if (a as number % 1 === 0)
  41. @@ -93,13 +101,23 @@ export class Context {
  42. }
  43.  
  44. decode(a: number): any {
  45. + const ret = this.decodeRaw(a);
  46. + if (this.isConstReference(a) ) {
  47. + let r = new ConstReference(ret);
  48. + console.log('decode', r);
  49. + return r;
  50. + }
  51. + return ret;
  52. + }
  53. +
  54. + private decodeRaw(a: number): any {
  55. switch (a & TAG_MASK) {
  56. case Tag.NUMBER:
  57. return a >> FIELD_SIZE;
  58. case Tag.NEGATIVE:
  59. return -(a >> FIELD_SIZE);
  60. case Tag.BOOLEAN_OR_VOID:
  61. - switch (a) {
  62. + switch (a & ~Flag.CONST_REF) {
  63. case Immediates.False:
  64. return false;
  65. case Immediates.True:
  66. @@ -127,7 +145,7 @@ export class Context {
  67. return this.stack[idx];
  68. }
  69.  
  70. - isConstReference(gbox: number): boolean {
  71. + private isConstReference(gbox: number): boolean {
  72. return !!((gbox & FLAG_MASK) === Flag.CONST_REF);
  73. }
  74.  
  75. @@ -143,12 +161,12 @@ export class Context {
  76. private encodeObject(a: any): number {
  77. const idx = this.stack.length;
  78. this.stack.push(a);
  79. - return this.encodeNumberAndTag(idx, Tag.ANY, isConst(a));
  80. + return this.encodeNumberAndTag(idx, Tag.ANY);
  81. }
  82.  
  83. - private encodeNumberAndTag(a: number, tag: number, isConst = false): number {
  84. + private encodeNumberAndTag(a: number, tag: number): number {
  85. assert(a < (1 << (32 - FIELD_SIZE)), 'number too big');
  86. - return (a << FIELD_SIZE) | tag | (isConst ? Flag.CONST_REF : 0);
  87. + return (a << FIELD_SIZE) | tag;
  88. }
  89.  
  90. private decodeComponent(component_idx: number): ComponentInstance {
  91. diff --git a/packages/@glimmer/runtime/test/gbox-test.ts b/packages/@glimmer/runtime/test/gbox-test.ts
  92. index 6784f21..f67a1fd 100644
  93. --- a/packages/@glimmer/runtime/test/gbox-test.ts
  94. +++ b/packages/@glimmer/runtime/test/gbox-test.ts
  95. @@ -44,6 +44,7 @@ QUnit.test("serializes JavaScript objects", assert => {
  96. QUnit.test("annotates ConstReference objects", assert => {
  97. let ref = new ConstReference(true);
  98. let gbox = ctx.encode(ref);
  99. - assert.strictEqual(ctx.decode(gbox), ref);
  100. - assert.ok(ctx.isConstReference(gbox));
  101. + let ref2 = ctx.decode(gbox);
  102. + assert.ok(ref2 instanceof ConstReference);
  103. + assert.strictEqual(ref2.value(), ref.value());
  104. });
Add Comment
Please, Sign In to add comment