Created
September 12, 2021 17:31
-
-
Save met4000/fc88ab764cba66d74a5bd83ae7e21d29 to your computer and use it in GitHub Desktop.
coolc_assembley_compiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var iMap = Object.fromEntries([ | |
"halt", | |
"nop", | |
"add", | |
"sub", | |
"mult", | |
"div", | |
"call", | |
"return", | |
"jmp", | |
"jeq", | |
"printi", | |
"prints", | |
"pushc", | |
"pusha", | |
"pushr", | |
"popa", | |
"popr", | |
].map((v, i) => [v.toUpperCase(), i])); | |
var convert = input => console.log("echo -e -n '" + (Array.isArray(input) ? input.join("\n") : input).toUpperCase().split("\n").filter(v => v.replace(/\s/g, "") != "").map(v => { var temp = v.split(" ").filter(v => v.replace(/\s/g, "") != ""); temp[0] = iMap[temp[0]]; return temp.map(v => (str => "\\x"+str[2]+str[3]+"\\x"+str[0]+str[1])(parseInt(v).toString(16).padStart(4, "0"))).join(""); }).join("") + "' > coolexe"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment