node/lib/metasm/samples/dynamic_ruby.rb
# add a new ruby function to the current @cp
add a new ruby function to the current @cp
add a new ruby function to the current @cp
def declare_newtopvar(name, initializer, type=value)
		v = C::Variable.new(name, type)
		v.storage = :static
		@cp.toplevel.symbol[v.name] = v
		pos = @cp.toplevel.statements.index @cp.toplevel.statements.find { |st|
			st.kind_of? C::Declaration and st.var.type.kind_of? C::Function and st.var.initializer
		} || -1
		@cp.toplevel.statements.insert pos, C::Declaration.new(v)
		if initializer
			pos = -1
			if name =~ /^intern_/
				pos = 0
				init.statements.each { |st|
					break unless st.kind_of? C::CExpression and st.op == :'=' and st.lexpr.kind_of? C::Variable and st.lexpr.name < name
					pos += 1
				}
			end
			init.statements.insert(pos, C::CExpression[v, :'=', initializer])
		end
		v
	end
def declare_newtopvar ( name , initializer , type = value ) v = C :: Variable . new ( name , type ) v . storage = :static @cp . toplevel . symbol [ v . name ] = v pos = @cp . toplevel . statements . index @cp . toplevel . statements . find { | st | st . kind_of? C :: Declaration and st . var . type . kind_of? C :: Function and st . var . initializer } || - 1 @cp . toplevel . statements . insert pos , C :: Declaration . new ( v ) if initializer pos = - 1 if name =~ / ^intern_ / pos = 0 init . statements . each { | st | break unless st . kind_of? C :: CExpression and st . op == :' = ' and st . lexpr . kind_of? C :: Variable and st . lexpr . name < name pos += 1 } end init . statements . insert ( pos , C :: CExpression [ v , :' = ' , initializer ] ) end v end
add a new ruby function to the current @cp
add a new ruby function to the current @cp
name
initializer
type
value