modules.js 3.2 KB

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