2022-03-01 02:41:22 +02:00
|
|
|
[PlugInstruction::] The Plug Construct.
|
2022-02-11 12:48:26 +02:00
|
|
|
|
|
|
|
Defining the symbol construct.
|
|
|
|
|
2022-03-13 13:28:33 +02:00
|
|
|
@ This is a pseudo-construct: it looks like an instruction in textual Inter
|
|
|
|
syntax, but specifies something else, and does not result in an |inter_tree_node|.
|
2022-02-11 12:48:26 +02:00
|
|
|
|
|
|
|
=
|
2022-03-01 02:41:22 +02:00
|
|
|
void PlugInstruction::define_construct(void) {
|
|
|
|
inter_construct *IC = InterInstruction::create_construct(PLUG_IST, I"plug");
|
|
|
|
InterInstruction::specify_syntax(IC, I"plug IDENTIFIER TOKENS");
|
|
|
|
METHOD_ADD(IC, CONSTRUCT_READ_MTID, PlugInstruction::read);
|
|
|
|
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, PlugInstruction::verify);
|
|
|
|
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-13 13:28:33 +02:00
|
|
|
void PlugInstruction::verify(inter_construct *IC, inter_tree_node *P,
|
|
|
|
inter_package *owner, inter_error_message **E) {
|
|
|
|
*E = Inode::error(P, I"PLUG_IST structures cannot exist", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ What it does is to specify a symbol which is a plug in the current tree:
|
|
|
|
this results in an entry in the symbols table for the current package (which
|
|
|
|
will always be |/main/connectors|, in fact) but not an instruction.
|
|
|
|
|
|
|
|
Surprisingly, this can actually result in a socket rather than a plug, but
|
|
|
|
only in the case where the plug asks to wire to something existing in the current
|
|
|
|
tree already.
|
|
|
|
|
|
|
|
=
|
|
|
|
void PlugInstruction::read(inter_construct *IC, inter_bookmark *IBM,
|
|
|
|
inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
|
|
|
|
text_stream *symbol_text = ilp->mr.exp[0];
|
|
|
|
text_stream *equate_text = ilp->mr.exp[1];
|
|
|
|
|
|
|
|
inter_tree *I = InterBookmark::tree(IBM);
|
|
|
|
inter_symbols_table *T = InterBookmark::scope(IBM);
|
|
|
|
inter_symbol *plug_s = TextualInter::new_symbol(eloc, T, symbol_text, E);
|
|
|
|
if (*E) return;
|
|
|
|
InterSymbol::make_plug(plug_s);
|
2022-02-11 12:48:26 +02:00
|
|
|
|
|
|
|
text_stream *equate_name = NULL;
|
|
|
|
int to_name = FALSE;
|
2022-03-13 13:28:33 +02:00
|
|
|
match_results mr = Regexp::create_mr();
|
|
|
|
if (Regexp::match(&mr, equate_text, L"~~> \"(%C+)\"")) {
|
|
|
|
equate_name = mr.exp[0];
|
2022-02-11 12:48:26 +02:00
|
|
|
to_name = TRUE;
|
2022-03-13 13:28:33 +02:00
|
|
|
} else if (Regexp::match(&mr, equate_text, L"~~> (%C+)")) {
|
|
|
|
equate_name = mr.exp[0];
|
2022-02-11 12:48:26 +02:00
|
|
|
} else {
|
2022-03-13 13:28:33 +02:00
|
|
|
Regexp::dispose_of(&mr);
|
2022-03-01 00:24:58 +02:00
|
|
|
*E = InterErrors::plain(I"bad plug syntax", eloc); return;
|
2022-02-11 12:48:26 +02:00
|
|
|
}
|
|
|
|
|
2022-03-13 13:28:33 +02:00
|
|
|
if (to_name) {
|
|
|
|
Wiring::make_plug_wanting_identifier(plug_s, equate_name);
|
2022-02-11 12:48:26 +02:00
|
|
|
} else {
|
2022-03-13 13:28:33 +02:00
|
|
|
inter_symbol *eq_s = InterSymbolsTable::URL_to_symbol(I, equate_name);
|
|
|
|
if (eq_s == NULL) Wiring::wire_to_name(plug_s, equate_name);
|
|
|
|
else Wiring::make_socket_to(plug_s, eq_s);
|
2022-02-11 12:48:26 +02:00
|
|
|
}
|
2022-03-13 13:28:33 +02:00
|
|
|
Regexp::dispose_of(&mr);
|
2022-02-11 12:48:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@ 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 PlugInstruction::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;
|
|
|
|
}
|
2022-02-14 01:44:50 +02:00
|
|
|
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(" ?");
|
|
|
|
}
|
|
|
|
}
|