Add compile time debugger
This commit is contained in:
parent
a20d7a6e0f
commit
327402db00
1 changed files with 17 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
|||
require "colorize"
|
||||
|
||||
module Hence
|
||||
module Assembler
|
||||
extend self
|
||||
|
@ -48,6 +50,21 @@ module Hence
|
|||
end
|
||||
|
||||
MACROS = {
|
||||
"debug" => ->(data : Data, args : Array(Parser::AST::Arg)) do
|
||||
args.each do |arg|
|
||||
arg_s = arg.to_s.gsub(/\n/, "\\n")
|
||||
|
||||
num = arg.resolve_as_number(data)
|
||||
slice = arg.resolve(data)
|
||||
|
||||
puts arg_s.colorize(:green)
|
||||
puts " => #{"0x#{num.to_s(16).rjust(4, '0')}".colorize(:magenta)}"
|
||||
puts " => #{num.colorize(:magenta)}"
|
||||
puts " => [#{slice.map { |n| "0x#{n.to_s(16).rjust(2, '0')}".colorize(:magenta) }.join(", ")}]"
|
||||
puts " => #{"\"#{String.new(slice).gsub(/\n/, "\\n")}\"".colorize(:light_green)}"
|
||||
puts
|
||||
end
|
||||
end,
|
||||
"org" => ->(data : Data, args : Array(Parser::AST::Arg)) do
|
||||
data.offset = args[0].resolve_as_number(data)
|
||||
end,
|
||||
|
|
Loading…
Reference in a new issue