Permalink
Browse files

Transcompiler work

* Added new compile that transcompiles dsl to javascript
* New 3D conways game of life example
  • Loading branch information...
1 parent d568f34 commit f61d04ff7b7dc788b466a280e8a38c79e0018504 @doug-martin doug-martin committed Jun 17, 2013
Showing with 19,683 additions and 4,091 deletions.
  1. +2 −2 Gruntfile.js
  2. +3 −0 Makefile
  3. +1 −1 benchmark/manners/benchmark.js
  4. +3 −3 bin/assets/compile_wrapper.tmpl
  5. +13 −1 bin/nools
  6. +6 −0 docs-md/examples.md
  7. +13 −0 docs/History.html
  8. +201 −0 docs/examples.html
  9. +3 −0 docs/examples/browser/assets/arguments-extended.js
  10. +174 −0 docs/examples/browser/assets/conways.css
  11. +3 −0 docs/examples/browser/assets/declare.js
  12. +3 −0 docs/examples/browser/assets/extended.js
  13. +3 −0 docs/examples/browser/assets/extender.js
  14. +3 −0 docs/examples/browser/assets/function-extended.js
  15. +3 −0 docs/examples/browser/assets/is-extended.js
  16. +364 −0 docs/examples/browser/assets/orbit_controls.js
  17. +214 −0 docs/examples/browser/conways_2d.html
  18. +123 −0 docs/examples/browser/conways_3d.html
  19. +117 −0 docs/examples/browser/fibonacci.html
  20. +144 −0 docs/examples/browser/manners.html
  21. +62 −0 docs/examples/browser/rules/conways.nools
  22. +84 −0 docs/examples/browser/rules/conways3d.nools
  23. +50 −0 docs/examples/browser/rules/fibonacci.nools
  24. +181 −0 docs/examples/browser/rules/manners.nools
  25. +64 −0 docs/examples/browser/src/cell.js
  26. +94 −0 docs/examples/browser/src/common.js
  27. +291 −0 docs/examples/browser/src/conway_3d.js
  28. +6,139 −0 docs/examples/browser/src/guests.js
  29. +151 −0 docs/examples/browser/src/patterns.js
  30. +222 −0 docs/examples/browser/src/patterns3d.js
  31. +2 −0 docs/index.html
  32. +10 −0 docs/nools.js
  33. +3 −0 examples/browser/assets/arguments-extended.js
  34. +174 −0 examples/browser/assets/conways.css
  35. +3 −0 examples/browser/assets/declare.js
  36. +3 −0 examples/browser/assets/extended.js
  37. +3 −0 examples/browser/assets/extender.js
  38. +3 −0 examples/browser/assets/function-extended.js
  39. +3 −0 examples/browser/assets/is-extended.js
  40. +364 −0 examples/browser/assets/orbit_controls.js
  41. +214 −0 examples/browser/conways_2d.html
  42. +123 −0 examples/browser/conways_3d.html
  43. +0 −56 examples/browser/fibonacci.dsl.html
  44. +55 −31 examples/browser/fibonacci.html
  45. +122 −321 examples/browser/manners.html
  46. +0 −57 examples/browser/parse.html
  47. +62 −0 examples/browser/rules/conways.nools
  48. +84 −0 examples/browser/rules/conways3d.nools
  49. +0 −1 examples/browser/rules/fibonacci.js
  50. +0 −1 examples/browser/rules/manners.js
  51. +2 −6 examples/browser/rules/manners.nools
  52. +64 −0 examples/browser/src/cell.js
  53. +94 −0 examples/browser/src/common.js
  54. +291 −0 examples/browser/src/conway_3d.js
  55. +6,139 −0 examples/browser/src/guests.js
  56. +151 −0 examples/browser/src/patterns.js
  57. +222 −0 examples/browser/src/patterns3d.js
  58. +0 −102 examples/conways/assets/conways.css
  59. +0 −123 examples/conways/index.html
  60. +0 −83 examples/conways/index.js
  61. +0 −89 examples/conways/patterns.json
  62. +0 −1 examples/conways/rules/conways.js
  63. +0 −137 examples/conways/rules/conways.nools
  64. +9 −0 history.md
  65. +51 −39 lib/agenda.js
  66. +0 −240 lib/compile.js
  67. +56 −0 lib/compile/common.js
  68. +189 −0 lib/compile/index.js
  69. +150 −0 lib/compile/transpile.js
  70. +16 −21 lib/context.js
  71. +2 −3 lib/extended.js
  72. +54 −48 lib/index.js
  73. +53 −0 lib/linkedList.js
  74. +12 −10 lib/nodes/joinNode.js
  75. +19 −11 lib/nodes/joinReferenceNode.js
  76. +2 −2 lib/nodes/node.js
  77. +18 −14 lib/nodes/notNode.js
  78. +1 −1 lib/rule.js
  79. +7 −25 lib/workingMemory.js
  80. +2,018 −2,441 nools.js
  81. +7 −7 nools.min.js
  82. +69 −66 package.json
  83. +8 −16 test/flow.compiled.test.js
  84. +3 −1 test/flow.dsl.test.js
  85. +6 −4 test/flow.test.js
  86. +1 −1 test/rules/agenda-group-compiled.js
  87. +1 −1 test/rules/auto-focus-compiled.js
  88. +1 −49 test/rules/diagnosis-compiled.js
  89. +1 −1 test/rules/fibonacci-compiled.js
  90. +1 −24 test/rules/notRule-compiled.js
  91. +1 −24 test/rules/orRule-compiled.js
  92. +1 −1 test/rules/scope-compiled.js
  93. +1 −26 test/rules/simple-compiled.js
