From 946db467eeb9d6c0d017966caf0f1b71d82ada58 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 28 Jul 2018 17:53:07 -0700 Subject: [PATCH] Format code. --- src/chalk/builtin.cr | 22 +++++------ src/chalk/codegen.cr | 70 +++++++++++++++++----------------- src/chalk/inline.cr | 89 ++++++++++++++++++++++---------------------- src/chalk/ir.cr | 38 +++++++++---------- 4 files changed, 109 insertions(+), 110 deletions(-) diff --git a/src/chalk/builtin.cr b/src/chalk/builtin.cr index 561a25d..066767a 100644 --- a/src/chalk/builtin.cr +++ b/src/chalk/builtin.cr @@ -1,21 +1,21 @@ module Chalk class BuiltinFunction - getter param_count : Int32 + getter param_count : Int32 - def initialize(@param_count) - end + def initialize(@param_count) + end - def generate!(into) - end + def generate!(into) + end end class InlineFunction - getter param_count : Int32 - - def initialize(@param_count) - end + getter param_count : Int32 - def generate!(codegen, params, table, target, free) - end + def initialize(@param_count) + end + + def generate!(codegen, params, table, target, free) + end end end diff --git a/src/chalk/codegen.cr b/src/chalk/codegen.cr index 06c569d..3615a5f 100644 --- a/src/chalk/codegen.cr +++ b/src/chalk/codegen.cr @@ -22,45 +22,45 @@ module Chalk end def generate!(tree, function : InlineFunction, table, target, free) - start = free - function.generate!(self, tree.params, table, target, free) + start = free + function.generate!(self, tree.params, table, target, free) end def generate!(tree, function : TreeFunction | BuiltinFunction, table, target, free) - start_at = free - # Move I to stack - setis - # Get to correct stack position - addi STACK_REG - # Store variables - store (start_at - 1) unless start_at == 0 - # Increment I and stack position - load free, start_at - opr TokenType::OpAdd, STACK_REG, free - addi free + start_at = free + # Move I to stack + setis + # Get to correct stack position + addi STACK_REG + # Store variables + store (start_at - 1) unless start_at == 0 + # Increment I and stack position + load free, start_at + opr TokenType::OpAdd, STACK_REG, free + addi free - # Calculate the parameters - tree.params.each do |param| - generate! param, table, free, free + 1 - free += 1 - end - # Call the function - tree.params.size.times do |time| - loadr time, time + start_at - end - call tree.name + # Calculate the parameters + tree.params.each do |param| + generate! param, table, free, free + 1 + free += 1 + end + # Call the function + tree.params.size.times do |time| + loadr time, time + start_at + end + call tree.name - # Reduce stack pointer - load free, start_at - opr TokenType::OpSub, STACK_REG, free - # Move I to stack - setis - # Get to correct stack position - addi STACK_REG - # Restore - restore (start_at - 1) unless start_at == 0 - # Get call value into target - loadr target, RETURN_REG + # Reduce stack pointer + load free, start_at + opr TokenType::OpSub, STACK_REG, free + # Move I to stack + setis + # Get to correct stack position + addi STACK_REG + # Restore + restore (start_at - 1) unless start_at == 0 + # Get call value into target + loadr target, RETURN_REG end def generate!(tree, table, target, free) @@ -124,7 +124,7 @@ module Chalk old_size = @instructions.size generate! tree.block, table, free, free + 1 after_jump = jr 0 - + cond_jump.offset = @instructions.size - old_size + 1 after_jump.offset = before_cond - instructions.size + 1 when TreeReturn diff --git a/src/chalk/inline.cr b/src/chalk/inline.cr index 5988204..62f6e68 100644 --- a/src/chalk/inline.cr +++ b/src/chalk/inline.cr @@ -1,59 +1,58 @@ module Chalk - class InlineDrawFunction < InlineFunction - def initialize - @param_count = 3 - end - - def generate!(emitter, params, table, target, free) - if !params[2].is_a?(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 << DrawInstruction.new free, free + 1, params[2].as(TreeLit).lit.to_i32 - end + class InlineDrawFunction < InlineFunction + def initialize + @param_count = 3 end - class InlineAwaitKeyFunction < InlineFunction - def initialize - @param_count = 0 - end + def generate!(emitter, params, table, target, free) + if !params[2].is_a?(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 << DrawInstruction.new free, free + 1, params[2].as(TreeLit).lit.to_i32 + end + end - def generate!(emitter, params, table, target, free) - emitter.instructions << AwaitKeyInstruction.new target - end + class InlineAwaitKeyFunction < InlineFunction + def initialize + @param_count = 0 end - class InlineGetFontFunction < InlineFunction - def initialize - @param_count = 1 - end + def generate!(emitter, params, table, target, free) + emitter.instructions << AwaitKeyInstruction.new target + end + end - def generate!(emitter, params, table, target, free) - emitter.generate! params[0], table, free, free + 1 - emitter.instructions << GetFontInstruction.new free - - end + class InlineGetFontFunction < InlineFunction + def initialize + @param_count = 1 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 << GetFontInstruction.new free + end + end - def generate!(emitter, params, table, target, free) - emitter.generate! params[0], table, free, free + 1 - emitter.instructions << SetDelayTimerInstruction.new free - end + class InlineSetDelayFunction < InlineFunction + def initialize + @param_count = 1 end - class InlineGetDelayFunction < InlineFunction - def initialize - @param_count = 0 - end - - def generate!(emitter, params, table, target, free) - emitter.instructions << GetDelayTimerInstruction.new target - 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 diff --git a/src/chalk/ir.cr b/src/chalk/ir.cr index 12ac53a..e7258d2 100644 --- a/src/chalk/ir.cr +++ b/src/chalk/ir.cr @@ -295,15 +295,15 @@ module Chalk end def to_s(io) - io << "draw R" - x.to_s(16, io) - io << " R" - y.to_s(16, io) - io << " " << height + io << "draw R" + x.to_s(16, io) + io << " R" + y.to_s(16, io) + io << " " << height end def to_bin(i, index) - return 0xd000 | (@x << 8) | (@y << 4) | height + return 0xd000 | (@x << 8) | (@y << 4) | height end end @@ -314,28 +314,28 @@ module Chalk end def to_s(io) - io << "getk R" - @into.to_s(16, io) + io << "getk R" + @into.to_s(16, io) end def to_bin(i, index) - return 0xf00a | (@into << 8) + 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) + io << "font R" + @from.to_s(16, io) end def to_bin(i, index) - return 0xf029 | (@from << 8) + return 0xf029 | (@from << 8) end end @@ -346,12 +346,12 @@ module Chalk end def to_s(io) - io << "set_delay R" - @from.to_s(16, io) + io << "set_delay R" + @from.to_s(16, io) end def to_bin(i, index) - return 0xf015 | (@from << 8) + return 0xf015 | (@from << 8) end end @@ -362,12 +362,12 @@ module Chalk end def to_s(io) - io << "get_delay R" - @into.to_s(16, io) + io << "get_delay R" + @into.to_s(16, io) end def to_bin(i, index) - return 0xf007 | (@into << 8) + return 0xf007 | (@into << 8) end end end