Browse Source

Merge pull request #990 from herby/deprecating-ambervm

Deprecating amber_vm
Nicolas Petton 10 years ago
parent
commit
104895b7bc

+ 1 - 1
external/amber-cli/package.json

@@ -40,7 +40,7 @@
     "grunt-init-amber": "0.0.1",
     "grunt-init": "~0.3.1",
     "bower": "~1.3.2",
-    "amber-dev": "~0.1.0"
+    "amber-dev": "~0.1.1"
   },
   "devDependencies": {
     "grunt": "~0.4.0",

+ 18 - 10
external/amber-dev/lib/amberc.js

@@ -38,16 +38,17 @@ function createConcatenator () {
 		start: function () {
 			this.add(
 				'var define = (' + require('amdefine') + ')(null, function (id) { throw new Error("Dependency not found: " +  id); }), requirejs = define.require;',
-				'define("amber_vm/browser-compatibility", [], {});'
+				'define("amber_vm/browser-compatibility", [], {});',
+				'define("amber/browser-compatibility", [], {});'
 			);
 		},
 		finish: function (realWork) {
 			this.add(
-				'define("amber_vm/_init", ["amber_vm/smalltalk", "amber_vm/globals", "' + this.ids.join('","') + '"], function (vm, globals) {',
-				'vm.initialize();',
+				'define("amber/_init", ["' + this.ids.join('","') + '"], function (boot) {',
+				'boot.vm.initialize();',
 				realWork,
 				'});',
-				'requirejs("amber_vm/_init");'
+				'requirejs("amber/_init");'
 			);
 		},
 		toString: function () {
@@ -71,6 +72,7 @@ function AmberCompiler(amber_dir) {
 	}
 
 	this.amber_dir = amber_dir;
+	// Important: in next list, boot MUST be first
 	this.kernel_libraries = ['boot', 'smalltalk', 'globals', 'nil', '_st', 'Kernel-Objects', 'Kernel-Classes', 'Kernel-Methods',
 							'Kernel-Collections', 'Kernel-Infrastructure', 'Kernel-Exceptions', 'Kernel-Transcript',
 							'Kernel-Announcements'];
@@ -120,6 +122,7 @@ AmberCompiler.prototype.main = function(configuration, finished_callback) {
 	if (undefined !== configuration.jsLibraryDirs) {
 		configuration.jsLibraryDirs.push(path.join(this.amber_dir, 'src'));
 		configuration.jsLibraryDirs.push(path.join(this.amber_dir, 'support'));
+		configuration.jsLibraryDirs.push(path.join(this.amber_dir, 'support', 'deprecated-vm-files'));
 	}
 
 	console.ambercLog = console.log;
@@ -325,9 +328,9 @@ function create_compiler(configuration) {
 			// data is an array where index 0 is the error code and index 1 contains the data
 			builder.add(data);
 			// matches and returns the "module_id" string in the AMD definition: define("module_id", ...)
-			var match = ('' + data).match(/^define\("([^"]*)"/);
+			var match = ('' + data).match(/(^|\n)define\("([^"]*)"/);
 			if (match) {
-				builder.addId(match[1]);
+				builder.addId(match[2]);
 			}
 		});
 	})
@@ -362,8 +365,11 @@ function create_compiler(configuration) {
 				loadIds.push(match[1]);
 			}
 		});
+		//backward compatibility
+		if (builder.ids.indexOf("amber_vm/boot") === -1) { console.log(builder.ids); console.log("defining amber_vm/boot"); builder.add('define("amber_vm/boot", ["amber/boot"], function (boot) { return boot; });'); }
+
 		// store the generated smalltalk env in configuration.{vm,globals}
-		builder.finish('configuration.vm = vm; configuration.globals = globals;');
+		builder.finish('configuration.vm = boot.vm; configuration.globals = boot.globals;');
 		loadIds.forEach(function (id) {
 			builder.add('requirejs("' + id + '");');
 		});