View
@@ -29,8 +29,8 @@ module.exports = function (grunt) {
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>;' +
- ' Licensed <%= pkg.license %> */\n',
- report: 'gzip'
+ ' Licensed <%= pkg.license %> */\n'
+ //report: 'gzip'
},
min: {
files: {
View
@@ -9,6 +9,9 @@ docs: docclean
docclean :
rm -rf docs/*
+ mkdir -p ./docs/examples/browser
+ cp -r ./examples/browser/ ./docs/examples/browser
+ cp ./nools.min.js ./docs/nools.js
benchmarks:
for file in $(BENCHMARKS) ; do \
@@ -4,7 +4,7 @@
nools = require("../../index");
var flow = nools.compile(__dirname + "/manners.nools");
- var guests = data.load(flow).manners16;
+ var guests = data.load(flow).manners32;
var session = flow.getSession.apply(flow, guests);
session.assert(new (flow.getDefined("count"))({value: 1}));
var start = new Date();
@@ -1,18 +1,18 @@
(function(){
function _getCompiled(nools){
- return nools.compile({source}, {name : "{name}"});
+ return {source}
}
if ("undefined" !== typeof exports) {
if ("undefined" !== typeof module && module.exports) {
- return _getCompiled(require("{noolsLocation}"));
+ module.exports = _getCompiled(require("{noolsLocation}"));
}
} else if ("function" === typeof define && define.amd) {
define(["{noolsLocation}"], function (nools) {
return _getCompiled(nools);
});
} else {
- _getCompiled(this.nools);
+ _getCompiled(this.nools)();
}
}).call(this);
View
@@ -7,8 +7,18 @@ var nools = require(".."),
path = require("path"),
template = fs.readFileSync(path.join(__dirname, "assets", "compile_wrapper.tmpl"), "utf8"),
str = require("string-extended"),
+ uglifyjs = require("uglify-js"),
program = require('commander');
+function uglify(source) {
+ try {
+ return uglifyjs.minify(source, {fromString: true, mangle: false, output: {beautify: true}}).code;
+ } catch (e) {
+ console.error(e.message);
+ console.error(e.stack);
+ }
+}
+
program
.version('0.0.1');
@@ -24,10 +34,12 @@ program.command("compile")
var noolsLocation = program["nools_location"] || "nools";
files.forEach(function (file) {
var name = program.name || path.basename(file, path.extname(file));
- console.log(str.format(template, { source: JSON.stringify(nools.parse(path.resolve(process.cwd(), file))), name: name, noolsLocation: noolsLocation}).replace(/\s+/g, " "));
+ console.log(str.format(template, { source: uglify(nools.transpile(path.resolve(process.cwd(), file), {name: name})), noolsLocation: noolsLocation}).replace(/\s+/g, " "));
});
});
+//return uglifyjs.minify(ret.join(""), {fromString: true, mangle: false, output: {beautify: true}}).code;
+
program.parse(process.argv);
View
@@ -0,0 +1,6 @@
+## Examples
+
+ * [Conways 2D](./examples/browser/conways_2d.html)
+ * [Conways 3D](./examples/browser/conways_3d.html)
+ * [Fibonacci](./examples/browser/fibonacci.html)
+ * [Miss Manners](./examples/browser/manners.html)
View
@@ -148,6 +148,8 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Docs<b class="caret"></b></a>
<ul class="dropdown-menu">
+ <li><a href="./examples.html">Examples</a></li>
+
<li><a href="./History.html">Change Log</a></li>
</ul>
@@ -176,6 +178,17 @@
+<h1>v0.1.5 / 2012-06-17</h1>
+<ul>
+<li>More Examples</li>
+<li>Changed nools compile to transpile to Javascript!</li>
+<li>Better performance<ul>
+<li>Simple Benchmark: Before ~600ms, Now ~350ms</li>
+<li>Manners Benchmark (32): Before ~10s, Now ~4sec</li>
+<li>WaltzDB: Before ~30sec, Now ~15sec</li>
+</ul>
+</li>
+</ul>
<h1>v0.1.4 / 2012-05-25</h1>
<ul>
<li>Added new agenda-group (#29)</li>
View
@@ -0,0 +1,201 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>nools</title>
+ <link rel="stylesheet" href="./assets/css/bootstrap.min.css">
+ <link rel="stylesheet" href="./assets/css/prettify.css">
+ <style type="text/css">
+
+
+/*.subnav-inner {*/
+ /*width: 100%;*/
+ /*height: 36px;*/
+ /*background-color: #EEE;*/
+ /*background-repeat: repeat-x;*/
+ /*background-image: -moz-linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, whiteSmoke), color-stop(100%, #EEE));*/
+ /*background-image: -webkit-linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*background-image: -ms-linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*background-image: -o-linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#f5f5f5', endColorstr = '#eeeeee', GradientType = 0);*/
+ /*background-image: linear-gradient(top, whiteSmoke 0%, #EEE 100%);*/
+ /*-webkit-border-radius: 4px;*/
+ /*-moz-border-radius: 4px;*/
+ /*border-radius: 4px;*/
+/*}*/
+
+/*.subnav .nav > li > a:hover {*/
+ /*color: black !important;*/
+/*}*/
+
+/*.subnav .nav li.dropdown .dropdown-toggle .caret,*/
+/*.subnav .nav li.dropdown.open .caret {*/
+ /*border-top-color: #999 !important;*/
+ /*border-bottom-color: #999 !important;*/
+/*}*/
+
+/*.subnav-fixed {*/
+ /*position: fixed;*/
+ /*width : 90%;*/
+ /*margin-right: auto;*/
+ /*margin-left: auto;*/
+ /*top: 40px;*/
+ /*left: 0;*/
+ /*right: 0;*/
+ /*z-index: 1020;*/
+ /*border-color: #D5D5D5;*/
+ /*border-width: 0 0 1px;*/
+ /*-webkit-border-radius: 0;*/
+ /*-moz-border-radius: 0;*/
+ /*border-radius: 0;*/
+ /*-webkit-box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1);*/
+ /*-moz-box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1);*/
+ /*box-shadow: inset 0 1px 0 #fff, 0 1px 5px rgba(0,0,0,.1);*/
+ /*filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);*/
+/*}*/
+
+/*.navbar .nav .dropdown-menu {*/
+ /*max-height: 500px;*/
+ /*overflow: auto;*/
+/*}​*/
+
+ </style>
+ <style type="text/css">
+ body {
+ padding: 90px;
+ }
+
+ .subnav{
+ margin-top: 40px;
+ margin-right: auto;
+ margin-left: auto;
+ z-index: 1000;
+ }
+
+ .dropdown-menu{
+ max-height: 500px;
+ overflow-y: auto;
+ }
+
+ @media (max-width:979px) {
+ .subnav{
+ margin-top: auto;
+ }
+ }
+ </style>
+ <link rel="stylesheet" href="./assets/css/bootstrap-responsive.min.css">
+ <script type="text/javascript">
+ var init = (function () {
+ "use strict";
+
+ var processScroll = (function () {
+ var curr = null, prev = null;
+ return function (nav) {
+ var $win = $(window);
+ $('.subnav').each(function () {
+ var nav = $(this);
+ var navTop = $win.width() < 980 ? 0 : nav.offset().top - 40;
+
+ var scrollTop = $win.scrollTop();
+ if (scrollTop >= navTop && curr != nav) {
+ if(curr){
+ curr.removeClass('subnav-fixed')
+ prev = curr;
+ }
+ curr = nav;
+ curr.addClass('subnav-fixed')
+ } else if (curr == nav && scrollTop <= navTop) {
+ curr.removeClass('subnav-fixed');
+ prev.addClass('subnav-fixed');
+ curr = prev;
+ }else{
+ nav.removeClass('subnav-fixed');
+ }
+ });
+ };
+ })();
+
+ return function () {
+ window.prettyPrint && prettyPrint();
+ $(".collapse").collapse();
+ var $window = $(window);
+ //$(".subnav").affix ();
+ // fix sub nav on scroll
+// processScroll();
+// $(window).on('scroll', processScroll)
+ }
+ })();
+ </script>
+</head>
+<body onload="init()">
+<div class="navbar navbar-fixed-top navbar-inverse">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ <span class="icon-bar"> </span>
+ </a>
+
+ <a href="./index.html" class="brand">nools</a>
+
+ <div class="nav-collapse">
+ <ul class="nav">
+
+ <li class="dropdown">
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">Docs<b class="caret"></b></a>
+ <ul class="dropdown-menu">
+
+ <li><a href="./examples.html">Examples</a></li>
+
+ <li><a href="./History.html">Change Log</a></li>
+
+ </ul>
+
+
+
+
+ </ul>
+
+ <ul class="nav pull-right">
+
+ <li class="divider-vertical"></li>
+ <li><a href="https://github.com/C2FO/nools" target="#github" class="pull-right">github</a></li>
+ </ul>
+
+ </div>
+ </div>
+ </div>
+</div>
+
+
+
+<div class="container-fluid">
+ <a name="top"></a>
+ <div class="container">
+
+
+
+<h2>Examples</h2>
+<ul>
+<li><a href="./examples/browser/conways_2d.html">Conways 2D</a></li>
+<li><a href="./examples/browser/conways_3d.html">Conways 3D</a></li>
+<li><a href="./examples/browser/fibonacci.html">Fibonacci</a></li>
+<li><a href="./examples/browser/manners.html">Miss Manners</a></li>
+</ul>
+
+<hr>
+
+Documentation generated using <a href="https://github.com/doug-martin/coddoc">coddoc</a>.
+
+
+</div>
+</div>
+<script type="text/javascript" src="./assets/js/jquery.js"></script>
+<script type="text/javascript" src="./assets/js/bootstrap.min.js"></script>
+<script type="text/javascript" src="./assets/js/prettify.js"></script>
+
+</body>
+</html>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit f61d04f

Please sign in to comment.