Fixed constants not resolving on declaration
This commit is contained in:
parent
327402db00
commit
fb9fa4353c
2 changed files with 24 additions and 1 deletions
|
@ -12,7 +12,7 @@ module Hence
|
||||||
when Parser::AST::ConstantDeclarationNode
|
when Parser::AST::ConstantDeclarationNode
|
||||||
raise "Constants can't be redefined" if data.constants[node.name]?
|
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
|
when Parser::AST::LabelNode
|
||||||
raise "Labels can't be redefined" if data.constants[node.name]?
|
raise "Labels can't be redefined" if data.constants[node.name]?
|
||||||
|
|
||||||
|
|
|
@ -213,6 +213,29 @@ module Hence
|
||||||
end
|
end
|
||||||
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
|
class StringArg < Arg
|
||||||
property string
|
property string
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue