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

149 lines
5.7 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 =
InterSymbolsTables::symbol_from_name(Inter::Packages::scope(pack), name);
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) {
inter_symbol *def_s = InterSymbolsTables::symbol_from_name(Inter::Packages::scope(pack), name);
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.
=
2022-01-05 01:10:34 +02:00
inter_tree_node *Synoptic::get_optional_definition(inter_package *pack, text_stream *name) {
inter_symbol *def_s = InterSymbolsTables::symbol_from_name(Inter::Packages::scope(pack), name);
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) {
return InterSymbolsTables::create_with_unique_name(Inter::Packages::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) {
Inter::Symbols::annotate_i(con_s, TEXT_LITERAL_IANN, 1);
2022-01-30 15:32:38 +02:00
inter_ti ID = InterWarehouse::create_text(InterTree::warehouse(I),
2022-01-27 01:59:02 +02:00
InterBookmark::package(IBM));
2022-01-30 15:32:38 +02:00
Str::copy(InterWarehouse::get_text(InterTree::warehouse(I), ID), S);
Produce::guard(Inter::Constant::new_textual(IBM,
2022-01-27 01:59:02 +02:00
InterSymbolsTables::id_from_symbol(I, InterBookmark::package(IBM), con_s),
InterSymbolsTables::id_from_symbol(I, InterBookmark::package(IBM),
2021-11-15 01:40:33 +02:00
RunningPipelines::get_symbol(step, unchecked_kind_RPSYM)),
2022-01-27 01:59:02 +02:00
ID, (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);
inter_symbol *fn_s = InterNames::define(iname);
Produce::guard(Inter::Constant::new_function(Packaging::at(I),
2022-01-27 01:59:02 +02:00
InterSymbolsTables::id_from_symbol(I, InterBookmark::package(Packaging::at(I)), fn_s),
InterSymbolsTables::id_from_symbol(I, InterBookmark::package(Packaging::at(I)),
2022-01-05 01:10:34 +02:00
RunningPipelines::get_symbol(step, unchecked_kind_RPSYM)),
synoptic_fn_package,
Produce::baseline(Packaging::at(I)), NULL));
2022-01-22 18:44:52 +02:00
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) {
return Produce::local(I, K_value, name, 0, 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_array_ps = Packaging::enter_home_of(iname);
2022-01-22 18:44:52 +02:00
inter_symbol *con_s = InterNames::define(iname);
2022-01-28 01:38:14 +02:00
synoptic_array_node = Inode::new_with_3_data_fields(Packaging::at(I), CONSTANT_IST,
InterSymbolsTables::id_from_IRS_and_symbol(Packaging::at(I), con_s),
2022-01-05 01:10:34 +02:00
InterSymbolsTables::id_from_IRS_and_symbol(Packaging::at(I),
RunningPipelines::get_symbol(step, list_of_unchecked_kind_RPSYM)),
CONSTANT_INDIRECT_LIST, 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-01-05 01:10:34 +02:00
inter_error_message *E = Inter::Defn::verify_construct(
2022-01-27 01:59:02 +02:00
InterBookmark::package(Packaging::at(I)), synoptic_array_node);
if (E) {
Inter::Errors::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:
=
void Synoptic::numeric_entry(inter_ti val2) {
2022-01-30 15:32:38 +02:00
Inode::extend_instruction_by(synoptic_array_node, 2);
synoptic_array_node->W.instruction[synoptic_array_node->W.extent-2] = LITERAL_IVAL;
synoptic_array_node->W.instruction[synoptic_array_node->W.extent-1] = val2;
}
void Synoptic::symbol_entry(inter_symbol *S) {
2022-01-30 15:32:38 +02:00
Inode::extend_instruction_by(synoptic_array_node, 2);
inter_package *pack = Inter::Packages::container(synoptic_array_node);
2022-01-05 01:10:34 +02:00
inter_symbol *local_S =
InterSymbolsTables::create_with_unique_name(Inter::Packages::scope(pack), S->symbol_name);
2022-01-04 01:40:23 +02:00
Wiring::wire_to(local_S, S);
inter_ti val1 = 0, val2 = 0;
Inter::Symbols::to_data(Inter::Packages::tree(pack), pack, local_S, &val1, &val2);
2022-01-30 15:32:38 +02:00
synoptic_array_node->W.instruction[synoptic_array_node->W.extent-2] = ALIAS_IVAL;
synoptic_array_node->W.instruction[synoptic_array_node->W.extent-1] = val2;
}
void Synoptic::textual_entry(text_stream *text) {
2022-01-30 15:32:38 +02:00
Inode::extend_instruction_by(synoptic_array_node, 2);
inter_package *pack = Inter::Packages::container(synoptic_array_node);
inter_tree *I = Inter::Packages::tree(pack);
2022-01-30 15:32:38 +02:00
inter_ti val2 = InterWarehouse::create_text(InterTree::warehouse(I), pack);
text_stream *glob_storage = InterWarehouse::get_text(InterTree::warehouse(I), val2);
Str::copy(glob_storage, text);
2022-01-30 15:32:38 +02:00
synoptic_array_node->W.instruction[synoptic_array_node->W.extent-2] = LITERAL_TEXT_IVAL;
synoptic_array_node->W.instruction[synoptic_array_node->W.extent-1] = val2;
}