Add compile time debugger

This commit is contained in:
Dominic Grimm 2022-06-18 12:32:57 +02:00
parent a20d7a6e0f
commit 327402db00
No known key found for this signature in database
GPG key ID: A6C051C716D2CE65

View file

@ -1,3 +1,5 @@
require "colorize"
module Hence module Hence
module Assembler module Assembler
extend self extend self
@ -48,6 +50,21 @@ module Hence
end end
MACROS = { 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 "org" => ->(data : Data, args : Array(Parser::AST::Arg)) do
data.offset = args[0].resolve_as_number(data) data.offset = args[0].resolve_as_number(data)
end, end,