chalk/src/chalk/inline.cr

65 lines
2.2 KiB
Crystal
Raw Normal View History

2018-08-03 01:13:23 -07:00
require "./builtin"
require "./type"
module Chalk
2018-08-01 22:40:41 -07:00
module Builtin
2018-08-02 01:09:48 -07:00
# Inline function to draw sprite at address I.
2018-08-01 22:40:41 -07:00
class InlineDrawFunction < InlineFunction
def generate!(emitter, params, table, target, free)
if !params[2].is_a?(Trees::TreeLit)
raise "Third parameter must be a constant."
end
emitter.generate! params[0], table, free, free + 1
emitter.generate! params[1], table, free + 1, free + 2
emitter.instructions << Ir::DrawInstruction.new free, free + 1, params[2].as(Trees::TreeLit).lit.to_i32
2018-07-28 17:53:07 -07:00
end
2018-08-03 01:13:23 -07:00
def type
return Compiler::FunctionType.new([Compiler::Type::U8] * 3, Compiler::Type::U0)
end
2018-07-28 17:53:07 -07:00
end
2018-08-02 01:09:48 -07:00
# Inline function to await for a key and return it.
2018-08-01 22:40:41 -07:00
class InlineAwaitKeyFunction < InlineFunction
def generate!(emitter, params, table, target, free)
emitter.instructions << Ir::AwaitKeyInstruction.new target
end
2018-08-03 01:13:23 -07:00
def type
return Compiler::FunctionType.new(([] of Compiler::Type), Compiler::Type::U8)
end
2018-07-28 17:53:07 -07:00
end
2018-07-28 17:43:19 -07:00
2018-08-02 01:09:48 -07:00
# Inline function to get font for a given value.
2018-08-01 22:40:41 -07:00
class InlineGetFontFunction < InlineFunction
def generate!(emitter, params, table, target, free)
emitter.generate! params[0], table, free, free + 1
emitter.instructions << Ir::GetFontInstruction.new free
end
2018-08-03 01:13:23 -07:00
def type
return Compiler::FunctionType.new([Compiler::Type::U8], Compiler::Type::U0)
end
2018-07-28 17:43:19 -07:00
end
2018-08-02 01:09:48 -07:00
# Inline function to set the delay timer.
2018-08-01 22:40:41 -07:00
class InlineSetDelayFunction < InlineFunction
def generate!(emitter, params, table, target, free)
emitter.generate! params[0], table, free, free + 1
emitter.instructions << Ir::SetDelayTimerInstruction.new free
end
2018-08-03 01:13:23 -07:00
def type
return Compiler::FunctionType.new([Compiler::Type::U8], Compiler::Type::U0)
end
2018-07-28 17:43:19 -07:00
end
2018-08-02 01:09:48 -07:00
# Inline function to get the delay timer.
2018-08-01 22:40:41 -07:00
class InlineGetDelayFunction < InlineFunction
def generate!(emitter, params, table, target, free)
emitter.instructions << Ir::GetDelayTimerInstruction.new target
end
2018-08-03 01:13:23 -07:00
def type
return Compiler::FunctionType.new(([] of Compiler::Type), Compiler::Type::U8)
end
2018-07-28 17:43:19 -07:00
end
2018-07-28 17:53:07 -07:00
end
end