Permalink
Browse files

Reorganzed files, and included the Arc code in the test directory.

  • Loading branch information...
1 parent 71ef532 commit b906e2d8b938673454d89aed02c97317f7ce63eb @rocketnia rocketnia committed Jan 27, 2012
Showing with 15,693 additions and 37 deletions.
  1. +3 −3 .gitignore
  2. +130 −0 build.js
  3. +0 −33 node/build.js
  4. 0 { → scrap}/rainbow.test.js
  5. 0 { → src}/node/rainbow-node-src.js
  6. 0 { → src}/rainbow.js
  7. 0 {test → src/web}/index-first.js
  8. 0 {test → src/web}/index-last.js
  9. +167 −0 src/web/index.html
  10. +1,498 −0 test/ac.scm
  11. +672 −0 test/app.arc
  12. +1,698 −0 test/arc.arc
  13. +16 −0 test/as.scm
  14. +95 −0 test/blog.arc
  15. +48 −0 test/brackets.scm
  16. +61 −0 test/code.arc
  17. +2 −0 test/copyright
  18. +44 −0 test/how-to-run-news
  19. +415 −0 test/html.arc
  20. +1 −1 test/index-min.js
  21. +105 −0 test/lib/ab.arc
  22. +207 −0 test/lib/ake.arc
  23. +253 −0 test/lib/bag-of-tricks.arc
  24. +63 −0 test/lib/bm-tests.arc
  25. +37 −0 test/lib/dq.arc
  26. +78 −0 test/lib/midi/midi-writer.arc
  27. +303 −0 test/lib/midi/midi.arc
  28. +70 −0 test/lib/midi/prelude.arc
  29. +345 −0 test/lib/midi/rondo.arc
  30. +105 −0 test/lib/nbody.arc
  31. +337 −0 test/lib/parser.arc
  32. +35 −0 test/lib/pidigits.arc
  33. +13 −0 test/lib/primes.arc
  34. +51 −0 test/lib/source.arc
  35. +143 −0 test/lib/tests/core-errors-continuations-test.arc
  36. +164 −0 test/lib/tests/core-evaluation-test.arc
  37. +89 −0 test/lib/tests/core-lists-test.arc
  38. +116 −0 test/lib/tests/core-macros-test.arc
  39. +188 −0 test/lib/tests/core-maths-test.arc
  40. +243 −0 test/lib/tests/core-predicates-test.arc
  41. +268 −0 test/lib/tests/core-special-forms-test.arc
  42. +340 −0 test/lib/tests/core-typing-test.arc
  43. +306 −0 test/lib/tests/foundation-test.arc
  44. +112 −0 test/lib/tests/misc-tests.arc
  45. +120 −0 test/lib/tests/parser-test.arc
  46. +93 −0 test/lib/unit-test.arc
  47. +13 −0 test/libs.arc
  48. +2,617 −0 test/news.arc
  49. +79 −0 test/pprint.arc
  50. +119 −0 test/prompt.arc
  51. +3 −0 test/rainbow.sh
  52. +208 −0 test/rainbow/build/optimisers.arc
  53. +99 −0 test/rainbow/fsb.arc
  54. +43 −0 test/rainbow/img.arc
  55. +60 −0 test/rainbow/midi/midi.arc
  56. +175 −0 test/rainbow/mines.arc
  57. +16 −0 test/rainbow/prime-bench.arc
  58. +164 −0 test/rainbow/profile.arc
  59. +23 −0 test/rainbow/rainbow-libs.arc
  60. +117 −0 test/rainbow/rainbow.arc
  61. +18 −0 test/rainbow/rpn.arc
  62. +260 −0 test/rainbow/spiral.arc
  63. +235 −0 test/rainbow/swing.arc
  64. +15 −0 test/rainbow/tests/anarki-compatibility-test.arc
  65. +15 −0 test/rainbow/tests/chained-ssexpand-test.arc
  66. +132 −0 test/rainbow/tests/extra-math-test.arc
  67. +37 −0 test/rainbow/tests/java-interface-test.arc
  68. +27 −0 test/rainbow/tests/string-interpolation-test.arc
  69. +220 −0 test/rainbow/tetris.arc
  70. +751 −0 test/rainbow/welder.arc
  71. +578 −0 test/srv.arc
  72. BIN test/static/arc.png
  73. BIN test/static/grayarrow.gif
  74. BIN test/static/graydown.gif
  75. 0 test/static/robots.txt
  76. BIN test/static/s.gif
  77. +191 −0 test/static/spiral-intro.html
  78. BIN test/static/spiral-sample-1.png
  79. BIN test/static/spiral-sample-10.png
  80. BIN test/static/spiral-sample-11.png
  81. BIN test/static/spiral-sample-12.png
  82. BIN test/static/spiral-sample-13.png
  83. BIN test/static/spiral-sample-14.png
  84. BIN test/static/spiral-sample-15.png
  85. BIN test/static/spiral-sample-16.png
  86. BIN test/static/spiral-sample-17.png
  87. BIN test/static/spiral-sample-18.png
  88. BIN test/static/spiral-sample-2.png
  89. BIN test/static/spiral-sample-3.png
  90. BIN test/static/spiral-sample-4.png
  91. BIN test/static/spiral-sample-5.png
  92. BIN test/static/spiral-sample-6.png
  93. BIN test/static/spiral-sample-7.png
  94. BIN test/static/spiral-sample-8.png
  95. BIN test/static/spiral-sample-9.png
  96. +22 −0 test/static/spiral.css
  97. +196 −0 test/static/spiral.js
  98. BIN test/static/test.png
  99. BIN test/static/y18.gif
  100. +226 −0 test/strings.arc
