2
0

REPL.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. smalltalk.addPackage('REPL', {});
  2. smalltalk.addClass('Repl', smalltalk.Object, ['readline', 'interface', 'util'], 'REPL');
  3. smalltalk.addMethod(
  4. "_close",
  5. smalltalk.method({
  6. selector: "close",
  7. category: 'actions',
  8. fn: function (){
  9. var self=this;
  10. smalltalk.send(smalltalk.send((typeof process == 'undefined' ? nil : process), "_stdin", []), "_destroy", []);
  11. return self;},
  12. args: [],
  13. source: "close\x0a\x09process stdin destroy",
  14. messageSends: ["destroy", "stdin"],
  15. referencedClasses: []
  16. }),
  17. smalltalk.Repl);
  18. smalltalk.addMethod(
  19. "_createInterface",
  20. smalltalk.method({
  21. selector: "createInterface",
  22. category: 'actions',
  23. fn: function (){
  24. var self=this;
  25. (self['@interface']=smalltalk.send(self['@readline'], "_createInterface_stdout_", [smalltalk.send((typeof process == 'undefined' ? nil : process), "_stdin", []), smalltalk.send((typeof process == 'undefined' ? nil : process), "_stdout", [])]));
  26. smalltalk.send(self['@interface'], "_on_do_", ["line", (function(buffer){return smalltalk.send(self, "_eval_", [buffer]);})]);
  27. smalltalk.send(self['@interface'], "_on_do_", ["close", (function(){return smalltalk.send(self, "_close", []);})]);
  28. smalltalk.send(self, "_setPrompt", []);
  29. smalltalk.send(self['@interface'], "_prompt", []);
  30. return self;},
  31. args: [],
  32. source: "createInterface\x0a\x09\x22No completion for now\x22\x0a\x09interface := readline createInterface: process stdin stdout: process stdout.\x0a\x09interface on: 'line' do: [:buffer | self eval: buffer].\x0a\x09interface on: 'close' do: [self close].\x0a\x09self setPrompt.\x0a\x09interface prompt",
  33. messageSends: ["createInterface:stdout:", "stdin", "stdout", "on:do:", "eval:", "close", "setPrompt", "prompt"],
  34. referencedClasses: []
  35. }),
  36. smalltalk.Repl);
  37. smalltalk.addMethod(
  38. "_eval_",
  39. smalltalk.method({
  40. selector: "eval:",
  41. category: 'actions',
  42. fn: function (buffer){
  43. var self=this;
  44. var result=nil;
  45. ((($receiver = smalltalk.send(buffer, "_isEmpty", [])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return smalltalk.send(self, "_try_catch_", [(function(){(result=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_loadExpression_", [buffer]));return smalltalk.send((smalltalk.Transcript || Transcript), "_show_", [result]);}), (function(e){return ((($receiver = smalltalk.send(e, "_isSmalltalkError", [])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(smalltalk.send((smalltalk.ErrorHandler || ErrorHandler), "_new", []), "_handleError_", [e]);})() : (function(){return smalltalk.send(smalltalk.send((typeof process == 'undefined' ? nil : process), "_stdout", []), "_write_", [smalltalk.send(e, "_jsStack", [])]);})()) : smalltalk.send($receiver, "_ifTrue_ifFalse_", [(function(){return smalltalk.send(smalltalk.send((smalltalk.ErrorHandler || ErrorHandler), "_new", []), "_handleError_", [e]);}), (function(){return smalltalk.send(smalltalk.send((typeof process == 'undefined' ? nil : process), "_stdout", []), "_write_", [smalltalk.send(e, "_jsStack", [])]);})]));})]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return smalltalk.send(self, "_try_catch_", [(function(){(result=smalltalk.send(smalltalk.send((smalltalk.Compiler || Compiler), "_new", []), "_loadExpression_", [buffer]));return smalltalk.send((smalltalk.Transcript || Transcript), "_show_", [result]);}), (function(e){return ((($receiver = smalltalk.send(e, "_isSmalltalkError", [])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(smalltalk.send((smalltalk.ErrorHandler || ErrorHandler), "_new", []), "_handleError_", [e]);})() : (function(){return smalltalk.send(smalltalk.send((typeof process == 'undefined' ? nil : process), "_stdout", []), "_write_", [smalltalk.send(e, "_jsStack", [])]);})()) : smalltalk.send($receiver, "_ifTrue_ifFalse_", [(function(){return smalltalk.send(smalltalk.send((smalltalk.ErrorHandler || ErrorHandler), "_new", []), "_handleError_", [e]);}), (function(){return smalltalk.send(smalltalk.send((typeof process == 'undefined' ? nil : process), "_stdout", []), "_write_", [smalltalk.send(e, "_jsStack", [])]);})]));})]);})]));
  46. smalltalk.send(self['@interface'], "_prompt", []);
  47. return self;},
  48. args: ["buffer"],
  49. source: "eval: buffer\x0a\x09| result |\x0a\x09buffer isEmpty ifFalse: [\x0a\x09\x09self try: [\x0a\x09\x09\x09result := Compiler new loadExpression: buffer.\x0a\x09\x09\x09Transcript show: result]\x0a\x09\x09catch: [:e |\x0a\x09\x09\x09e isSmalltalkError\x0a\x09\x09\x09 ifTrue: [ErrorHandler new handleError: e]\x0a\x09\x09\x09 ifFalse: [process stdout write: e jsStack]]].\x0a\x09interface prompt",
  50. messageSends: ["ifFalse:", "isEmpty", "try:catch:", "loadExpression:", "new", "show:", "ifTrue:ifFalse:", "isSmalltalkError", "handleError:", "write:", "stdout", "jsStack", "prompt"],
  51. referencedClasses: ["Compiler", "Transcript", "ErrorHandler"]
  52. }),
  53. smalltalk.Repl);
  54. smalltalk.addMethod(
  55. "_initialize",
  56. smalltalk.method({
  57. selector: "initialize",
  58. category: 'initialization',
  59. fn: function (){
  60. var self=this;
  61. smalltalk.send(self, "_initialize", [], smalltalk.Object);
  62. (self['@readline']=smalltalk.send((typeof require == 'undefined' ? nil : require), "_value_", ["readline"]));
  63. (self['@util']=smalltalk.send((typeof require == 'undefined' ? nil : require), "_value_", ["util"]));
  64. return self;},
  65. args: [],
  66. source: "initialize\x0a\x09super initialize.\x0a\x09readline := require value: 'readline'.\x0a\x09util := require value: 'util'",
  67. messageSends: ["initialize", "value:"],
  68. referencedClasses: []
  69. }),
  70. smalltalk.Repl);
  71. smalltalk.addMethod(
  72. "_prompt",
  73. smalltalk.method({
  74. selector: "prompt",
  75. category: 'accessing',
  76. fn: function (){
  77. var self=this;
  78. return "amber >> ";
  79. return self;},
  80. args: [],
  81. source: "prompt\x0a\x09^'amber >> '",
  82. messageSends: [],
  83. referencedClasses: []
  84. }),
  85. smalltalk.Repl);
  86. smalltalk.addMethod(
  87. "_setPrompt",
  88. smalltalk.method({
  89. selector: "setPrompt",
  90. category: 'actions',
  91. fn: function (){
  92. var self=this;
  93. smalltalk.send(self['@interface'], "_setPrompt_", [smalltalk.send(self, "_prompt", [])]);
  94. return self;},
  95. args: [],
  96. source: "setPrompt\x0a\x09interface setPrompt: self prompt",
  97. messageSends: ["setPrompt:", "prompt"],
  98. referencedClasses: []
  99. }),
  100. smalltalk.Repl);
  101. smalltalk.addMethod(
  102. "_main",
  103. smalltalk.method({
  104. selector: "main",
  105. category: 'not yet classified',
  106. fn: function (){
  107. var self=this;
  108. smalltalk.send(smalltalk.send(self, "_new", []), "_createInterface", []);
  109. return self;},
  110. args: [],
  111. source: "main\x0a\x09self new createInterface",
  112. messageSends: ["createInterface", "new"],
  113. referencedClasses: []
  114. }),
  115. smalltalk.Repl.klass);