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

136 lines
6.1 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) {
inter_construct *IC = InterConstruct::create_construct(INSTANCE_IST, I"instance");
InterConstruct::specify_syntax(IC, I"instance IDENTIFIER TOKENS");
InterConstruct::permit(IC, INSIDE_PLAIN_PACKAGE_ICUP);
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Instance::read);
METHOD_ADD(IC, CONSTRUCT_TRANSPOSE_MTID, Inter::Instance::transpose);
2019-07-09 08:45:46 +03:00
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) {
2022-02-09 12:33:49 +02:00
*E = InterConstruct::check_level_in_package(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
if (SymbolAnnotation::nonempty(&(ilp->set))) { *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]; }
inter_symbol *inst_name = TextualInter::new_symbol(eloc, InterBookmark::scope(IBM), ilp->mr.exp[0], E);
2019-07-09 08:45:46 +03:00
if (*E) return;
2022-02-11 12:48:26 +02:00
inter_symbol *inst_kind = TextualInter::find_symbol(IBM, eloc, 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
2020-07-01 02:58:55 +03:00
inter_ti v1 = UNDEF_IVAL, v2 = 0;
2019-02-05 02:44:07 +02:00
if (vtext) {
2022-02-18 11:32:46 +02:00
*E = Inter::Types::read_data_pair(ilp->line, eloc, IBM, Inter::Types::untyped(), vtext, &v1, &v2, InterBookmark::scope(IBM));
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
}
2022-02-03 17:51:44 +02:00
*E = Inter::Instance::new(IBM, InterSymbolsTable::id_from_symbol_at_bookmark(IBM, inst_name), InterSymbolsTable::id_from_symbol_at_bookmark(IBM, inst_kind), v1, v2, (inter_ti) ilp->indent_level, eloc);
2019-02-05 02:44:07 +02:00
}
2020-07-01 02:58:55 +03:00
inter_error_message *Inter::Instance::new(inter_bookmark *IBM, inter_ti SID, inter_ti KID, inter_ti V1, inter_ti V2, inter_ti level, inter_error_location *eloc) {
2022-01-27 01:59:02 +02:00
inter_warehouse *warehouse = InterBookmark::warehouse(IBM);
2022-01-30 15:32:38 +02:00
inter_ti L1 = InterWarehouse::create_node_list(warehouse, InterBookmark::package(IBM));
inter_ti L2 = InterWarehouse::create_node_list(warehouse, InterBookmark::package(IBM));
2022-01-28 01:38:14 +02:00
inter_tree_node *P = Inode::new_with_6_data_fields(IBM, INSTANCE_IST, SID, KID, V1, V2, L1, L2, eloc, level);
2022-02-07 00:33:07 +02:00
inter_error_message *E = InterConstruct::verify_construct(InterBookmark::package(IBM), P);
2019-02-05 02:44:07 +02:00
if (E) return E;
2022-01-27 01:59:02 +02:00
NodePlacement::move_to_moving_bookmark(P, IBM);
2019-02-05 02:44:07 +02:00
return NULL;
}
2020-07-01 02:58:55 +03:00
void Inter::Instance::transpose(inter_construct *IC, inter_tree_node *P, inter_ti *grid, inter_ti grid_extent, inter_error_message **E) {
2022-01-30 15:32:38 +02:00
P->W.instruction[PLIST_INST_IFLD] = grid[P->W.instruction[PLIST_INST_IFLD]];
P->W.instruction[PERM_LIST_INST_IFLD] = grid[P->W.instruction[PERM_LIST_INST_IFLD]];
}
2019-07-24 20:15:07 +03:00
void Inter::Instance::verify(inter_construct *IC, inter_tree_node *P, inter_package *owner, inter_error_message **E) {
2020-05-11 17:21:29 +03:00
if (P->W.extent != EXTENT_INST_IFR) { *E = Inode::error(P, I"extent wrong", NULL); return; }
*E = Inter::Verify::defn(owner, P, DEFN_INST_IFLD); if (*E) return;
2022-02-03 17:51:44 +02:00
inter_symbol *inst_name = InterSymbolsTable::symbol_from_ID(InterPackage::scope(owner), P->W.instruction[DEFN_INST_IFLD]);
2022-01-30 15:32:38 +02:00
*E = Inter::Verify::symbol(owner, P, P->W.instruction[KIND_INST_IFLD], KIND_IST); if (*E) return;
2022-02-03 17:51:44 +02:00
inter_symbol *inst_kind = InterSymbolsTable::symbol_from_ID(InterPackage::scope(owner), P->W.instruction[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)) {
2022-01-30 15:32:38 +02:00
if (P->W.instruction[VAL1_INST_IFLD] == UNDEF_IVAL) {
P->W.instruction[VAL1_INST_IFLD] = LITERAL_IVAL;
P->W.instruction[VAL2_INST_IFLD] = Inter::Kind::next_enumerated_value(inst_kind);
2019-02-05 02:44:07 +02:00
}
2020-05-11 17:21:29 +03:00
} else { *E = Inode::error(P, I"not a kind which has instances", NULL); return; }
2022-02-18 11:32:46 +02:00
*E = Inter::Types::validate_pair(owner, P, VAL1_INST_IFLD, Inter::Types::from_symbol(inst_kind)); if (*E) return;
2019-02-05 02:44:07 +02:00
2022-01-29 02:21:23 +02:00
inter_ti vcount = Inode::bump_verification_count(P);
if (vcount == 0) {
Inter::Kind::new_instance(inst_kind, inst_name);
}
2019-02-05 02:44:07 +02:00
}
2020-07-01 02:58:55 +03:00
inter_ti Inter::Instance::permissions_list(inter_symbol *kind_symbol) {
2019-02-05 02:44:07 +02:00
if (kind_symbol == NULL) return 0;
inter_tree_node *D = InterSymbol::definition(kind_symbol);
if (D == NULL) return 0;
2022-01-30 15:32:38 +02:00
return D->W.instruction[PERM_LIST_INST_IFLD];
2019-02-05 02:44:07 +02:00
}
2019-07-24 20:15:07 +03:00
void Inter::Instance::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
2022-02-03 17:51:44 +02:00
inter_symbol *inst_name = InterSymbolsTable::symbol_from_ID_at_node(P, DEFN_INST_IFLD);
inter_symbol *inst_kind = InterSymbolsTable::symbol_from_ID_at_node(P, KIND_INST_IFLD);
2019-02-05 02:44:07 +02:00
if ((inst_name) && (inst_kind)) {
inter_data_type *idt = Inter::Kind::data_type(inst_kind);
if (idt) {
WRITE("instance %S %S = ", InterSymbol::identifier(inst_name), InterSymbol::identifier(inst_kind));
2022-02-17 12:38:00 +02:00
Inter::Types::write_pair(OUT, P,
2022-01-31 01:49:12 +02:00
P->W.instruction[VAL1_INST_IFLD], P->W.instruction[VAL2_INST_IFLD], InterPackage::scope_of(P), FALSE);
2020-05-11 17:21:29 +03:00
} else { *E = Inode::error(P, I"instance with bad data type", NULL); return; }
} else { *E = Inode::error(P, I"bad instance", NULL); return; }
SymbolAnnotation::write_annotations(OUT, P, inst_name);
2019-02-05 02:44:07 +02:00
}
2020-07-01 02:58:55 +03:00
inter_ti Inter::Instance::properties_list(inter_symbol *inst_name) {
2019-02-05 02:44:07 +02:00
if (inst_name == NULL) return 0;
inter_tree_node *D = InterSymbol::definition(inst_name);
if (D == NULL) return 0;
2022-01-30 15:32:38 +02:00
return D->W.instruction[PLIST_INST_IFLD];
2019-02-05 02:44:07 +02:00
}
inter_type Inter::Instance::type_of(inter_symbol *inst_name) {
if (inst_name == NULL) return Inter::Types::untyped();
inter_tree_node *D = InterSymbol::definition(inst_name);
if (D == NULL) return Inter::Types::untyped();
if (D->W.instruction[ID_IFLD] != INSTANCE_IST) return Inter::Types::untyped();
return Inter::Types::from_symbol(InterSymbolsTable::symbol_from_ID_at_node(D, KIND_INST_IFLD));
}
inter_symbol *Inter::Instance::kind_of(inter_symbol *inst_name) {
return Inter::Types::conceptual_type(Inter::Instance::type_of(inst_name));
2019-02-05 02:44:07 +02:00
}