Remove code made obsolete with type checking.
This commit is contained in:
parent
f8320bcb82
commit
3fa292347f
|
@ -4,11 +4,8 @@ module Chalk
|
||||||
# that is provided by chalk's standard library, and therefore
|
# that is provided by chalk's standard library, and therefore
|
||||||
# has predefined output.
|
# has predefined output.
|
||||||
abstract class BuiltinFunction
|
abstract class BuiltinFunction
|
||||||
# Gets the number of parameters this function has.
|
|
||||||
getter param_count : Int32
|
|
||||||
|
|
||||||
# Creates a new function with *param_count* parameters.
|
# Creates a new function with *param_count* parameters.
|
||||||
def initialize(@param_count)
|
def initialize()
|
||||||
end
|
end
|
||||||
|
|
||||||
# Uses the given `Compiler::Emitter` to output code.
|
# Uses the given `Compiler::Emitter` to output code.
|
||||||
|
@ -22,11 +19,8 @@ module Chalk
|
||||||
# function also accepts trees rather than register numbers,
|
# function also accepts trees rather than register numbers,
|
||||||
# and therefore can accept and manipulate trees.
|
# and therefore can accept and manipulate trees.
|
||||||
abstract class InlineFunction
|
abstract class InlineFunction
|
||||||
# Gets the number of parameters this function has.
|
|
||||||
getter param_count : Int32
|
|
||||||
|
|
||||||
# Creates a new function with *param_count* parameters.
|
# Creates a new function with *param_count* parameters.
|
||||||
def initialize(@param_count)
|
def initialize()
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generates code like `Compiler::CodeGenerator` would.
|
# Generates code like `Compiler::CodeGenerator` would.
|
||||||
|
|
|
@ -96,12 +96,9 @@ module Chalk
|
||||||
generate! tree.right, table, free, free + 1
|
generate! tree.right, table, free, free + 1
|
||||||
opr tree.op, target, free
|
opr tree.op, target, free
|
||||||
when Trees::TreeCall
|
when Trees::TreeCall
|
||||||
entry = table[tree.name]?
|
entry = table[tree.name]?.not_nil!
|
||||||
raise "Unknown function" unless entry &&
|
raise "Unknown function" unless entry.is_a?(FunctionEntry)
|
||||||
entry.is_a?(FunctionEntry)
|
generate! tree, entry.function, table, target, free
|
||||||
function = entry.function
|
|
||||||
raise "Invalid call" if tree.params.size != function.param_count
|
|
||||||
generate! tree, function, table, target, free
|
|
||||||
when Trees::TreeBlock
|
when Trees::TreeBlock
|
||||||
table = Table.new(table)
|
table = Table.new(table)
|
||||||
tree.children.each do |child|
|
tree.children.each do |child|
|
||||||
|
|
|
@ -5,10 +5,6 @@ module Chalk
|
||||||
module Builtin
|
module Builtin
|
||||||
# Inline function to draw sprite at address I.
|
# Inline function to draw sprite at address I.
|
||||||
class InlineDrawFunction < InlineFunction
|
class InlineDrawFunction < InlineFunction
|
||||||
def initialize
|
|
||||||
@param_count = 3
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate!(emitter, params, table, target, free)
|
def generate!(emitter, params, table, target, free)
|
||||||
if !params[2].is_a?(Trees::TreeLit)
|
if !params[2].is_a?(Trees::TreeLit)
|
||||||
raise "Third parameter must be a constant."
|
raise "Third parameter must be a constant."
|
||||||
|
@ -24,10 +20,6 @@ module Chalk
|
||||||
|
|
||||||
# Inline function to await for a key and return it.
|
# Inline function to await for a key and return it.
|
||||||
class InlineAwaitKeyFunction < InlineFunction
|
class InlineAwaitKeyFunction < InlineFunction
|
||||||
def initialize
|
|
||||||
@param_count = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate!(emitter, params, table, target, free)
|
def generate!(emitter, params, table, target, free)
|
||||||
emitter.instructions << Ir::AwaitKeyInstruction.new target
|
emitter.instructions << Ir::AwaitKeyInstruction.new target
|
||||||
end
|
end
|
||||||
|
@ -38,10 +30,6 @@ module Chalk
|
||||||
|
|
||||||
# Inline function to get font for a given value.
|
# Inline function to get font for a given value.
|
||||||
class InlineGetFontFunction < InlineFunction
|
class InlineGetFontFunction < InlineFunction
|
||||||
def initialize
|
|
||||||
@param_count = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate!(emitter, params, table, target, free)
|
def generate!(emitter, params, table, target, free)
|
||||||
emitter.generate! params[0], table, free, free + 1
|
emitter.generate! params[0], table, free, free + 1
|
||||||
emitter.instructions << Ir::GetFontInstruction.new free
|
emitter.instructions << Ir::GetFontInstruction.new free
|
||||||
|
@ -53,14 +41,11 @@ module Chalk
|
||||||
|
|
||||||
# Inline function to set the delay timer.
|
# Inline function to set the delay timer.
|
||||||
class InlineSetDelayFunction < InlineFunction
|
class InlineSetDelayFunction < InlineFunction
|
||||||
def initialize
|
|
||||||
@param_count = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate!(emitter, params, table, target, free)
|
def generate!(emitter, params, table, target, free)
|
||||||
emitter.generate! params[0], table, free, free + 1
|
emitter.generate! params[0], table, free, free + 1
|
||||||
emitter.instructions << Ir::SetDelayTimerInstruction.new free
|
emitter.instructions << Ir::SetDelayTimerInstruction.new free
|
||||||
end
|
end
|
||||||
|
|
||||||
def type
|
def type
|
||||||
return Compiler::FunctionType.new([Compiler::Type::U8], Compiler::Type::U0)
|
return Compiler::FunctionType.new([Compiler::Type::U8], Compiler::Type::U0)
|
||||||
end
|
end
|
||||||
|
@ -68,10 +53,6 @@ module Chalk
|
||||||
|
|
||||||
# Inline function to get the delay timer.
|
# Inline function to get the delay timer.
|
||||||
class InlineGetDelayFunction < InlineFunction
|
class InlineGetDelayFunction < InlineFunction
|
||||||
def initialize
|
|
||||||
@param_count = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate!(emitter, params, table, target, free)
|
def generate!(emitter, params, table, target, free)
|
||||||
emitter.instructions << Ir::GetDelayTimerInstruction.new target
|
emitter.instructions << Ir::GetDelayTimerInstruction.new target
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user