class Object

ЗАДАЧА ПРЕПРОЦЕССОРА:

1. (готово) замена оператора присваивания: "=" на ".c_assign="
2. (готово )замена всех цифр(целые, дробные, отриц.)
3a. (не готово) Замена условий (find_far_pos - возвращать позицию с учетом длины идентификатора)
3b. (готово) Замена циклов
3c. Замена управляющих структур: break, next, redo, retry
4. замена строк "123" => UserVariable.new("123")
        - строки "это_строка" и 'это_строка'
5. Поиск необъявленных переменных и выдача ошибок
6. Предупреждение об использовании зарезервированных переменных и методов
        все  они начинаются на "__rubim__"
        (напр. __rubim__times или __rubim__classparams)
7. Предупреждение об использовании зарезервированных классов
        UserClass, UserArray (лучше заменить на RubimClass, RubimArray)
8. Добавление предка к пользовательским классам
9. Замена return на __rubim_return
10. Сохранить все пользовательские комментарии в генерируемом коде
11. Цикл for - хз-чо делать...

Public Instance Methods

array(var, with: {type: 'UserVariable', size: nil}) click to toggle source
# File lib/rubimc/init_var.rb, line 83
def array(var, with: {type: 'UserVariable', size: nil})
        with[:size] = with[:size].to_i
        with[:type] = with[:type].to_s
        if with[:size].nil? or with[:type].nil?
                RubimCode.perror "Необходимо указать параметры массива (напр.: with: {type: :float, size: n, ...})"
                return
        end

        user_class = with[:type]
        with[:type] = 'int' if with[:type] == 'integer'
        with[:type] = 'bool' if with[:type] == 'boolean'
        if (with[:type].in? ['bool','int','float','double','string']) 
                user_class = "UserVariable"
        end

        arr = with[:size].times.map do |i| 
                eval("RubimCode::#{user_class}.new('#{var}[#{i}]', '#{with[:type]}')")
        end
        instance_variable_set("@#{var}", RubimCode::UserArray.new(arr))
        eval ("@#{var}.name = '#{var}'")
        eval ("@#{var}.type = \"#{with[:type]}\"")
        RubimCode.pout "#{with[:type]} #{var}[#{with[:size]}];"
end
array_of_integer(var, size: nil) click to toggle source

NOTE! When add NEW TYPES, modify preprocessor: method ‘add_binding_to_init’ #

# File lib/rubimc/init_var.rb, line 79
def array_of_integer(var, size: nil)
        array(var, with: {type: :integer, size: size})
end
bool(*variables)
Alias for: boolean
boolean(*variables) click to toggle source
# File lib/rubimc/init_var.rb, line 57
def boolean(*variables)
        RubimCode.init_vars("bool", *variables)
end
Also aliased as: bool
double(*variables) click to toggle source
# File lib/rubimc/init_var.rb, line 71
def double(*variables)
        RubimCode.init_vars("double", *variables)
end
float(*variables) click to toggle source
# File lib/rubimc/init_var.rb, line 67
def float(*variables)
        RubimCode.init_vars("float", *variables)
end
has_parent?(name) click to toggle source
# File lib/rubimc/ruby_classes.rb, line 6
def has_parent?(name)
        return false unless self.respond_to? :ancestors
        self!=name and self.ancestors.include?(name)
end
in?(array) click to toggle source
# File lib/rubimc/preprocessor.rb, line 26
def in?(array)
        array.each {|x| return true if x == self}
        return false
end
input(var, port: nil, pin: nil) click to toggle source
# File lib/rubimc/io_ports.rb, line 32
def input (var, port: nil, pin: nil)
        RubimCode.init_io(self.class, 'input', var, port: port, pin: pin)
end
int(*variables)
Alias for: integer
integer(*variables) click to toggle source
# File lib/rubimc/init_var.rb, line 62
def integer(*variables)
        RubimCode.init_vars("int", *variables)
end
Also aliased as: int
not_nil?() click to toggle source
# File lib/rubimc/ruby_classes.rb, line 2
def not_nil?
        !self.nil?
end
output(var, port: nil, pin: nil) click to toggle source
# File lib/rubimc/io_ports.rb, line 28
def output(var, port: nil, pin: nil)
        RubimCode.init_io(self.class, 'output', var, port: port, pin: pin)
end
print_comment(comment) click to toggle source
printf(str, *args) click to toggle source
# File lib/rubimc/printer.rb, line 7
def printf(str, *args)
        if args.empty?
                RubimCode.pout("printf(#{str.dump});")
        else
                args_str = args.join(', ')
                RubimCode.pout("printf(#{str.dump}, #{args_str});")
        end
end
to_rubim() click to toggle source
# File lib/rubimc/ruby_classes.rb, line 11
def to_rubim
        type = case self.class.name
                                when "Fixnum" then 'int'
                                when "Float" then 'float'
                                when "String" then 'string'
                                else nil
                        end
        if type.nil? or self.to_s.nil?
                RubimCode.perror "Неизвестный тип переменной"
        end
        UserVariable.new(self.to_s, type)
end