Class: Object

Inherits:
BasicObject
Defined in:
lib/wilson.rb,
lib/wilson.rb

Constant Summary collapse

@@asm =
{}

Instance Method Summary collapse

Instance Method Details

#asm(name, *args, &block) ⇒ Object



1225
1226
1227
1228
1229
# File 'lib/wilson.rb', line 1225

def asm(name, *args, &block)
  code = @@asm[name] ||= assemble(&block).to_ptr

  return execute_asm(code) # code is the function pointer, wrapped
end

#assemble(arg_count = 0, &block) ⇒ Object



1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
# File 'lib/wilson.rb', line 1188

def assemble arg_count = 0, &block
  asm = Wilson::MachineCodeX86.new

  # TODO: enter?
  asm.ebp.push
  asm.ebp.mov asm.esp

  size = asm.stream.size

  asm.instance_eval(&block)

  if asm.stream.size == size  # return nil
    warn "returning nil for #{self}##{name}"
    asm.eax.mov 4
  end

  asm.leave
  asm.ret

  code = asm.stream.pack("C*")

  if $DEBUG then
    path = "#{$$}.obj"
    File.open path, "wb" do |f|
      f.write code
    end

    puts code.unpack("C*").map { |n| "%02X" % n }.join(' ')
    system "ndisasm -u #{path}"

    File.unlink path
  end

  code
end

#no!Object Also known as: address?, future_label?, immediate?, immediate_value?, label?, offset?, operand?, register?, special_register?



8
# File 'lib/wilson.rb', line 8

def no!; false end

#subclass_responsibilityObject



7
# File 'lib/wilson.rb', line 7

def subclass_responsibility; raise "subclass responsibility" end