2
0

modules.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. var RTL$ = {
  2. extend: function extend(methods){
  3. function Type(){
  4. for(var m in methods)
  5. this[m] = methods[m];
  6. }
  7. Type.prototype = this.prototype;
  8. var result = methods.init;
  9. result.prototype = new Type(); // inherit this.prototype
  10. result.prototype.constructor = result; // to see constructor name in diagnostic
  11. result.extend = extend;
  12. return result;
  13. },
  14. typeGuard: function (from, to){
  15. if (!(from instanceof to))
  16. throw new Error("typeguard assertion failed");
  17. return from;
  18. },
  19. makeRef: function (obj, prop){
  20. return {set: function(v){ obj[prop] = v; },
  21. get: function(){ return obj[prop]; }};
  22. },
  23. makeArray: function (/*dimensions, initializer*/){
  24. var forward = Array.prototype.slice.call(arguments);
  25. var result = new Array(forward.shift());
  26. var i;
  27. if (forward.length == 1){
  28. var init = forward[0];
  29. if (typeof init == "function")
  30. for(i = 0; i < result.length; ++i)
  31. result[i] = init();
  32. else
  33. for(i = 0; i < result.length; ++i)
  34. result[i] = init;
  35. }
  36. else
  37. for(i = 0; i < result.length; ++i)
  38. result[i] = this.makeArray.apply(this, forward);
  39. return result;
  40. }
  41. };
  42. var m1 = function (){
  43. var ci = 123;
  44. var Base = RTL$.extend({
  45. init: function Base(){
  46. this.i = 0;
  47. }
  48. });
  49. var T = Base.extend({
  50. init: function T(){
  51. Base.prototype.init.call(this);
  52. }
  53. });
  54. var TPA = RTL$.extend({
  55. init: function TPA(){
  56. }
  57. });
  58. var TPB = Base.extend({
  59. init: function TPB(){
  60. Base.prototype.init.call(this);
  61. }
  62. });
  63. var i = 0;
  64. var anonymous$1 = RTL$.extend({
  65. init: function anonymous$1(){
  66. this.i = 0;
  67. }
  68. });
  69. var pr = null;
  70. var pr2 = null;
  71. function p(){
  72. }
  73. function makeTPA(){
  74. var result = null;
  75. result = new TPA();
  76. return result;
  77. }
  78. function makeTPB(){
  79. var result = null;
  80. result = new TPB();
  81. return result;
  82. }
  83. pr = new anonymous$1();
  84. return {
  85. ci: ci,
  86. Base: Base,
  87. T: T,
  88. TPA: TPA,
  89. TPB: TPB,
  90. i: function(){return i;},
  91. pr: function(){return pr;},
  92. pr2: function(){return pr2;},
  93. p: p,
  94. makeTPA: makeTPA,
  95. makeTPB: makeTPB
  96. }
  97. }();
  98. var m2 = function (m1){
  99. var T = m1.T.extend({
  100. init: function T(){
  101. m1.T.prototype.init.call(this);
  102. this.i2 = 0;
  103. }
  104. });
  105. var r = new m1.T();
  106. var r2 = new T();
  107. var pb = null;
  108. var ptr = null;
  109. var ptr2 = null;
  110. var ptrA = null;
  111. function p(i/*INTEGER*/){
  112. }
  113. function ref(i/*VAR INTEGER*/){
  114. }
  115. ptr = new m1.T();
  116. pb = ptr;
  117. RTL$.typeGuard(pb, m1.T).i = 123;
  118. ptr2 = new T();
  119. ptr2.i = 1;
  120. ptr2.i2 = 2;
  121. ptrA = m1.makeTPA();
  122. m1.p();
  123. p(m1.i());
  124. p(m1.ci);
  125. ref(RTL$.makeRef(m1.pr2(), "i"));
  126. }(m1);
  127. var m3 = function (m1, m2){
  128. var T = m2.T.extend({
  129. init: function T(){
  130. m2.T.prototype.init.call(this);
  131. }
  132. });
  133. var r = new m2.T();
  134. var r2 = new T();
  135. var a = RTL$.makeArray(3, function(){return new m2.Base();});
  136. var ptr = null;
  137. var pb = null;
  138. var pTPB = null;
  139. ptr = new m2.T();
  140. pb = ptr;
  141. RTL$.typeGuard(pb, m2.T).i = 123;
  142. pb = m2.makeTPB();
  143. pTPB = RTL$.typeGuard(pb, m2.TPB);
  144. m2.p();
  145. }(m2, m1);