├── .gitignore ├── COPYING ├── README.md ├── talks └── jsconfeu2012 │ ├── bootstrap │ ├── css │ │ ├── bootstrap-responsive.css │ │ ├── bootstrap-responsive.min.css │ │ ├── bootstrap.css │ │ └── bootstrap.min.css │ ├── img │ │ ├── glyphicons-halflings-white.png │ │ └── glyphicons-halflings.png │ └── js │ │ ├── bootstrap.js │ │ └── bootstrap.min.js │ ├── codemirror │ ├── lib │ │ ├── codemirror.css │ │ ├── codemirror.js │ │ └── util │ │ │ ├── closetag.js │ │ │ ├── dialog.css │ │ │ ├── dialog.js │ │ │ ├── foldcode.js │ │ │ ├── formatting.js │ │ │ ├── javascript-hint.js │ │ │ ├── loadmode.js │ │ │ ├── match-highlighter.js │ │ │ ├── multiplex.js │ │ │ ├── overlay.js │ │ │ ├── pig-hint.js │ │ │ ├── runmode-standalone.js │ │ │ ├── runmode.js │ │ │ ├── search.js │ │ │ ├── searchcursor.js │ │ │ ├── simple-hint.css │ │ │ ├── simple-hint.js │ │ │ └── xml-hint.js │ └── mode │ │ ├── clike │ │ ├── clike.js │ │ ├── index.html │ │ └── scala.html │ │ ├── clojure │ │ ├── clojure.js │ │ └── index.html │ │ ├── coffeescript │ │ ├── LICENSE │ │ ├── coffeescript.js │ │ └── index.html │ │ ├── commonlisp │ │ ├── commonlisp.js │ │ └── index.html │ │ ├── css │ │ ├── css.js │ │ ├── index.html │ │ └── test.js │ │ ├── diff │ │ ├── diff.js │ │ └── index.html │ │ ├── ecl │ │ ├── ecl.js │ │ └── index.html │ │ ├── erlang │ │ ├── erlang.js │ │ └── index.html │ │ ├── gfm │ │ ├── gfm.js │ │ └── index.html │ │ ├── go │ │ ├── go.js │ │ └── index.html │ │ ├── groovy │ │ ├── groovy.js │ │ └── index.html │ │ ├── haskell │ │ ├── haskell.js │ │ └── index.html │ │ ├── haxe │ │ ├── haxe.js │ │ └── index.html │ │ ├── htmlembedded │ │ ├── htmlembedded.js │ │ └── index.html │ │ ├── htmlmixed │ │ ├── htmlmixed.js │ │ └── index.html │ │ ├── javascript │ │ ├── index.html │ │ └── javascript.js │ │ ├── jinja2 │ │ ├── index.html │ │ └── jinja2.js │ │ ├── less │ │ ├── index.html │ │ └── less.js │ │ ├── lua │ │ ├── index.html │ │ └── lua.js │ │ ├── markdown │ │ ├── index.html │ │ ├── markdown.js │ │ └── test.js │ │ ├── mysql │ │ ├── index.html │ │ └── mysql.js │ │ ├── ntriples │ │ ├── index.html │ │ └── ntriples.js │ │ ├── ocaml │ │ ├── index.html │ │ └── ocaml.js │ │ ├── pascal │ │ ├── LICENSE │ │ ├── index.html │ │ └── pascal.js │ │ ├── perl │ │ ├── LICENSE │ │ ├── index.html │ │ └── perl.js │ │ ├── php │ │ ├── index.html │ │ └── php.js │ │ ├── pig │ │ ├── index.html │ │ └── pig.js │ │ ├── plsql │ │ ├── index.html │ │ └── plsql.js │ │ ├── properties │ │ ├── index.html │ │ └── properties.js │ │ ├── python │ │ ├── LICENSE.txt │ │ ├── index.html │ │ └── python.js │ │ ├── r │ │ ├── LICENSE │ │ ├── index.html │ │ └── r.js │ │ ├── rpm │ │ ├── changes │ │ │ ├── changes.js │ │ │ └── index.html │ │ └── spec │ │ │ ├── index.html │ │ │ ├── spec.css │ │ │ └── spec.js │ │ ├── rst │ │ ├── index.html │ │ └── rst.js │ │ ├── ruby │ │ ├── LICENSE │ │ ├── index.html │ │ └── ruby.js │ │ ├── rust │ │ ├── index.html │ │ └── rust.js │ │ ├── scheme │ │ ├── index.html │ │ └── scheme.js │ │ ├── shell │ │ ├── index.html │ │ └── shell.js │ │ ├── sieve │ │ ├── LICENSE │ │ ├── index.html │ │ └── sieve.js │ │ ├── smalltalk │ │ ├── index.html │ │ └── smalltalk.js │ │ ├── smarty │ │ ├── index.html │ │ └── smarty.js │ │ ├── sparql │ │ ├── index.html │ │ └── sparql.js │ │ ├── stex │ │ ├── index.html │ │ ├── stex.js │ │ └── test.js │ │ ├── tiddlywiki │ │ ├── index.html │ │ ├── tiddlywiki.css │ │ └── tiddlywiki.js │ │ ├── tiki │ │ ├── index.html │ │ ├── tiki.css │ │ └── tiki.js │ │ ├── vb │ │ ├── LICENSE.txt │ │ ├── index.html │ │ └── vb.js │ │ ├── vbscript │ │ ├── index.html │ │ └── vbscript.js │ │ ├── velocity │ │ ├── index.html │ │ └── velocity.js │ │ ├── verilog │ │ ├── index.html │ │ └── verilog.js │ │ ├── xml │ │ ├── index.html │ │ └── xml.js │ │ ├── xquery │ │ ├── LICENSE │ │ ├── index.html │ │ ├── test │ │ │ ├── index.html │ │ │ ├── testBase.js │ │ │ ├── testEmptySequenceKeyword.js │ │ │ ├── testMultiAttr.js │ │ │ ├── testNamespaces.js │ │ │ ├── testProcessingInstructions.js │ │ │ └── testQuotes.js │ │ └── xquery.js │ │ └── yaml │ │ ├── index.html │ │ └── yaml.js │ ├── harmony-collections.min.js │ ├── ic.css │ ├── ics.js │ ├── index.html │ ├── indirections.png │ ├── inline_caches.json │ ├── jquery-1.8.2.min.js │ ├── moe.js.js │ ├── pages.js │ ├── pages.json │ ├── plan-a--1.png │ ├── plan-a-0.png │ ├── plan-a-1.png │ ├── plan-a-2.png │ ├── plan-a-3.png │ ├── plan-a-4.png │ ├── plan-a-5.png │ ├── plan-b.png │ ├── prettify.js │ ├── raphael-min.js │ ├── sigtrap.png │ ├── slides.js │ ├── styles.css │ └── tools │ └── shaky │ ├── .gitignore │ ├── README │ ├── deploy │ ├── packages │ │ └── browser │ │ │ ├── dart.js │ │ │ └── interop.js │ ├── shaky.css │ ├── shaky.dart │ ├── shaky.dart.js │ ├── shaky.dart.js.deps │ ├── shaky.dart.js.map │ └── shaky.html │ ├── pubspec.lock │ ├── pubspec.yaml │ └── web │ ├── shaky.css │ ├── shaky.dart │ ├── shaky.dart.js │ ├── shaky.dart.js.deps │ ├── shaky.dart.js.map │ └── shaky.html └── tracing ├── README.md ├── engine-tests.js ├── engine ├── assert.js ├── bc2ir.js ├── bytecode-builder.js ├── bytecode.js ├── cse.js ├── ic.js ├── index.js ├── interpreter.js ├── ir.js ├── ir2js.js ├── ir2llvm.js ├── makeloop.js ├── runtime.js ├── tracer.js └── utils.js ├── points-baseline.js └── points-interpreted.js /.gitignore: -------------------------------------------------------------------------------- 1 | ./node_modules 2 | *.sublime-project 3 | *.sublime-workspace 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mö.js - explaining virtual machines in javascript 2 | === 3 | 4 | This is an umbrella project for the effort to make JavaScript VMs more transparent and understandable for JavaScript programmers by emulating and reimplementing their parts in JavaScript. 5 | 6 | These samples should not be viewed as a production ready parts of a real JavaScript VM implemented in JavaScript. They are merely illustrations for concepts and technologies behind JavaScript VMs. 7 | 8 | Blog posts covering different parts of moe.js 9 | --- 10 | - [Inline caching](http://mrale.ph/blog/2012/06/03/explaining-js-vms-in-js-inline-caches.html) 11 | - [Trace compilation](http://mrale.ph/blog/) 12 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/bootstrap/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/bootstrap/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/bootstrap/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/bootstrap/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/dialog.css: -------------------------------------------------------------------------------- 1 | .CodeMirror-dialog { 2 | position: relative; 3 | } 4 | 5 | .CodeMirror-dialog > div { 6 | position: absolute; 7 | top: 0; left: 0; right: 0; 8 | background: white; 9 | border-bottom: 1px solid #eee; 10 | z-index: 15; 11 | padding: .1em .8em; 12 | overflow: hidden; 13 | color: #333; 14 | } 15 | 16 | .CodeMirror-dialog input { 17 | border: none; 18 | outline: none; 19 | background: transparent; 20 | width: 20em; 21 | color: inherit; 22 | font-family: monospace; 23 | } 24 | 25 | .CodeMirror-dialog button { 26 | font-size: 70%; 27 | } -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/dialog.js: -------------------------------------------------------------------------------- 1 | // Open simple dialogs on top of an editor. Relies on dialog.css. 2 | 3 | (function() { 4 | function dialogDiv(cm, template) { 5 | var wrap = cm.getWrapperElement(); 6 | var dialog = wrap.insertBefore(document.createElement("div"), wrap.firstChild); 7 | dialog.className = "CodeMirror-dialog"; 8 | dialog.innerHTML = '
' + template + '
'; 9 | return dialog; 10 | } 11 | 12 | CodeMirror.defineExtension("openDialog", function(template, callback) { 13 | var dialog = dialogDiv(this, template); 14 | var closed = false, me = this; 15 | function close() { 16 | if (closed) return; 17 | closed = true; 18 | dialog.parentNode.removeChild(dialog); 19 | } 20 | var inp = dialog.getElementsByTagName("input")[0], button; 21 | if (inp) { 22 | CodeMirror.connect(inp, "keydown", function(e) { 23 | if (e.keyCode == 13 || e.keyCode == 27) { 24 | CodeMirror.e_stop(e); 25 | close(); 26 | me.focus(); 27 | if (e.keyCode == 13) callback(inp.value); 28 | } 29 | }); 30 | inp.focus(); 31 | CodeMirror.connect(inp, "blur", close); 32 | } else if (button = dialog.getElementsByTagName("button")[0]) { 33 | CodeMirror.connect(button, "click", function() { 34 | close(); 35 | me.focus(); 36 | }); 37 | button.focus(); 38 | CodeMirror.connect(button, "blur", close); 39 | } 40 | return close; 41 | }); 42 | 43 | CodeMirror.defineExtension("openConfirm", function(template, callbacks) { 44 | var dialog = dialogDiv(this, template); 45 | var buttons = dialog.getElementsByTagName("button"); 46 | var closed = false, me = this, blurring = 1; 47 | function close() { 48 | if (closed) return; 49 | closed = true; 50 | dialog.parentNode.removeChild(dialog); 51 | me.focus(); 52 | } 53 | buttons[0].focus(); 54 | for (var i = 0; i < buttons.length; ++i) { 55 | var b = buttons[i]; 56 | (function(callback) { 57 | CodeMirror.connect(b, "click", function(e) { 58 | CodeMirror.e_preventDefault(e); 59 | close(); 60 | if (callback) callback(me); 61 | }); 62 | })(callbacks[i]); 63 | CodeMirror.connect(b, "blur", function() { 64 | --blurring; 65 | setTimeout(function() { if (blurring <= 0) close(); }, 200); 66 | }); 67 | CodeMirror.connect(b, "focus", function() { ++blurring; }); 68 | } 69 | }); 70 | })(); -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/loadmode.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js"; 3 | 4 | var loading = {}; 5 | function splitCallback(cont, n) { 6 | var countDown = n; 7 | return function() { if (--countDown == 0) cont(); }; 8 | } 9 | function ensureDeps(mode, cont) { 10 | var deps = CodeMirror.modes[mode].dependencies; 11 | if (!deps) return cont(); 12 | var missing = []; 13 | for (var i = 0; i < deps.length; ++i) { 14 | if (!CodeMirror.modes.hasOwnProperty(deps[i])) 15 | missing.push(deps[i]); 16 | } 17 | if (!missing.length) return cont(); 18 | var split = splitCallback(cont, missing.length); 19 | for (var i = 0; i < missing.length; ++i) 20 | CodeMirror.requireMode(missing[i], split); 21 | } 22 | 23 | CodeMirror.requireMode = function(mode, cont) { 24 | if (typeof mode != "string") mode = mode.name; 25 | if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont); 26 | if (loading.hasOwnProperty(mode)) return loading[mode].push(cont); 27 | 28 | var script = document.createElement("script"); 29 | script.src = CodeMirror.modeURL.replace(/%N/g, mode); 30 | var others = document.getElementsByTagName("script")[0]; 31 | others.parentNode.insertBefore(script, others); 32 | var list = loading[mode] = [cont]; 33 | var count = 0, poll = setInterval(function() { 34 | if (++count > 100) return clearInterval(poll); 35 | if (CodeMirror.modes.hasOwnProperty(mode)) { 36 | clearInterval(poll); 37 | loading[mode] = null; 38 | ensureDeps(mode, function() { 39 | for (var i = 0; i < list.length; ++i) list[i](); 40 | }); 41 | } 42 | }, 200); 43 | }; 44 | 45 | CodeMirror.autoLoadMode = function(instance, mode) { 46 | if (!CodeMirror.modes.hasOwnProperty(mode)) 47 | CodeMirror.requireMode(mode, function() { 48 | instance.setOption("mode", instance.getOption("mode")); 49 | }); 50 | }; 51 | }()); 52 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/match-highlighter.js: -------------------------------------------------------------------------------- 1 | // Define match-highlighter commands. Depends on searchcursor.js 2 | // Use by attaching the following function call to the onCursorActivity event: 3 | //myCodeMirror.matchHighlight(minChars); 4 | // And including a special span.CodeMirror-matchhighlight css class (also optionally a separate one for .CodeMirror-focused -- see demo matchhighlighter.html) 5 | 6 | (function() { 7 | var DEFAULT_MIN_CHARS = 2; 8 | 9 | function MatchHighlightState() { 10 | this.marked = []; 11 | } 12 | function getMatchHighlightState(cm) { 13 | return cm._matchHighlightState || (cm._matchHighlightState = new MatchHighlightState()); 14 | } 15 | 16 | function clearMarks(cm) { 17 | var state = getMatchHighlightState(cm); 18 | for (var i = 0; i < state.marked.length; ++i) 19 | state.marked[i].clear(); 20 | state.marked = []; 21 | } 22 | 23 | function markDocument(cm, className, minChars) { 24 | clearMarks(cm); 25 | minChars = (typeof minChars !== 'undefined' ? minChars : DEFAULT_MIN_CHARS); 26 | if (cm.somethingSelected() && cm.getSelection().replace(/^\s+|\s+$/g, "").length >= minChars) { 27 | var state = getMatchHighlightState(cm); 28 | var query = cm.getSelection(); 29 | cm.operation(function() { 30 | if (cm.lineCount() < 2000) { // This is too expensive on big documents. 31 | for (var cursor = cm.getSearchCursor(query); cursor.findNext();) { 32 | //Only apply matchhighlight to the matches other than the one actually selected 33 | if (!(cursor.from().line === cm.getCursor(true).line && cursor.from().ch === cm.getCursor(true).ch)) 34 | state.marked.push(cm.markText(cursor.from(), cursor.to(), className)); 35 | } 36 | } 37 | }); 38 | } 39 | } 40 | 41 | CodeMirror.defineExtension("matchHighlight", function(className, minChars) { 42 | markDocument(this, className, minChars); 43 | }); 44 | })(); 45 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/multiplex.js: -------------------------------------------------------------------------------- 1 | CodeMirror.multiplexingMode = function(outer /*, others */) { 2 | // Others should be {open, close, mode [, delimStyle]} objects 3 | var others = Array.prototype.slice.call(arguments, 1); 4 | var n_others = others.length; 5 | 6 | function indexOf(string, pattern, from) { 7 | if (typeof pattern == "string") return string.indexOf(pattern, from); 8 | var m = pattern.exec(from ? string.slice(from) : string); 9 | return m ? m.index + from : -1; 10 | } 11 | 12 | return { 13 | startState: function() { 14 | return { 15 | outer: CodeMirror.startState(outer), 16 | innerActive: null, 17 | inner: null 18 | }; 19 | }, 20 | 21 | copyState: function(state) { 22 | return { 23 | outer: CodeMirror.copyState(outer, state.outer), 24 | innerActive: state.innerActive, 25 | inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner) 26 | }; 27 | }, 28 | 29 | token: function(stream, state) { 30 | if (!state.innerActive) { 31 | var cutOff = Infinity, oldContent = stream.string; 32 | for (var i = 0; i < n_others; ++i) { 33 | var other = others[i]; 34 | var found = indexOf(oldContent, other.open, stream.pos); 35 | if (found == stream.pos) { 36 | stream.match(other.open); 37 | state.innerActive = other; 38 | state.inner = CodeMirror.startState(other.mode, outer.indent ? outer.indent(state.outer, "") : 0); 39 | return other.delimStyle; 40 | } else if (found != -1 && found < cutOff) { 41 | cutOff = found; 42 | } 43 | } 44 | if (cutOff != Infinity) stream.string = oldContent.slice(0, cutOff); 45 | var outerToken = outer.token(stream, state.outer); 46 | if (cutOff != Infinity) stream.string = oldContent; 47 | return outerToken; 48 | } else { 49 | var curInner = state.innerActive, oldContent = stream.string; 50 | var found = indexOf(oldContent, curInner.close, stream.pos); 51 | if (found == stream.pos) { 52 | stream.match(curInner.close); 53 | state.innerActive = state.inner = null; 54 | return curInner.delimStyle; 55 | } 56 | if (found > -1) stream.string = oldContent.slice(0, found); 57 | var innerToken = curInner.mode.token(stream, state.inner); 58 | if (found > -1) stream.string = oldContent; 59 | var cur = stream.current(), found = cur.indexOf(curInner.close); 60 | if (found > -1) stream.backUp(cur.length - found); 61 | return innerToken; 62 | } 63 | }, 64 | 65 | indent: function(state, textAfter) { 66 | var mode = state.innerActive ? state.innerActive.mode : outer; 67 | if (!mode.indent) return CodeMirror.Pass; 68 | return mode.indent(state.innerActive ? state.inner : state.outer, textAfter); 69 | }, 70 | 71 | electricChars: outer.electricChars, 72 | 73 | innerMode: function(state) { 74 | return state.inner ? {state: state.inner, mode: state.innerActive.mode} : {state: state.outer, mode: outer}; 75 | } 76 | }; 77 | }; 78 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/overlay.js: -------------------------------------------------------------------------------- 1 | // Utility function that allows modes to be combined. The mode given 2 | // as the base argument takes care of most of the normal mode 3 | // functionality, but a second (typically simple) mode is used, which 4 | // can override the style of text. Both modes get to parse all of the 5 | // text, but when both assign a non-null style to a piece of code, the 6 | // overlay wins, unless the combine argument was true, in which case 7 | // the styles are combined. 8 | 9 | // overlayParser is the old, deprecated name 10 | CodeMirror.overlayMode = CodeMirror.overlayParser = function(base, overlay, combine) { 11 | return { 12 | startState: function() { 13 | return { 14 | base: CodeMirror.startState(base), 15 | overlay: CodeMirror.startState(overlay), 16 | basePos: 0, baseCur: null, 17 | overlayPos: 0, overlayCur: null 18 | }; 19 | }, 20 | copyState: function(state) { 21 | return { 22 | base: CodeMirror.copyState(base, state.base), 23 | overlay: CodeMirror.copyState(overlay, state.overlay), 24 | basePos: state.basePos, baseCur: null, 25 | overlayPos: state.overlayPos, overlayCur: null 26 | }; 27 | }, 28 | 29 | token: function(stream, state) { 30 | if (stream.start == state.basePos) { 31 | state.baseCur = base.token(stream, state.base); 32 | state.basePos = stream.pos; 33 | } 34 | if (stream.start == state.overlayPos) { 35 | stream.pos = stream.start; 36 | state.overlayCur = overlay.token(stream, state.overlay); 37 | state.overlayPos = stream.pos; 38 | } 39 | stream.pos = Math.min(state.basePos, state.overlayPos); 40 | if (stream.eol()) state.basePos = state.overlayPos = 0; 41 | 42 | if (state.overlayCur == null) return state.baseCur; 43 | if (state.baseCur != null && combine) return state.baseCur + " " + state.overlayCur; 44 | else return state.overlayCur; 45 | }, 46 | 47 | indent: base.indent && function(state, textAfter) { 48 | return base.indent(state.base, textAfter); 49 | }, 50 | electricChars: base.electricChars, 51 | 52 | innerMode: function(state) { return {state: state.base, mode: base}; } 53 | }; 54 | }; 55 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/runmode-standalone.js: -------------------------------------------------------------------------------- 1 | /* Just enough of CodeMirror to run runMode under node.js */ 2 | 3 | function splitLines(string){ return string.split(/\r?\n|\r/); }; 4 | 5 | function StringStream(string) { 6 | this.pos = this.start = 0; 7 | this.string = string; 8 | } 9 | StringStream.prototype = { 10 | eol: function() {return this.pos >= this.string.length;}, 11 | sol: function() {return this.pos == 0;}, 12 | peek: function() {return this.string.charAt(this.pos) || null;}, 13 | next: function() { 14 | if (this.pos < this.string.length) 15 | return this.string.charAt(this.pos++); 16 | }, 17 | eat: function(match) { 18 | var ch = this.string.charAt(this.pos); 19 | if (typeof match == "string") var ok = ch == match; 20 | else var ok = ch && (match.test ? match.test(ch) : match(ch)); 21 | if (ok) {++this.pos; return ch;} 22 | }, 23 | eatWhile: function(match) { 24 | var start = this.pos; 25 | while (this.eat(match)){} 26 | return this.pos > start; 27 | }, 28 | eatSpace: function() { 29 | var start = this.pos; 30 | while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos; 31 | return this.pos > start; 32 | }, 33 | skipToEnd: function() {this.pos = this.string.length;}, 34 | skipTo: function(ch) { 35 | var found = this.string.indexOf(ch, this.pos); 36 | if (found > -1) {this.pos = found; return true;} 37 | }, 38 | backUp: function(n) {this.pos -= n;}, 39 | column: function() {return this.start;}, 40 | indentation: function() {return 0;}, 41 | match: function(pattern, consume, caseInsensitive) { 42 | if (typeof pattern == "string") { 43 | function cased(str) {return caseInsensitive ? str.toLowerCase() : str;} 44 | if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) { 45 | if (consume !== false) this.pos += pattern.length; 46 | return true; 47 | } 48 | } 49 | else { 50 | var match = this.string.slice(this.pos).match(pattern); 51 | if (match && consume !== false) this.pos += match[0].length; 52 | return match; 53 | } 54 | }, 55 | current: function(){return this.string.slice(this.start, this.pos);} 56 | }; 57 | exports.StringStream = StringStream; 58 | 59 | exports.startState = function(mode, a1, a2) { 60 | return mode.startState ? mode.startState(a1, a2) : true; 61 | }; 62 | 63 | var modes = exports.modes = {}, mimeModes = exports.mimeModes = {}; 64 | exports.defineMode = function(name, mode) { modes[name] = mode; }; 65 | exports.defineMIME = function(mime, spec) { mimeModes[mime] = spec; }; 66 | exports.getMode = function(options, spec) { 67 | if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) 68 | spec = mimeModes[spec]; 69 | if (typeof spec == "string") 70 | var mname = spec, config = {}; 71 | else if (spec != null) 72 | var mname = spec.name, config = spec; 73 | var mfactory = modes[mname]; 74 | if (!mfactory) throw new Error("Unknown mode: " + spec); 75 | return mfactory(options, config || {}); 76 | }; 77 | 78 | exports.runMode = function(string, modespec, callback) { 79 | var mode = exports.getMode({indentUnit: 2}, modespec); 80 | var lines = splitLines(string), state = exports.startState(mode); 81 | for (var i = 0, e = lines.length; i < e; ++i) { 82 | if (i) callback("\n"); 83 | var stream = new exports.StringStream(lines[i]); 84 | while (!stream.eol()) { 85 | var style = mode.token(stream, state); 86 | callback(stream.current(), style, i, stream.start); 87 | stream.start = stream.pos; 88 | } 89 | } 90 | }; 91 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/runmode.js: -------------------------------------------------------------------------------- 1 | CodeMirror.runMode = function(string, modespec, callback, options) { 2 | function esc(str) { 3 | return str.replace(/[<&]/, function(ch) { return ch == "<" ? "<" : "&"; }); 4 | } 5 | 6 | var mode = CodeMirror.getMode(CodeMirror.defaults, modespec); 7 | var isNode = callback.nodeType == 1; 8 | var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize; 9 | if (isNode) { 10 | var node = callback, accum = [], col = 0; 11 | callback = function(text, style) { 12 | if (text == "\n") { 13 | accum.push("
"); 14 | col = 0; 15 | return; 16 | } 17 | var escaped = ""; 18 | // HTML-escape and replace tabs 19 | for (var pos = 0;;) { 20 | var idx = text.indexOf("\t", pos); 21 | if (idx == -1) { 22 | escaped += esc(text.slice(pos)); 23 | col += text.length - pos; 24 | break; 25 | } else { 26 | col += idx - pos; 27 | escaped += esc(text.slice(pos, idx)); 28 | var size = tabSize - col % tabSize; 29 | col += size; 30 | for (var i = 0; i < size; ++i) escaped += " "; 31 | pos = idx + 1; 32 | } 33 | } 34 | 35 | if (style) 36 | accum.push("" + escaped + ""); 37 | else 38 | accum.push(escaped); 39 | }; 40 | } 41 | var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode); 42 | for (var i = 0, e = lines.length; i < e; ++i) { 43 | if (i) callback("\n"); 44 | var stream = new CodeMirror.StringStream(lines[i]); 45 | while (!stream.eol()) { 46 | var style = mode.token(stream, state); 47 | callback(stream.current(), style, i, stream.start); 48 | stream.start = stream.pos; 49 | } 50 | } 51 | if (isNode) 52 | node.innerHTML = accum.join(""); 53 | }; 54 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/simple-hint.css: -------------------------------------------------------------------------------- 1 | .CodeMirror-completions { 2 | position: absolute; 3 | z-index: 10; 4 | overflow: hidden; 5 | -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2); 6 | -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2); 7 | box-shadow: 2px 3px 5px rgba(0,0,0,.2); 8 | } 9 | .CodeMirror-completions select { 10 | background: #fafafa; 11 | outline: none; 12 | border: none; 13 | padding: 0; 14 | margin: 0; 15 | font-family: monospace; 16 | } 17 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/simple-hint.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | CodeMirror.simpleHint = function(editor, getHints, givenOptions) { 3 | // Determine effective options based on given values and defaults. 4 | var options = {}, defaults = CodeMirror.simpleHint.defaults; 5 | for (var opt in defaults) 6 | if (defaults.hasOwnProperty(opt)) 7 | options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt]; 8 | 9 | function collectHints(previousToken) { 10 | // We want a single cursor position. 11 | if (editor.somethingSelected()) return; 12 | 13 | var tempToken = editor.getTokenAt(editor.getCursor()); 14 | 15 | // Don't show completions if token has changed and the option is set. 16 | if (options.closeOnTokenChange && previousToken != null && 17 | (tempToken.start != previousToken.start || tempToken.className != previousToken.className)) { 18 | return; 19 | } 20 | 21 | var result = getHints(editor); 22 | if (!result || !result.list.length) return; 23 | var completions = result.list; 24 | function insert(str) { 25 | editor.replaceRange(str, result.from, result.to); 26 | } 27 | // When there is only one completion, use it directly. 28 | if (completions.length == 1) {insert(completions[0]); return true;} 29 | 30 | // Build the select widget 31 | var complete = document.createElement("div"); 32 | complete.className = "CodeMirror-completions"; 33 | var sel = complete.appendChild(document.createElement("select")); 34 | // Opera doesn't move the selection when pressing up/down in a 35 | // multi-select, but it does properly support the size property on 36 | // single-selects, so no multi-select is necessary. 37 | if (!window.opera) sel.multiple = true; 38 | for (var i = 0; i < completions.length; ++i) { 39 | var opt = sel.appendChild(document.createElement("option")); 40 | opt.appendChild(document.createTextNode(completions[i])); 41 | } 42 | sel.firstChild.selected = true; 43 | sel.size = Math.min(10, completions.length); 44 | var pos = editor.cursorCoords(); 45 | complete.style.left = pos.x + "px"; 46 | complete.style.top = pos.yBot + "px"; 47 | document.body.appendChild(complete); 48 | // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor. 49 | var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth); 50 | if(winW - pos.x < sel.clientWidth) 51 | complete.style.left = (pos.x - sel.clientWidth) + "px"; 52 | // Hack to hide the scrollbar. 53 | if (completions.length <= 10) 54 | complete.style.width = (sel.clientWidth - 1) + "px"; 55 | 56 | var done = false; 57 | function close() { 58 | if (done) return; 59 | done = true; 60 | complete.parentNode.removeChild(complete); 61 | } 62 | function pick() { 63 | insert(completions[sel.selectedIndex]); 64 | close(); 65 | setTimeout(function(){editor.focus();}, 50); 66 | } 67 | CodeMirror.connect(sel, "blur", close); 68 | CodeMirror.connect(sel, "keydown", function(event) { 69 | var code = event.keyCode; 70 | // Enter 71 | if (code == 13) {CodeMirror.e_stop(event); pick();} 72 | // Escape 73 | else if (code == 27) {CodeMirror.e_stop(event); close(); editor.focus();} 74 | else if (code != 38 && code != 40 && code != 33 && code != 34) { 75 | close(); editor.focus(); 76 | // Pass the event to the CodeMirror instance so that it can handle things like backspace properly. 77 | editor.triggerOnKeyDown(event); 78 | // Don't show completions if the code is backspace and the option is set. 79 | if (!options.closeOnBackspace || code != 8) { 80 | setTimeout(function(){collectHints(tempToken);}, 50); 81 | } 82 | } 83 | }); 84 | CodeMirror.connect(sel, "dblclick", pick); 85 | 86 | sel.focus(); 87 | // Opera sometimes ignores focusing a freshly created node 88 | if (window.opera) setTimeout(function(){if (!done) sel.focus();}, 100); 89 | return true; 90 | } 91 | return collectHints(); 92 | }; 93 | CodeMirror.simpleHint.defaults = { 94 | closeOnBackspace: true, 95 | closeOnTokenChange: false 96 | }; 97 | })(); 98 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/lib/util/xml-hint.js: -------------------------------------------------------------------------------- 1 | 2 | (function() { 3 | 4 | CodeMirror.xmlHints = []; 5 | 6 | CodeMirror.xmlHint = function(cm, simbol) { 7 | 8 | if(simbol.length > 0) { 9 | var cursor = cm.getCursor(); 10 | cm.replaceSelection(simbol); 11 | cursor = {line: cursor.line, ch: cursor.ch + 1}; 12 | cm.setCursor(cursor); 13 | } 14 | 15 | // dirty hack for simple-hint to receive getHint event on space 16 | var getTokenAt = editor.getTokenAt; 17 | 18 | editor.getTokenAt = function() { return 'disabled'; }; 19 | CodeMirror.simpleHint(cm, getHint); 20 | 21 | editor.getTokenAt = getTokenAt; 22 | }; 23 | 24 | var getHint = function(cm) { 25 | 26 | var cursor = cm.getCursor(); 27 | 28 | if (cursor.ch > 0) { 29 | 30 | var text = cm.getRange({line: 0, ch: 0}, cursor); 31 | var typed = ''; 32 | var simbol = ''; 33 | for(var i = text.length - 1; i >= 0; i--) { 34 | if(text[i] == ' ' || text[i] == '<') { 35 | simbol = text[i]; 36 | break; 37 | } 38 | else { 39 | typed = text[i] + typed; 40 | } 41 | } 42 | 43 | text = text.slice(0, text.length - typed.length); 44 | 45 | var path = getActiveElement(cm, text) + simbol; 46 | var hints = CodeMirror.xmlHints[path]; 47 | 48 | if(typeof hints === 'undefined') 49 | hints = ['']; 50 | else { 51 | hints = hints.slice(0); 52 | for (var i = hints.length - 1; i >= 0; i--) { 53 | if(hints[i].indexOf(typed) != 0) 54 | hints.splice(i, 1); 55 | } 56 | } 57 | 58 | return { 59 | list: hints, 60 | from: { line: cursor.line, ch: cursor.ch - typed.length }, 61 | to: cursor 62 | }; 63 | }; 64 | }; 65 | 66 | var getActiveElement = function(codeMirror, text) { 67 | 68 | var element = ''; 69 | 70 | if(text.length >= 0) { 71 | 72 | var regex = new RegExp('<([^!?][^\\s/>]*).*?>', 'g'); 73 | 74 | var matches = []; 75 | var match; 76 | while ((match = regex.exec(text)) != null) { 77 | matches.push({ 78 | tag: match[1], 79 | selfclose: (match[0].slice(match[0].length - 2) === '/>') 80 | }); 81 | } 82 | 83 | for (var i = matches.length - 1, skip = 0; i >= 0; i--) { 84 | 85 | var item = matches[i]; 86 | 87 | if (item.tag[0] == '/') 88 | { 89 | skip++; 90 | } 91 | else if (item.selfclose == false) 92 | { 93 | if (skip > 0) 94 | { 95 | skip--; 96 | } 97 | else 98 | { 99 | element = '<' + item.tag + '>' + element; 100 | } 101 | } 102 | } 103 | 104 | element += getOpenTag(text); 105 | } 106 | 107 | return element; 108 | }; 109 | 110 | var getOpenTag = function(text) { 111 | 112 | var open = text.lastIndexOf('<'); 113 | var close = text.lastIndexOf('>'); 114 | 115 | if (close < open) 116 | { 117 | text = text.slice(open); 118 | 119 | if(text != '<') { 120 | 121 | var space = text.indexOf(' '); 122 | if(space < 0) 123 | space = text.indexOf('\t'); 124 | if(space < 0) 125 | space = text.indexOf('\n'); 126 | 127 | if (space < 0) 128 | space = text.length; 129 | 130 | return text.slice(0, space); 131 | } 132 | } 133 | 134 | return ''; 135 | }; 136 | 137 | })(); 138 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/clike/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: C-like mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: C-like mode

14 | 15 |
82 | 83 | 90 | 91 |

Simple mode that tries to handle C-like languages as well as it 92 | can. Takes two configuration parameters: keywords, an 93 | object whose property names are the keywords in the language, 94 | and useCPP, which determines whether C preprocessor 95 | directives are recognized.

96 | 97 |

MIME types defined: text/x-csrc 98 | (C code), text/x-c++src (C++ 99 | code), text/x-java (Java 100 | code), text/x-csharp (C#).

101 | 102 | 103 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/clojure/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Clojure mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Clojure mode

14 |
60 | 63 | 64 |

MIME types defined: text/x-clojure.

65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/coffeescript/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2011 Jeff Pickhardt 4 | Modified from the Python CodeMirror mode, Copyright (c) 2010 Timothy Farrell 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/commonlisp/commonlisp.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("commonlisp", function (config) { 2 | var assumeBody = /^with|^def|^do|^prog|case$|^cond$|bind$|when$|unless$/; 3 | var numLiteral = /^(?:[+\-]?(?:\d+|\d*\.\d+)(?:[efd][+\-]?\d+)?|[+\-]?\d+(?:\/[+\-]?\d+)?|#b[+\-]?[01]+|#o[+\-]?[0-7]+|#x[+\-]?[\da-f]+)/; 4 | var symbol = /[^\s'`,@()\[\]";]/; 5 | var type; 6 | 7 | function readSym(stream) { 8 | var ch; 9 | while (ch = stream.next()) { 10 | if (ch == "\\") stream.next(); 11 | else if (!symbol.test(ch)) { stream.backUp(1); break; } 12 | } 13 | return stream.current(); 14 | } 15 | 16 | function base(stream, state) { 17 | if (stream.eatSpace()) {type = "ws"; return null;} 18 | if (stream.match(numLiteral)) return "number"; 19 | var ch = stream.next(); 20 | if (ch == "\\") ch = stream.next(); 21 | 22 | if (ch == '"') return (state.tokenize = inString)(stream, state); 23 | else if (ch == "(") { type = "open"; return "bracket"; } 24 | else if (ch == ")" || ch == "]") { type = "close"; return "bracket"; } 25 | else if (ch == ";") { stream.skipToEnd(); type = "ws"; return "comment"; } 26 | else if (/['`,@]/.test(ch)) return null; 27 | else if (ch == "|") { 28 | if (stream.skipTo("|")) { stream.next(); return "symbol"; } 29 | else { stream.skipToEnd(); return "error"; } 30 | } else if (ch == "#") { 31 | var ch = stream.next(); 32 | if (ch == "[") { type = "open"; return "bracket"; } 33 | else if (/[+\-=\.']/.test(ch)) return null; 34 | else if (/\d/.test(ch) && stream.match(/^\d*#/)) return null; 35 | else if (ch == "|") return (state.tokenize = inComment)(stream, state); 36 | else if (ch == ":") { readSym(stream); return "meta"; } 37 | else return "error"; 38 | } else { 39 | var name = readSym(stream); 40 | if (name == ".") return null; 41 | type = "symbol"; 42 | if (name == "nil" || name == "t") return "atom"; 43 | if (name.charAt(0) == ":") return "keyword"; 44 | if (name.charAt(0) == "&") return "variable-2"; 45 | return "variable"; 46 | } 47 | } 48 | 49 | function inString(stream, state) { 50 | var escaped = false, next; 51 | while (next = stream.next()) { 52 | if (next == '"' && !escaped) { state.tokenize = base; break; } 53 | escaped = !escaped && next == "\\"; 54 | } 55 | return "string"; 56 | } 57 | 58 | function inComment(stream, state) { 59 | var next, last; 60 | while (next = stream.next()) { 61 | if (next == "#" && last == "|") { state.tokenize = base; break; } 62 | last = next; 63 | } 64 | type = "ws"; 65 | return "comment"; 66 | } 67 | 68 | return { 69 | startState: function () { 70 | return {ctx: {prev: null, start: 0, indentTo: 0}, tokenize: base}; 71 | }, 72 | 73 | token: function (stream, state) { 74 | if (stream.sol() && typeof state.ctx.indentTo != "number") 75 | state.ctx.indentTo = state.ctx.start + 1; 76 | 77 | type = null; 78 | var style = state.tokenize(stream, state); 79 | if (type != "ws") { 80 | if (state.ctx.indentTo == null) { 81 | if (type == "symbol" && assumeBody.test(stream.current())) 82 | state.ctx.indentTo = state.ctx.start + config.indentUnit; 83 | else 84 | state.ctx.indentTo = "next"; 85 | } else if (state.ctx.indentTo == "next") { 86 | state.ctx.indentTo = stream.column(); 87 | } 88 | } 89 | if (type == "open") state.ctx = {prev: state.ctx, start: stream.column(), indentTo: null}; 90 | else if (type == "close") state.ctx = state.ctx.prev || state.ctx; 91 | return style; 92 | }, 93 | 94 | indent: function (state, textAfter) { 95 | var i = state.ctx.indentTo; 96 | return typeof i == "number" ? i : state.ctx.start + 1; 97 | } 98 | }; 99 | }); 100 | 101 | CodeMirror.defineMIME("text/x-common-lisp", "commonlisp"); 102 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/css/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: CSS mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: CSS mode

14 |
49 | 52 | 53 |

MIME types defined: text/css.

54 | 55 |

Parsing/Highlighting Tests: normal, verbose.

56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/diff/diff.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("diff", function() { 2 | 3 | var TOKEN_NAMES = { 4 | '+': 'tag', 5 | '-': 'string', 6 | '@': 'meta' 7 | }; 8 | 9 | return { 10 | token: function(stream) { 11 | var tw_pos = stream.string.search(/[\t ]+?$/); 12 | 13 | if (!stream.sol() || tw_pos === 0) { 14 | stream.skipToEnd(); 15 | return ("error " + ( 16 | TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, ''); 17 | } 18 | 19 | var token_name = TOKEN_NAMES[stream.peek()] || stream.skipToEnd(); 20 | 21 | if (tw_pos === -1) { 22 | stream.skipToEnd(); 23 | } else { 24 | stream.pos = tw_pos; 25 | } 26 | 27 | return token_name; 28 | } 29 | }; 30 | }); 31 | 32 | CodeMirror.defineMIME("text/x-diff", "diff"); 33 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/diff/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Diff mode 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19 |

CodeMirror: Diff mode

20 |
98 | 101 | 102 |

MIME types defined: text/x-diff.

103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/ecl/index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | CodeMirror: ECL mode 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |

CodeMirror: ECL mode

13 |
31 | 37 | 38 |

Based on CodeMirror's clike mode. For more information see HPCC Systems web site.

39 |

MIME types defined: text/x-ecl.

40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/erlang/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Erlang mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

CodeMirror: Erlang mode

15 | 16 |
51 | 52 | 60 | 61 |

MIME types defined: text/x-erlang.

62 | 63 | 64 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/gfm/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: GFM mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |

CodeMirror: GFM mode

18 | 19 | 20 |
37 | 38 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/go/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Go mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

CodeMirror: Go mode

15 | 16 |
59 | 60 | 70 | 71 |

MIME type: text/x-go

72 | 73 | 74 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/groovy/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Groovy mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Groovy mode

14 | 15 |
61 | 62 | 69 | 70 |

MIME types defined: text/x-groovy

71 | 72 | 73 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/haskell/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Haskell mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

CodeMirror: Haskell mode

15 | 16 |
50 | 51 | 58 | 59 |

MIME types defined: text/x-haskell.

60 | 61 | 62 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/haxe/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Haxe mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Haxe mode

14 | 15 |
79 | 80 | 88 | 89 |

MIME types defined: text/x-haxe.

90 | 91 | 92 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/htmlembedded/htmlembedded.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("htmlembedded", function(config, parserConfig) { 2 | 3 | //config settings 4 | var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i, 5 | scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i; 6 | 7 | //inner modes 8 | var scriptingMode, htmlMixedMode; 9 | 10 | //tokenizer when in html mode 11 | function htmlDispatch(stream, state) { 12 | if (stream.match(scriptStartRegex, false)) { 13 | state.token=scriptingDispatch; 14 | return scriptingMode.token(stream, state.scriptState); 15 | } 16 | else 17 | return htmlMixedMode.token(stream, state.htmlState); 18 | } 19 | 20 | //tokenizer when in scripting mode 21 | function scriptingDispatch(stream, state) { 22 | if (stream.match(scriptEndRegex, false)) { 23 | state.token=htmlDispatch; 24 | return htmlMixedMode.token(stream, state.htmlState); 25 | } 26 | else 27 | return scriptingMode.token(stream, state.scriptState); 28 | } 29 | 30 | 31 | return { 32 | startState: function() { 33 | scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec); 34 | htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed"); 35 | return { 36 | token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch, 37 | htmlState : htmlMixedMode.startState(), 38 | scriptState : scriptingMode.startState() 39 | }; 40 | }, 41 | 42 | token: function(stream, state) { 43 | return state.token(stream, state); 44 | }, 45 | 46 | indent: function(state, textAfter) { 47 | if (state.token == htmlDispatch) 48 | return htmlMixedMode.indent(state.htmlState, textAfter); 49 | else 50 | return scriptingMode.indent(state.scriptState, textAfter); 51 | }, 52 | 53 | copyState: function(state) { 54 | return { 55 | token : state.token, 56 | htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState), 57 | scriptState : CodeMirror.copyState(scriptingMode, state.scriptState) 58 | }; 59 | }, 60 | 61 | electricChars: "/{}:", 62 | 63 | innerMode: function(state) { 64 | if (state.token == scriptingDispatch) return {state: state.scriptState, mode: scriptingMode}; 65 | else return {state: state.htmlState, mode: htmlMixedMode}; 66 | } 67 | }; 68 | }, "htmlmixed"); 69 | 70 | CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"}); 71 | CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"}); 72 | CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"}); 73 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/htmlembedded/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Html Embedded Scripts mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |

CodeMirror: Html Embedded Scripts mode

18 | 19 |
31 | 32 | 43 | 44 |

Mode for html embedded scripts like JSP and ASP.NET. Depends on HtmlMixed which in turn depends on 45 | JavaScript, CSS and XML.
Other dependancies include those of the scriping language chosen.

46 | 47 |

MIME types defined: application/x-aspx (ASP.NET), 48 | application/x-ejs (Embedded Javascript), application/x-jsp (JavaServer Pages)

49 | 50 | 51 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/htmlmixed/htmlmixed.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("htmlmixed", function(config) { 2 | var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true}); 3 | var jsMode = CodeMirror.getMode(config, "javascript"); 4 | var cssMode = CodeMirror.getMode(config, "css"); 5 | 6 | function html(stream, state) { 7 | var style = htmlMode.token(stream, state.htmlState); 8 | if (style == "tag" && stream.current() == ">" && state.htmlState.context) { 9 | if (/^script$/i.test(state.htmlState.context.tagName)) { 10 | state.token = javascript; 11 | state.localState = jsMode.startState(htmlMode.indent(state.htmlState, "")); 12 | } 13 | else if (/^style$/i.test(state.htmlState.context.tagName)) { 14 | state.token = css; 15 | state.localState = cssMode.startState(htmlMode.indent(state.htmlState, "")); 16 | } 17 | } 18 | return style; 19 | } 20 | function maybeBackup(stream, pat, style) { 21 | var cur = stream.current(); 22 | var close = cur.search(pat), m; 23 | if (close > -1) stream.backUp(cur.length - close); 24 | else if (m = cur.match(/<\/?$/)) { 25 | stream.backUp(cur[0].length); 26 | if (!stream.match(pat, false)) stream.match(cur[0]); 27 | } 28 | return style; 29 | } 30 | function javascript(stream, state) { 31 | if (stream.match(/^<\/\s*script\s*>/i, false)) { 32 | state.token = html; 33 | state.localState = null; 34 | return html(stream, state); 35 | } 36 | return maybeBackup(stream, /<\/\s*script\s*>/, 37 | jsMode.token(stream, state.localState)); 38 | } 39 | function css(stream, state) { 40 | if (stream.match(/^<\/\s*style\s*>/i, false)) { 41 | state.token = html; 42 | state.localState = null; 43 | return html(stream, state); 44 | } 45 | return maybeBackup(stream, /<\/\s*style\s*>/, 46 | cssMode.token(stream, state.localState)); 47 | } 48 | 49 | return { 50 | startState: function() { 51 | var state = htmlMode.startState(); 52 | return {token: html, localState: null, mode: "html", htmlState: state}; 53 | }, 54 | 55 | copyState: function(state) { 56 | if (state.localState) 57 | var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState); 58 | return {token: state.token, localState: local, mode: state.mode, 59 | htmlState: CodeMirror.copyState(htmlMode, state.htmlState)}; 60 | }, 61 | 62 | token: function(stream, state) { 63 | return state.token(stream, state); 64 | }, 65 | 66 | indent: function(state, textAfter) { 67 | if (state.token == html || /^\s*<\//.test(textAfter)) 68 | return htmlMode.indent(state.htmlState, textAfter); 69 | else if (state.token == javascript) 70 | return jsMode.indent(state.localState, textAfter); 71 | else 72 | return cssMode.indent(state.localState, textAfter); 73 | }, 74 | 75 | electricChars: "/{}:", 76 | 77 | innerMode: function(state) { 78 | var mode = state.token == html ? htmlMode : state.token == javascript ? jsMode : cssMode; 79 | return {state: state.localState || state.htmlState, mode: mode}; 80 | } 81 | }; 82 | }, "xml", "javascript", "css"); 83 | 84 | CodeMirror.defineMIME("text/html", "htmlmixed"); 85 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/htmlmixed/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: HTML mixed mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |

CodeMirror: HTML mixed mode

17 |
41 | 44 | 45 |

The HTML mixed mode depends on the XML, JavaScript, and CSS modes.

46 | 47 |

MIME types defined: text/html 48 | (redefined, only takes effect if you load this parser after the 49 | XML parser).

50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/javascript/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: JavaScript mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: JavaScript mode

14 | 15 |
64 | 65 | 71 | 72 |

JavaScript mode supports a single configuration 73 | option, json, which will set the mode to expect JSON 74 | data rather than a JavaScript program.

75 | 76 |

MIME types defined: text/javascript, application/json.

77 | 78 | 79 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/jinja2/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Jinja2 mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Jinja2 mode

14 |
32 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/jinja2/jinja2.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("jinja2", function(config, parserConf) { 2 | var keywords = ["block", "endblock", "for", "endfor", "in", "true", "false", 3 | "loop", "none", "self", "super", "if", "as", "not", "and", 4 | "else", "import", "with", "without", "context"]; 5 | keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b"); 6 | 7 | function tokenBase (stream, state) { 8 | var ch = stream.next(); 9 | if (ch == "{") { 10 | if (ch = stream.eat(/\{|%|#/)) { 11 | stream.eat("-"); 12 | state.tokenize = inTag(ch); 13 | return "tag"; 14 | } 15 | } 16 | } 17 | function inTag (close) { 18 | if (close == "{") { 19 | close = "}"; 20 | } 21 | return function (stream, state) { 22 | var ch = stream.next(); 23 | if ((ch == close || (ch == "-" && stream.eat(close))) 24 | && stream.eat("}")) { 25 | state.tokenize = tokenBase; 26 | return "tag"; 27 | } 28 | if (stream.match(keywords)) { 29 | return "keyword"; 30 | } 31 | return close == "#" ? "comment" : "string"; 32 | }; 33 | } 34 | return { 35 | startState: function () { 36 | return {tokenize: tokenBase}; 37 | }, 38 | token: function (stream, state) { 39 | return state.tokenize(stream, state); 40 | } 41 | }; 42 | }); 43 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/lua/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Lua mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

CodeMirror: Lua mode

15 |
56 | 63 | 64 |

Loosely based on Franciszek 65 | Wawrzak's CodeMirror 66 | 1 mode. One configuration parameter is 67 | supported, specials, to which you can provide an 68 | array of strings to have those identifiers highlighted with 69 | the lua-special style.

70 |

MIME types defined: text/x-lua.

71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/mysql/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: MySQL mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: MySQL mode

14 |
31 | 38 | 39 |

MIME types defined: text/x-mysql.

40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/ntriples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: NTriples mode 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 |

CodeMirror: NTriples mode

18 |
19 | 26 |
27 | 28 | 31 |

MIME types defined: text/n-triples.

32 | 33 | 34 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/ocaml/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | CodeMirror: OCaml mode 4 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 |

CodeMirror: OCaml mode

16 | 17 | 121 | 122 | 129 | 130 |

MIME types defined: text/x-ocaml.

131 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/ocaml/ocaml.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode('ocaml', function(config) { 2 | 3 | var words = { 4 | 'true': 'atom', 5 | 'false': 'atom', 6 | 'let': 'keyword', 7 | 'rec': 'keyword', 8 | 'in': 'keyword', 9 | 'of': 'keyword', 10 | 'and': 'keyword', 11 | 'succ': 'keyword', 12 | 'if': 'keyword', 13 | 'then': 'keyword', 14 | 'else': 'keyword', 15 | 'for': 'keyword', 16 | 'to': 'keyword', 17 | 'while': 'keyword', 18 | 'do': 'keyword', 19 | 'done': 'keyword', 20 | 'fun': 'keyword', 21 | 'function': 'keyword', 22 | 'val': 'keyword', 23 | 'type': 'keyword', 24 | 'mutable': 'keyword', 25 | 'match': 'keyword', 26 | 'with': 'keyword', 27 | 'try': 'keyword', 28 | 'raise': 'keyword', 29 | 'begin': 'keyword', 30 | 'end': 'keyword', 31 | 'open': 'builtin', 32 | 'trace': 'builtin', 33 | 'ignore': 'builtin', 34 | 'exit': 'builtin', 35 | 'print_string': 'builtin', 36 | 'print_endline': 'builtin' 37 | }; 38 | 39 | function tokenBase(stream, state) { 40 | var sol = stream.sol(); 41 | var ch = stream.next(); 42 | 43 | if (ch === '"') { 44 | state.tokenize = tokenString; 45 | return state.tokenize(stream, state); 46 | } 47 | if (ch === '(') { 48 | if (stream.eat('*')) { 49 | state.commentLevel++; 50 | state.tokenize = tokenComment; 51 | return state.tokenize(stream, state); 52 | } 53 | } 54 | if (ch === '~') { 55 | stream.eatWhile(/\w/); 56 | return 'variable-2'; 57 | } 58 | if (ch === '`') { 59 | stream.eatWhile(/\w/); 60 | return 'quote'; 61 | } 62 | if (/\d/.test(ch)) { 63 | stream.eatWhile(/[\d]/); 64 | if (stream.eat('.')) { 65 | stream.eatWhile(/[\d]/); 66 | } 67 | return 'number'; 68 | } 69 | if ( /[+\-*&%=<>!?|]/.test(ch)) { 70 | return 'operator'; 71 | } 72 | stream.eatWhile(/\w/); 73 | var cur = stream.current(); 74 | return words[cur] || 'variable'; 75 | } 76 | 77 | function tokenString(stream, state) { 78 | var next, end = false, escaped = false; 79 | while ((next = stream.next()) != null) { 80 | if (next === '"' && !escaped) { 81 | end = true; 82 | break; 83 | } 84 | escaped = !escaped && next === '\\'; 85 | } 86 | if (end && !escaped) { 87 | state.tokenize = tokenBase; 88 | } 89 | return 'string'; 90 | }; 91 | 92 | function tokenComment(stream, state) { 93 | var prev, next; 94 | while(state.commentLevel > 0 && (next = stream.next()) != null) { 95 | if (prev === '(' && next === '*') state.commentLevel++; 96 | if (prev === '*' && next === ')') state.commentLevel--; 97 | prev = next; 98 | } 99 | if (state.commentLevel <= 0) { 100 | state.tokenize = tokenBase; 101 | } 102 | return 'comment'; 103 | } 104 | 105 | return { 106 | startState: function() {return {tokenize: tokenBase, commentLevel: 0};}, 107 | token: function(stream, state) { 108 | if (stream.eatSpace()) return null; 109 | return state.tokenize(stream, state); 110 | } 111 | }; 112 | }); 113 | 114 | CodeMirror.defineMIME('text/x-ocaml', 'ocaml'); 115 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/pascal/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 souceLair 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/pascal/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Pascal mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Pascal mode

14 | 15 |
38 | 39 | 46 | 47 |

MIME types defined: text/x-pascal.

48 | 49 | 50 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/pascal/pascal.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("pascal", function(config) { 2 | function words(str) { 3 | var obj = {}, words = str.split(" "); 4 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 5 | return obj; 6 | } 7 | var keywords = words("and array begin case const div do downto else end file for forward integer " + 8 | "boolean char function goto if in label mod nil not of or packed procedure " + 9 | "program record repeat set string then to type until var while with"); 10 | var atoms = {"null": true}; 11 | 12 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; 13 | 14 | function tokenBase(stream, state) { 15 | var ch = stream.next(); 16 | if (ch == "#" && state.startOfLine) { 17 | stream.skipToEnd(); 18 | return "meta"; 19 | } 20 | if (ch == '"' || ch == "'") { 21 | state.tokenize = tokenString(ch); 22 | return state.tokenize(stream, state); 23 | } 24 | if (ch == "(" && stream.eat("*")) { 25 | state.tokenize = tokenComment; 26 | return tokenComment(stream, state); 27 | } 28 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { 29 | return null; 30 | } 31 | if (/\d/.test(ch)) { 32 | stream.eatWhile(/[\w\.]/); 33 | return "number"; 34 | } 35 | if (ch == "/") { 36 | if (stream.eat("/")) { 37 | stream.skipToEnd(); 38 | return "comment"; 39 | } 40 | } 41 | if (isOperatorChar.test(ch)) { 42 | stream.eatWhile(isOperatorChar); 43 | return "operator"; 44 | } 45 | stream.eatWhile(/[\w\$_]/); 46 | var cur = stream.current(); 47 | if (keywords.propertyIsEnumerable(cur)) return "keyword"; 48 | if (atoms.propertyIsEnumerable(cur)) return "atom"; 49 | return "variable"; 50 | } 51 | 52 | function tokenString(quote) { 53 | return function(stream, state) { 54 | var escaped = false, next, end = false; 55 | while ((next = stream.next()) != null) { 56 | if (next == quote && !escaped) {end = true; break;} 57 | escaped = !escaped && next == "\\"; 58 | } 59 | if (end || !escaped) state.tokenize = null; 60 | return "string"; 61 | }; 62 | } 63 | 64 | function tokenComment(stream, state) { 65 | var maybeEnd = false, ch; 66 | while (ch = stream.next()) { 67 | if (ch == ")" && maybeEnd) { 68 | state.tokenize = null; 69 | break; 70 | } 71 | maybeEnd = (ch == "*"); 72 | } 73 | return "comment"; 74 | } 75 | 76 | // Interface 77 | 78 | return { 79 | startState: function(basecolumn) { 80 | return {tokenize: null}; 81 | }, 82 | 83 | token: function(stream, state) { 84 | if (stream.eatSpace()) return null; 85 | var style = (state.tokenize || tokenBase)(stream, state); 86 | if (style == "comment" || style == "meta") return style; 87 | return style; 88 | }, 89 | 90 | electricChars: "{}" 91 | }; 92 | }); 93 | 94 | CodeMirror.defineMIME("text/x-pascal", "pascal"); 95 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/perl/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011 by Sabaca under the MIT license. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/perl/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Perl mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Perl mode

14 | 15 |
53 | 54 | 60 | 61 |

MIME types defined: text/x-perl.

62 | 63 | 64 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/php/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: PHP mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |

CodeMirror: PHP mode

18 | 19 |
30 | 31 | 42 | 43 |

Simple HTML/PHP mode based on 44 | the C-like mode. Depends on XML, 45 | JavaScript, CSS, and C-like modes.

46 | 47 |

MIME types defined: application/x-httpd-php (HTML with PHP code), text/x-php (plain, non-wrapped PHP code).

48 | 49 | 50 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/pig/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Pig Latin mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Pig Latin mode

14 | 15 |
27 | 28 | 36 | 37 |

38 | Simple mode that handles Pig Latin language. 39 |

40 | 41 |

MIME type defined: text/x-pig 42 | (PIG code) 43 | 44 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/plsql/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Oracle PL/SQL mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Oracle PL/SQL mode

14 | 15 |
47 | 48 | 56 | 57 |

58 | Simple mode that handles Oracle PL/SQL language (and Oracle SQL, of course). 59 |

60 | 61 |

MIME type defined: text/x-plsql 62 | (PLSQL code) 63 | 64 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/properties/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Properties files mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Properties files mode

14 |
33 | 36 | 37 |

MIME types defined: text/x-properties, 38 | text/x-ini.

39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/properties/properties.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("properties", function() { 2 | return { 3 | token: function(stream, state) { 4 | var sol = stream.sol() || state.afterSection; 5 | var eol = stream.eol(); 6 | 7 | state.afterSection = false; 8 | 9 | if (sol) { 10 | if (state.nextMultiline) { 11 | state.inMultiline = true; 12 | state.nextMultiline = false; 13 | } else { 14 | state.position = "def"; 15 | } 16 | } 17 | 18 | if (eol && ! state.nextMultiline) { 19 | state.inMultiline = false; 20 | state.position = "def"; 21 | } 22 | 23 | if (sol) { 24 | while(stream.eatSpace()); 25 | } 26 | 27 | var ch = stream.next(); 28 | 29 | if (sol && (ch === "#" || ch === "!" || ch === ";")) { 30 | state.position = "comment"; 31 | stream.skipToEnd(); 32 | return "comment"; 33 | } else if (sol && ch === "[") { 34 | state.afterSection = true; 35 | stream.skipTo("]"); stream.eat("]"); 36 | return "header"; 37 | } else if (ch === "=" || ch === ":") { 38 | state.position = "quote"; 39 | return null; 40 | } else if (ch === "\\" && state.position === "quote") { 41 | if (stream.next() !== "u") { // u = Unicode sequence \u1234 42 | // Multiline value 43 | state.nextMultiline = true; 44 | } 45 | } 46 | 47 | return state.position; 48 | }, 49 | 50 | startState: function() { 51 | return { 52 | position : "def", // Current position, "def", "quote" or "comment" 53 | nextMultiline : false, // Is the next line multiline value 54 | inMultiline : false, // Is the current line a multiline value 55 | afterSection : false // Did we just open a section 56 | }; 57 | } 58 | 59 | }; 60 | }); 61 | 62 | CodeMirror.defineMIME("text/x-properties", "properties"); 63 | CodeMirror.defineMIME("text/x-ini", "properties"); 64 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/python/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2010 Timothy Farrell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/python/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Python mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Python mode

14 | 15 |
104 | 115 |

Configuration Options:

116 | 120 | 121 |

MIME types defined: text/x-python.

122 | 123 | 124 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/r/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, Ubalo, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the Ubalo, Inc nor the names of its 12 | contributors may be used to endorse or promote products derived 13 | from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL UBALO, INC BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/r/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: R mode 6 | 7 | 8 | 9 | 16 | 17 | 18 | 19 |

CodeMirror: R mode

20 |
63 | 66 | 67 |

MIME types defined: text/x-rsrc.

68 | 69 |

Development of the CodeMirror R mode was kindly sponsored 70 | by Ubalo, who hold 71 | the license.

72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/rpm/changes/changes.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("changes", function(config, modeConfig) { 2 | var headerSeperator = /^-+$/; 3 | var headerLine = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ?\d{1,2} \d{2}:\d{2}(:\d{2})? [A-Z]{3,4} \d{4} - /; 4 | var simpleEmail = /^[\w+.-]+@[\w.-]+/; 5 | 6 | return { 7 | token: function(stream) { 8 | if (stream.sol()) { 9 | if (stream.match(headerSeperator)) { return 'tag'; } 10 | if (stream.match(headerLine)) { return 'tag'; } 11 | } 12 | if (stream.match(simpleEmail)) { return 'string'; } 13 | stream.next(); 14 | return null; 15 | } 16 | }; 17 | }); 18 | 19 | CodeMirror.defineMIME("text/x-rpm-changes", "changes"); 20 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/rpm/changes/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: RPM changes mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: RPM changes mode

14 | 15 |
42 | 51 | 52 |

MIME types defined: text/x-rpm-changes.

53 | 54 | 55 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/rpm/spec/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: RPM spec mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

CodeMirror: RPM spec mode

15 | 16 |
89 | 97 | 98 |

MIME types defined: text/x-rpm-spec.

99 | 100 | 101 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/rpm/spec/spec.css: -------------------------------------------------------------------------------- 1 | .cm-s-default span.cm-preamble {color: #b26818; font-weight: bold;} 2 | .cm-s-default span.cm-macro {color: #b218b2;} 3 | .cm-s-default span.cm-section {color: green; font-weight: bold;} 4 | .cm-s-default span.cm-script {color: red;} 5 | .cm-s-default span.cm-issue {color: yellow;} 6 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/rpm/spec/spec.js: -------------------------------------------------------------------------------- 1 | // Quick and dirty spec file highlighting 2 | 3 | CodeMirror.defineMode("spec", function(config, modeConfig) { 4 | var arch = /^(i386|i586|i686|x86_64|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/; 5 | 6 | var preamble = /^(Name|Version|Release|License|Summary|Url|Group|Source|BuildArch|BuildRequires|BuildRoot|AutoReqProv|Provides|Requires(\(\w+\))?|Obsoletes|Conflicts|Recommends|Source\d*|Patch\d*|ExclusiveArch|NoSource|Supplements):/; 7 | var section = /^%(debug_package|package|description|prep|build|install|files|clean|changelog|preun|postun|pre|post|triggerin|triggerun|pretrans|posttrans|verifyscript|check|triggerpostun|triggerprein|trigger)/; 8 | var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros 9 | var control_flow_simple = /^%(else|endif)/; // rpm control flow macros 10 | var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros 11 | 12 | return { 13 | startState: function () { 14 | return { 15 | controlFlow: false, 16 | macroParameters: false, 17 | section: false 18 | }; 19 | }, 20 | token: function (stream, state) { 21 | var ch = stream.peek(); 22 | if (ch == "#") { stream.skipToEnd(); return "comment"; } 23 | 24 | if (stream.sol()) { 25 | if (stream.match(preamble)) { return "preamble"; } 26 | if (stream.match(section)) { return "section"; } 27 | } 28 | 29 | if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT' 30 | if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}' 31 | 32 | if (stream.match(control_flow_simple)) { return "keyword"; } 33 | if (stream.match(control_flow_complex)) { 34 | state.controlFlow = true; 35 | return "keyword"; 36 | } 37 | if (state.controlFlow) { 38 | if (stream.match(operators)) { return "operator"; } 39 | if (stream.match(/^(\d+)/)) { return "number"; } 40 | if (stream.eol()) { state.controlFlow = false; } 41 | } 42 | 43 | if (stream.match(arch)) { return "number"; } 44 | 45 | // Macros like '%make_install' or '%attr(0775,root,root)' 46 | if (stream.match(/^%[\w]+/)) { 47 | if (stream.match(/^\(/)) { state.macroParameters = true; } 48 | return "macro"; 49 | } 50 | if (state.macroParameters) { 51 | if (stream.match(/^\d+/)) { return "number";} 52 | if (stream.match(/^\)/)) { 53 | state.macroParameters = false; 54 | return "macro"; 55 | } 56 | } 57 | if (stream.match(/^%\{\??[\w \-]+\}/)) { return "macro"; } // Macros like '%{defined fedora}' 58 | 59 | //TODO: Include bash script sub-parser (CodeMirror supports that) 60 | stream.next(); 61 | return null; 62 | } 63 | }; 64 | }); 65 | 66 | CodeMirror.defineMIME("text/x-rpm-spec", "spec"); 67 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/ruby/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, Ubalo, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the Ubalo, Inc. nor the names of its 12 | contributors may be used to endorse or promote products derived 13 | from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL UBALO, INC BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/rust/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Rust mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Rust mode

14 | 15 |
38 | 39 | 46 | 47 |

MIME types defined: text/x-rustsrc.

48 | 49 | 50 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/scheme/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Scheme mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Scheme mode

14 |
58 | 61 | 62 |

MIME types defined: text/x-scheme.

63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/shell/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | CodeMirror: Shell mode 4 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 |

CodeMirror: Shell mode

16 | 17 | 41 | 42 | 49 | 50 |

MIME types defined: text/x-sh.

51 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/shell/shell.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode('shell', function(config) { 2 | 3 | var words = {}; 4 | function define(style, string) { 5 | var split = string.split(' '); 6 | for(var i = 0; i < split.length; i++) { 7 | words[split[i]] = style; 8 | } 9 | }; 10 | 11 | // Atoms 12 | define('atom', 'true false'); 13 | 14 | // Keywords 15 | define('keyword', 'if then do else elif while until for in esac fi fin ' + 16 | 'fil done exit set unset export function'); 17 | 18 | // Commands 19 | define('builtin', 'ab awk bash beep cat cc cd chown chmod chroot clear cp ' + 20 | 'curl cut diff echo find gawk gcc get git grep kill killall ln ls make ' + 21 | 'mkdir openssl mv nc node npm ping ps restart rm rmdir sed service sh ' + 22 | 'shopt shred source sort sleep ssh start stop su sudo tee telnet top ' + 23 | 'touch vi vim wall wc wget who write yes zsh'); 24 | 25 | function tokenBase(stream, state) { 26 | 27 | var sol = stream.sol(); 28 | var ch = stream.next(); 29 | 30 | if (ch === '\'' || ch === '"' || ch === '`') { 31 | state.tokens.unshift(tokenString(ch)); 32 | return tokenize(stream, state); 33 | } 34 | if (ch === '#') { 35 | if (sol && stream.eat('!')) { 36 | stream.skipToEnd(); 37 | return 'meta'; // 'comment'? 38 | } 39 | stream.skipToEnd(); 40 | return 'comment'; 41 | } 42 | if (ch === '$') { 43 | state.tokens.unshift(tokenDollar); 44 | return tokenize(stream, state); 45 | } 46 | if (ch === '+' || ch === '=') { 47 | return 'operator'; 48 | } 49 | if (ch === '-') { 50 | stream.eat('-'); 51 | stream.eatWhile(/\w/); 52 | return 'attribute'; 53 | } 54 | if (/\d/.test(ch)) { 55 | stream.eatWhile(/\d/); 56 | if(!/\w/.test(stream.peek())) { 57 | return 'number'; 58 | } 59 | } 60 | stream.eatWhile(/\w/); 61 | var cur = stream.current(); 62 | if (stream.peek() === '=' && /\w+/.test(cur)) return 'def'; 63 | return words.hasOwnProperty(cur) ? words[cur] : null; 64 | } 65 | 66 | function tokenString(quote) { 67 | return function(stream, state) { 68 | var next, end = false, escaped = false; 69 | while ((next = stream.next()) != null) { 70 | if (next === quote && !escaped) { 71 | end = true; 72 | break; 73 | } 74 | if (next === '$' && !escaped && quote !== '\'') { 75 | escaped = true; 76 | stream.backUp(1); 77 | state.tokens.unshift(tokenDollar); 78 | break; 79 | } 80 | escaped = !escaped && next === '\\'; 81 | } 82 | if (end || !escaped) { 83 | state.tokens.shift(); 84 | } 85 | return (quote === '`' || quote === ')' ? 'quote' : 'string'); 86 | }; 87 | }; 88 | 89 | var tokenDollar = function(stream, state) { 90 | if (state.tokens.length > 1) stream.eat('$'); 91 | var ch = stream.next(), hungry = /\w/; 92 | if (ch === '{') hungry = /[^}]/; 93 | if (ch === '(') { 94 | state.tokens[0] = tokenString(')'); 95 | return tokenize(stream, state); 96 | } 97 | if (!/\d/.test(ch)) { 98 | stream.eatWhile(hungry); 99 | stream.eat('}'); 100 | } 101 | state.tokens.shift(); 102 | return 'def'; 103 | }; 104 | 105 | function tokenize(stream, state) { 106 | return (state.tokens[0] || tokenBase) (stream, state); 107 | }; 108 | 109 | return { 110 | startState: function() {return {tokens:[]};}, 111 | token: function(stream, state) { 112 | if (stream.eatSpace()) return null; 113 | return tokenize(stream, state); 114 | } 115 | }; 116 | }); 117 | 118 | CodeMirror.defineMIME('text/x-sh', 'shell'); 119 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/sieve/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 Thomas Schmid 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | Please note that some subdirectories of the CodeMirror distribution 22 | include their own LICENSE files, and are released under different 23 | licences. 24 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/sieve/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Sieve (RFC5228) mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Sieve (RFC5228) mode

14 |
74 | 77 | 78 |

MIME types defined: application/sieve.

79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/sieve/sieve.js: -------------------------------------------------------------------------------- 1 | /* 2 | * See LICENSE in this directory for the license under which this code 3 | * is released. 4 | */ 5 | 6 | CodeMirror.defineMode("sieve", function(config) { 7 | function words(str) { 8 | var obj = {}, words = str.split(" "); 9 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 10 | return obj; 11 | } 12 | 13 | var keywords = words("if elsif else stop require"); 14 | var atoms = words("true false not"); 15 | var indentUnit = config.indentUnit; 16 | 17 | function tokenBase(stream, state) { 18 | 19 | var ch = stream.next(); 20 | if (ch == "/" && stream.eat("*")) { 21 | state.tokenize = tokenCComment; 22 | return tokenCComment(stream, state); 23 | } 24 | 25 | if (ch === '#') { 26 | stream.skipToEnd(); 27 | return "comment"; 28 | } 29 | 30 | if (ch == "\"") { 31 | state.tokenize = tokenString(ch); 32 | return state.tokenize(stream, state); 33 | } 34 | 35 | if (ch === "{") 36 | { 37 | state._indent++; 38 | return null; 39 | } 40 | 41 | if (ch === "}") 42 | { 43 | state._indent--; 44 | return null; 45 | } 46 | 47 | if (/[{}\(\),;]/.test(ch)) 48 | return null; 49 | 50 | // 1*DIGIT "K" / "M" / "G" 51 | if (/\d/.test(ch)) { 52 | stream.eatWhile(/[\d]/); 53 | stream.eat(/[KkMmGg]/); 54 | return "number"; 55 | } 56 | 57 | // ":" (ALPHA / "_") *(ALPHA / DIGIT / "_") 58 | if (ch == ":") { 59 | stream.eatWhile(/[a-zA-Z_]/); 60 | stream.eatWhile(/[a-zA-Z0-9_]/); 61 | 62 | return "operator"; 63 | } 64 | 65 | stream.eatWhile(/[\w\$_]/); 66 | var cur = stream.current(); 67 | 68 | // "text:" *(SP / HTAB) (hash-comment / CRLF) 69 | // *(multiline-literal / multiline-dotstart) 70 | // "." CRLF 71 | if ((cur == "text") && stream.eat(":")) 72 | { 73 | state.tokenize = tokenMultiLineString; 74 | return "string"; 75 | } 76 | 77 | if (keywords.propertyIsEnumerable(cur)) 78 | return "keyword"; 79 | 80 | if (atoms.propertyIsEnumerable(cur)) 81 | return "atom"; 82 | } 83 | 84 | function tokenMultiLineString(stream, state) 85 | { 86 | state._multiLineString = true; 87 | // the first line is special it may contain a comment 88 | if (!stream.sol()) { 89 | stream.eatSpace(); 90 | 91 | if (stream.peek() == "#") { 92 | stream.skipToEnd(); 93 | return "comment"; 94 | } 95 | 96 | stream.skipToEnd(); 97 | return "string"; 98 | } 99 | 100 | if ((stream.next() == ".") && (stream.eol())) 101 | { 102 | state._multiLineString = false; 103 | state.tokenize = tokenBase; 104 | } 105 | 106 | return "string"; 107 | } 108 | 109 | function tokenCComment(stream, state) { 110 | var maybeEnd = false, ch; 111 | while ((ch = stream.next()) != null) { 112 | if (maybeEnd && ch == "/") { 113 | state.tokenize = tokenBase; 114 | break; 115 | } 116 | maybeEnd = (ch == "*"); 117 | } 118 | return "comment"; 119 | } 120 | 121 | function tokenString(quote) { 122 | return function(stream, state) { 123 | var escaped = false, ch; 124 | while ((ch = stream.next()) != null) { 125 | if (ch == quote && !escaped) 126 | break; 127 | escaped = !escaped && ch == "\\"; 128 | } 129 | if (!escaped) state.tokenize = tokenBase; 130 | return "string"; 131 | }; 132 | } 133 | 134 | return { 135 | startState: function(base) { 136 | return {tokenize: tokenBase, 137 | baseIndent: base || 0, 138 | _indent: 0}; 139 | }, 140 | 141 | token: function(stream, state) { 142 | if (stream.eatSpace()) 143 | return null; 144 | 145 | return (state.tokenize || tokenBase)(stream, state);; 146 | }, 147 | 148 | indent: function(state, textAfter) { 149 | return state.baseIndent + state._indent * indentUnit; 150 | }, 151 | 152 | electricChars: "}" 153 | }; 154 | }); 155 | 156 | CodeMirror.defineMIME("application/sieve", "sieve"); 157 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/smalltalk/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Smalltalk mode 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 |

CodeMirror: Smalltalk mode

18 | 19 |
42 | 43 | 51 | 52 |

Simple Smalltalk mode.

53 | 54 |

MIME types defined: text/x-stsrc.

55 | 56 | 57 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/smalltalk/smalltalk.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode('smalltalk', function(config, modeConfig) { 2 | 3 | var specialChars = /[+\-/\\*~<>=@%|&?!.:;^]/; 4 | var keywords = /true|false|nil|self|super|thisContext/; 5 | 6 | var Context = function(tokenizer, parent) { 7 | this.next = tokenizer; 8 | this.parent = parent; 9 | }; 10 | 11 | var Token = function(name, context, eos) { 12 | this.name = name; 13 | this.context = context; 14 | this.eos = eos; 15 | }; 16 | 17 | var State = function() { 18 | this.context = new Context(next, null); 19 | this.expectVariable = true; 20 | this.indentation = 0; 21 | this.userIndentationDelta = 0; 22 | }; 23 | 24 | State.prototype.userIndent = function(indentation) { 25 | this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0; 26 | }; 27 | 28 | var next = function(stream, context, state) { 29 | var token = new Token(null, context, false); 30 | var aChar = stream.next(); 31 | 32 | if (aChar === '"') { 33 | token = nextComment(stream, new Context(nextComment, context)); 34 | 35 | } else if (aChar === '\'') { 36 | token = nextString(stream, new Context(nextString, context)); 37 | 38 | } else if (aChar === '#') { 39 | stream.eatWhile(/[^ .]/); 40 | token.name = 'string-2'; 41 | 42 | } else if (aChar === '$') { 43 | stream.eatWhile(/[^ ]/); 44 | token.name = 'string-2'; 45 | 46 | } else if (aChar === '|' && state.expectVariable) { 47 | token.context = new Context(nextTemporaries, context); 48 | 49 | } else if (/[\[\]{}()]/.test(aChar)) { 50 | token.name = 'bracket'; 51 | token.eos = /[\[{(]/.test(aChar); 52 | 53 | if (aChar === '[') { 54 | state.indentation++; 55 | } else if (aChar === ']') { 56 | state.indentation = Math.max(0, state.indentation - 1); 57 | } 58 | 59 | } else if (specialChars.test(aChar)) { 60 | stream.eatWhile(specialChars); 61 | token.name = 'operator'; 62 | token.eos = aChar !== ';'; // ; cascaded message expression 63 | 64 | } else if (/\d/.test(aChar)) { 65 | stream.eatWhile(/[\w\d]/); 66 | token.name = 'number'; 67 | 68 | } else if (/[\w_]/.test(aChar)) { 69 | stream.eatWhile(/[\w\d_]/); 70 | token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null; 71 | 72 | } else { 73 | token.eos = state.expectVariable; 74 | } 75 | 76 | return token; 77 | }; 78 | 79 | var nextComment = function(stream, context) { 80 | stream.eatWhile(/[^"]/); 81 | return new Token('comment', stream.eat('"') ? context.parent : context, true); 82 | }; 83 | 84 | var nextString = function(stream, context) { 85 | stream.eatWhile(/[^']/); 86 | return new Token('string', stream.eat('\'') ? context.parent : context, false); 87 | }; 88 | 89 | var nextTemporaries = function(stream, context, state) { 90 | var token = new Token(null, context, false); 91 | var aChar = stream.next(); 92 | 93 | if (aChar === '|') { 94 | token.context = context.parent; 95 | token.eos = true; 96 | 97 | } else { 98 | stream.eatWhile(/[^|]/); 99 | token.name = 'variable'; 100 | } 101 | 102 | return token; 103 | }; 104 | 105 | return { 106 | startState: function() { 107 | return new State; 108 | }, 109 | 110 | token: function(stream, state) { 111 | state.userIndent(stream.indentation()); 112 | 113 | if (stream.eatSpace()) { 114 | return null; 115 | } 116 | 117 | var token = state.context.next(stream, state.context, state); 118 | state.context = token.context; 119 | state.expectVariable = token.eos; 120 | 121 | state.lastToken = token; 122 | return token.name; 123 | }, 124 | 125 | blankLine: function(state) { 126 | state.userIndent(0); 127 | }, 128 | 129 | indent: function(state, textAfter) { 130 | var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta; 131 | return (state.indentation + i) * config.indentUnit; 132 | }, 133 | 134 | electricChars: ']' 135 | }; 136 | 137 | }); 138 | 139 | CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'}); -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/smarty/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Smarty mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Smarty mode

14 | 15 |
36 | 37 | 43 | 44 |
45 | 46 |
67 | 68 | 78 | 79 |

A plain text/Smarty mode which allows for custom delimiter tags (defaults to { and }).

80 | 81 |

MIME types defined: text/x-smarty

82 | 83 | 84 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/sparql/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: SPARQL mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: SPARQL mode

14 |
30 | 37 | 38 |

MIME types defined: application/x-sparql-query.

39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/stex/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: sTeX mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: sTeX mode

14 |
89 | 92 | 93 |

MIME types defined: text/x-stex.

94 | 95 |

Parsing/Highlighting Tests: normal, verbose.

96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/tiddlywiki/tiddlywiki.css: -------------------------------------------------------------------------------- 1 | span.cm-underlined { 2 | text-decoration: underline; 3 | } 4 | span.cm-strikethrough { 5 | text-decoration: line-through; 6 | } 7 | span.cm-brace { 8 | color: #170; 9 | font-weight: bold; 10 | } 11 | span.cm-table { 12 | color: blue; 13 | font-weight: bold; 14 | } 15 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/tiki/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: Tiki wiki mode 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: Tiki wiki mode

14 | 15 |
72 | 73 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/tiki/tiki.css: -------------------------------------------------------------------------------- 1 | .cm-tw-syntaxerror { 2 | color: #FFFFFF; 3 | background-color: #990000; 4 | } 5 | 6 | .cm-tw-deleted { 7 | text-decoration: line-through; 8 | } 9 | 10 | .cm-tw-header5 { 11 | font-weight: bold; 12 | } 13 | .cm-tw-listitem:first-child { /*Added first child to fix duplicate padding when highlighting*/ 14 | padding-left: 10px; 15 | } 16 | 17 | .cm-tw-box { 18 | border-top-width: 0px ! important; 19 | border-style: solid; 20 | border-width: 1px; 21 | border-color: inherit; 22 | } 23 | 24 | .cm-tw-underline { 25 | text-decoration: underline; 26 | } -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/vb/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2012 Codility Limited, 107 Cheapside, London EC2V 6DN, UK 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/vb/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: VB.NET mode 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 | 18 |

CodeMirror: VB.NET mode

19 | 81 | 82 | 83 |
84 | 85 |
86 |

87 |   

MIME type defined: text/x-vb.

88 | 89 | 90 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/vbscript/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: VBScript mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: VBScript mode

14 | 15 |
32 | 33 | 39 | 40 |

MIME types defined: text/vbscript.

41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/vbscript/vbscript.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("vbscript", function() { 2 | var regexVBScriptKeyword = /^(?:Call|Case|CDate|Clear|CInt|CLng|Const|CStr|Description|Dim|Do|Each|Else|ElseIf|End|Err|Error|Exit|False|For|Function|If|LCase|Loop|LTrim|Next|Nothing|Now|Number|On|Preserve|Quit|ReDim|Resume|RTrim|Select|Set|Sub|Then|To|Trim|True|UBound|UCase|Until|VbCr|VbCrLf|VbLf|VbTab)$/im; 3 | 4 | return { 5 | token: function(stream) { 6 | if (stream.eatSpace()) return null; 7 | var ch = stream.next(); 8 | if (ch == "'") { 9 | stream.skipToEnd(); 10 | return "comment"; 11 | } 12 | if (ch == '"') { 13 | stream.skipTo('"'); 14 | return "string"; 15 | } 16 | 17 | if (/\w/.test(ch)) { 18 | stream.eatWhile(/\w/); 19 | if (regexVBScriptKeyword.test(stream.current())) return "keyword"; 20 | } 21 | return null; 22 | } 23 | }; 24 | }); 25 | 26 | CodeMirror.defineMIME("text/vbscript", "vbscript"); 27 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/velocity/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Velocity mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

CodeMirror: Velocity mode

15 |
90 | 100 | 101 |

MIME types defined: text/velocity.

102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/xml/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: XML mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: XML mode

14 |
26 | 32 |

The XML mode supports two configuration parameters:

33 |
34 |
htmlMode (boolean)
35 |
This switches the mode to parse HTML instead of XML. This 36 | means attributes do not have to be quoted, and some elements 37 | (such as br) do not require a closing tag.
38 |
alignCDATA (boolean)
39 |
Setting this to true will force the opening tag of CDATA 40 | blocks to not be indented.
41 |
42 | 43 |

MIME types defined: application/xml, text/html.

44 | 45 | 46 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/xquery/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011 by MarkLogic Corporation 2 | Author: Mike Brevoort 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/xquery/test/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |

XQuery CodeMirror Mode

21 |

22 |

23 |
    24 |
25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/xquery/test/testEmptySequenceKeyword.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | module("testEmptySequenceKeyword"); 3 | test("testEmptySequenceKeyword", function() { 4 | expect(1); 5 | 6 | var input = '"foo" instance of empty-sequence()'; 7 | var expected = '"foo" instance of empty-sequence()'; 8 | 9 | $("#sandbox").html(''); 10 | var editor = CodeMirror.fromTextArea($("#editor")[0]); 11 | var result = $(".CodeMirror-lines div div pre")[0].innerHTML; 12 | 13 | equal(result, expected); 14 | $("#editor").html(""); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/xquery/test/testMultiAttr.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | module("testMultiAttr"); 3 | test("test1", function() { 4 | expect(1); 5 | 6 | var expected = '<p a1="foo" a2="bar">hello world</p>'; 7 | 8 | $("#sandbox").html(''); 9 | $("#editor").html('

hello world

'); 10 | var editor = CodeMirror.fromTextArea($("#editor")[0]); 11 | var result = $(".CodeMirror-lines div div pre")[0].innerHTML; 12 | 13 | equal(result, expected); 14 | $("#editor").html(""); 15 | }); 16 | }); -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/xquery/test/testProcessingInstructions.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | module("testProcessingInstructions"); 3 | test("testProcessingInstructions", function() { 4 | expect(1); 5 | 6 | var input = 'data() instance of xs:string'; 7 | var expected = 'data(<?target content?>) instance of xs:string'; 8 | 9 | $("#sandbox").html(''); 10 | var editor = CodeMirror.fromTextArea($("#editor")[0]); 11 | var result = $(".CodeMirror-lines div div pre")[0].innerHTML; 12 | 13 | equal(result, expected); 14 | $("#editor").html(""); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/xquery/test/testQuotes.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | module("testQuoteEscape"); 3 | test("testQuoteEscapeDouble", function() { 4 | expect(1); 5 | 6 | var input = 'let $rootfolder := "c:\\builds\\winnt\\HEAD\\qa\\scripts\\"\ 7 | let $keysfolder := concat($rootfolder, "keys\\")\ 8 | return\ 9 | $keysfolder'; 10 | var expected = 'let $rootfolder := "c:\\builds\\winnt\\HEAD\\qa\\scripts\\"let $keysfolder := concat($rootfolder, "keys\\")return$keysfolder'; 11 | 12 | $("#sandbox").html(''); 13 | var editor = CodeMirror.fromTextArea($("#editor")[0]); 14 | var result = $(".CodeMirror-lines div div pre")[0].innerHTML; 15 | 16 | equal(result, expected); 17 | $("#editor").html(""); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/yaml/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: YAML mode 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

CodeMirror: YAML mode

14 |
61 | 64 | 65 |

MIME types defined: text/x-yaml.

66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/codemirror/mode/yaml/yaml.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("yaml", function() { 2 | 3 | var cons = ['true', 'false', 'on', 'off', 'yes', 'no']; 4 | var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i'); 5 | 6 | return { 7 | token: function(stream, state) { 8 | var ch = stream.peek(); 9 | var esc = state.escaped; 10 | state.escaped = false; 11 | /* comments */ 12 | if (ch == "#") { stream.skipToEnd(); return "comment"; } 13 | if (state.literal && stream.indentation() > state.keyCol) { 14 | stream.skipToEnd(); return "string"; 15 | } else if (state.literal) { state.literal = false; } 16 | if (stream.sol()) { 17 | state.keyCol = 0; 18 | state.pair = false; 19 | state.pairStart = false; 20 | /* document start */ 21 | if(stream.match(/---/)) { return "def"; } 22 | /* document end */ 23 | if (stream.match(/\.\.\./)) { return "def"; } 24 | /* array list item */ 25 | if (stream.match(/\s*-\s+/)) { return 'meta'; } 26 | } 27 | /* pairs (associative arrays) -> key */ 28 | if (!state.pair && stream.match(/^\s*([a-z0-9\._-])+(?=\s*:)/i)) { 29 | state.pair = true; 30 | state.keyCol = stream.indentation(); 31 | return "atom"; 32 | } 33 | if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; } 34 | 35 | /* inline pairs/lists */ 36 | if (stream.match(/^(\{|\}|\[|\])/)) { 37 | if (ch == '{') 38 | state.inlinePairs++; 39 | else if (ch == '}') 40 | state.inlinePairs--; 41 | else if (ch == '[') 42 | state.inlineList++; 43 | else 44 | state.inlineList--; 45 | return 'meta'; 46 | } 47 | 48 | /* list seperator */ 49 | if (state.inlineList > 0 && !esc && ch == ',') { 50 | stream.next(); 51 | return 'meta'; 52 | } 53 | /* pairs seperator */ 54 | if (state.inlinePairs > 0 && !esc && ch == ',') { 55 | state.keyCol = 0; 56 | state.pair = false; 57 | state.pairStart = false; 58 | stream.next(); 59 | return 'meta'; 60 | } 61 | 62 | /* start of value of a pair */ 63 | if (state.pairStart) { 64 | /* block literals */ 65 | if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; }; 66 | /* references */ 67 | if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; } 68 | /* numbers */ 69 | if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; } 70 | if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; } 71 | /* keywords */ 72 | if (stream.match(keywordRegex)) { return 'keyword'; } 73 | } 74 | 75 | /* nothing found, continue */ 76 | state.pairStart = false; 77 | state.escaped = (ch == '\\'); 78 | stream.next(); 79 | return null; 80 | }, 81 | startState: function() { 82 | return { 83 | pair: false, 84 | pairStart: false, 85 | keyCol: 0, 86 | inlinePairs: 0, 87 | inlineList: 0, 88 | literal: false, 89 | escaped: false 90 | }; 91 | } 92 | }; 93 | }); 94 | 95 | CodeMirror.defineMIME("text/x-yaml", "yaml"); 96 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/ic.css: -------------------------------------------------------------------------------- 1 | span.function span { 2 | position: absolute; 3 | width: 16pt; 4 | height: 16pt; 5 | /* border-radius: 10px; */ 6 | background: rgba(173, 216, 230, 0.5); 7 | content: ""; 8 | overflow: visible; 9 | cursor: pointer; 10 | 11 | -webkit-transition: all 100ms ease-in; 12 | -o-transition: all 0.5s ease-in; 13 | -moz-transition: all 100ms ease-in; 14 | transition: all 100ms ease-in; 15 | } 16 | 17 | span.function span.optimized { 18 | background: rgba(255, 165, 0, 0.5) !important; 19 | } 20 | 21 | span.function:hover span { 22 | background: lightblue !important; 23 | } 24 | 25 | span.function:hover span.optimized { 26 | background: rgba(255, 165, 0, 1.0) !important; 27 | } 28 | 29 | span.ic span { 30 | position: absolute; 31 | top: -13pt; 32 | left: -5pt; 33 | width: 16pt; 34 | height: 16pt; 35 | border-radius: 10px; 36 | background: grey; 37 | opacity: 0.5; 38 | content: ""; 39 | overflow: visible; 40 | cursor: pointer; 41 | } 42 | 43 | span.ic.ic-state-MONOMORPHIC span { 44 | background: green !important; 45 | } 46 | 47 | span.ic.ic-state-MEGAMORPHIC span { 48 | background: #c00 !important; 49 | } 50 | 51 | .popover pre { 52 | font-size: 12pt !important; 53 | line-height: 12pt !important; 54 | } -------------------------------------------------------------------------------- /talks/jsconfeu2012/indirections.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/indirections.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/plan-a--1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/plan-a--1.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/plan-a-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/plan-a-0.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/plan-a-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/plan-a-1.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/plan-a-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/plan-a-2.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/plan-a-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/plan-a-3.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/plan-a-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/plan-a-4.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/plan-a-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/plan-a-5.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/plan-b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/plan-b.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/sigtrap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mraleph/moe-js/2d291ee4dbcc075b5a3f554054329f76a3b9e16f/talks/jsconfeu2012/sigtrap.png -------------------------------------------------------------------------------- /talks/jsconfeu2012/tools/shaky/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | packages 3 | web/packages 4 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/tools/shaky/README: -------------------------------------------------------------------------------- 1 | This folder contains a tool used to create diagrams in the talk. 2 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/tools/shaky/deploy/packages/browser/dart.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | (function() { 6 | // Bootstrap support for Dart scripts on the page as this script. 7 | if (navigator.userAgent.indexOf('(Dart)') === -1) { 8 | // TODO: 9 | // - Support in-browser compilation. 10 | // - Handle inline Dart scripts. 11 | 12 | // Fall back to compiled JS. Run through all the scripts and 13 | // replace them if they have a type that indicate that they source 14 | // in Dart code (type="application/dart"). 15 | var scripts = document.getElementsByTagName("script"); 16 | var length = scripts.length; 17 | for (var i = 0; i < length; ++i) { 18 | if (scripts[i].type == "application/dart") { 19 | // Remap foo.dart to foo.dart.js. 20 | if (scripts[i].src && scripts[i].src != '') { 21 | var script = document.createElement('script'); 22 | script.src = scripts[i].src.replace(/\.dart(?=\?|$)/, '.dart.js'); 23 | var parent = scripts[i].parentNode; 24 | // TODO(vsm): Find a solution for issue 8455 that works with more 25 | // than one script. 26 | document.currentScript = script; 27 | parent.replaceChild(script, scripts[i]); 28 | } 29 | } 30 | } 31 | } 32 | })(); 33 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/tools/shaky/deploy/packages/browser/interop.js: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | // TODO(jmesserly): remove this script after a deprecation period. 6 | if (typeof console == "object" && typeof console.warn == "function") { 7 | console.warn(' 26 | 27 | 28 | 29 | 30 |
31 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/tools/shaky/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See http://pub.dartlang.org/doc/glossary.html#lockfile 3 | packages: 4 | browser: 5 | description: browser 6 | source: hosted 7 | version: "0.10.0+2" 8 | js: 9 | description: js 10 | source: hosted 11 | version: "0.2.2" 12 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/tools/shaky/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: shaky 2 | description: Shaky Diagramming 3 | dependencies: 4 | browser: any 5 | js: 0.2.2 6 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/tools/shaky/web/shaky.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | background-color: #F8F8F8; 4 | font-family: 'Open Sans', sans-serif; 5 | font-size: 14px; 6 | font-weight: normal; 7 | line-height: 1.2em; 8 | margin: 15px; 9 | } 10 | -------------------------------------------------------------------------------- /talks/jsconfeu2012/tools/shaky/web/shaky.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 26 | 27 | 28 | 29 | 30 |
31 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /tracing/README.md: -------------------------------------------------------------------------------- 1 | This toy tracing compiler is based on ideas from [LuaJIT2](http://luajit.org) tracing compiler developed by Mike Pall. -------------------------------------------------------------------------------- /tracing/engine-tests.js: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | "use strict"; 16 | 17 | // 18 | // Test for correct PHI insertion and resolution for loop carried dependence. 19 | // 20 | 21 | var engine = require("./engine"); 22 | var assert = require("assert"); 23 | 24 | var r = engine.FunctionBuilder.r; 25 | var k = engine.FunctionBuilder.k; 26 | 27 | // LOAD (B) will be forwarded to (A) 28 | var func_bc = new engine.FunctionBuilder().function_begin() 29 | .loadconst(r(1), k(0)) 30 | .loadconst(r(2), k(0)) 31 | .label("loop") 32 | .loop(4) 33 | .lessthan(r(1), k(100)) 34 | .jmp("exit") 35 | .mul(r(4), r(1), k(2)) 36 | .load(r(4), r(0), r(4)) /* (A) */ 37 | .add(r(2), r(2), r(4)) 38 | .add(r(1), r(1), k(1)) 39 | .mul(r(4), r(1), k(2)) 40 | .load(r(4), r(0), r(4)) /* (B) */ 41 | .add(r(2), r(2), r(4)) 42 | .jmp("loop") 43 | .label("exit") 44 | .ret(r(2)) 45 | .end(); 46 | 47 | var obj = Runtime_NewTable(); 48 | 49 | for (var i = 0; i <= 200; i++) Runtime_Store(obj, i, i); 50 | 51 | function func_js(obj) { 52 | var x = 0; 53 | for (var i = 0; i < 100;) { 54 | x += Runtime_Load(obj, i * 2); 55 | i++; 56 | x += Runtime_Load(obj, i * 2); 57 | } 58 | return x; 59 | } 60 | 61 | var result = new engine.Interpreter().evaluate(func_bc, [obj]); 62 | var expected = func_js(obj); 63 | 64 | assert(result === expected); 65 | 66 | // 67 | // Test cycle dependency between phies 68 | // 69 | 70 | var func_bc = new engine.FunctionBuilder().function_begin() 71 | .loadconst(r(0), k(0)) 72 | .loadconst(r(1), k(1)) 73 | .loadconst(r(2), k(2)) 74 | .label("loop") 75 | .loop(3) 76 | .lessthan(r(0), k(100)) 77 | .jmp("exit") 78 | .move(r(3), r(1)) 79 | .move(r(1), r(2)) 80 | .move(r(2), r(3)) 81 | .add(r(0), r(0), k(1)) 82 | .jmp("loop") 83 | .label("exit") 84 | .mul(r(2), r(2), k(4)) 85 | .add(r(1), r(1), r(2)) 86 | .ret(r(1)) 87 | .end(); 88 | 89 | var result = new engine.Interpreter().evaluate(func_bc); 90 | var expected = (function () { 91 | var a = 1; 92 | var b = 2; 93 | for (var i = 0; i < 100; i++) { 94 | var t = a; 95 | a = b; 96 | b = t; 97 | } 98 | return a + (b * 4); 99 | })(); 100 | 101 | assert(result === expected); 102 | -------------------------------------------------------------------------------- /tracing/engine/assert.js: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | function assert(cond) { if (!cond) throw new Error("assertion failure"); } 16 | 17 | function unimplemented() { throw new Error("unimplemented"); } 18 | -------------------------------------------------------------------------------- /tracing/engine/bytecode.js: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var utils = require('./utils.js'); 16 | 17 | // 18 | // Bytecode 19 | // 20 | 21 | function encodeOp(op, a, b, c) { 22 | a = a & 0xFF; 23 | b = b & 0xFF; 24 | c = c & 0xFF; 25 | return (b << 24) | (c << 16) | (a << 8) | op; 26 | } 27 | 28 | function OPCODE(op) { return op & 0xFF; } 29 | function A(op) { return (op >> 8) & 0xFF; } 30 | function B(op) { return (op >> 24) & 0xFF; } 31 | function C(op) { return (op >> 16) & 0xFF; } 32 | 33 | var BC = module.exports = utils.bytecode([ 34 | "MOVE RA, RB", 35 | "LOADCONST RA, KB", 36 | "LOAD RA, RB, RKC", 37 | "STORE RA, RKB, RKC", 38 | "LOADGLOBAL RA, RKB", 39 | "STOREGLOBAL RKA, RKB", 40 | "LESSTHAN RKA, RKB", 41 | "JMP SD", 42 | "ADD RA, RKB, RKC", 43 | "MUL RA, RKB, RKC", 44 | "UNM RA, RB", 45 | "NEWCLOSURE", 46 | "NEWTABLE", 47 | "CALL RA, B", 48 | "RET RA", 49 | "LOOP A", 50 | "JLOOP A" 51 | ]); 52 | 53 | BC.Disassembler.prototype.prefix = function () { return this.pc + ": "; }; 54 | 55 | BC.Disassembler.prototype.epilogue = BC.Disassembler.prototype.suffix = function () { }; 56 | 57 | BC.Disassembler.prototype.formatR = function (r) { return "r" + r; }; 58 | 59 | BC.Disassembler.prototype.formatK = function (k) { return "#" + this.data.closure.pool[k]; }; 60 | 61 | BC.Disassembler.prototype.formatRK = function fmtRK(rk) { 62 | return (rk >= BC.CONSTANT_BIAS) ? this.formatK(rk - BC.CONSTANT_BIAS) : this.formatR(rk); 63 | }; 64 | 65 | BC.Disassembler.prototype.opcode = function (op) { return OPCODE(op); }; 66 | 67 | BC.Disassembler.prototype.operand = function (op, operand) { 68 | switch (operand) { 69 | case "A": return A(op).toString(); 70 | case "B": return B(op).toString(); 71 | case "C": return C(op).toString(); 72 | case "RA": return this.formatR(A(op)); 73 | case "RB": return this.formatR(B(op)); 74 | case "RC": return this.formatR(C(op)); 75 | case "KB": return this.formatK(B(op)); 76 | case "RKA": return this.formatRK(A(op)); 77 | case "RKB": return this.formatRK(B(op)); 78 | case "RKC": return this.formatRK(C(op)); 79 | case "SD": return (op >> 8).toString(); 80 | default: return operand; 81 | } 82 | }; 83 | 84 | BC.Disassembler.prototype.LOOP = function () { this.pc++; }; 85 | BC.Disassembler.prototype.JLOOP = function () { this.pc++; }; 86 | 87 | BC.CONSTANT_BIAS = 0x80; 88 | 89 | BC.IS_CONSTANT = function (ref) { 90 | return ref >= BC.CONSTANT_BIAS; 91 | }; 92 | 93 | BC.encodeOp = encodeOp; 94 | BC.OPCODE = OPCODE; 95 | BC.A = A; 96 | BC.B = B; 97 | BC.C = C; 98 | -------------------------------------------------------------------------------- /tracing/engine/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | "use strict"; 16 | 17 | var FLAGS = exports.FLAGS = { print_ir: false, print_trace: false, notracing: false, nollvm: false }; 18 | 19 | process.argv.slice(2).forEach(function (flag) { 20 | var flag = flag.replace(/^\-\-/, "").replace(/\-/g, "_"); 21 | if (flag in FLAGS) FLAGS[flag] = true; 22 | }); 23 | 24 | exports.FunctionBuilder = require('./bytecode-builder.js').FunctionBuilder; 25 | exports.Interpreter = require('./interpreter.js'); 26 | exports.runtime = require('./runtime.js'); -------------------------------------------------------------------------------- /tracing/engine/ir2llvm.js: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | var engine = require('./'); 16 | 17 | var IR = require('./ir.js'); 18 | var OPCODE = IR.OPCODE, A = IR.A, B = IR.B; 19 | 20 | var assert = require('assert'); 21 | 22 | try { 23 | var Meldo = require('meldo'); 24 | } catch (e) { 25 | exports.Compile = function (ir) { throw new Error("Meldo is not available"); }; 26 | return; 27 | } 28 | 29 | // 30 | // LLVM IR emitter. 31 | // 32 | 33 | exports.Compile = function (ir) { 34 | if (engine.FLAGS.nollvm) throw new Error("llvm backend disabled"); 35 | 36 | var meldo = new Meldo; 37 | 38 | with (meldo) { 39 | var S = arg(0); 40 | 41 | var R = elements(property(S, 0)); 42 | 43 | var G = property(S, 2); 44 | 45 | var pool = elements(arg(1)); 46 | 47 | var $ = ir.translator({ 48 | literal: meldo.literal.bind(meldo), 49 | constant: meldo.element.bind(meldo, pool), 50 | loop: function () { 51 | this.preheader = currentBlock(); 52 | this.loopentry = meldo.block(); 53 | branch(this.loopentry); 54 | setCurrentBlock(this.loopentry); 55 | }, 56 | 57 | phi: function (a, b) { 58 | var type = ir.isNumber(a) ? meldo.double_ty : meldo.ptr_ty; 59 | var phi = meldo.phi(type, 2); 60 | phi.addIncoming($(a), this.preheader); 61 | return phi; 62 | }, 63 | 64 | translate: function (ref, opcode, a, b) { 65 | return translate(ref, opcode, a, b); 66 | }, 67 | 68 | backedge: function (phis) { 69 | phis.forEach(function (phi) { 70 | $(A(phi)).addIncoming($(B(phi)), currentBlock()); 71 | }); 72 | branch(this.loopentry); 73 | } 74 | }); 75 | 76 | var FieldPtr = function (obj, idx) { 77 | return elementptr(elements(property(obj, 1)), idx); 78 | }; 79 | 80 | var ElementPtr = function (obj, idx) { 81 | return elementptr(elements(property(obj, 2)), idx); 82 | }; 83 | 84 | var exitIfNot = function (val, ref) { 85 | if_(not(val), function () { 86 | ir.envs[ref].frames[0].forEachRegister(function (reg, ref) { 87 | var value = $(ref); 88 | if (ir.isNumber(ref)) value = boxNumber(value); 89 | setelement(R, reg, value); 90 | }); 91 | ret(); // Return undefined. 92 | }); 93 | } 94 | 95 | var translate = function (ref, opcode, a, b) { 96 | switch (opcode) { 97 | case IR.REG: 98 | return element(R, IR.FROM_LITERAL(a)); 99 | 100 | case IR.CHECKK: 101 | return exitIfNot(icmpeq(property($(a), 0), $(b)), ref); 102 | 103 | case IR.CHECKV: 104 | return exitIfNot(icmpeq($(a), $(b)), ref); 105 | 106 | case IR.CHECKN: 107 | return unboxNumber($(a)); 108 | 109 | case IR.CHECKI32: 110 | return unboxInteger32($(a), function (success) { exitIfNot(success, ref); }); 111 | 112 | case IR.PROPF: 113 | return FieldPtr($(a), IR.FROM_LITERAL(b)); 114 | 115 | case IR.PROPI: 116 | return ElementPtr($(a), $(b)); 117 | 118 | case IR.LOAD: 119 | return load($(a)); 120 | 121 | case IR.LOADGLOBAL: 122 | return load(FieldPtr(G, IR.FROM_LITERAL(a))); 123 | 124 | case IR.MUL: 125 | return fmul($(a), $(b)); 126 | 127 | case IR.ADD: 128 | return fadd($(a), $(b)); 129 | 130 | case IR.LESSTHAN: 131 | return exitIfNot(fcmpolt($(a), $(b)), ref); 132 | 133 | case IR.CHECKFAST: 134 | return null; 135 | 136 | default: 137 | throw new Error("unsupported instruction"); 138 | } 139 | } 140 | } 141 | 142 | $.translate(); 143 | 144 | var jsfunc = meldo.meld(); 145 | 146 | if (engine.FLAGS.print_ir) meldo.dump(); 147 | 148 | return jsfunc; 149 | }; -------------------------------------------------------------------------------- /tracing/engine/tracer.js: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | "use strict"; 16 | 17 | module.exports = Tracer; 18 | 19 | var engine = require('./'); 20 | 21 | var BC = require('./bytecode.js'); 22 | var A = BC.A, B = BC.B, C = BC.C, OPCODE = BC.OPCODE; 23 | 24 | var Interpreter = require('./interpreter'); 25 | 26 | var bc2ir = require('./bc2ir.js'); 27 | var makeloop = require('./makeloop.js'); 28 | 29 | var ir2llvm = require('./ir2llvm.js'); 30 | var ir2js = require('./ir2js.js'); 31 | 32 | var assert = require('assert'); 33 | 34 | // 35 | // Tracer. 36 | // 37 | // Records executed bytecodes and type information required to specialize 38 | // generated code. 39 | // 40 | 41 | function Tracer(interpreter) { 42 | this.S = interpreter; 43 | 44 | this.bc2ir = bc2ir.CreateTranslator(this.S); 45 | this.start_pc = null; 46 | this.start_closure = null; 47 | 48 | this.traces = []; 49 | } 50 | 51 | 52 | Tracer.prototype = { 53 | // Start recording trace. Replace dispatch table on the interpreter with the 54 | // one that can record bytecodes. 55 | start: function () { 56 | if (this.start_pc !== null) return; 57 | this.start_pc = this.S.pc - 2; 58 | this.start_closure = this.S.closure; 59 | 60 | var nvars = A(this.start_closure.code[this.start_pc]); 61 | this.bc2ir.initialize(nvars); 62 | 63 | this.S.DISPATCH = this.bc2ir.DISPATCH; 64 | }, 65 | 66 | // Stop tracing, compile collected trace and patch LOOP header 67 | // to point to the compiled code. 68 | stop: function () { 69 | var ir = this.bc2ir.finalize(); 70 | 71 | if (engine.FLAGS.print_ir) ir.print(); 72 | makeloop.MakeLoop(ir); 73 | 74 | try { 75 | var jsfunc = ir2llvm.Compile(ir); 76 | } catch (e) { 77 | if (engine.FLAGS.print_ir) console.log("ir2llvm failed: " + e.stack); 78 | var jsfunc = ir2js.Compile(ir); 79 | } 80 | 81 | var compiled = { f: jsfunc, pool: ir.pool.arr }; 82 | 83 | var trace_id = this.traces.length; 84 | this.traces.push(compiled); 85 | assert(BC.OPCODE(this.start_closure.code[this.start_pc]) === BC.LOOP); 86 | this.start_closure.code[this.start_pc] = BC.encodeOp(BC.JLOOP, trace_id); 87 | 88 | this.reset(); 89 | }, 90 | 91 | // Abort tracing and discard collected bytecode. 92 | abort: function () { 93 | this.reset(); 94 | }, 95 | 96 | reset: function () { 97 | this.S.DISPATCH = Interpreter.DISPATCH; 98 | this.start_pc = this.start_closure = null; 99 | this.ir = null; 100 | } 101 | 102 | }; 103 | 104 | 105 | -------------------------------------------------------------------------------- /tracing/engine/utils.js: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Helper function to define bytecodes. 16 | exports.bytecode = function bytecode(ops) { 17 | var OPCODES = {}; 18 | OPCODES.names = []; 19 | 20 | OPCODES.Disassembler = function (data) { 21 | this.data = data; 22 | this.DISPATCH = OPCODES.Disassembler.DISPATCH; 23 | }; 24 | 25 | OPCODES.Disassembler.DISPATCH = []; 26 | 27 | OPCODES.Disassembler.prototype.disassemble = function (code) { 28 | var result = []; 29 | this.pc = 0; 30 | this.code = code; 31 | while (this.pc < this.code.length) { 32 | var prefix = this.prefix(); 33 | var suffix = this.suffix(); 34 | if (typeof suffix === "string") suffix = " ; " + suffix; else suffix = ""; 35 | var op = this.code[this.pc++]; 36 | result.push(prefix + this.DISPATCH[this.opcode(op)].call(this, op) + suffix); 37 | } 38 | var epilogue = this.epilogue(); 39 | if (typeof epilogue === "string") result.push(" ; " + epilogue); 40 | return result; 41 | }; 42 | 43 | OPCODES.disassemble = function (seq, data) { 44 | var d = new OPCODES.Disassembler(data); 45 | return d.disassemble(seq); 46 | }; 47 | 48 | OPCODES.print = function (seq, data) { 49 | console.log('-----------------------'); 50 | console.log(this.disassemble(seq, data).join('\n')); 51 | }; 52 | 53 | function mkOpcode(id, fmt) { 54 | var m = fmt.match(/^(\w+)(.*)$/); 55 | var name = m[1]; 56 | var operands = m[2]; 57 | 58 | OPCODES[name] = id; 59 | OPCODES.names.push(name); 60 | 61 | OPCODES.Disassembler.DISPATCH[id] = function (op) { 62 | var self = this; 63 | var result = name + operands.replace(/(\w+)/g, function (operand) { return self.operand(op, operand); }); 64 | if (name in this) this[name](op); 65 | return result; 66 | }; 67 | } 68 | 69 | for (var i = 0; i < ops.length; i++) { 70 | mkOpcode(i, ops[i]); 71 | } 72 | 73 | return OPCODES; 74 | } 75 | 76 | // Quick check for int32 values. 77 | exports.IsInt32 = function (x) { 78 | return (x|0) === x; 79 | }; 80 | -------------------------------------------------------------------------------- /tracing/points-baseline.js: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | function reduce (a, f, x) { 16 | for (var i = 0; i < a.n; i++) x = f(x, a[i]); 17 | return x; 18 | } 19 | 20 | function dot (a, b) { 21 | return a.x * b.x + a.y * b.y; 22 | } 23 | 24 | function MakePoint(x, y) { 25 | var point = {}; 26 | point.x = x; 27 | point.y = y; 28 | return point; 29 | } 30 | 31 | function MakeArrayOfPoints(N) { 32 | var array = {}; 33 | var m = -1; 34 | for (var i = 0; i < N; i++) { 35 | m = m * -1; 36 | array[i] = MakePoint(m * i, m * -i); 37 | } 38 | array.n = N; 39 | return array; 40 | } 41 | 42 | function Summator(sum, p) { 43 | return sum + dot(p, p); 44 | } 45 | 46 | function Program() { 47 | var N = 1000; 48 | var points = MakeArrayOfPoints(N); 49 | return function () { return reduce(points, Summator, 0) }; 50 | } 51 | 52 | function test(cl, K) { 53 | for (var i = 0; i < K; i++) { 54 | var result = cl(); 55 | if (result !== 665667000) throw new Error("computation failed: " + result); 56 | } 57 | } 58 | 59 | var cl = Program(); 60 | test(cl, 10); // warm up 61 | var start = Date.now(); 62 | test(cl, 2000); 63 | var end = Date.now(); 64 | console.log(end - start); 65 | -------------------------------------------------------------------------------- /tracing/points-interpreted.js: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Google Inc. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | "use strict"; 16 | 17 | var engine = require("./engine"); 18 | 19 | var program = (function (r, k) { 20 | return new engine.FunctionBuilder().function_begin() 21 | .function_begin() 22 | .loadconst(r(3), k(0)) 23 | .label("loop") 24 | .loop(4) 25 | .load(r(4), r(0), k("n")) 26 | .lessthan(r(3), r(4)) 27 | .jmp("exit") 28 | .move(r(4), r(1)) 29 | .move(r(5), r(2)) 30 | .load(r(6), r(0), r(3)) 31 | .call(r(4), 2) 32 | .move(r(2), r(4)) 33 | .add(r(3), r(3), k(1)) 34 | .jmp("loop") 35 | .label("exit") 36 | .ret(r(2)) 37 | .end() 38 | 39 | .function_begin() 40 | .load(r(2), r(0), k("x")) 41 | .load(r(3), r(1), k("x")) 42 | .mul(r(2), r(2), r(3)) 43 | .load(r(3), r(0), k("y")) 44 | .load(r(4), r(1), k("y")) 45 | .mul(r(3), r(3), r(4)) 46 | .add(r(2), r(2), r(3)) 47 | .ret(r(2)) 48 | .end() 49 | 50 | .function_begin() 51 | .newtable(r(2)) 52 | .store(r(2), k("x"), r(0)) 53 | .store(r(2), k("y"), r(1)) 54 | .ret(r(2)) 55 | .end() 56 | 57 | .function_begin() 58 | .newtable(r(1)) 59 | .loadconst(r(2), k(-1)) 60 | .loadconst(r(3), k(0)) 61 | .label("loop") 62 | .loop(4) 63 | .lessthan(r(3), r(0)) 64 | .jmp("exit") 65 | .mul(r(2), r(2), k(-1)) 66 | .loadglobal(r(4), k("MakePoint")) 67 | .mul(r(5), r(2), r(3)) 68 | .unm(r(6), r(3)) 69 | .mul(r(6), r(2), r(6)) 70 | .call(r(4), 2) 71 | .store(r(1), r(3), r(4)) 72 | .add(r(3), r(3), k(1)) 73 | .jmp("loop") 74 | .label("exit") 75 | .store(r(1), k("n"), r(0)) 76 | .ret(r(1)) 77 | .end() 78 | 79 | .function_begin() 80 | .function_begin() 81 | .loadglobal(r(2), k("dot")) 82 | .move(r(3), r(1)) 83 | .move(r(4), r(1)) 84 | .call(r(2), 2) 85 | .add(r(2), r(0), r(2)) 86 | .ret(r(2)) 87 | .end() 88 | 89 | .loadglobal(r(0), k("reduce")) 90 | .loadglobal(r(1), k("points")) 91 | .newclosure(r(2), 0) 92 | .loadconst(r(3), k(0)) 93 | .call(r(0), 3) 94 | .ret() 95 | .end() 96 | 97 | .newclosure(r(0), 0) 98 | .storeglobal(k("reduce"), r(0)) 99 | .newclosure(r(0), 1) 100 | .storeglobal(k("dot"), r(0)) 101 | .newclosure(r(0), 2) 102 | .storeglobal(k("MakePoint"), r(0)) 103 | .newclosure(r(0), 3) 104 | .storeglobal(k("MakeArrayOfPoints"), r(0)) 105 | .storeglobal(k("N"), k(1000)) 106 | .loadglobal(r(0), k("MakeArrayOfPoints")) 107 | .loadglobal(r(1), k("N")) 108 | .call(r(0), 1) 109 | .storeglobal(k("points"), r(0)) 110 | .newclosure(r(0), 4) 111 | .ret(r(0)) 112 | .end(); 113 | })(engine.FunctionBuilder.r, engine.FunctionBuilder.k); 114 | 115 | var interpreter = new engine.Interpreter(); 116 | 117 | function test(cl, K) { 118 | for (var i = 0; i < K; i++) { 119 | var result = interpreter.evaluate(cl); 120 | var expected = 665667000; 121 | if (result !== expected) throw new Error("computation " + i + " failed: " + result + " != " + expected); 122 | } 123 | return result; 124 | } 125 | 126 | var cl = interpreter.evaluate(engine.runtime.NewClosure(program)); 127 | test(cl, 10); // warm up 128 | 129 | var start = Date.now(); 130 | var result = test(cl, 2000); 131 | var end = Date.now(); 132 | console.log(end - start); 133 | console.log(result); 134 | --------------------------------------------------------------------------------