class RubimCode::Printer
Attributes
sandbox[RW]
Public Class Methods
code_type()
click to toggle source
# File lib/rubimc/printer.rb, line 100 def self.code_type if not Controllers.all.empty? "avr-gcc" elsif Controllers.all.empty? and eval("self.private_methods.include? :main") "gcc" else RubimCode.perror "Can not to define type of code" end end
generate_cc()
click to toggle source
# File lib/rubimc/printer.rb, line 169 def self.generate_cc if Controllers.all.count > 1 RubimCode.perror "In current version in one file you can define only one Controller Class" end if self.code_type == "avr-gcc" # if compile program for MCU Controllers.all.each do |mcu_class| print_layout(:before_main) do mcu_class.mcu_layout if mcu_class.respond_to? :mcu_layout end mcu = mcu_class.new # print initialize section print_main_loop {mcu.main_loop} # print body of main loop print_layout(:after_main) RubimCode::Interrupts.print() RubimCode::Printer.print_instance_vars() end # each Controllers.all elsif self.code_type == "gcc" # if compile clear-C program if Controllers.all.empty? and eval("self.private_methods.include? :main") print_layout(:before_main) eval("main(RubimCode::CC_ARGS.new)") # execute user`s method :main (CC_ARGS - helper for C agruments argc/argv) print_layout(:after_main) end end end
instance_vars_cc()
click to toggle source
# File lib/rubimc/printer.rb, line 80 def self.instance_vars_cc @@instance_vars_cc end
mcu_type()
click to toggle source
# File lib/rubimc/printer.rb, line 110 def self.mcu_type code_type == "avr-gcc" ? Controllers.all.first::MCU_NAME : "undefined" end
pout_destination()
click to toggle source
# File lib/rubimc/printer.rb, line 85 def self.pout_destination @@pout_destination end
pout_destination=(dest)
click to toggle source
# File lib/rubimc/printer.rb, line 88 def self.pout_destination=(dest) if dest.nil? perror "Wrong parameter for method #{__method__}. Set destination string" end if dest.class.name == "String" or dest.in? [:default, :h_file] # dest.is_a?(String) not work...WTF @@pout_destination = dest else perror "Wrong parameter for method #{__method__}. Only string variable or ':default' value is permit as a parameters" end end
print_instance_vars()
click to toggle source
# File lib/rubimc/printer.rb, line 159 def self.print_instance_vars RubimCode::Printer.pout_destination = :h_file @@instance_vars_cc.each do |var| if var.is_a? RubimCode::UserVariable RubimCode.pout "#{var.type} #{var.name};" end end RubimCode::Printer.pout_destination = :default end
print_layout(position) { || ... }
click to toggle source
# File lib/rubimc/printer.rb, line 114 def self.print_layout(position, &mcu_layout) return if RubimCode::Printer.sandbox == true # don`t print output in sandbox h_name = File.basename(ARGV[0], '.c') + '.h' if position == :before_main RubimCode::Printer.pout_destination = :h_file RubimCode.pout "/**************************************************************" RubimCode.pout " * This code was generated by RubimC micro-framework" RubimCode.pout " * Include file for \"#{ARGV[0]}\"" RubimCode.pout " **************************************************************/" RubimCode::Printer.pout_destination = :default RubimCode.pout "/**************************************************************" RubimCode.pout " * This code was generated by RubimC micro-framework" RubimCode.pout " * RubimC version: #{RubimCode::VERSION}" RubimCode.pout " * RubimC author: Evgeny Danilov" RubimCode.pout " * File created at #{Time.now}" RubimCode.pout " **************************************************************/" RubimCode.pout RubimCode.pout "#include <stdbool.h>" RubimCode.pout "#include <stdio.h>" RubimCode.pout yield if block_given? # print includes for current MCU (see mcu libraries) RubimCode.pout RubimCode.pout "#include \"#{h_name}\"" RubimCode.pout RubimCode.pout "int main(int argc, char *argv[]) {" RubimCode.level += 1 else RubimCode.pout RubimCode.pout "return 1;" RubimCode.level -= 1 RubimCode.pout "}" end end
print_main_loop() { || ... }
click to toggle source
# File lib/rubimc/printer.rb, line 149 def self.print_main_loop RubimCode.pout RubimCode.pout "// === Main Infinite Loop === //" RubimCode.pout "while (true) {" RubimCode.level += 1 yield # print body of main loop RubimCode.level -= 1 RubimCode.pout"} // end main loop" end