@@ -547,9 +553,9 @@ function compose_js_files(configuration) {
 				console.log('Adding : ' + file);
 				var buffer = fs.readFileSync(file);
 				// matches and returns the "module_id" string in the AMD define: define("module_id", ...)
-				var match = buffer.toString().match(/^define\("([^"]*)"/);
+				var match = buffer.toString().match(/(^|\n)define\("([^"]*)"/);
 				if (match /*&& match[1].slice(0,9) !== "amber_vm/"*/) {
-					builder.addId(match[1]);
+					builder.addId(match[2]);
 				}
 				builder.add(buffer);
 			} else {
@@ -557,8 +563,10 @@ function compose_js_files(configuration) {
 				reject(Error('Can not find file ' + file));
 			}
 		});
+		//backward compatibility
+		if (builder.ids.indexOf("amber_vm/boot") === -1) { builder.add('define("amber_vm/boot", ["amber/boot"], function (boot) { return boot; });'); }
 
-		var mainFunctionOrFile = '';
+		var mainFunctionOrFile = 'var vm = boot.vm, globals = boot.globals;\n';
 
 		if (undefined !== configuration.main) {
 			console.log('Adding call to: %s>>main', configuration.main);

+ 1 - 1
external/amber-dev/package.json

@@ -1,6 +1,6 @@
 {
   "name": "amber-dev",
-  "version": "0.1.0",
+  "version": "0.1.1",
   "description": "Development goodies for Amber Smalltalk",
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"

+ 1 - 1
grunt/tasks/grunt-peg.js

@@ -18,7 +18,7 @@ module.exports = function(grunt) {
       export_var: 'module.exports'
     });
     var parser = PEG.buildParser(grunt.file.read(this.data.src), options);
-    var content = 'define("amber_vm/parser", ["./globals", "./nil"], function(globals, nil) {\n'+options.export_var + ' = ' + parser + ';\n});';
+    var content = 'define("amber/parser", ["./boot"], function(boot) {\nvar globals = boot.globals, nil = boot.nil;\n'+options.export_var + ' = ' + parser + ';\n});';
     grunt.file.write(this.data.dest, content);
   });
 };

+ 1 - 1
package.json

@@ -33,7 +33,7 @@
     "grunt": "~0.4.0",
     "grunt-contrib-jshint": "~0.3.0",
     "grunt-execute": "~0.2.1",
-    "amber-dev": "~0.1.0",
+    "amber-dev": "~0.1.1",
     "grunt-contrib-clean": "~0.5.0"
   }
 }

+ 9 - 4
src/Kernel-ImportExport.js

