From 3fa292347fe6c5a7a7e688ad608703e6a7e4a6b4 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 3 Aug 2018 13:52:40 -0700 Subject: [PATCH] Remove code made obsolete with type checking. --- src/chalk/builtin.cr | 10 ++-------- src/chalk/codegen.cr | 9 +++------ src/chalk/inline.cr | 21 +-------------------- 3 files changed, 6 insertions(+), 34 deletions(-) diff --git a/src/chalk/builtin.cr b/src/chalk/builtin.cr index 987cd94..b4fed25 100644 --- a/src/chalk/builtin.cr +++ b/src/chalk/builtin.cr @@ -4,11 +4,8 @@ module Chalk # that is provided by chalk's standard library, and therefore # has predefined output. abstract class BuiltinFunction - # Gets the number of parameters this function has. - getter param_count : Int32 - # Creates a new function with *param_count* parameters. - def initialize(@param_count) + def initialize() end # Uses the given `Compiler::Emitter` to output code. @@ -22,11 +19,8 @@ module Chalk # function also accepts trees rather than register numbers, # and therefore can accept and manipulate trees. abstract class InlineFunction - # Gets the number of parameters this function has. - getter param_count : Int32 - # Creates a new function with *param_count* parameters. - def initialize(@param_count) + def initialize() end # Generates code like `Compiler::CodeGenerator` would. diff --git a/src/chalk/codegen.cr b/src/chalk/codegen.cr index 5b83fb0..d9c826a 100644 --- a/src/chalk/codegen.cr +++ b/src/chalk/codegen.cr @@ -96,12 +96,9 @@ module Chalk generate! tree.right, table, free, free + 1 opr tree.op, target, free when Trees::TreeCall - entry = table[tree.name]? - raise "Unknown function" unless entry && - entry.is_a?(FunctionEntry) - function = entry.function - raise "Invalid call" if tree.params.size != function.param_count - generate! tree, function, table, target, free + entry = table[tree.name]?.not_nil! + raise "Unknown function" unless entry.is_a?(FunctionEntry) + generate! tree, entry.function, table, target, free when Trees::TreeBlock table = Table.new(table) tree.children.each do |child| diff --git a/src/chalk/inline.cr b/src/chalk/inline.cr index ac3a36d..9a0b4d0 100644 --- a/src/chalk/inline.cr +++ b/src/chalk/inline.cr @@ -5,10 +5,6 @@ module Chalk module Builtin # Inline function to draw sprite at address I. class InlineDrawFunction < InlineFunction - def initialize - @param_count = 3 - end - def generate!(emitter, params, table, target, free) if !params[2].is_a?(Trees::TreeLit) raise "Third parameter must be a constant." @@ -24,10 +20,6 @@ module Chalk # Inline function to await for a key and return it. class InlineAwaitKeyFunction < InlineFunction - def initialize - @param_count = 0 - end - def generate!(emitter, params, table, target, free) emitter.instructions << Ir::AwaitKeyInstruction.new target end @@ -38,10 +30,6 @@ module Chalk # Inline function to get font for a given value. 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 << Ir::GetFontInstruction.new free @@ -53,14 +41,11 @@ module Chalk # Inline function to set the delay timer. 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 << Ir::SetDelayTimerInstruction.new free end + def type return Compiler::FunctionType.new([Compiler::Type::U8], Compiler::Type::U0) end @@ -68,10 +53,6 @@ module Chalk # Inline function to get the delay timer. class InlineGetDelayFunction < InlineFunction - def initialize - @param_count = 0 - end - def generate!(emitter, params, table, target, free) emitter.instructions << Ir::GetDelayTimerInstruction.new target end