1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-08 01:54:21 +03:00
inform7/inter/bytecode-module/Chapter 6/The Socket Construct.w

82 lines
3 KiB
OpenEdge ABL
Raw Normal View History

2022-03-01 02:41:22 +02:00
[SocketInstruction::] The Socket Construct.
2022-02-11 12:48:26 +02:00
Defining the socket construct.
@
=
2022-03-01 02:41:22 +02:00
void SocketInstruction::define_construct(void) {
inter_construct *IC = InterInstruction::create_construct(SOCKET_IST, I"socket");
InterInstruction::specify_syntax(IC, I"socket IDENTIFIER TOKENS");
METHOD_ADD(IC, CONSTRUCT_READ_MTID, SocketInstruction::read);
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, SocketInstruction::verify);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, SocketInstruction::write);
InterInstruction::allow_in_depth_range(IC, 0, 1);
InterInstruction::permit(IC, INSIDE_PLAIN_PACKAGE_ICUP);
2022-02-11 12:48:26 +02:00
}
2022-03-01 02:41:22 +02:00
void SocketInstruction::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
inter_package *routine = InterBookmark::package(IBM);
2022-02-11 12:48:26 +02:00
text_stream *symbol_name = ilp->mr.exp[0];
text_stream *equate_name = NULL;
match_results mr2 = Regexp::create_mr();
if (Regexp::match(&mr2, ilp->mr.exp[1], L"~~> \"(%C+)\"")) {
*E = InterErrors::plain(I"a socket cannot wire to a name", eloc); return;
2022-02-11 12:48:26 +02:00
} else if (Regexp::match(&mr2, ilp->mr.exp[1], L"~~> (%C+)")) {
equate_name = mr2.exp[0];
} else {
*E = InterErrors::plain(I"bad socket syntax", eloc); return;
2022-02-11 12:48:26 +02:00
}
inter_symbol *name_name = NULL;
inter_ti level = 0;
if (routine) {
inter_symbols_table *locals = InterPackage::scope(routine);
if (locals == NULL) { *E = InterErrors::plain(I"function has no symbols table", eloc); return; }
2022-02-11 12:48:26 +02:00
name_name = TextualInter::new_symbol(eloc, locals, symbol_name, E);
if (*E) return;
inter_symbol *eq = InterSymbolsTable::URL_to_symbol(InterBookmark::tree(IBM), equate_name);
if (eq == NULL) eq = InterSymbolsTable::symbol_from_name(InterBookmark::scope(IBM), equate_name);
if (eq == NULL) {
InterSymbol::make_socket(name_name);
Wiring::wire_to_name(name_name, equate_name);
} else {
Wiring::make_socket_to(name_name, eq);
}
level = (inter_ti) ilp->indent_level;
} else {
*E = InterErrors::plain(I"sockets can exist only in the connectors package", eloc); return;
2022-02-11 12:48:26 +02:00
}
}
2022-03-01 02:41:22 +02:00
void SocketInstruction::verify(inter_construct *IC, inter_tree_node *P, inter_package *owner, inter_error_message **E) {
2022-02-11 12:48:26 +02:00
internal_error("SOCKET_IST structures cannot exist");
}
2022-03-01 02:41:22 +02:00
void SocketInstruction::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
2022-02-11 12:48:26 +02:00
internal_error("SOCKET_IST structures cannot exist");
}
@ The following writes a valid line of textual Inter to declare a plug or socket,
appearing at level |N| in the hierarchy.
=
2022-03-01 02:41:22 +02:00
void SocketInstruction::write_declaration(OUTPUT_STREAM, inter_symbol *S, int N) {
2022-02-11 12:48:26 +02:00
for (int L=0; L<N; L++) WRITE("\t");
switch (InterSymbol::get_type(S)) {
case PLUG_ISYMT: WRITE("plug"); break;
case SOCKET_ISYMT: WRITE("socket"); break;
default: internal_error("not a connector"); break;
}
WRITE(" %S", InterSymbol::identifier(S));
2022-02-11 12:48:26 +02:00
if (Wiring::is_wired_to_name(S)) {
WRITE(" ~~> \"%S\"", Wiring::wired_to_name(S));
} else if (Wiring::is_wired(S)) {
WRITE(" ~~> ");
InterSymbolsTable::write_symbol_URL(OUT, Wiring::wired_to(S));
} else {
WRITE(" ?");
}
}