@@ -1,4 +1,5 @@
-define("amber_core/Kernel-ImportExport", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_vm/globals", "amber_core/Kernel-Objects", "amber_core/Kernel-Infrastructure"], function(smalltalk,nil,_st, globals){
+define("amber_core/Kernel-ImportExport", ["amber/boot", "amber_core/Kernel-Objects", "amber_core/Kernel-Infrastructure"], function($boot){
+var smalltalk=$boot.vm,nil=$boot.nil,_st=$boot.asReceiver,globals=$boot.globals;
 smalltalk.addPackage('Kernel-ImportExport');
 smalltalk.packages["Kernel-ImportExport"].transport = {"type":"amd","amdNamespace":"amber_core"};
 
@@ -1098,13 +1099,17 @@ _st(aStream)._nextPutAll_(_st(aPackage)._name());
 $ctx1.sendIdx["nextPutAll:"]=4;
 _st(aStream)._nextPutAll_("\x22, ");
 $ctx1.sendIdx["nextPutAll:"]=5;
-_st(aStream)._nextPutAll_(_st(["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_vm/globals"].__comma(self._amdNamesOfPackages_(_st(aPackage)._loadDependencies())))._asJavascript());
+_st(aStream)._nextPutAll_(_st(["amber/boot"].__comma(self._amdNamesOfPackages_(_st(aPackage)._loadDependencies())))._asJavascript());
 $ctx1.sendIdx["nextPutAll:"]=6;
-_st(aStream)._nextPutAll_(", function(smalltalk,nil,_st, globals){");
+_st(aStream)._nextPutAll_(", function($boot){");
+$ctx1.sendIdx["nextPutAll:"]=7;
+_st(aStream)._lf();
+$ctx1.sendIdx["lf"]=1;
+_st(aStream)._nextPutAll_("var smalltalk=$boot.vm,nil=$boot.nil,_st=$boot.asReceiver,globals=$boot.globals;");
 $1=_st(aStream)._lf();
 return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOf:on:",{aPackage:aPackage,aStream:aStream},globals.AmdExporter)})},
 args: ["aPackage", "aStream"],
-source: "exportPackagePrologueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'define(\x22';\x0a\x09\x09nextPutAll: (self amdNamespaceOfPackage: aPackage);\x0a\x09\x09nextPutAll: '/';\x0a\x09\x09nextPutAll: aPackage name;\x0a\x09\x09nextPutAll: '\x22, ';\x0a\x09\x09nextPutAll: (#('amber_vm/smalltalk' 'amber_vm/nil' 'amber_vm/_st' 'amber_vm/globals'), (self amdNamesOfPackages: aPackage loadDependencies)) asJavascript;\x0a\x09\x09nextPutAll: ', function(smalltalk,nil,_st, globals){';\x0a\x09\x09lf",
+source: "exportPackagePrologueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'define(\x22';\x0a\x09\x09nextPutAll: (self amdNamespaceOfPackage: aPackage);\x0a\x09\x09nextPutAll: '/';\x0a\x09\x09nextPutAll: aPackage name;\x0a\x09\x09nextPutAll: '\x22, ';\x0a\x09\x09nextPutAll: (#('amber/boot'), (self amdNamesOfPackages: aPackage loadDependencies)) asJavascript;\x0a\x09\x09nextPutAll: ', function($boot){';\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: 'var smalltalk=$boot.vm,nil=$boot.nil,_st=$boot.asReceiver,globals=$boot.globals;';\x0a\x09\x09lf",
 messageSends: ["nextPutAll:", "amdNamespaceOfPackage:", "name", "asJavascript", ",", "amdNamesOfPackages:", "loadDependencies", "lf"],
 referencedClasses: []
 }),

+ 4 - 2
src/Kernel-ImportExport.st

@@ -386,8 +386,10 @@ exportPackagePrologueOf: aPackage on: aStream
 		nextPutAll: '/';
 		nextPutAll: aPackage name;
 		nextPutAll: '", ';
-		nextPutAll: (#('amber_vm/smalltalk' 'amber_vm/nil' 'amber_vm/_st' 'amber_vm/globals'), (self amdNamesOfPackages: aPackage loadDependencies)) asJavascript;
-		nextPutAll: ', function(smalltalk,nil,_st, globals){';
+		nextPutAll: (#('amber/boot'), (self amdNamesOfPackages: aPackage loadDependencies)) asJavascript;
+		nextPutAll: ', function($boot){';
+		lf;
+		nextPutAll: 'var smalltalk=$boot.vm,nil=$boot.nil,_st=$boot.asReceiver,globals=$boot.globals;';
 		lf
 ! !
 

+ 0 - 20
support/_st.js

@@ -1,20 +0,0 @@
-// !!! THIS FILE IS DEPRECATED !!!
-// Use as-receiver.js instead.
-
-/**
- * _st is a function used all over the compiled amber code that
- * takes any value (JavaScript or Smalltalk)
- * and returns a proper Amber Smalltalk receiver.
- *
- * null or undefined -> nil,
- * plain JS object -> wrapped JS object,
- * otherwise unchanged
- */
-
-define("amber_vm/_st", ["./globals", "./nil"], function (globals, nil) {
-    return function (o) {
-        if (o == null) { return nil; }
-        if (o.klass) { return o; }
-        return globals.JSObjectProxy._on_(o);
-    };
-});

+ 2 - 2
support/amber.js

@@ -77,8 +77,8 @@ require = function (require) {
     var config = {
         paths: {
             'amber': amber_home + '/support',
-            'amber_vm': amber_home + '/support',
-            'amber_vm/_st': amber_home + '/support/as-receiver',
+            'amber_vm': amber_home + '/support/deprecated-vm-files',
+            'amber_vm/_st': amber_home + '/support/deprecated-vm-files/as-receiver',
             'amber_css': amber_home + '/css',
             'amber_lib': library_home,
             'amber_core': amber_home + '/src',

+ 0 - 18
support/as-receiver.js

@@ -1,18 +0,0 @@
-
-/**
- * _st is a function used all over the compiled amber code that
- * takes any value (JavaScript or Smalltalk)
- * and returns a proper Amber Smalltalk receiver.
- *
- * null or undefined -> nil,
- * plain JS object -> wrapped JS object,
- * otherwise unchanged
- */
-
-define("amber_vm/_st", ["./globals", "./nil"], function (globals, nil) {
-    return function (o) {
-        if (o == null) { return nil; }
-        if (o.klass) { return o; }
-        return globals.JSObjectProxy._on_(o);
-    };
-});

+ 25 - 2
support/boot.js

@@ -38,7 +38,7 @@
  ==================================================================== */
 
 
-define("amber_vm/boot", [ 'require', './browser-compatibility' ], function (require) {
+define("amber/boot", [ 'require', './browser-compatibility' ], function (require) {
 
 	/* Reconfigurable micro composition system, https://github.com/amber-smalltalk/brikz */
 
@@ -1122,6 +1122,28 @@ define("amber_vm/boot", [ 'require', './browser-compatibility' ], function (requ
 		};
 	}
 
+    /* Defines asReceiver to be present at load time */
+    /* (logically it belongs more to PrimitiveBrik) */
+    function AsReceiverBrik(brikz, st) {
+
+        var nil = brikz.ensure("root").nil;
+
+        /**
+         * This function is used all over the compiled amber code.
+         * It takes any value (JavaScript or Smalltalk)
+         * and returns a proper Amber Smalltalk receiver.
+         *
+         * null or undefined -> nil,
+         * plain JS object -> wrapped JS object,
+         * otherwise unchanged
+         */
+        this.asReceiver = function (o) {
+            if (o == null) { return nil; }
+            if (o.klass) { return o; }
+            return globals.JSObjectProxy._on_(o);
+        };
+    }
+
 
 	/* Making smalltalk that can load */
 
@@ -1136,6 +1158,7 @@ define("amber_vm/boot", [ 'require', './browser-compatibility' ], function (requ
 	brikz.stInit = SmalltalkInitBrik;
 	brikz.augments = AugmentsBrik;
 	brikz.amdBrik = AMDBrik;
+	brikz.asReceiverBrik = AsReceiverBrik;
 
 	brikz.rebuild();
 
@@ -1149,5 +1172,5 @@ define("amber_vm/boot", [ 'require', './browser-compatibility' ], function (requ
 		brikz.rebuild();
 	};
 
-	return { vm: api, nil: brikz.root.nil, globals: globals };
+	return { vm: api, nil: brikz.root.nil, globals: globals, asReceiver: brikz.asReceiverBrik.asReceiver };
 });

+ 1 - 1
support/browser-compatibility.js

@@ -1,4 +1,4 @@
-define("amber_vm/browser-compatibility", [
+define([
     './ensure-console',
     'amber_lib/es5-shim/es5-shim.min',
     'amber_lib/es5-shim/es5-sham.min'

+ 3 - 0
support/deprecated-vm-files/_st.js

@@ -0,0 +1,3 @@
+define("amber_vm/_st", ["./boot"], function (boot) {
+    return boot.asReceiver;
+});

+ 3 - 0
support/deprecated-vm-files/as-receiver.js

@@ -0,0 +1,3 @@
+define("amber_vm/_st", ["./boot"], function (boot) {
+    return boot.asReceiver;
+});

+ 3 - 0
support/deprecated-vm-files/boot.js

@@ -0,0 +1,3 @@
+define("amber_vm/boot", ["amber/boot"], function (boot) {
+    return boot;
+});

+ 0 - 0
support/globals.js → support/deprecated-vm-files/globals.js


+ 0 - 0
support/nil.js → support/deprecated-vm-files/nil.js


+ 0 - 0
support/smalltalk.js → support/deprecated-vm-files/smalltalk.js


+ 1 - 1
support/lang.js

@@ -1,7 +1,7 @@
 define([
 	'./helpers', // pre-fetch, dep of ./deploy
 	'./deploy',
-	'amber_vm/parser',
+	'amber/parser',
 	'amber_core/Kernel-ImportExport',
 	'amber_core/Compiler-Exceptions',
 	'amber_core/Compiler-Core',

+ 2 - 1
support/parser.js

@@ -1,4 +1,5 @@
-define("amber_vm/parser", ["./globals", "./nil"], function(globals, nil) {
+define("amber/parser", ["./boot"], function(boot) {
+var globals = boot.globals, nil = boot.nil;
 globals.SmalltalkParser = (function() {
   /*
    * Generated by PEG.js 0.8.0.