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) {
// data chunk
if (Buffer.isBuffer(chunk)) {
return chunk.toString('hex')
// data?
if (Buffer.isBuffer(chunk)) return chunk.toString('hex')
// opcode
} else {
return REVERSE_OPS[chunk]
}
// opcode!
return REVERSE_OPS[chunk]
}).join(' ')
}
function fromASM (asm) {
typeforce(types.String, asm)
var strChunks = asm.split(' ')
var chunks = strChunks.map(function (strChunk) {
// opcode
if (strChunk in OPS) {
return OPS[strChunk]
return compile(asm.split(' ').map(function (chunkStr) {
// opcode?
if (OPS[chunkStr] !== undefined) return OPS[chunkStr]
// data chunk
} else {
return new Buffer(strChunk, 'hex')
}
})
return compile(chunks)
// data!
return new Buffer(chunkStr, 'hex')
}))
}
function compile (chunks) {