Module: ClassHDL::AssignDefOpertor
- Included in:
- HDLFunctionIvoke, StructVar, Clock, Integer, Logic, NqString, Numeric, Reset, String, TdlSpace::ArrayChain
- Defined in:
- lib/tdl/class_hdl/hdl_redefine_opertor.rb
Constant Summary collapse
- OP_SYMBOLS =
OP_SYMBOLS = %w- * / % > < >= <= == != << | &
ClassHDL::OP_SYMBOLS
- @@included_class =
[]
- @@curr_assign_block =
HDLAssignBlock ##HDLAlwaysCombBlock
HDLAssignBlock.new
- @@curr_assign_block_stack =
[HDLAssignBlock.new ]
- @@curr_opertor_stack =
[:old]
Class Method Summary collapse
- .curr_assign_block ⇒ Object
- .curr_assign_block=(b) ⇒ Object
- .curr_assign_block_stack ⇒ Object
- .curr_opertor_stack ⇒ Object
- .included(mod) ⇒ Object
- .init_op_methods(aclass) ⇒ Object
- .use_new_yield_opertors ⇒ Object
- .use_old_cond_opertors ⇒ Object
- .with_new_assign_block(na, &block) ⇒ Object
- .with_new_opertor(&block) ⇒ Object
- .with_normal_opertor(&block) ⇒ Object
- .with_rollback_opertors(use_op, &block) ⇒ Object
Class Method Details
.curr_assign_block ⇒ Object
214 215 216 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 214 def self.curr_assign_block @@curr_assign_block end |
.curr_assign_block=(b) ⇒ Object
218 219 220 221 222 223 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 218 def self.curr_assign_block=(b) unless b raise TdlError.new('Assign Block cant be nil') end @@curr_assign_block = b end |
.curr_assign_block_stack ⇒ Object
225 226 227 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 225 def self.curr_assign_block_stack @@curr_assign_block_stack end |
.curr_opertor_stack ⇒ Object
210 211 212 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 210 def self.curr_opertor_stack @@curr_opertor_stack end |
.included(mod) ⇒ Object
245 246 247 248 249 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 245 def self.included(mod) @@included_class.push mod mod.extend self init_op_methods(mod) end |
.init_op_methods(aclass) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 251 def self.init_op_methods(aclass) # if aclass.methods.include? :inst # class_inst = aclass.nc_create # else # class_inst = aclass.new # end aclass.class_eval do def operation_tow(symb,b) # puts "aclass #{symb} #{b.class}" if b.is_a? OpertorChain b.slaver = true end new_op = OpertorChain.new new_op.tree.push([self]) new_op.tree.push([b,symb]) if @@curr_assign_block @@curr_assign_block.opertor_chains.push(new_op) else raise TdlError.new("operation_tow[#{symb}] <#{b}> Error: curr_assign_block is nil ") end return new_op end ClassHDL::OP_SYMBOLS.each do |symb| # if class_inst.respond_to?(symb) if self.instance_methods.include?(symb.to_sym) alias_method "_old_#{symb}__",symb else define_method("_old_#{symb}__") do |b| operation_tow(symb,b) end end ## define new define_method("_new_#{symb}__") do |b| operation_tow(symb,b) end end ## 定义片选 def new_slice_cc(*a) if a.size == 1 if a[0].is_a? Range "#{self}[#{a[0].first}:#{a[1].last}]".to_nq else "#{self}[#{a[0]}]".to_nq end else "#{self}[#{a[0]}:#{a[1]}]".to_nq end end if self.instance_methods.include?("[]".to_sym) alias_method "_old_slice_","[]" else alias_method "_old_slice_","new_slice_cc" end end end |
.use_new_yield_opertors ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 316 def self.use_new_yield_opertors # NqString.class_exec do # define_method("+") do |a| # "+++++" # end # end @@included_class.each do |oc| oc.class_eval do ClassHDL::OP_SYMBOLS.each do |symb| # if symb.eql? "<=" # alias_method symb,:_assign_small_and_eq # # define_method(symb,instance_method(:_assign_small_and_eq)) # else # alias_method symb,"_new_#{symb}__" # # define_method(symb,instance_method("_new_#{symb}__")) # end alias_method symb,"_new_#{symb}__" # define_method(symb,instance_method("_new_#{symb}__")) ## 测试用 # define_method(symb) do |a| # "+++++++" # end end end end end |
.use_old_cond_opertors ⇒ Object
344 345 346 347 348 349 350 351 352 353 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 344 def self.use_old_cond_opertors ClassHDL::OP_SYMBOLS.each do |symb| @@included_class.each do |oc| oc.class_eval do alias_method symb,"_old_#{symb}__" # define_method(symb,instance_method("_old_#{symb}__")) end end end end |
.with_new_assign_block(na, &block) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 229 def self.with_new_assign_block(na,&block) unless na raise TdlError.new('Assign Block cant be nil') end @@curr_assign_block = na @@curr_assign_block_stack.push(na) rels = yield(na) @@curr_assign_block_stack.pop @@curr_assign_block = @@curr_assign_block_stack.last rels end |
.with_new_opertor(&block) ⇒ Object
378 379 380 381 382 383 384 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 378 def self.with_new_opertor(&block) use_new_yield_opertors @@curr_opertor_stack.push :new rels = yield @@curr_opertor_stack.pop rels end |
.with_normal_opertor(&block) ⇒ Object
386 387 388 389 390 391 392 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 386 def self.with_normal_opertor(&block) use_old_cond_opertors @@curr_opertor_stack.push :old rels = yield @@curr_opertor_stack.pop rels end |
.with_rollback_opertors(use_op, &block) ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 355 def self.with_rollback_opertors(use_op,&block) case(use_op) when :new rels = with_new_opertor(&block) when :old rels = with_normal_opertor(&block) else end case(@@curr_opertor_stack.last) when :new use_new_yield_opertors when :old use_old_cond_opertors else use_old_cond_opertors end rels end |