node/lib/metasm/samples/dynamic_ruby.rb
def compile_args_m2(func, args)
		v = C::Variable.new("arglist", value)
		@scope.symbol[v.name] = v
		func.type.args << v

		args[1].times { |i|
			local(i+2, fcall('rb_ary_shift', v))
		}

		# populate arguments with default values
		if args[2]
			# [:block, [:lasgn, 2, [:lit, 4]]]
			raise Fail, "unhandled vararglist #{args.inspect}" if args[2][0] != :block
			args[2][1..-1].each { |a|
				raise Fail, "unhandled arg #{a.inspect}" if a[0] != :lasgn
				t = C::CExpression[local(a[1], :none), :'=', fcall('rb_ary_shift', v)]
				e = C::Block.new(@scope)
				ast_to_c([:lasgn, a[1], a[2]], e, false)
				@scope.statements << C::If.new(rb_ary_len(v), t, e)
			}
		end

		if args[3]
			raise Fail, "unhandled vararglist3 #{args.inspect}" if args[3][0] != :lasgn
			local(args[3][1], C::CExpression[v])
		end
	end
# update func prototype to reflect arity -2
# VALUE func(VALUE self, VALUE arg_array)
update func prototype to reflect arity -2
VALUE func(VALUE self, VALUE arg_array)
update func prototype to reflect arity - 2 VALUE func ( VALUE self VALUE arg_array )
def compile_args_m2(func, args)
		v = C::Variable.new("arglist", value)
		@scope.symbol[v.name] = v
		func.type.args << v
		args[1].times { |i|
			local(i+2, fcall('rb_ary_shift', v))
		}
		if args[2]
			raise Fail, "unhandled vararglist #{args.inspect}" if args[2][0] != :block
			args[2][1..-1].each { |a|
				raise Fail, "unhandled arg #{a.inspect}" if a[0] != :lasgn
				t = C::CExpression[local(a[1], :none), :'=', fcall('rb_ary_shift', v)]
				e = C::Block.new(@scope)
				ast_to_c([:lasgn, a[1], a[2]], e, false)
				@scope.statements << C::If.new(rb_ary_len(v), t, e)
			}
		end
		if args[3]
			raise Fail, "unhandled vararglist3 #{args.inspect}" if args[3][0] != :lasgn
			local(args[3][1], C::CExpression[v])
		end
	end
def compile_args_m2 ( func , args ) v = C :: Variable . new ( "arglist" , value ) @scope . symbol [ v . name ] = v func . type . args << v args [ 1 ] . times { | i | local ( i + 2 , fcall ( 'rb_ary_shift' , v ) ) } if args [ 2 ] raise Fail , "unhandled vararglist #{args.inspect}" if args [ 2 ] [ 0 ] != :block args [ 2 ] [ 1 .. - 1 ] . each { | a | raise Fail , "unhandled arg #{a.inspect}" if a [ 0 ] != :lasgn t = C :: CExpression [ local ( a [ 1 ] , :none ) , :' = ' , fcall ( 'rb_ary_shift' , v ) ] e = C :: Block . new ( @scope ) ast_to_c ( [ :lasgn , a [ 1 ] , a [ 2 ] ] , e , false ) @scope . statements << C :: If . new ( rb_ary_len ( v ) , t , e ) } end if args [ 3 ] raise Fail , "unhandled vararglist3 #{args.inspect}" if args [ 3 ] [ 0 ] != :lasgn local ( args [ 3 ] [ 1 ] , C :: CExpression [ v ] ) end end
update func prototype to reflect arity -2
VALUE func(VALUE self, VALUE arg_array)
update func prototype to reflect arity - 2 VALUE func ( VALUE self VALUE arg_array )
# populate arguments with default values # [:block, [:lasgn, 2, [:lit, 4]]]
func
args