scripts: refactor to/from ASM

This commit is contained in:
Daniel Cousens 2015-08-18 09:12:02 +10:00
parent b933c6da44
commit ab1215adc1

View file

@ -19,33 +19,24 @@ function toASM (chunks) {
} }
return chunks.map(function (chunk) { return chunks.map(function (chunk) {
// data chunk // data?
if (Buffer.isBuffer(chunk)) { if (Buffer.isBuffer(chunk)) return chunk.toString('hex')
return chunk.toString('hex')
// opcode // opcode!
} else { return REVERSE_OPS[chunk]
return REVERSE_OPS[chunk]
}
}).join(' ') }).join(' ')
} }
function fromASM (asm) { function fromASM (asm) {
typeforce(types.String, asm) typeforce(types.String, asm)
var strChunks = asm.split(' ') return compile(asm.split(' ').map(function (chunkStr) {
var chunks = strChunks.map(function (strChunk) { // opcode?
// opcode if (OPS[chunkStr] !== undefined) return OPS[chunkStr]
if (strChunk in OPS) {
return OPS[strChunk]
// data chunk // data!
} else { return new Buffer(chunkStr, 'hex')
return new Buffer(strChunk, 'hex') }))
}
})
return compile(chunks)
} }
function compile (chunks) { function compile (chunks) {