Merge pull request #301 from ethereum/cleanup-compiler-editor

Cleanup the compiler
pull/1/head
chriseth 8 years ago committed by GitHub
commit 6698a74e8f
  1. 23
      src/app.js
  2. 24
      src/app/compiler.js
  3. 9
      test/compiler-test.js

@ -452,7 +452,7 @@ var run = function () {
}
var executionContext = new ExecutionContext()
var compiler = new Compiler(editor, handleImportCall)
var compiler = new Compiler(handleImportCall)
var formalVerification = new FormalVerification($('#verificationView'), compiler.event)
var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)
@ -483,6 +483,15 @@ var run = function () {
autoCompile = document.querySelector('#autoCompile').checked
})
function runCompiler () {
var files = {}
var target = utils.fileNameFromKey(editor.getCacheFile())
files[target] = editor.getValue()
compiler.compile(files, target)
}
var previousInput = ''
var compileTimeout = null
var saveTimeout = null
@ -518,21 +527,21 @@ var run = function () {
if (compileTimeout) {
window.clearTimeout(compileTimeout)
}
compileTimeout = window.setTimeout(compiler.compile, 300)
compileTimeout = window.setTimeout(runCompiler, 300)
}
editor.onChangeSetup(editorOnChange)
$('#compile').click(function () {
compiler.compile()
runCompiler()
})
executionContext.event.register('contextChanged', this, function (context) {
compiler.compile()
runCompiler()
})
executionContext.event.register('web3EndpointChanged', this, function (context) {
compiler.compile()
runCompiler()
})
compiler.event.register('loadingCompiler', this, function (url, usingWorker) {
@ -542,7 +551,7 @@ var run = function () {
compiler.event.register('compilerLoaded', this, function (version) {
previousInput = ''
setVersionText(version)
compiler.compile()
runCompiler()
if (queryParams.get().endpointurl) {
executionContext.setEndPointUrl(queryParams.get().endpointurl)
@ -604,7 +613,7 @@ var run = function () {
var optimize = document.querySelector('#optimize').checked
queryParams.update({ optimize: optimize })
compiler.setOptimize(optimize)
compiler.compile()
runCompiler()
})
// ----------------- version selector-------------

@ -11,7 +11,7 @@ var EventManager = require('../lib/eventManager')
/*
trigger compilationFinished, compilerLoaded, compilationStarted
*/
function Compiler (editor, handleImportCall) {
function Compiler (handleImportCall) {
var self = this
this.event = new EventManager()
@ -28,8 +28,8 @@ function Compiler (editor, handleImportCall) {
optimize = _optimize
}
var internalCompile = function (files, missingInputs) {
gatherImports(files, missingInputs, function (error, input) {
var internalCompile = function (files, target, missingInputs) {
gatherImports(files, target, missingInputs, function (error, input) {
if (error) {
self.lastCompilationResult = null
self.event.trigger('compilationFinished', [false, { 'error': error }, files])
@ -39,13 +39,9 @@ function Compiler (editor, handleImportCall) {
})
}
var compile = function () {
var compile = function (files, target) {
self.event.trigger('compilationStarted', [])
var input = editor.getValue()
var files = {}
files[utils.fileNameFromKey(editor.getCacheFile())] = input
internalCompile(files)
internalCompile(files, target)
}
this.compile = compile
@ -124,7 +120,7 @@ function Compiler (editor, handleImportCall) {
self.event.trigger('compilationFinished', [false, data, source])
} else if (missingInputs !== undefined && missingInputs.length > 0) {
// try compiling again with the new set of inputs
internalCompile(source.sources, missingInputs)
internalCompile(source.sources, source.target, missingInputs)
} else {
data = updateInterface(data)
@ -212,10 +208,10 @@ function Compiler (editor, handleImportCall) {
worker.postMessage({cmd: 'loadVersion', data: url})
}
function gatherImports (files, importHints, cb) {
function gatherImports (files, target, importHints, cb) {
importHints = importHints || []
if (!compilerAcceptsMultipleFiles) {
cb(null, files[editor.getCacheFile()])
cb(null, files[target])
return
}
@ -250,14 +246,14 @@ function Compiler (editor, handleImportCall) {
cb(err)
} else {
files[m] = content
gatherImports(files, importHints, cb)
gatherImports(files, target, importHints, cb)
}
})
return
}
cb(null, { 'sources': files })
cb(null, { 'sources': files, 'target': target })
}
function truncateVersion (version) {

@ -3,17 +3,14 @@
var test = require('tape')
var Compiler = require('../src/app/compiler')
var EventManager = require('../src/lib/eventManager')
test('compiler.compile smoke', function (t) {
t.plan(1)
var noop = function () {}
var getCacheFile = function () { return 'fakeCacheFile' }
var fakeEditor = {onChangeSetup: noop, clearAnnotations: noop, getValue: noop, setCacheFileContent: noop, getCacheFile: getCacheFile}
var fakeQueryParams = {get: function () { return {} }}
var compiler = new Compiler(fakeEditor, fakeQueryParams, null, null, new EventManager())
var fakeImport = function (url, cb) { cb('Not implemented') }
var compiler = new Compiler(fakeImport)
compiler.setCompileJSON(noop)
compiler.compile()
compiler.compile({ 'test': '' }, 'test')
t.ok(compiler)
})

Loading…
Cancel
Save