Fixed constants not resolving on declaration

This commit is contained in:
Dominic Grimm 2022-06-18 13:02:52 +02:00
parent 327402db00
commit fb9fa4353c
No known key found for this signature in database
GPG key ID: A6C051C716D2CE65
2 changed files with 24 additions and 1 deletions

View file

@ -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]?

View file

@ -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