1 require "#{File.dirname(__FILE__)}/../../lib/compiler/system_hints"
5 fd = File.open("auto.h", "w")
7 puts "#include \"shotgun.h\""
9 Compiler::Bootstrap::TYPES.each do |name, klass|
12 fields = Compiler::Bootstrap::HINTS[klass] || Hash.new
14 fields.each do |field_as_ivar, field_index|
15 if field_as_ivar == :@__ivars__
16 field_name = "instance_variables"
18 field_name = field_as_ivar.to_s.gsub(/^@/,'')
20 func_name = "#{prefix.upcase}f_#{field_name.upcase}"
21 fd.puts "#define #{func_name} #{field_index}"
22 fd.puts "#define #{prefix}get_#{field_name}(obj) NTH_FIELD(obj, #{func_name})"
23 fd.puts "#define #{prefix}set_#{field_name}(obj, val) SET_FIELD(obj, #{func_name}, val)"
24 sz = field_index if field_index > sz
28 puts "OBJECT #{prefix}allocate_with_extra(STATE, int extra) {"
29 puts " return NEW_OBJECT(BASIC_CLASS(#{name}), #{sz} + extra);"
32 puts "OBJECT #{prefix}allocate_mature(STATE, int extra) {"
33 puts " return object_memory_new_object_mature(state->om, BASIC_CLASS(#{name}), #{sz} + extra);"
38 fd.puts "#define #{prefix}allocate(st) #{prefix}allocate_with_extra(st, 0)"
39 fd.puts "#define #{prefix.upcase}FIELDS #{sz}"
41 fd.puts "OBJECT #{prefix}allocate_with_extra(STATE, int extra);"
42 fd.puts "OBJECT #{prefix}allocate_mature(STATE, int extra);"
44 has_ivars = !fields[:@__ivars__].nil?
45 klasses << [name, sz, has_ivars]
48 puts "\n/* Code to create the types into classes */\n\n"
50 klasses.each do |name, sz, has_ivars|
51 fd.puts "OBJECT _#{name}_basic_class(STATE, OBJECT sup);"
52 puts "OBJECT _#{name}_basic_class(STATE, OBJECT sup) {"
54 puts " cls = class_allocate_mature(state, 0);"
55 puts " class_set_instance_fields(cls, I2N(#{sz}));"
56 puts " class_set_has_ivars(cls, #{has_ivars ? 'Qtrue' : 'Qfalse'});"
57 puts " class_set_needs_cleanup(cls, Qfalse);"
58 puts " class_set_object_type(cls, I2N(ObjectType));"
59 puts " class_set_superclass(cls, sup);"
64 fd.puts "OBJECT _#{name}_class(STATE, OBJECT sup);"
65 puts "OBJECT _#{name}_class(STATE, OBJECT sup) {"
67 puts " cls = _#{name}_basic_class(state, sup);"
68 puts " object_create_metaclass(state, cls, (OBJECT)0);"