proto object
This commit is contained in:
parent
bcbafc9972
commit
3ef6812784
@ -601,7 +601,39 @@ void CgenClassTable::code_dispatchTable() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CgenClassTable::code_prototypeObject() {}
|
void CgenClassTable::code_prototypeObject() {
|
||||||
|
auto int_default = inttable.lookup_string("0");
|
||||||
|
auto str_default = stringtable.lookup_string("");
|
||||||
|
auto bool_default = &falsebool;
|
||||||
|
|
||||||
|
for (auto node : nodes) {
|
||||||
|
str << WORD << "-1\n"; // GC tag
|
||||||
|
str << node->name << PROTOBJ_SUFFIX << LABEL; // proto obj label
|
||||||
|
str << WORD << node->get_class_tag() << endl; // class tag
|
||||||
|
str << WORD << node->get_object_size() << endl; // object size
|
||||||
|
str << WORD << node->get_name() << DISPTAB_SUFFIX << endl; // dispatch ptr
|
||||||
|
for (auto attr : *node->get_attributes()) {
|
||||||
|
if (attr->type_decl == Int) {
|
||||||
|
str << WORD;
|
||||||
|
int_default->code_ref(str);
|
||||||
|
str << endl;
|
||||||
|
} else if (attr->type_decl == Bool) {
|
||||||
|
str << WORD;
|
||||||
|
bool_default->code_ref(str);
|
||||||
|
str << endl;
|
||||||
|
} else if (attr->type_decl == Str) {
|
||||||
|
str << WORD;
|
||||||
|
str_default->code_ref(str);
|
||||||
|
str << endl;
|
||||||
|
} else {
|
||||||
|
// for other types(including _prim_slot type), set to void(null pointer)
|
||||||
|
str << WORD;
|
||||||
|
str << 0;
|
||||||
|
str << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CgenClassTable::CgenClassTable(Classes classes, ostream &s) : str(s) {
|
CgenClassTable::CgenClassTable(Classes classes, ostream &s) : str(s) {
|
||||||
enterscope();
|
enterscope();
|
||||||
@ -903,11 +935,10 @@ void CgenClassTable::code() {
|
|||||||
nodes[0]->traverse_generate_object();
|
nodes[0]->traverse_generate_object();
|
||||||
// nodes[0] is the Object class
|
// nodes[0] is the Object class
|
||||||
code_dispatchTable();
|
code_dispatchTable();
|
||||||
// Add your code to emit
|
|
||||||
// - prototype objects
|
if (cgen_debug)
|
||||||
// - class_nameTab
|
cout << "coding prototype objects" << endl;
|
||||||
// - dispatch tables
|
code_prototypeObject();
|
||||||
//
|
|
||||||
|
|
||||||
if (cgen_debug)
|
if (cgen_debug)
|
||||||
cout << "coding global text" << endl;
|
cout << "coding global text" << endl;
|
||||||
|
|||||||
@ -21,6 +21,7 @@ class B inherits A {
|
|||||||
|
|
||||||
class C inherits A {
|
class C inherits A {
|
||||||
attr_C_1 : String <- "This is C\n";
|
attr_C_1 : String <- "This is C\n";
|
||||||
|
attr_C_2 : SELF_TYPE;
|
||||||
method_common(x1: Int) : SELF_TYPE {
|
method_common(x1: Int) : SELF_TYPE {
|
||||||
self
|
self
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user