1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-05 16:44:21 +03:00
inform7/inter/inter-module/Chapter 4/The Instance Construct.w

124 lines
5.3 KiB
OpenEdge ABL
Raw Normal View History

2019-02-05 02:44:07 +02:00
[Inter::Instance::] The Instance Construct.
Defining the instance construct.
@
@e INSTANCE_IST
=
void Inter::Instance::define(void) {
2019-07-09 08:45:46 +03:00
inter_construct *IC = Inter::Defn::create_construct(
2019-02-05 02:44:07 +02:00
INSTANCE_IST,
L"instance (%i+) (%c+)",
I"instance", I"instances");
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Instance::read);
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, Inter::Instance::verify);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Instance::write);
2019-02-05 02:44:07 +02:00
}
@
@d DEFN_INST_IFLD 2
@d KIND_INST_IFLD 3
@d VAL1_INST_IFLD 4
@d VAL2_INST_IFLD 5
@d PLIST_INST_IFLD 6
@d PERM_LIST_INST_IFLD 7
@d EXTENT_INST_IFR 8
=
2019-07-14 12:44:07 +03:00
void Inter::Instance::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
*E = Inter::Defn::vet_level(IBM, INSTANCE_IST, ilp->indent_level, eloc);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
2019-07-09 08:45:46 +03:00
if (ilp->no_annotations > 0) { *E = Inter::Errors::plain(I"__annotations are not allowed", eloc); return; }
2019-02-05 02:44:07 +02:00
text_stream *ktext = ilp->mr.exp[1], *vtext = NULL;
match_results mr2 = Regexp::create_mr();
if (Regexp::match(&mr2, ktext, L"(%i+) = (%c+)")) { ktext = mr2.exp[0]; vtext = mr2.exp[1]; }
2019-07-14 12:44:07 +03:00
inter_symbol *inst_name = Inter::Textual::new_symbol(eloc, Inter::Bookmarks::scope(IBM), ilp->mr.exp[0], E);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-07-23 01:34:28 +03:00
inter_symbol *inst_kind = Inter::Textual::find_symbol(Inter::Bookmarks::tree(IBM), eloc, Inter::Bookmarks::scope(IBM), ktext, KIND_IST, E);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
inter_data_type *idt = Inter::Kind::data_type(inst_kind);
if (Inter::Types::is_enumerated(idt) == FALSE)
2019-07-09 08:45:46 +03:00
{ *E = Inter::Errors::quoted(I"not a kind which has instances", ilp->mr.exp[1], eloc); return; }
2019-02-05 02:44:07 +02:00
inter_t v1 = UNDEF_IVAL, v2 = 0;
if (vtext) {
2019-07-23 01:34:28 +03:00
*E = Inter::Types::read(ilp->line, eloc, Inter::Bookmarks::tree(IBM), Inter::Bookmarks::package(IBM), NULL, vtext, &v1, &v2, Inter::Bookmarks::scope(IBM));
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
}
2019-07-14 12:44:07 +03:00
*E = Inter::Instance::new(IBM, Inter::SymbolsTables::id_from_IRS_and_symbol(IBM, inst_name), Inter::SymbolsTables::id_from_IRS_and_symbol(IBM, inst_kind), v1, v2, (inter_t) ilp->indent_level, eloc);
2019-02-05 02:44:07 +02:00
}
2019-07-14 12:44:07 +03:00
inter_error_message *Inter::Instance::new(inter_bookmark *IBM, inter_t SID, inter_t KID, inter_t V1, inter_t V2, inter_t level, inter_error_location *eloc) {
2019-07-23 01:34:28 +03:00
inter_frame P = Inter::Frame::fill_6(IBM, INSTANCE_IST, SID, KID, V1, V2, Inter::create_frame_list(Inter::Bookmarks::tree(IBM)), Inter::create_frame_list(Inter::Bookmarks::tree(IBM)), eloc, level);
2019-07-14 12:44:07 +03:00
inter_error_message *E = Inter::Defn::verify_construct(Inter::Bookmarks::package(IBM), P);
2019-02-05 02:44:07 +02:00
if (E) return E;
2019-07-14 12:44:07 +03:00
Inter::Frame::insert(P, IBM);
2019-02-05 02:44:07 +02:00
return NULL;
}
void Inter::Instance::verify(inter_construct *IC, inter_frame P, inter_package *owner, inter_error_message **E) {
2019-07-09 08:45:46 +03:00
if (P.extent != EXTENT_INST_IFR) { *E = Inter::Frame::error(&P, I"extent wrong", NULL); return; }
*E = Inter__Verify__defn(owner, P, DEFN_INST_IFLD); if (*E) return;
inter_symbol *inst_name = Inter::SymbolsTables::symbol_from_id(Inter::Packages::scope(owner), P.data[DEFN_INST_IFLD]);
*E = Inter::Verify::symbol(owner, P, P.data[KIND_INST_IFLD], KIND_IST); if (*E) return;
inter_symbol *inst_kind = Inter::SymbolsTables::symbol_from_id(Inter::Packages::scope(owner), P.data[KIND_INST_IFLD]);
2019-02-05 02:44:07 +02:00
inter_data_type *idt = Inter::Kind::data_type(inst_kind);
if (Inter::Types::is_enumerated(idt)) {
if (P.data[VAL1_INST_IFLD] == UNDEF_IVAL) {
P.data[VAL1_INST_IFLD] = LITERAL_IVAL;
P.data[VAL2_INST_IFLD] = Inter::Kind::next_enumerated_value(inst_kind);
}
2019-07-09 08:45:46 +03:00
} else { *E = Inter::Frame::error(&P, I"not a kind which has instances", NULL); return; }
*E = Inter::Verify::value(owner, P, VAL1_INST_IFLD, inst_kind); if (*E) return;
2019-02-05 02:44:07 +02:00
inter_t vcount = P.repo_segment->bytecode[P.index + PREFRAME_VERIFICATION_COUNT]++;
if (vcount == 0) {
Inter::Kind::new_instance(inst_kind, inst_name);
}
2019-02-05 02:44:07 +02:00
}
inter_t Inter::Instance::permissions_list(inter_symbol *kind_symbol) {
if (kind_symbol == NULL) return 0;
inter_frame D = Inter::Symbols::defining_frame(kind_symbol);
if (Inter::Frame::valid(&D) == FALSE) return 0;
return D.data[PERM_LIST_INST_IFLD];
}
2019-07-09 08:45:46 +03:00
void Inter::Instance::write(inter_construct *IC, OUTPUT_STREAM, inter_frame P, inter_error_message **E) {
2019-02-05 02:44:07 +02:00
inter_symbol *inst_name = Inter::SymbolsTables::symbol_from_frame_data(P, DEFN_INST_IFLD);
inter_symbol *inst_kind = Inter::SymbolsTables::symbol_from_frame_data(P, KIND_INST_IFLD);
if ((inst_name) && (inst_kind)) {
inter_data_type *idt = Inter::Kind::data_type(inst_kind);
if (idt) {
WRITE("instance %S %S = ", inst_name->symbol_name, inst_kind->symbol_name);
Inter::Types::write(OUT, &P, NULL,
2019-02-05 02:44:07 +02:00
P.data[VAL1_INST_IFLD], P.data[VAL2_INST_IFLD], Inter::Packages::scope_of(P), FALSE);
2019-07-09 08:45:46 +03:00
} else { *E = Inter::Frame::error(&P, I"instance with bad data type", NULL); return; }
} else { *E = Inter::Frame::error(&P, I"bad instance", NULL); return; }
Inter::Symbols::write_annotations(OUT, &P, inst_name);
2019-02-05 02:44:07 +02:00
}
inter_t Inter::Instance::properties_list(inter_symbol *inst_name) {
if (inst_name == NULL) return 0;
inter_frame D = Inter::Symbols::defining_frame(inst_name);
if (Inter::Frame::valid(&D) == FALSE) return 0;
return D.data[PLIST_INST_IFLD];
}
inter_symbol *Inter::Instance::kind_of(inter_symbol *inst_name) {
if (inst_name == NULL) return NULL;
inter_frame D = Inter::Symbols::defining_frame(inst_name);
if (Inter::Frame::valid(&D) == FALSE) return NULL;
if (D.data[ID_IFLD] != INSTANCE_IST) return NULL;
return Inter::SymbolsTables::symbol_from_frame_data(D, KIND_INST_IFLD);
}