Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Better way to do #17

  • Loading branch information...
commit 0d0910376cc909a1e13c94f5f2d47d594efd0efa 1 parent e913e4b
@jussi-kalliokoski authored
View
10 Makefile
@@ -0,0 +1,10 @@
+IN := lib/jspp/lang/es5.js src/jsdefs.js src/jsparse.js src/typed-es3.js src/compiler.js typesys/strict.js
+OUT := jspp.js
+
+all: $(OUT)
+
+$(OUT): $(IN)
+ cat $^ > $@
+
+clean:
+ rm $(OUT) -rf
View
122 bin/jspp
@@ -0,0 +1,122 @@
+#!/usr/bin/env node
+
+var fs = require('fs'),
+ paramon = require('paramon'),
+ jspp = require('javascript-plusplus'),
+ compiler = jspp.compiler;
+
+function jsparse () {
+ return jspp.narcissus.jsparse.apply(jspp.narcissus, arguments);
+}
+
+var args = paramon.readFormat(process.argv, {
+ name: "js++",
+ usage: "js++ file(s) [options]",
+ params: [
+ /*{
+ name: 'execute',
+ args: ['--execute', '-e'],
+ desc: 'Instead of printing output, execute. You can optionally specify the command to execute it with.',
+ maxParams: 1,
+ },*/
+ {
+ name: 'wrap',
+ args: ['--closure', '-c'],
+ desc: 'Wrap in a function (closure).',
+ maxParams: 0,
+ },
+ {
+ name: 'debug',
+ args: ['--debug', '-d'],
+ desc: 'Debug mode.',
+ maxParams: 0,
+ },
+ {
+ name: 'warnings',
+ args: ['--warnings', '-w'],
+ desc: 'Display warnings.',
+ maxParams: 0,
+ },
+ {
+ name: 'encoding',
+ args: ['--encoding', '-e'],
+ desc: 'The encoding to use for reading the files.',
+ maxParams: 1,
+ minParams: 1,
+ },
+ {
+ name: 'output',
+ args: ['--output', '-o'],
+ desc: 'The output target. Default=-',
+ maxParams: 1,
+ minParams: 1,
+ }
+ ],
+});
+
+args.debug || process.on('uncaughtException', function (e) {
+ console.error(e);
+ process.exit(1);
+});
+
+if (!args['$!stray'].length) throw "No files specified.";
+
+/* Heavy async soup */
+
+function Dummy(){}
+Dummy.prototype.toString = function () {
+ return this.r;
+};
+Dummy.prototype.r = '';
+
+var asReady = 0;
+
+function ready () {
+ if (++asReady !== files.length) return;
+
+ /* All files ready, let's get going */
+
+ var code = files.join('\n');
+
+ var t = +new Date;
+
+ var c = new compiler(jsparse(code), {
+ debug: args["debug"],
+ nowrap: !args["wrap"],
+ warnings: args["warnings"],
+ });
+
+ c.preprocess();
+
+ var output = c.compile();
+
+ console.error('Compiled in ' + (+new Date - t) + ' milliseconds.');
+
+ var filename = args["output"] || '-';
+
+ if (filename === '-') {
+ console.log(output);
+ } else {
+ fs.writeFileSync(filename, output, args["encoding"] || 'UTF-8');
+ }
+}
+
+
+var files = args['$!stray'].map(function(f){
+ var r = new Dummy;
+ if (f === '-') {
+ process.stdin.resume();
+ process.stdin.on('data', function (data) {
+ r.r += String(data);
+ });
+ process.stdin.on('end', ready);
+ } else {
+ fs.readFile(f, args["encoding"] || 'UTF-8', function(e, data) {
+ if (e) throw "Reading file '" + f + "' failed.";
+
+ r.r = String(data);
+ ready();
+ });
+ }
+ return r;
+});
View
8 compiler.html
@@ -17,10 +17,10 @@
<textarea id="compiled" style="width:100%;" rows="15"></textarea>
<script type="text/javascript" src="lib/jspp/lang/es5.js"></script>
-<script type="text/javascript" src="jsdefs.js"></script>
-<script type="text/javascript" src="jsparse.js"></script>
-<script type="text/javascript" src="typed-es3.js"></script>
-<script type="text/javascript" src="compiler.js"></script>
+<script type="text/javascript" src="src/jsdefs.js"></script>
+<script type="text/javascript" src="src/jsparse.js"></script>
+<script type="text/javascript" src="src/typed-es3.js"></script>
+<script type="text/javascript" src="src/compiler.js"></script>
<script type="text/javascript" src="typesys/strict.js"></script>
<script type="text/javascript">
function compile() {
View
29 package.json
@@ -0,0 +1,29 @@
+{
+ "name": "javascript-plusplus",
+ "author": "Brendan Eich, Guillaume Lathoud, Roger Poon",
+ "version": "0.011.0",
+ "description": "javascript++",
+ "main": "./jspp.js",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/rogp/jspp"
+ },
+ "engines": {
+ "node": ">=0.2.0-0"
+ },
+ "dependencies": {
+ "paramon": ">=0.1.0"
+ },
+ "bugs": {
+ "url": "http://github.com/rogp/jspp/issues"
+ },
+ "bin": {
+ "js++": "bin/jspp"
+ },
+ "scripts": {
+ "preinstall": "make jspp.js"
+ },
+ "directories": {
+ "lib": "."
+ }
+}
View
2  compiler.js → src/compiler.js
@@ -3053,3 +3053,5 @@ compiler.prototype.preprocess = function(ast) {
return ast;
};
+
+this.compiler = compiler;
View
0  jsdefs.js → src/jsdefs.js
File renamed without changes
View
0  jsparse.js → src/jsparse.js
File renamed without changes
View
0  typed-es3.js → src/typed-es3.js
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.