Procházet zdrojové kódy

amberc.js: remove now unneeded init.js code + formatting

Manfred Kroehnert před 10 roky
rodič
revize
0f4523968a
1 změnil soubory, kde provedl 35 přidání a 43 odebrání
  1. 35 43
      bin/amberc.js

+ 35 - 43
bin/amberc.js

@@ -55,24 +55,32 @@ function makeBuilder () {
 	return {
 		elements: [],
 		ids: [],
-		add: function () { this.elements.push.apply(this.elements, arguments); },
-		addId: function () { this.ids.push.apply(this.ids, arguments); },
-		forEach: function () { this.elements.forEach.apply(this.elements, arguments); },
+		add: function () {
+			this.elements.push.apply(this.elements, arguments);
+		},
+		addId: function () {
+			this.ids.push.apply(this.ids, arguments);
+		},
+		forEach: function () {
+			this.elements.forEach.apply(this.elements, arguments);
+		},
 		start: function () {
 			this.add(
-				'var define = ('+(''+defineDefine).replace('$SRC$', ""+require('amdefine'))+')(), requirejs = define.require;',
+				'var define = (' + ('' + defineAmdDefine).replace('$SRC$', '' + require('amdefine')) + ')(), requirejs = define.require;',
 				'define("amber_vm/browser-compatibility", [], {});'
 			);
 		},
 		finish: function (realWork) {
 			this.add(
-				'define("amber_vm/_init", ["amber_vm/smalltalk","'+this.ids.join('","')+'"], function (smalltalk) {',
+				'define("amber_vm/_init", ["amber_vm/smalltalk","' + this.ids.join('","') + '"], function (smalltalk) {',
 				'smalltalk.initialize();',
 				realWork,
 				'});', 'requirejs("amber_vm/_init");'
 			);
 		},
-		toString: function () { return this.elements.join('\n'); }
+		toString: function () {
+			return this.elements.join('\n');
+		}
 	};
 }
 
