1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-17 06:24:24 +03:00
inform7/inter/bytecode-module/Chapter 4/The Append Construct.w

86 lines
3.5 KiB
OpenEdge ABL
Raw Normal View History

2022-03-01 02:41:22 +02:00
[AppendInstruction::] The Append Construct.
2019-02-05 02:44:07 +02:00
Defining the append construct.
2022-03-01 02:41:22 +02:00
@h Definition.
For what this does and why it is used, see //inter: Data Packages in Textual Inter//.
But please use it as little as possible: in an ideal world it would be abolished.
2019-02-05 02:44:07 +02:00
=
2022-03-01 02:41:22 +02:00
void AppendInstruction::define_construct(void) {
inter_construct *IC = InterInstruction::create_construct(APPEND_IST, I"append");
InterInstruction::specify_syntax(IC, I"append IDENTIFIER TEXT");
2022-03-14 15:53:55 +02:00
InterInstruction::data_extent_always(IC, 2);
2022-03-01 02:41:22 +02:00
InterInstruction::permit(IC, INSIDE_PLAIN_PACKAGE_ICUP);
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, AppendInstruction::verify);
2022-03-02 02:04:54 +02:00
METHOD_ADD(IC, CONSTRUCT_TRANSPOSE_MTID, AppendInstruction::transpose);
2022-03-01 02:41:22 +02:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, AppendInstruction::read);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, AppendInstruction::write);
2019-02-05 02:44:07 +02:00
}
2022-03-02 02:04:54 +02:00
@h Instructions.
2022-03-14 00:08:41 +02:00
In bytecode, the frame of an |append| instruction is laid out with the
compulsory words -- see //Inter Nodes// -- followed by:
2019-02-05 02:44:07 +02:00
2022-03-14 00:08:41 +02:00
@d SYMBOL_APPEND_IFLD (DATA_IFLD + 0)
@d CONTENT_APPEND_IFLD (DATA_IFLD + 1)
2019-02-05 02:44:07 +02:00
=
2022-03-01 02:41:22 +02:00
inter_error_message *AppendInstruction::new(inter_bookmark *IBM, inter_symbol *S,
2022-03-02 02:04:54 +02:00
text_stream *append_text, inter_ti level, struct inter_error_location *eloc) {
2022-03-01 02:41:22 +02:00
inter_tree_node *P = Inode::new_with_2_data_fields(IBM, APPEND_IST,
2022-03-11 23:38:53 +02:00
/* SYMBOL_APPEND_IFLD: */ InterSymbolsTable::id_at_bookmark(IBM, S),
2022-03-02 02:04:54 +02:00
/* CONTENT_APPEND_IFLD: */ InterWarehouse::create_text_at(IBM, append_text),
2022-03-01 02:41:22 +02:00
eloc, level);
inter_error_message *E = VerifyingInter::instruction(InterBookmark::package(IBM), P);
if (E) return E;
NodePlacement::move_to_moving_bookmark(P, IBM);
return NULL;
}
2019-02-05 02:44:07 +02:00
2022-03-02 02:04:54 +02:00
void AppendInstruction::transpose(inter_construct *IC, inter_tree_node *P,
inter_ti *grid, inter_ti grid_extent, inter_error_message **E) {
P->W.instruction[CONTENT_APPEND_IFLD] = grid[P->W.instruction[CONTENT_APPEND_IFLD]];
}
2022-03-01 02:41:22 +02:00
@ Verification consists of sanity checks followed by some cross-referencing.
2019-02-05 02:44:07 +02:00
2022-03-01 02:41:22 +02:00
=
void AppendInstruction::verify(inter_construct *IC, inter_tree_node *P,
inter_package *owner, inter_error_message **E) {
*E = VerifyingInter::SID_field(owner, P, SYMBOL_APPEND_IFLD, INVALID_IST);
if (*E) return;
*E = VerifyingInter::text_field(owner, P, CONTENT_APPEND_IFLD);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
2022-03-01 02:41:22 +02:00
inter_symbol *S = InterSymbolsTable::symbol_from_ID_at_node(P, SYMBOL_APPEND_IFLD);
text_stream *content = Inode::ID_to_text(P, P->W.instruction[CONTENT_APPEND_IFLD]);
SymbolAnnotation::set_t(P->tree, P->package, S, APPEND_IANN, content);
2019-02-05 02:44:07 +02:00
}
2022-03-01 02:41:22 +02:00
@h Creating from textual Inter syntax.
=
void AppendInstruction::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp,
inter_error_location *eloc, inter_error_message **E) {
text_stream *identifier = ilp->mr.exp[0], *content = ilp->mr.exp[1];
2019-02-05 02:44:07 +02:00
2022-03-01 02:41:22 +02:00
inter_symbol *S = InterSymbolsTable::symbol_from_name(InterBookmark::scope(IBM), identifier);
if (S == NULL) { *E = InterErrors::quoted(I"no such identifier", identifier, eloc); return; }
2019-02-05 02:44:07 +02:00
2022-03-02 02:04:54 +02:00
TEMPORARY_TEXT(raw)
*E = TextualInter::parse_literal_text(raw, content, 0, Str::len(content), eloc);
if (*E == NULL) *E = AppendInstruction::new(IBM, S, raw, (inter_ti) ilp->indent_level, eloc);
DISCARD_TEXT(content)
2019-02-05 02:44:07 +02:00
}
2022-03-01 02:41:22 +02:00
@h Writing to textual Inter syntax.
=
2022-03-13 13:28:33 +02:00
void AppendInstruction::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P) {
2022-03-01 02:41:22 +02:00
inter_symbol *S = InterSymbolsTable::symbol_from_ID_at_node(P, SYMBOL_APPEND_IFLD);
text_stream *content = Inode::ID_to_text(P, P->W.instruction[CONTENT_APPEND_IFLD]);
WRITE("append %S ", InterSymbol::identifier(S));
TextualInter::write_text(OUT, content);
2019-02-05 02:44:07 +02:00
}