Implement some inline function.
This commit is contained in:
parent
75e031745b
commit
3f931c4a65
|
@ -46,6 +46,9 @@ module Chalk
|
|||
|
||||
table["draw"] = FunctionEntry.new InlineDrawFunction.new
|
||||
table["get_key"] = FunctionEntry.new InlineAwaitKeyFunction.new
|
||||
table["get_font"] = FunctionEntry.new InlineGetFontFunction.new
|
||||
table["set_delay"] = FunctionEntry.new InlineSetDelayFunction.new
|
||||
table["get_delay"] = FunctionEntry.new InlineGetDelayFunction.new
|
||||
return table
|
||||
end
|
||||
|
||||
|
|
|
@ -23,4 +23,37 @@ module Chalk
|
|||
emitter.instructions << AwaitKeyInstruction.new target
|
||||
end
|
||||
end
|
||||
|
||||
class InlineGetFontFunction < InlineFunction
|
||||
def initialize
|
||||
@param_count = 1
|
||||
end
|
||||
|
||||
def generate!(emitter, params, table, target, free)
|
||||
emitter.generate! params[0], table, free, free + 1
|
||||
emitter.instructions << GetFontInstruction.new free
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
class InlineSetDelayFunction < InlineFunction
|
||||
def initialize
|
||||
@param_count = 1
|
||||
end
|
||||
|
||||
def generate!(emitter, params, table, target, free)
|
||||
emitter.generate! params[0], table, free, free + 1
|
||||
emitter.instructions << SetDelayTimerInstruction.new free
|
||||
end
|
||||
end
|
||||
|
||||
class InlineGetDelayFunction < InlineFunction
|
||||
def initialize
|
||||
@param_count = 0
|
||||
end
|
||||
|
||||
def generate!(emitter, params, table, target, free)
|
||||
emitter.instructions << GetDelayTimerInstruction.new target
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -317,5 +317,57 @@ module Chalk
|
|||
io << "getk R"
|
||||
@into.to_s(16, io)
|
||||
end
|
||||
|
||||
def to_bin(i, index)
|
||||
return 0xf00a | (@into << 8)
|
||||
end
|
||||
end
|
||||
|
||||
class GetFontInstruction < Instruction
|
||||
property from : Int32
|
||||
|
||||
def initialize(@from)
|
||||
end
|
||||
|
||||
def to_s(io)
|
||||
io << "font R"
|
||||
@from.to_s(16, io)
|
||||
end
|
||||
|
||||
def to_bin(i, index)
|
||||
return 0xf029 | (@from << 8)
|
||||
end
|
||||
end
|
||||
|
||||
class SetDelayTimerInstruction < Instruction
|
||||
property from : Int32
|
||||
|
||||
def initialize(@from)
|
||||
end
|
||||
|
||||
def to_s(io)
|
||||
io << "set_delay R"
|
||||
@from.to_s(16, io)
|
||||
end
|
||||
|
||||
def to_bin(i, index)
|
||||
return 0xf015 | (@from << 8)
|
||||
end
|
||||
end
|
||||
|
||||
class GetDelayTimerInstruction < Instruction
|
||||
property into : Int32
|
||||
|
||||
def initialize(@into)
|
||||
end
|
||||
|
||||
def to_s(io)
|
||||
io << "get_delay R"
|
||||
@into.to_s(16, io)
|
||||
end
|
||||
|
||||
def to_bin(i, index)
|
||||
return 0xf007 | (@into << 8)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user