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 5/The Label Construct.w

75 lines
3.2 KiB
OpenEdge ABL
Raw Normal View History

2019-02-05 02:44:07 +02:00
[Inter::Label::] The Label Construct.
Defining the label construct.
@
@e LABEL_IST
=
void Inter::Label::define(void) {
inter_construct *IC = InterConstruct::create_construct(LABEL_IST, I"label");
2022-02-24 01:37:43 +02:00
InterConstruct::defines_symbol_in_fields(IC, DEFN_LABEL_IFLD, -1);
InterConstruct::specify_syntax(IC, I".IDENTIFIER");
2022-02-24 01:37:43 +02:00
InterConstruct::fix_instruction_length_between(IC, EXTENT_LABEL_IFR, EXTENT_LABEL_IFR);
InterConstruct::allow_in_depth_range(IC, 0, INFINITELY_DEEP);
InterConstruct::permit(IC, INSIDE_CODE_PACKAGE_ICUP);
InterConstruct::permit(IC, CAN_HAVE_CHILDREN_ICUP);
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Label::read);
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, Inter::Label::verify);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Label::write);
2019-02-05 02:44:07 +02:00
}
@
@d BLOCK_LABEL_IFLD 2
@d DEFN_LABEL_IFLD 3
@d EXTENT_LABEL_IFR 4
2019-02-05 02:44:07 +02:00
=
2019-07-14 12:44:07 +03:00
void Inter::Label::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
if (SymbolAnnotation::nonempty(&(ilp->set))) { *E = InterErrors::plain(I"__annotations are not allowed", eloc); return; }
2022-02-09 12:33:49 +02:00
*E = InterConstruct::check_level_in_package(IBM, LABEL_IST, ilp->indent_level, eloc);
2019-07-09 08:45:46 +03:00
if (*E) return;
inter_package *routine = InterBookmark::package(IBM);
if (routine == NULL) { *E = InterErrors::plain(I"'label' used outside function", eloc); return; }
2022-01-31 01:49:12 +02:00
inter_symbols_table *locals = InterPackage::scope(routine);
if (locals == NULL) { *E = InterErrors::plain(I"function has no symbols table", eloc); return; }
2019-02-05 02:44:07 +02:00
2022-02-03 17:51:44 +02:00
inter_symbol *lab_name = InterSymbolsTable::symbol_from_name(locals, ilp->mr.exp[0]);
2022-02-11 12:48:26 +02:00
if (lab_name == NULL) {
lab_name = TextualInter::new_symbol(eloc, locals, ilp->mr.exp[0], E);
if (*E) return;
} else if (InterSymbol::is_defined(lab_name)) {
*E = InterErrors::plain(I"label defined in function once already", eloc);
2022-02-11 12:48:26 +02:00
return;
}
InterSymbol::make_label(lab_name);
2020-07-01 02:58:55 +03:00
*E = Inter::Label::new(IBM, lab_name, (inter_ti) ilp->indent_level, eloc);
2019-02-05 02:44:07 +02:00
}
2020-07-01 02:58:55 +03:00
inter_error_message *Inter::Label::new(inter_bookmark *IBM, inter_symbol *lab_name, inter_ti level, inter_error_location *eloc) {
2022-02-03 17:51:44 +02:00
inter_tree_node *P = Inode::new_with_2_data_fields(IBM, LABEL_IST, 0, InterSymbolsTable::id_from_symbol_at_bookmark(IBM, lab_name), eloc, level);
2022-02-24 01:37:43 +02:00
inter_error_message *E = Inter::Verify::instruction(InterBookmark::package(IBM), P); if (E) return E;
2022-01-27 01:59:02 +02:00
NodePlacement::move_to_moving_bookmark(P, IBM);
2019-02-05 02:44:07 +02:00
return NULL;
}
2019-07-24 20:15:07 +03:00
void Inter::Label::verify(inter_construct *IC, inter_tree_node *P, inter_package *owner, inter_error_message **E) {
2022-02-03 17:51:44 +02:00
inter_symbol *lab_name = InterSymbolsTable::symbol_from_ID_in_package(owner, P->W.instruction[DEFN_LABEL_IFLD]);
if (InterSymbol::is_label(lab_name) == FALSE) {
*E = Inode::error(P, I"not a label", (lab_name)?(InterSymbol::identifier(lab_name)):NULL);
2019-07-09 08:45:46 +03:00
return;
2019-02-05 02:44:07 +02:00
}
2022-01-30 15:32:38 +02:00
if (P->W.instruction[LEVEL_IFLD] < 1) { *E = Inode::error(P, I"label with bad level", NULL); return; }
2019-02-05 02:44:07 +02:00
}
2019-07-24 20:15:07 +03:00
void Inter::Label::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
2022-01-31 01:49:12 +02:00
inter_package *pack = InterPackage::container(P);
2022-02-03 17:51:44 +02:00
inter_symbol *lab_name = InterSymbolsTable::symbol_from_ID_in_package(pack, P->W.instruction[DEFN_LABEL_IFLD]);
2019-02-05 02:44:07 +02:00
if (lab_name) {
WRITE("%S", InterSymbol::identifier(lab_name));
2020-05-11 17:21:29 +03:00
} else { *E = Inode::error(P, I"cannot write label", NULL); return; }
2019-02-05 02:44:07 +02:00
}