
7 changed files with 203 additions and 32 deletions
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="JavaScriptLibraryMappings"> |
||||
<includedPredefinedLibrary name="Node.js Core" /> |
||||
</component> |
||||
</project> |
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="ProjectRootManager" version="2" assert-keyword="false" jdk-15="false" /> |
||||
</project> |
@ -0,0 +1,83 @@
|
||||
define(function (require) { |
||||
"use strict"; |
||||
var CodeMirror = require('codemirror'); |
||||
var $ = require('jquery'); |
||||
require('asm-mode'); |
||||
|
||||
var options = require('options'); |
||||
var compilers = options.compilers; |
||||
|
||||
function Compiler(hub, container, state) { |
||||
var self = this; |
||||
var domRoot = container.getElement(); |
||||
domRoot.html($('#compiler').html()); |
||||
|
||||
var outputEditor = CodeMirror.fromTextArea(domRoot.find("textarea")[0], { |
||||
lineNumbers: true, |
||||
mode: "text/x-asm", |
||||
readOnly: true, |
||||
gutters: ['CodeMirror-linenumbers'], |
||||
lineWrapping: true |
||||
}); |
||||
|
||||
function resize() { |
||||
outputEditor.setSize(domRoot.width(), domRoot.height()); |
||||
outputEditor.refresh(); |
||||
} |
||||
|
||||
container.on('resize', resize); |
||||
container.on('open', resize); |
||||
container.setTitle("Compiled"); |
||||
container.on('close', function () { |
||||
hub.removeCompiler(self); |
||||
}); |
||||
|
||||
this.source = state.source || 1; |
||||
this.sourceEditor = null; |
||||
} |
||||
|
||||
var debouncedAjax = _.debounce($.ajax, 500); |
||||
|
||||
Compiler.prototype.compile = function (fromEditor) { |
||||
var self = this; |
||||
if (!this.sourceEditor) return; |
||||
var request = { |
||||
fromEditor: fromEditor, |
||||
source: this.sourceEditor.getSource(), |
||||
compiler: compilers[0].id, // TODO
|
||||
options: "-O1", // TODO
|
||||
filters: {} |
||||
}; |
||||
debouncedAjax({ |
||||
type: 'POST', |
||||
url: '/compile', |
||||
dataType: 'json', |
||||
contentType: 'application/json', |
||||
data: JSON.stringify(request), |
||||
success: function (result) { |
||||
self.onCompileResponse(request, result); |
||||
}, |
||||
error: function (xhr, e_status, error) { |
||||
console.log("AJAX request failed, reason : " + error); |
||||
}, |
||||
cache: false |
||||
}); |
||||
}; |
||||
|
||||
Compiler.prototype.onCompileResponse = function (request, result) { |
||||
console.log(request, result); |
||||
}; |
||||
|
||||
Compiler.prototype.onEditorListChange = function () { |
||||
// TODO: if we can't find our source, select none?
|
||||
// TODO: Update dropdown of source
|
||||
}; |
||||
Compiler.prototype.onEditorChange = function (editor) { |
||||
if (editor.getId() == this.source) { |
||||
this.sourceEditor = editor; |
||||
this.compile(); |
||||
} |
||||
}; |
||||
|
||||
return Compiler; |
||||
}); |
@ -0,0 +1,83 @@
|
||||
define(function (require) { |
||||
"use strict"; |
||||
|
||||
var _ = require('underscore'); |
||||
var options = require('options'); |
||||
var Editor = require('editor'); |
||||
var Compiler = require('compiler'); |
||||
|
||||
function Hub(layout) { |
||||
this.layout = layout; |
||||
this.compilers = []; |
||||
this.editors = {}; |
||||
this.initialised = false; |
||||
|
||||
var self = this; |
||||
layout.registerComponent('codeEditor', function (container, state) { |
||||
return self.codeEditorFactory(container, state); |
||||
}); |
||||
layout.registerComponent('compilerOutput', function (container, state) { |
||||
return self.compilerOutputFactory(container, state); |
||||
}); |
||||
layout.init(); |
||||
|
||||
this.initialised = true; |
||||
|
||||
_.each(this.editors, function (editor) { |
||||
self.onEditorChange(editor); |
||||
}); |
||||
this.onEditorListChange(); |
||||
} |
||||
|
||||
Hub.prototype.addCompiler = function (compiler) { |
||||
this.compilers.push(compiler); |
||||
}; |
||||
Hub.prototype.removeCompiler = function (compiler) { |
||||
this.compilers = _.without(this.compilers, compiler); |
||||
}; |
||||
|
||||
Hub.prototype.addEditor = function (editor) { |
||||
this.editors[editor.getId()] = editor; |
||||
this.onEditorListChange(); |
||||
}; |
||||
Hub.prototype.removeEditor = function (editor) { |
||||
delete this.editors[editor.getId()]; |
||||
this.onEditorListChange(); |
||||
}; |
||||
|
||||
Hub.prototype.onEditorListChange = function () { |
||||
if (!this.initialised) return; |
||||
_.each(this.compilers, function (compiler) { |
||||
compiler.onEditorListChange(); |
||||
}); |
||||
}; |
||||
|
||||
Hub.prototype.nextEditorId = function () { |
||||
for (var i = 1; i < 100000; ++i) { |
||||
if (!this.editors[i]) return i; |
||||
} |
||||
throw "Ran out of ids!?"; |
||||
}; |
||||
|
||||
Hub.prototype.codeEditorFactory = function (container, state) { |
||||
var id = state.id || this.nextEditorId(); |
||||
var editor = new Editor(this, id, container, options.language); |
||||
this.addEditor(editor); |
||||
return editor; |
||||
}; |
||||
|
||||
Hub.prototype.compilerOutputFactory = function (container, state) { |
||||
var compiler = new Compiler(this, container, state); |
||||
this.addCompiler(compiler); |
||||
return compiler; |
||||
}; |
||||
|
||||
Hub.prototype.onEditorChange = function (editor) { |
||||
if (!this.initialised) return; |
||||
_.each(this.compilers, function (compiler) { |
||||
compiler.onEditorChange(editor); |
||||
}); |
||||
}; |
||||
|
||||
return Hub; |
||||
}); |
Loading…
Reference in new issue