@@ -135,7 +143,6 @@ var createDefaults = function(amber_dir, finished_callback){
 
 	return {
 		'load': [],
-//		'init': path.join(amber_dir, 'js', 'init.js'),
 		'main': undefined,
 		'mainfile': undefined,
 		'stFiles': [],
@@ -199,9 +206,6 @@ AmberC.prototype.check_configuration_ok = function(configuration) {
 	if (undefined === configuration) {
 		throw new Error('AmberC.check_configuration_ok(): missing configuration object');
 	}
-	if (undefined === configuration.init) {
-//		throw new Error('AmberC.check_configuration_ok(): init value missing in configuration object');
-	}
 
 	if (0 === configuration.jsFiles.length && 0 === configuration.stFiles.lenght) {
 		throw new Error('AmberC.check_configuration_ok(): no files to compile/link specified in configuration object');
@@ -259,10 +263,12 @@ AmberC.prototype.check_for_closure_compiler = function(callback) {
  */
 AmberC.prototype.resolve_js = function(filename, callback) {
 	var special = filename[0] == "@";
-	if (special) { filename = filename.slice(1); }
+	if (special) {
+		filename = filename.slice(1);
+	}
 	var baseName = path.basename(filename, '.js');
 	var jsFile = baseName + this.defaults.loadsuffix + '.js';
-	var amberJsFile = path.join(this.amber_dir, special?'js/lib':'js', jsFile);
+	var amberJsFile = path.join(this.amber_dir, (special ? 'js/lib' : 'js'), jsFile);
 	console.log('Resolving: ' + jsFile);
 	fs.exists(jsFile, function(exists) {
 		if (exists) {
@@ -364,7 +370,7 @@ AmberC.prototype.resolve_libraries = function() {
 	// Resolve libraries listed in this.kernel_libraries
 	var self = this;
 	var all_resolved = new Combo(function(resolved_kernel_files, resolved_compiler_files) {
-		self.resolve_init(resolved_compiler_files[0]);
+		self.create_compiler(resolved_compiler_files[0]);
 	});
 	this.resolve_kernel(all_resolved.add());
 	this.resolve_compiler(all_resolved.add());
@@ -424,23 +430,6 @@ AmberC.prototype.resolve_compiler = function(callback) {
 };
 
 
-/**
- * Resolves default.init and adds it to compilerFiles.
- * Followed by create_compiler().
- */
-AmberC.prototype.resolve_init = function(compilerFiles) {
-	// check and add init.js
-//	var initFile = this.defaults.init;
-//	if ('.js' !== path.extname(initFile)) {
-//		initFile = this.resolve_js(initFile);
-//		this.defaults.init = initFile;
-//	}
-//	compilerFiles.push(initFile);
-
-	this.create_compiler(compilerFiles);
-};
-
-
 /**
  * Read all .js files needed by compiler and eval() them.
  * The finished Compiler gets stored in defaults.smalltalk.
@@ -456,9 +445,12 @@ AmberC.prototype.create_compiler = function(compilerFilesArray) {
 		Array.prototype.slice.call(arguments).forEach(function(data) {
 			// data is an array where index 0 is the error code and index 1 contains the data
 			builder.add(data[1]);
-			var match = (""+data[1]).match(/^define\("([^"]*)"/);
-			if (match) builder.addId(match[1]);
+			var match = ('' + data[1]).match(/^define\("([^"]*)"/);
+			if (match) {
+				builder.addId(match[1]);
+			}
 		});
+		// store the generated smalltalk env in self.defaults.smalltalk
 		builder.finish('self.defaults.smalltalk = smalltalk;');
 		builder.add('})();');
 		eval(builder.toString());
@@ -614,11 +606,6 @@ AmberC.prototype.compose_js_files = function() {
 		program_files.push.apply(program_files, compiledFiles);
 	}
 
-	if (undefined !== defaults.init) {
-//		console.log('Adding initializer ' + defaults.init);
-//		program_files.push(defaults.init);
-	}
-
 	console.ambercLog('Writing program file: %s.js', programFile);
 
 	var fileStream = fs.createWriteStream(programFile + defaults.suffix_used + '.js');
@@ -639,7 +626,9 @@ AmberC.prototype.compose_js_files = function() {
 			console.log('Adding : ' + file);
 			var buffer = fs.readFileSync(file);
 			var match = buffer.toString().match(/^define\("([^"]*)"/);
-			if (match /*&& match[1].slice(0,9) !== "amber_vm/"*/) { builder.addId(match[1]); }
+			if (match /*&& match[1].slice(0,9) !== "amber_vm/"*/) {
+				builder.addId(match[1]);
+			}
 			builder.add(buffer);
 		} else {
 			fileStream.end();
@@ -647,22 +636,25 @@ AmberC.prototype.compose_js_files = function() {
 		}
 	});
 
-	var realWork = '';
+	var mainFunctionOrFile = '';
 
 	if (undefined !== defaults.main) {
 		console.log('Adding call to: %s>>main', defaults.main);
-		realWork += 'smalltalk.' + defaults.main + '._main();';
+		mainFunctionOrFile += 'smalltalk.' + defaults.main + '._main();';
 	}
 
 	if (undefined !== defaults.mainfile && fs.existsSync(defaults.mainfile)) {
 		console.log('Adding main file: ' + defaults.mainfile);
-		realWork += '\n' + fs.readFileSync(defaults.mainfile);
+		mainFunctionOrFile += '\n' + fs.readFileSync(defaults.mainfile);
 	}
 
-	builder.finish(realWork);
+	builder.finish(mainFunctionOrFile);
 
 	console.log('Writing...');
-	builder.forEach(function (element) { fileStream.write(element); fileStream.write('\n'); });
+	builder.forEach(function (element) {
+		fileStream.write(element);
+		fileStream.write('\n');
+	});
 	console.log('Done.');
 	fileStream.end();
 };