# === DISASSEMBLER =================================================== # The disassembler converts dino bytecode into text assembly code. DATA: dis.i is number dis.j is number dis.x is number dis.pad is number dis.len is number dis.opcode is number dis.text is text dis.text.i is number dis.text.l is number dis.text.t is text dis.text.char is text PROCEDURE: # Convert \n to \\n and so on inside a text value. # IN: dis.text # OUT: dis.text sub-procedure dis.text-filter store 0 in dis.text.i store "" in dis.text.t store length of dis.text in dis.text.l while dis.text.i is less than dis.text.l do get character at dis.text.i from dis.text in dis.text.char if dis.text.char is equal to "\n" then join dis.text.t and "\\n" in dis.text.t else if dis.text.char is equal to "\r" then join dis.text.t and "\\r" in dis.text.t else if dis.text.char is equal to "\0" then join dis.text.t and "\\0" in dis.text.t else if dis.text.char is equal to "\e" then join dis.text.t and "\\e" in dis.text.t else if dis.text.char is equal to "\t" then join dis.text.t and "\\t" in dis.text.t else join dis.text.t and dis.text.char in dis.text.t end if incr dis.text.i repeat store dis.text.t in dis.text end sub-procedure # Tries to turn dino bytecode into dino assembly and print it. # IN: vm.Code # vm.Code* sub-procedure dis.Print store $OFFSET.CODE in dis.i while dis.i is less than vm.Code* do store vm.Code:dis.i in dis.opcode display "\e[36m" if dis.i is less than 10 then display "0" end if store length of $NAMES:dis.opcode in dis.len subtract dis.len from 6 in dis.pad display dis.i " \e[33m" store 0 in dis.x while dis.x is less than dis.pad do display " " incr dis.x repeat display $NAMES:dis.opcode display " " if $SIZES:dis.opcode is greater than 0 then display "\e[32m" store $SIZES:dis.opcode in dis.x store 0 in dis.j while dis.j is less than dis.x do add 1 and dis.i in dis.i display "\e[35m" store vm.Code:dis.i in dis.opcode if dis.opcode is greater than or equal to $OFFSET.TLIT then store vm.Text:dis.opcode in dis.text call dis.text-filter display "\"" dis.text "\"" else display dis.opcode end if add 1 and dis.j in dis.j if dis.j is less than dis.x then display "\e[0m, " end if repeat end if display "\e[0m" crlf add 1 and dis.i in dis.i repeat end sub-procedure