boot.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* ====================================================================
  2. |
  3. | Amber Smalltalk
  4. | http://amber-lang.net
  5. |
  6. ======================================================================
  7. ======================================================================
  8. |
  9. | Copyright (c) 2010-2014
  10. | Nicolas Petton <petton.nicolas@gmail.com>
  11. |
  12. | Copyright (c) 2012-2020
  13. | The Amber team https://lolg.it/org/amber/members
  14. | Amber contributors (see /CONTRIBUTORS)
  15. |
  16. | Amber is released under the MIT license
  17. |
  18. | Permission is hereby granted, free of charge, to any person obtaining
  19. | a copy of this software and associated documentation files (the
  20. | 'Software'), to deal in the Software without restriction, including
  21. | without limitation the rights to use, copy, modify, merge, publish,
  22. | distribute, sublicense, and/or sell copies of the Software, and to
  23. | permit persons to whom the Software is furnished to do so, subject to
  24. | the following conditions:
  25. |
  26. | The above copyright notice and this permission notice shall be
  27. | included in all copies or substantial portions of the Software.
  28. |
  29. | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  30. | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  32. | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  33. | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  34. | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  35. | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36. |
  37. ==================================================================== */
  38. //jshint eqnull:true
  39. define([
  40. 'require', './kernel-checks', './brikz', './kernel-fundamentals', './kernel-language'
  41. ], function (require, _, Brikz, FundamentalsFactory, LanguageFactory) {
  42. "use strict";
  43. var globals = Object.create(global);
  44. var emit = Object.create(null);
  45. var runtimeLoadedPromise = new Promise(function (resolve, reject) {
  46. require(['./kernel-runtime'], resolve, reject);
  47. });
  48. function SmalltalkInitBrik (brikz, st) {
  49. var initialized = false;
  50. globals.SmalltalkSettings = {};
  51. /* Smalltalk initialization. Called on page load */
  52. st.initialize = function () {
  53. return runtimeLoadedPromise.then(function (RuntimeFactory) {
  54. if (initialized) return;
  55. brikz.classModel.bootstrapHierarchy(globals.Class);
  56. RuntimeFactory(globals, emit).configure(brikz);
  57. return Promise.resolve(brikz.startImage.run())
  58. .then(function () {
  59. initialized = true;
  60. });
  61. });
  62. };
  63. }
  64. var api = {};
  65. var brikz = Brikz(api);
  66. var fundamentals = FundamentalsFactory(globals, emit);
  67. fundamentals.configure(brikz);
  68. LanguageFactory(fundamentals.specialConstructors, emit).configure(brikz);
  69. brikz.stInit = SmalltalkInitBrik;
  70. brikz();
  71. return {
  72. api: api,
  73. nilAsReceiver: brikz.nil.nilAsReceiver,
  74. nilAsValue: brikz.nil.nilAsValue,
  75. nilAsClass: brikz.classModel.nilAsClass,
  76. globals: globals,
  77. asReceiver: brikz.classModel.asReceiver
  78. };
  79. });