diff --git a/src/hence/assembler.cr b/src/hence/assembler.cr index 4eceeb7..7645d62 100644 --- a/src/hence/assembler.cr +++ b/src/hence/assembler.cr @@ -12,7 +12,7 @@ module Hence when Parser::AST::ConstantDeclarationNode raise "Constants can't be redefined" if data.constants[node.name]? - data.constants[node.name] = node.value + data.constants[node.name] = Parser::AST::BytesArg.new(node.value.resolve(data)) when Parser::AST::LabelNode raise "Labels can't be redefined" if data.constants[node.name]? diff --git a/src/hence/parser.cr b/src/hence/parser.cr index 39fed74..ee85e9e 100644 --- a/src/hence/parser.cr +++ b/src/hence/parser.cr @@ -213,6 +213,29 @@ module Hence end end + class BytesArg < Arg + property bytes + + def initialize(@bytes : Bytes) + end + + def resolve(_data : Assembler::Data) : Bytes + @bytes + end + + def resolve_as_number(_data : Assembler::Data) : UInt16 + if @bytes.size == 1 + @bytes[0].to_u16 + else + Utils.merge_uint16(@bytes[0], @bytes[1]) + end + end + + def to_s : String + "\"#{String.new(@bytes).gsub(/\n/, "\\n")}\"" + end + end + class StringArg < Arg property string