Work in progress on refactoring

refactor
Matt Godbolt 11 years ago
parent 186cabb021
commit 770069192d

@ -0,0 +1,9 @@
In progress
-----------
Currently in progress is the difference view. In order to achieve this we need two "compiler" views; an "A" and "B". I'm in the progress of splitting out all the compiler-specifics into a class of sorts in the mainline, as this is a sensible refactor anyway. In the "diffs" branch I'm sketching out the UI.
Notes:
* storage in both hash tag and in local storage need to change. Specifically they are too tied to the notion of a single compiler.
* should ensure backwards compatibility: store off some hash tags and test the decode to the same view in the new scheme.

@ -42,13 +42,14 @@ function clearBackground(cm) {
}
}
function Compiler(domRoot) {
function Compiler(domRoot, origFilters) {
var compilersByExe = {};
var pendingTimeout = null;
var asmCodeMirror = null;
var cppEditor = null;
var lastRequest = null;
var currentAssembly = null;
var filters = origFilters;
var ignoreChanges = true; // Horrible hack to avoid onChange doing anything on first starting, ie before we've set anything up.
cppEditor = CodeMirror.fromTextArea(domRoot.find(".editor textarea")[0], {
@ -114,22 +115,21 @@ function Compiler(domRoot) {
var lastUpdatedAsm = null;
function updateAsm(forceUpdate) {
if (!currentAssembly) return;
var newFilters = getAsmFilters();
var hashedUpdate = JSON.stringify({
asm: currentAssembly,
filter: newFilters
filter: filters
});
if (!forceUpdate && lastUpdatedAsm == hashedUpdate) { return; }
lastUpdatedAsm = hashedUpdate;
var asm = processAsm(currentAssembly, newFilters);
var asm = processAsm(currentAssembly, filters);
var asmText = $.map(asm, function(x){ return x.text; }).join("\n");
var numberedLines = numberUsedLines(asm);
asmCodeMirror.setValue(asmText);
clearBackground(cppEditor);
clearBackground(asmCodeMirror);
if (newFilters.colouriseAsm) {
if (filters.colouriseAsm) {
$.each(numberedLines.source, function(line, ordinal) {
cppEditor.setLineClass(parseInt(line), null, "rainbow-" + (ordinal & 7));
});
@ -147,7 +147,7 @@ function Compiler(domRoot) {
source: cppEditor.getValue(),
compiler: $('.compiler').val(),
options: $('.compiler_options').val(),
filters: getAsmFilters()
filters: filters
};
window.localStorage['compiler'] = data.compiler;
window.localStorage['compilerOptions'] = data.options;
@ -179,7 +179,7 @@ function Compiler(domRoot) {
source: cppEditor.getValue(),
compiler: domRoot.find('.compiler').val(),
options: domRoot.find('.compiler_options').val(),
filterAsm: getAsmFilters()
filterAsm: filters
};
return encodeURIComponent(JSON.stringify(state));
}
@ -220,10 +220,16 @@ function Compiler(domRoot) {
onCompilerChange();
}
function setFilters(f) {
filters = f;
updateAsm();
}
return {
deserialiseState: deserialiseState,
setCompilers: setCompilers,
getSource: getSource,
setSource: setSource
setSource: setSource,
setFilters: setFilters
};
}

@ -120,11 +120,12 @@ function saveFileAs() {
}
function initialise() {
var compiler = new Compiler($('body'));
currentCompiler = compiler;
var defaultFilters = JSON.stringify(getAsmFilters());
setFilterUi($.parseJSON(window.localStorage['filter'] || defaultFilters));
var actualFilters = $.parseJSON(window.localStorage['filter'] || defaultFilters);
setFilterUi(actualFilters);
var compiler = new Compiler($('body'), actualFilters);
currentCompiler = compiler;
$('form').submit(function() { return false; });
$('.files .source').change(onSourceChange);
@ -160,8 +161,9 @@ function initialise() {
$('.filter button.btn').click(function(e) {
$(e.target).toggleClass('active');
window.localStorage['filter'] = JSON.stringify(getAsmFilters());
currentCompiler.onChange();
var filters = getAsmFilters();
window.localStorage['filter'] = JSON.stringify(filters);
currentCompiler.setFilters(filters);
});
function loadFromHash() {

Loading…
Cancel
Save