Format code.
This commit is contained in:
parent
3f931c4a65
commit
946db467ee
@ -1,21 +1,21 @@
|
|||||||
module Chalk
|
module Chalk
|
||||||
class BuiltinFunction
|
class BuiltinFunction
|
||||||
getter param_count : Int32
|
getter param_count : Int32
|
||||||
|
|
||||||
def initialize(@param_count)
|
def initialize(@param_count)
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate!(into)
|
def generate!(into)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class InlineFunction
|
class InlineFunction
|
||||||
getter param_count : Int32
|
getter param_count : Int32
|
||||||
|
|
||||||
def initialize(@param_count)
|
def initialize(@param_count)
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate!(codegen, params, table, target, free)
|
def generate!(codegen, params, table, target, free)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,45 +22,45 @@ module Chalk
|
|||||||
end
|
end
|
||||||
|
|
||||||
def generate!(tree, function : InlineFunction, table, target, free)
|
def generate!(tree, function : InlineFunction, table, target, free)
|
||||||
start = free
|
start = free
|
||||||
function.generate!(self, tree.params, table, target, free)
|
function.generate!(self, tree.params, table, target, free)
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate!(tree, function : TreeFunction | BuiltinFunction, table, target, free)
|
def generate!(tree, function : TreeFunction | BuiltinFunction, table, target, free)
|
||||||
start_at = free
|
start_at = free
|
||||||
# Move I to stack
|
# Move I to stack
|
||||||
setis
|
setis
|
||||||
# Get to correct stack position
|
# Get to correct stack position
|
||||||
addi STACK_REG
|
addi STACK_REG
|
||||||
# Store variables
|
# Store variables
|
||||||
store (start_at - 1) unless start_at == 0
|
store (start_at - 1) unless start_at == 0
|
||||||
# Increment I and stack position
|
# Increment I and stack position
|
||||||
load free, start_at
|
load free, start_at
|
||||||
opr TokenType::OpAdd, STACK_REG, free
|
opr TokenType::OpAdd, STACK_REG, free
|
||||||
addi free
|
addi free
|
||||||
|
|
||||||
# Calculate the parameters
|
# Calculate the parameters
|
||||||
tree.params.each do |param|
|
tree.params.each do |param|
|
||||||
generate! param, table, free, free + 1
|
generate! param, table, free, free + 1
|
||||||
free += 1
|
free += 1
|
||||||
end
|
end
|
||||||
# Call the function
|
# Call the function
|
||||||
tree.params.size.times do |time|
|
tree.params.size.times do |time|
|
||||||
loadr time, time + start_at
|
loadr time, time + start_at
|
||||||
end
|
end
|
||||||
call tree.name
|
call tree.name
|
||||||
|
|
||||||
# Reduce stack pointer
|
# Reduce stack pointer
|
||||||
load free, start_at
|
load free, start_at
|
||||||
opr TokenType::OpSub, STACK_REG, free
|
opr TokenType::OpSub, STACK_REG, free
|
||||||
# Move I to stack
|
# Move I to stack
|
||||||
setis
|
setis
|
||||||
# Get to correct stack position
|
# Get to correct stack position
|
||||||
addi STACK_REG
|
addi STACK_REG
|
||||||
# Restore
|
# Restore
|
||||||
restore (start_at - 1) unless start_at == 0
|
restore (start_at - 1) unless start_at == 0
|
||||||
# Get call value into target
|
# Get call value into target
|
||||||
loadr target, RETURN_REG
|
loadr target, RETURN_REG
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate!(tree, table, target, free)
|
def generate!(tree, table, target, free)
|
||||||
|
@ -1,59 +1,58 @@
|
|||||||
module Chalk
|
module Chalk
|
||||||
class InlineDrawFunction < InlineFunction
|
class InlineDrawFunction < InlineFunction
|
||||||
def initialize
|
def initialize
|
||||||
@param_count = 3
|
@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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class InlineAwaitKeyFunction < InlineFunction
|
def generate!(emitter, params, table, target, free)
|
||||||
def initialize
|
if !params[2].is_a?(TreeLit)
|
||||||
@param_count = 0
|
raise "Third parameter must be a constant."
|
||||||
end
|
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)
|
class InlineAwaitKeyFunction < InlineFunction
|
||||||
emitter.instructions << AwaitKeyInstruction.new target
|
def initialize
|
||||||
end
|
@param_count = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
class InlineGetFontFunction < InlineFunction
|
def generate!(emitter, params, table, target, free)
|
||||||
def initialize
|
emitter.instructions << AwaitKeyInstruction.new target
|
||||||
@param_count = 1
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate!(emitter, params, table, target, free)
|
class InlineGetFontFunction < InlineFunction
|
||||||
emitter.generate! params[0], table, free, free + 1
|
def initialize
|
||||||
emitter.instructions << GetFontInstruction.new free
|
@param_count = 1
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class InlineSetDelayFunction < InlineFunction
|
def generate!(emitter, params, table, target, free)
|
||||||
def initialize
|
emitter.generate! params[0], table, free, free + 1
|
||||||
@param_count = 1
|
emitter.instructions << GetFontInstruction.new free
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def generate!(emitter, params, table, target, free)
|
class InlineSetDelayFunction < InlineFunction
|
||||||
emitter.generate! params[0], table, free, free + 1
|
def initialize
|
||||||
emitter.instructions << SetDelayTimerInstruction.new free
|
@param_count = 1
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class InlineGetDelayFunction < InlineFunction
|
def generate!(emitter, params, table, target, free)
|
||||||
def initialize
|
emitter.generate! params[0], table, free, free + 1
|
||||||
@param_count = 0
|
emitter.instructions << SetDelayTimerInstruction.new free
|
||||||
end
|
|
||||||
|
|
||||||
def generate!(emitter, params, table, target, free)
|
|
||||||
emitter.instructions << GetDelayTimerInstruction.new target
|
|
||||||
end
|
|
||||||
end
|
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
|
end
|
||||||
|
@ -295,15 +295,15 @@ module Chalk
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
io << "draw R"
|
io << "draw R"
|
||||||
x.to_s(16, io)
|
x.to_s(16, io)
|
||||||
io << " R"
|
io << " R"
|
||||||
y.to_s(16, io)
|
y.to_s(16, io)
|
||||||
io << " " << height
|
io << " " << height
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_bin(i, index)
|
def to_bin(i, index)
|
||||||
return 0xd000 | (@x << 8) | (@y << 4) | height
|
return 0xd000 | (@x << 8) | (@y << 4) | height
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -314,12 +314,12 @@ module Chalk
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
io << "getk R"
|
io << "getk R"
|
||||||
@into.to_s(16, io)
|
@into.to_s(16, io)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_bin(i, index)
|
def to_bin(i, index)
|
||||||
return 0xf00a | (@into << 8)
|
return 0xf00a | (@into << 8)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -330,12 +330,12 @@ module Chalk
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
io << "font R"
|
io << "font R"
|
||||||
@from.to_s(16, io)
|
@from.to_s(16, io)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_bin(i, index)
|
def to_bin(i, index)
|
||||||
return 0xf029 | (@from << 8)
|
return 0xf029 | (@from << 8)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -346,12 +346,12 @@ module Chalk
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
io << "set_delay R"
|
io << "set_delay R"
|
||||||
@from.to_s(16, io)
|
@from.to_s(16, io)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_bin(i, index)
|
def to_bin(i, index)
|
||||||
return 0xf015 | (@from << 8)
|
return 0xf015 | (@from << 8)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -362,12 +362,12 @@ module Chalk
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
io << "get_delay R"
|
io << "get_delay R"
|
||||||
@into.to_s(16, io)
|
@into.to_s(16, io)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_bin(i, index)
|
def to_bin(i, index)
|
||||||
return 0xf007 | (@into << 8)
|
return 0xf007 | (@into << 8)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user