Георги обнови решението на 15.01.2014 13:44 (преди почти 11 години)
+class Asm_functions_module
+ def method_missing (name,*args,&block)
+ name.to_s
+ end
+
+ def mov destination_register, source
+ second = if source.is_a? Proc
+ source.call
+ else
+ source
+ end
+ destination_register.call "equal",second
+ end
+
+ def inc destination_register, value
+ second = if value.is_a? Proc
+ value.call
+ else
+ value
+ end
+ destination_register.call :+.to_proc,second
+ end
+
+ def dec destination_register, value
+ second = if value.is_a? Proc
+ value.call
+ else
+ value
+ end
+ destination_register.call :-.to_proc,second
+ end
+
+ def cmp register, value
+ second = if value.is_a? Proc
+ value.call
+ else
+ value
+ end
+ register.call <=> second
+ end
+end
+
+class Asm_functions
+ attr_accessor :functions
+ def initialize
+ @ax=0
+ @bx=0
+ @cx=0
+ @dx=0
+ @functions=[]
+ end
+
+ def method_missing(name, *args, &block)
+ @functions<<[name,args]
+ end
+
+ def ax
+ Proc.new do |function, value|
+ if not function
+ @ax
+ elsif function.is_a? Proc
+ @ax = function.call @ax,value
+ else
+ @ax=value
+ end
+ end
+ end
+
+ def bx
+ Proc.new do |function, value|
+ if not function
+ @bx
+ elsif function.is_a? Proc
+ @bx = function.call @bx,value
+ else
+ @bx=value
+ end
+ end
+ end
+
+ def cx
+ Proc.new do |function, value|
+ if not function
+ @cx
+ elsif function.is_a? Proc
+ @cx = function.call @cx,value
+ else
+ @cx=value
+ end
+ end
+ end
+
+ def dx
+ Proc.new do |function, value|
+ if not function
+ @dx
+ elsif function.is_a? Proc
+ @dx = function.call @dx,value
+ else
+ @dx=value
+ end
+ end
+ end
+
+ def result
+ functions = @functions[0..-1]
+ p functions
+ Asm_functions_module.new.instance_eval do
+ functions.each do |block_line|
+ send(block_line[0],block_line[1][0],block_line[1][1])
+ end
+ end
+ [@ax,@bx,@cx,@dx]
+ end
+
+end
+
+class Asm
+ def self.asm &block
+ asm=Asm_functions.new
+ asm.instance_eval &block
+ p asm.result
+ end
+end