Module: TypedRb

Defined in:
lib/typed.rb,
lib/typed/model.rb,
lib/typed/types.rb,
lib/typed/version.rb,
lib/typed/language.rb,
lib/typed/model/tm_abs.rb,
lib/typed/model/tm_for.rb,
lib/typed/model/tm_fun.rb,
lib/typed/model/tm_int.rb,
lib/typed/model/tm_nil.rb,
lib/typed/model/tm_try.rb,
lib/typed/model/tm_var.rb,
lib/typed/model/tm_mlhs.rb,
lib/typed/model/tm_next.rb,
lib/typed/model/tm_self.rb,
lib/typed/model/tm_send.rb,
lib/typed/model/tm_break.rb,
lib/typed/model/tm_class.rb,
lib/typed/model/tm_const.rb,
lib/typed/model/tm_error.rb,
lib/typed/model/tm_float.rb,
lib/typed/model/tm_super.rb,
lib/typed/model/tm_while.rb,
lib/typed/types/ty_error.rb,
lib/typed/typing_context.rb,
lib/typed/model/tm_module.rb,
lib/typed/model/tm_regexp.rb,
lib/typed/model/tm_rescue.rb,
lib/typed/model/tm_return.rb,
lib/typed/model/tm_string.rb,
lib/typed/model/tm_symbol.rb,
lib/typed/types/ty_either.rb,
lib/typed/types/ty_object.rb,
lib/typed/model/tm_boolean.rb,
lib/typed/model/tm_defined.rb,
lib/typed/model/tm_if_else.rb,
lib/typed/model/tm_s_class.rb,
lib/typed/types/ty_boolean.rb,
lib/typed/types/ty_dynamic.rb,
lib/typed/types/ty_function.rb,
lib/typed/model/tm_case_when.rb,
lib/typed/model/tm_mass_asgn.rb,
lib/typed/runtime/ast_parser.rb,
lib/typed/model/tm_global_var.rb,
lib/typed/model/tm_sequencing.rb,
lib/typed/runtime/type_parser.rb,
lib/typed/types/ty_stack_jump.rb,
lib/typed/model/tm_hash_literal.rb,
lib/typed/model/tm_instance_var.rb,
lib/typed/runtime/normalization.rb,
lib/typed/type_signature/parser.rb,
lib/typed/model/tm_array_literal.rb,
lib/typed/model/tm_range_literal.rb,
lib/typed/runtime/parser_context.rb,
lib/typed/types/singleton_object.rb,
lib/typed/model/tm_local_var_asgn.rb,
lib/typed/types/ty_generic_object.rb,
lib/typed/model/tm_boolean_operator.rb,
lib/typed/types/ty_existential_type.rb,
lib/typed/types/ty_generic_function.rb,
lib/typed/types/ty_singleton_object.rb,
lib/typed/types/ty_top_level_object.rb,
lib/typed/model/tm_string_interpolation.rb,
lib/typed/model/tm_symbol_interpolation.rb,
lib/typed/model/tm_global_var_assignment.rb,
lib/typed/types/polymorphism/unification.rb,
lib/typed/model/tm_instance_var_assignment.rb,
lib/typed/runtime/type_signature_processor.rb,
lib/typed/types/polymorphism/type_variable.rb,
lib/typed/runtime/normalization/validations.rb,
lib/typed/types/polymorphism/generic_object.rb,
lib/typed/types/ty_generic_existential_type.rb,
lib/typed/types/ty_generic_singleton_object.rb,
lib/typed/runtime/method_signature_processor.rb,
lib/typed/types/polymorphism/generic_variables.rb,
lib/typed/types/polymorphism/generic_comparisons.rb,
lib/typed/types/polymorphism/type_variable_register.rb,
lib/typed/types/polymorphism/existential_type_variable.rb

Defined Under Namespace

Modules: Model, Runtime, TypeSignature, Types Classes: AstParser, Language, ParsingContext, TermParsingError, TypeCheckError

Constant Summary collapse

VERSION =
'0.0.20'

Instance Method Summary collapse

Instance Method Details

#dynamic_warningsObject



112
113
114
# File 'lib/typed.rb', line 112

def dynamic_warnings
  @dynamic_warnings ||= {}
end

#log(client_binding, level, message) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/typed.rb', line 122

def log(client_binding, level, message)
  client = client_binding.receiver
  client_id = if client.instance_of?(Class)
                if client.name
                  client.name
                else
                  Class.for_name(client.to_s.match(/Class:(.*)>/)[1]).name
                end
              else
                if client.class.name
                  client.class.name
                else
                  Class.for_name(client.class.to_s.match(/Class:(.*)>/)[1]).name
                end
              end
  line = client_binding.eval('__LINE__')
  file = client_binding.eval('__FILE__')
  message = "#{file}:#{line}\n  #{message}\n"
  logger('[' + client_id.gsub('::', '/') + ']').send(level, message)
end

#log_dynamic_warning(node, owner, name) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/typed.rb', line 143

def log_dynamic_warning(node, owner, name)
  if options[:dynamic_warnings]
    error = TypeCheckError.new("Error type checking function #{owner}##{name}: Cannot find function type information for owner.", node)
    print '.'.yellow
    register_dynamic_warning(error)
  end
end

#logger(client) ⇒ Object



151
152
153
154
155
156
157
# File 'lib/typed.rb', line 151

def logger(client)
  logger = Log4r::Logger[client]
  logger = Log4r::Logger.new(client) if logger.nil?
  logger.outputters = Log4r::Outputter.stdout
  set_level(logger)
  logger
end

#optionsObject



104
105
106
# File 'lib/typed.rb', line 104

def options
  @options || {}
end

#options=(options) ⇒ Object



108
109
110
# File 'lib/typed.rb', line 108

def options=(options)
  @options = options
end

#register_dynamic_warning(warning) ⇒ Object



116
117
118
119
120
# File 'lib/typed.rb', line 116

def register_dynamic_warning(warning)
  file_warnings = dynamic_warnings[$TYPECHECK_FILE] || []
  file_warnings << warning
  dynamic_warnings[$TYPECHECK_FILE] = file_warnings
end

#set_level(logger) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/typed.rb', line 159

def set_level(logger)
  logger.level = case (ENV['LOG_LEVEL'] || ENV['log_level'] || '').upcase
                 when 'DEBUG'
                   Log4r::DEBUG
                 when 'INFO'
                   Log4r::INFO
                 when 'WARN'
                   Log4r::WARN
                 when 'ERROR'
                   Log4r::ERROR
                 when 'FATAL'
                   Log4r::FATAL
                 else
                   Log4r::INFO
                 end
end