1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-05 16:44:21 +03:00
inform7/inter/pipeline-module/Chapter 5/Synoptic Utilities.w

147 lines
5.1 KiB
OpenEdge ABL
Raw Normal View History

[Synoptic::] Synoptic Utilities.
2022-01-05 01:10:34 +02:00
Utility functions for generating the code in the synoptic module.
2022-01-05 01:10:34 +02:00
@h Dealing with symbols.
We are going to need to read and write these: for reading --
=
2022-01-05 01:10:34 +02:00
inter_symbol *Synoptic::get_symbol(inter_package *pack, text_stream *name) {
inter_symbol *loc_s =
2022-02-03 17:51:44 +02:00
InterSymbolsTable::symbol_from_name(InterPackage::scope(pack), name);
2022-01-05 01:10:34 +02:00
if (loc_s == NULL) Metadata::err("package symbol not found", pack, name);
return loc_s;
}
2022-01-05 01:10:34 +02:00
inter_tree_node *Synoptic::get_definition(inter_package *pack, text_stream *name) {
2022-02-03 17:51:44 +02:00
inter_symbol *def_s = InterSymbolsTable::symbol_from_name(InterPackage::scope(pack), name);
2022-01-05 01:10:34 +02:00
if (def_s == NULL) {
LOG("Unable to find symbol %S in $6\n", name, pack);
internal_error("no symbol");
}
2022-01-05 01:10:34 +02:00
inter_tree_node *D = def_s->definition;
if (D == NULL) {
LOG("Undefined symbol %S in $6\n", name, pack);
internal_error("undefined symbol");
}
2022-01-05 01:10:34 +02:00
return D;
}
2022-01-05 01:10:34 +02:00
@ To clarify: here, the symbol is optional, that is, need not exist; but if it
does exist, it must have a definition, and we return that.
=
inter_symbol *Synoptic::get_optional_symbol(inter_package *pack, text_stream *name) {
return InterSymbolsTable::symbol_from_name(InterPackage::scope(pack), name);
}
2022-01-05 01:10:34 +02:00
inter_tree_node *Synoptic::get_optional_definition(inter_package *pack, text_stream *name) {
2022-02-03 17:51:44 +02:00
inter_symbol *def_s = InterSymbolsTable::symbol_from_name(InterPackage::scope(pack), name);
2022-01-05 01:10:34 +02:00
if (def_s == NULL) return NULL;
inter_tree_node *D = def_s->definition;
if (D == NULL) internal_error("undefined symbol");
return D;
2021-04-30 20:48:22 +03:00
}
2022-01-05 01:10:34 +02:00
@ And this creates a new symbol:
=
inter_symbol *Synoptic::new_symbol(inter_package *pack, text_stream *name) {
2022-02-03 17:51:44 +02:00
return InterSymbolsTable::create_with_unique_name(InterPackage::scope(pack), name);
}
2022-01-05 01:10:34 +02:00
@h Making textual constants.
=
2022-01-05 01:10:34 +02:00
void Synoptic::textual_constant(inter_tree *I, pipeline_step *step,
2021-11-15 01:40:33 +02:00
inter_symbol *con_s, text_stream *S, inter_bookmark *IBM) {
2022-03-02 02:04:54 +02:00
Produce::guard(ConstantInstruction::new(IBM, con_s,
LargeScale::text_literal_type(I), InterValuePairs::from_text(IBM, S),
2022-03-02 02:04:54 +02:00
(inter_ti) InterBookmark::baseline(IBM) + 1, NULL));
}
2022-01-05 01:10:34 +02:00
@h Making functions.
=
inter_package *synoptic_fn_package = NULL;
packaging_state synoptic_fn_ps;
void Synoptic::begin_function(inter_tree *I, inter_name *iname) {
2022-01-22 18:44:52 +02:00
synoptic_fn_package = Produce::function_body(I, &synoptic_fn_ps, iname);
}
2021-11-15 01:40:33 +02:00
void Synoptic::end_function(inter_tree *I, pipeline_step *step, inter_name *iname) {
2022-01-22 18:44:52 +02:00
Produce::end_function_body(I);
Packaging::exit(I, synoptic_fn_ps);
}
2022-01-05 01:10:34 +02:00
@ To give such a function a local:
=
inter_symbol *Synoptic::local(inter_tree *I, text_stream *name, text_stream *comment) {
2022-03-20 15:41:13 +02:00
return Produce::local(I, K_value, name, comment);
}
2022-01-05 01:10:34 +02:00
@h Making arrays.
=
inter_tree_node *synoptic_array_node = NULL;
packaging_state synoptic_array_ps;
2022-01-05 01:10:34 +02:00
2021-11-15 01:40:33 +02:00
void Synoptic::begin_array(inter_tree *I, pipeline_step *step, inter_name *iname) {
Synoptic::begin_array_inner(I, step, iname, CONST_LIST_FORMAT_WORDS);
}
void Synoptic::begin_bounded_array(inter_tree *I, pipeline_step *step, inter_name *iname) {
Synoptic::begin_array_inner(I, step, iname, CONST_LIST_FORMAT_B_WORDS);
}
void Synoptic::begin_byte_array(inter_tree *I, pipeline_step *step, inter_name *iname) {
Synoptic::begin_array_inner(I, step, iname, CONST_LIST_FORMAT_BYTES);
}
void Synoptic::begin_array_inner(inter_tree *I, pipeline_step *step, inter_name *iname,
inter_ti format) {
synoptic_array_ps = Packaging::enter_home_of(iname);
2022-02-04 02:55:12 +02:00
inter_symbol *con_s = InterNames::to_symbol(iname);
2022-02-23 01:31:47 +02:00
inter_ti TID = InterTypes::to_TID(InterBookmark::scope(Packaging::at(I)),
InterTypes::from_constructor_code(LIST_ITCONC));
2022-01-28 01:38:14 +02:00
synoptic_array_node = Inode::new_with_3_data_fields(Packaging::at(I), CONSTANT_IST,
2022-03-11 23:38:53 +02:00
InterSymbolsTable::id_at_bookmark(Packaging::at(I), con_s),
TID, format, NULL,
2022-01-27 01:59:02 +02:00
(inter_ti) InterBookmark::baseline(Packaging::at(I)) + 1);
}
2022-01-05 01:10:34 +02:00
void Synoptic::end_array(inter_tree *I) {
2022-03-01 02:41:22 +02:00
inter_error_message *E = VerifyingInter::instruction(
2022-01-27 01:59:02 +02:00
InterBookmark::package(Packaging::at(I)), synoptic_array_node);
if (E) {
InterErrors::issue(E);
internal_error("synoptic array failed verification");
}
2022-01-27 01:59:02 +02:00
NodePlacement::move_to_moving_bookmark(synoptic_array_node, Packaging::at(I));
Packaging::exit(I, synoptic_array_ps);
}
2022-01-05 01:10:34 +02:00
@ Three ways to define an entry:
=
2022-02-25 13:42:06 +02:00
void Synoptic::numeric_entry(inter_ti N) {
2022-01-30 15:32:38 +02:00
Inode::extend_instruction_by(synoptic_array_node, 2);
2022-02-27 20:14:05 +02:00
InterValuePairs::set(synoptic_array_node, synoptic_array_node->W.extent-2,
2022-02-25 13:42:06 +02:00
InterValuePairs::number(N));
}
void Synoptic::symbol_entry(inter_symbol *S) {
2022-01-30 15:32:38 +02:00
Inode::extend_instruction_by(synoptic_array_node, 2);
2022-01-31 01:49:12 +02:00
inter_package *pack = InterPackage::container(synoptic_array_node);
inter_symbol *local_S = InterSymbolsTable::create_with_unique_name(
InterPackage::scope(pack), InterSymbol::identifier(S));
2022-01-04 01:40:23 +02:00
Wiring::wire_to(local_S, S);
2022-02-27 20:14:05 +02:00
InterValuePairs::set(synoptic_array_node, synoptic_array_node->W.extent-2,
2022-02-28 01:52:33 +02:00
InterValuePairs::symbolic_in(pack, local_S));
}
void Synoptic::textual_entry(text_stream *text) {
2022-02-28 01:52:33 +02:00
inter_tree *I = Inode::tree(synoptic_array_node);
2022-01-30 15:32:38 +02:00
Inode::extend_instruction_by(synoptic_array_node, 2);
2022-02-27 20:14:05 +02:00
InterValuePairs::set(synoptic_array_node, synoptic_array_node->W.extent-2,
2022-02-28 01:52:33 +02:00
InterValuePairs::from_text(Packaging::at(I), text));
}