View
@@ -17,8 +17,8 @@
# for Arc.
# Ignore some build artifacts but not others.
-/node/bin/
-#/test/index-min.js
+/bin/
+#/test/
# Ignore npm packages.
-/node/node_modules/
+/node_modules/
View
130 build.js
@@ -0,0 +1,130 @@
+// Copyright (c) 2012 Ross Angle
+//
+// This software is derived from Rainbow, software which is
+// copyright (c) 2011 Conan Dalton, distributed under the
+// Perl Foundation's Artistic License 2.0. In the sense described in
+// section (4)(c)(i) of that document, using its own terminology,
+// permission to use this "Modified Version" is granted under the
+// "Original License."
+//
+// This software may also be derived from Arc, software which is
+// copyright (c) Paul Graham and Robert Morris, distributed under the
+// Perl Foundation's Artistic License 2.0. In the sense described in
+// section (4)(b) of that document, using its own terminology, this
+// "Modified Version" bears a name that is different from any name
+// used for Arc.
+
+var fs = require( "fs" );
+var util = require( "util" );
+var $path = require( "path" );
+
+var missingLibs = [];
+// Turns out wrench wasn't useful here after all, since I'd rather
+// have a recursive copy that works on individual files and leaves
+// unrelated target directory contents alone. This is cpOver, below.
+//
+//try { var wrench = require( "wrench" ); } catch ( e ) {
+// missingLibs.push( { name: "wrench.js", npm: "wrench",
+// uri: "https://github.com/ryanmcgrath/wrench-js" } );
+//}
+if ( missingLibs.length !== 0 ) {
+ process.stderr.write(
+ "You need the following Node.js libraries to build " +
+ "Rainbow.js:\n" +
+ "\n" +
+ missingLibs.map( function ( lib ) {
+ return lib.name + " (\"npm install " + lib.npm + "\" " +
+ "or see <" + lib.uri + ">)";
+ } ).join( "\n" ) );
+ process.exit( 1 );
+}
+
+function stat( path, then ) {
+ $path.exists( path, function ( exists ) {
+ if ( !exists ) return void then( null, null );
+ fs.stat( path, then );
+ } );
+}
+
+function ensureDir( path, then ) {
+ stat( path, function ( e, stat ) {
+ if ( e ) return void then( e );
+ if ( stat === null ) return void fs.mkdir( path, then );
+ if ( stat.isDirectory() ) return void then();
+ then( new Error(
+ "Can't ensureDir a non-dir file: " + path ) );
+ } );
+}
+
+function eachAsync( xs, body, then ) {
+ var n = xs.length;
+ loop( 0 );
+ function loop( i ) {
+ if ( i === n )
+ return void then();
+ var x = xs[ i ];
+ body( x, function ( e ) {
+ if ( e ) return void then( e );
+ loop( i + 1 );
+ } );
+ }
+}
+
+function rm( path, then ) {
+ stat( path, function ( e, stat ) {
+ if ( e ) return void then( e );
+ if ( stat === null ) return then();
+ fs.unlink( path, then );
+ } );
+}
+
+function cpOver( from, to, then ) {
+ stat( from, function ( e, stat ) {
+ if ( e ) return void then( e );
+ if ( stat === null ) return void then();
+ if ( stat.isDirectory() )
+ fs.readdir( from, function ( e, files ) {
+ if ( e ) return void then( e );
+ ensureDir( to, function ( e ) {
+ if ( e ) return void then( e );
+ eachAsync( files, function ( file, then ) {
+ cpOver( from + "/" + file, to + "/" + file,
+ then );
+ }, then );
+ } );
+ } );
+ else
+ rm( to, function ( e ) {
+ var fromStream = fs.createReadStream( from );
+ var toStream = fs.createWriteStream( to );
+ fromStream.once( "open", function ( e ) {
+ util.pump( fromStream, toStream, then );
+ } );
+ } );
+ } );
+}
+
+
+ensureDir( "bin", function ( e ) {
+ if ( e ) throw e;
+cpOver( "src/arc", "bin/node", function ( e ) {
+ if ( e ) throw e;
+cpOver( "src/arc", "test", function ( e ) {
+ if ( e ) throw e;
+cpOver( "src/web/index.html", "test/index.html", function ( e ) {
+ if ( e ) throw e;
+fs.writeFileSync( "bin/node/rainbow-node.js",
+ "exports.makeRainbow = function (\n" +
+ " System_in, System_out, System_err, System_fs ) {\n" +
+ "\n" +
+ fs.readFileSync( "src/rainbow.js", "utf8" ) +
+ "\n" +
+ "return Console;\n" +
+ "\n" +
+ "};\n" +
+ "\n" +
+ fs.readFileSync( "src/node/rainbow-node-src.js", "utf8" ) );
+} );
+} );
+} );
+} );
View
@@ -1,33 +0,0 @@
-// Copyright (c) 2012 Ross Angle
-//
-// This software is derived from Rainbow, software which is
-// copyright (c) 2011 Conan Dalton, distributed under the
-// Perl Foundation's Artistic License 2.0. In the sense described in
-// section (4)(c)(i) of that document, using its own terminology,
-// permission to use this "Modified Version" is granted under the
-// "Original License."
-//
-// This software may also be derived from Arc, software which is
-// copyright (c) Paul Graham and Robert Morris, distributed under the
-// Perl Foundation's Artistic License 2.0. In the sense described in
-// section (4)(b) of that document, using its own terminology, this
-// "Modified Version" bears a name that is different from any name
-// used for Arc.
-
-var fs = require( "fs" );
-
-// https://github.com/ryanmcgrath/wrench-js
-var wrench = require( "wrench" );
-
-wrench.copyDirSyncRecursive( "../src/arc", "./bin/arc" );
-fs.writeFileSync( "./bin/arc/rainbow-node.js",
- "exports.makeRainbow = function (\n" +
- " System_in, System_out, System_err, System_fs ) {\n" +
- "\n" +
- fs.readFileSync( "../rainbow.js", "utf8" ) +
- "\n" +
- "return Console;\n" +
- "\n" +
- "};\n" +
- "\n" +
- fs.readFileSync( "./rainbow-node-src.js", "utf8" ) );
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,167 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
+<title>It's Rainbow in JavaScript!</title>
+<!-- http://rocketnia.github.com/rainbow-js/test/index.html -->
+<!--
+
+Copyright (c) 2011 Ross Angle
+
+This software is derived from Rainbow, software which is
+copyright (c) 2011 Conan Dalton, distributed under the
+Perl Foundation's Artistic License 2.0. In the sense described in
+section (4)(c)(i) of that document, using its own terminology,
+permission to use this "Modified Version" is granted under the
+"Original License."
+
+This software may also be derived from Arc, software which is
+copyright (c) Paul Graham and Robert Morris, distributed under the
+Perl Foundation's Artistic License 2.0. In the sense described in
+section (4)(b) of that document, using its own terminology, this
+"Modified Version" bears a name that is different from any name used
+for Arc.
+
+-->
+<meta name="viewport" content=
+ "initial-scale = 1.0, maximum-scale = 1.0, width = device-width" />
+<style type="text/css">
+html { font-family: sans-serif; margin: 2em; }
+
+body > pre { margin-left: 2em; }
+
+p, ul { max-width: 40em; }
+
+code { font-size: 1.2em; }
+
+#repl .scrollback {
+ display: block;
+ width: 95%;
+ height: 200px;
+ overflow: auto;
+ resize: vertical;
+ border: 2px solid black;
+}
+#repl .prompt { display: block; width: 95%; }
+#repl .eval {}
+</style>
+<!--
+<script type="text/javascript" src="index-first.js"></script>
+<script type="text/javascript" src="../rainbow.js"></script>
+<script type="text/javascript" src="index-last.js"></script>
+-->
+<script type="text/javascript" src="index-min.js"></script>
+</head>
+<body>
+<h1>Rainbow.js</h1>
+<div id="repl"></div>
+<p>(The "Eval" button is just there in case pressing enter doesn't
+ work for you. I run into this kind of snafu on mobile devices.)</p>
+<p>Above is a REPL for Rainbow.js, an implementation of most of
+ Rainbow, which is an implemenation of Arc. We don't load arc.arc or
+ friends automatically yet, but you can load them yourself by copying
+ <a href=
+ "https://github.com/conanite/rainbow/blob/92e07a98fd86f8e1985b32a7d2c265810eb76809/src/arc/arc.arc"
+ >Java Rainbow's arc.arc source</a>, and any other files you want to
+ load, and pasting all that code into the REPL. I've successfully
+ loaded all of Java Rainbow's automatically loaded files this
+ way,<sup>*</sup> but that doesn't mean all the functionality is
+ available. For instance, Rainbow.js doesn't implement file
+ operations at all, so even though arc.arc defines <code>load</code>,
+ it won't do us much good!</p>
+<p><sup>*</sup> Namely, I've successfully loaded arc.arc, strings.arc,
+ lib/bag-of-tricks.arc, rainbow.arc, pprint.arc, code.arc, html.arc,
+ srv.arc, app.arc, prompt.arc, profile.arc, unit-test.arc, and
+ parser.arc. Rainbow also automatically loads
+ rainbow/rainbow-libs.arc in order to load some of these, but that
+ file relies on <code>load</code>, so it won't work.</p>
+<p>I've tested this page in Chrome, Firefox, Opera, and IE. To compare
+ the browsers a bit, I pasted arc.arc surrounded by the following
+ code...</p>
+<pre>
+(assign starttime (msec))
+
+...
+
+(- (msec) starttime)
+</pre>
+<p>...and got these results:</p>
+<ul>
+ <li>Chrome 13.0.782.112 m: <b>1591 ms</b></li>
+ <li>Firefox 6.0: <b>2238 ms</b></li>
+ <li>Opera 11.50: <b>3310 ms</b></li>
+ <li>Internet Explorer 8.0.6001.18702: <b>32469 ms</b> (but this
+ includes the time it took for me to dismiss three "Stop running
+ this script?" dialogs)</li>
+</ul>
+<p>I was running all four browsers at the same time, so it was a
+ pretty casual test. But hey, at least I wasn't <i>testing</i> them
+ all at the same time. ^_^</p>
+<p>It seems the Closure Compiler boosted the performance by about
+ 20-25% on everything but Chrome. Now that we're using it, I've also
+ tried loading all those automatically loaded files I was talking
+ about, all in one paste:</p>
+<ul>
+ <li>Chrome 13.0.782.112 m: <b>5209 ms</b></li>
+ <li>Firefox 6.0: <b>7220 ms</b></li>
+ <li>Opera 11.50: <b>11369 ms</b></li>
+ <li>Internet Explorer 8.0.6001.18702: <b>216219 ms</b> (but this
+ includes the time it took for me to dismiss twelve "Stop running
+ this script?" dialogs)</li>
+</ul>
+<p>And on the same machine, Java Rainbow's own time is...</p>
+<pre>
+*** redefining no
+*** redefining map1
+*** redefining pr
+*** redefining list
+repl in 12296ms
+arc>
+</pre>
+<p>Could it be? Is Rainbow.js already faster than Java Rainbow (IE 8
+ notwithstanding)?! Maybe this is just a biased benchmark. After all,
+ Rainbow has to do file IO here. Yeah, that's gotta be it....</p>
+<h3>Doing JavaScript things</h3>
+<p>Since those tests, I've made an addition to this REPL. Now
+ <code>window</code>, which isn't defined in rainbow.js proper, is
+ defined in this REPL to be the page's window object, and you can
+ access it like this (using <code>java-invoke</code>, which <i>is</i>
+ defined in rainbow.js):</p>
+<pre>
+repl in 3ms
+arc> (assign list (fn a a))
+(fn a a)
+arc>
+ (assign jsget-impl
+ (java-invoke
+ window 'eval (list "(function ( o, k ) { return o[ k ]; })")))
+
+function ( o, k ) { return o[ k ]; }
+arc>
+ (assign jsget
+ (fn (o k) (java-invoke jsget-impl 'call (list nil o k))))
+
+(fn (o k) (java-invoke jsget-impl 'call (list nil o k)))
+arc> (jsget window "Object")
+function Object() { [native code] }
+</pre>
+<p>You <i>could</i> do crazy meta-things this way, like calling parts
+ of Rainbow.js's implementation. However, all the JavaScript code
+ this page uses is minified, so good luck with that. :-p</p>
+<p>Rainbow.js (like Java Rainbow) takes care of some simple type
+ conversions for you, like converting native strings to Arc
+ strings:</p>
+<pre>
+arc>
+ (+ "The title of the page is: "
+ (jsget (jsget window "document") "title"))
+
+"The title of the page is: It's Rainbow in JavaScript!"
+</pre>
+<p>I'm not sure I actually like that automatic conversion, since I'd
+ rather define my own conversion rules as a library. I'm also not
+ sure it's really appropriate to call <code>java-invoke</code> the
+ same thing as it's called in Java Rainbow. In some ways, Rainbow.js
+ may be staying a bit too true to the original. ^_^</p>
+</body>
+</html>
Oops, something went wrong.

0 comments on commit b906e2d

Please sign in to comment.