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 Local Construct.w

81 lines
3.5 KiB
OpenEdge ABL
Raw Normal View History

2019-02-05 02:44:07 +02:00
[Inter::Local::] The Local Construct.
Defining the local construct.
@
@e LOCAL_IST
=
void Inter::Local::define(void) {
inter_construct *IC = InterConstruct::create_construct(LOCAL_IST, I"local");
InterConstruct::specify_syntax(IC, I"local TOKEN TOKENS");
InterConstruct::permit(IC, INSIDE_CODE_PACKAGE_ICUP);
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Local::read);
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, Inter::Local::verify);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Local::write);
2019-02-05 02:44:07 +02:00
}
@
@d BLOCK_LOCAL_IFLD 2
@d DEFN_LOCAL_IFLD 3
@d KIND_LOCAL_IFLD 4
@d EXTENT_LOCAL_IFR 5
=
2019-07-14 12:44:07 +03:00
void Inter::Local::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
2022-02-09 12:33:49 +02:00
*E = InterConstruct::check_level_in_package(IBM, LOCAL_IST, ilp->indent_level, eloc);
2019-07-09 08:45:46 +03:00
if (*E) return;
inter_package *routine = InterBookmark::package(IBM);
2019-07-09 08:45:46 +03:00
if (routine == NULL) { *E = Inter::Errors::plain(I"'local' used outside function", eloc); return; }
2022-01-31 01:49:12 +02:00
inter_symbols_table *locals = InterPackage::scope(routine);
2019-07-09 08:45:46 +03:00
if (locals == NULL) { *E = Inter::Errors::plain(I"function has no symbols table", eloc); return; }
2019-02-05 02:44:07 +02:00
2022-02-11 12:48:26 +02:00
inter_symbol *var_name = TextualInter::new_symbol(eloc, locals, ilp->mr.exp[0], E);
2019-07-09 08:45:46 +03:00
if (*E) return;
2022-02-11 12:48:26 +02:00
InterSymbol::make_local(var_name);
2019-02-05 02:44:07 +02:00
2022-02-11 12:48:26 +02:00
inter_symbol *var_kind = TextualInter::find_symbol(IBM, eloc, ilp->mr.exp[1], KIND_IST, E);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
SymbolAnnotation::copy_set_to_symbol(&(ilp->set), var_name);
2019-02-05 02:44:07 +02:00
*E = Inter::Local::new(IBM, var_name, var_kind, (inter_ti) ilp->indent_level, eloc);
2019-02-05 02:44:07 +02:00
}
inter_error_message *Inter::Local::new(inter_bookmark *IBM, inter_symbol *var_name, inter_symbol *var_kind, inter_ti level, inter_error_location *eloc) {
2022-02-03 17:51:44 +02:00
inter_tree_node *P = Inode::new_with_3_data_fields(IBM, LOCAL_IST, 0, InterSymbolsTable::id_from_symbol_at_bookmark(IBM, var_name), var_kind?(InterSymbolsTable::id_from_symbol_at_bookmark(IBM, var_kind)):0, eloc, level);
2022-02-07 00:33:07 +02:00
inter_error_message *E = InterConstruct::verify_construct(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::Local::verify(inter_construct *IC, inter_tree_node *P, inter_package *owner, inter_error_message **E) {
2020-05-11 17:21:29 +03:00
if (P->W.extent != EXTENT_LOCAL_IFR) { *E = Inode::error(P, I"extent wrong", NULL); return; }
2022-01-31 01:49:12 +02:00
inter_symbols_table *locals = InterPackage::scope(owner);
2020-05-11 17:21:29 +03:00
if (locals == NULL) { *E = Inode::error(P, I"no symbols table in function", NULL); return; }
2019-07-09 08:45:46 +03:00
*E = Inter::Verify::local_defn(P, DEFN_LOCAL_IFLD, locals); if (*E) return;
2022-01-30 15:32:38 +02:00
*E = Inter::Verify::symbol(owner, P, P->W.instruction[KIND_LOCAL_IFLD], KIND_IST); if (*E) return;
2019-02-05 02:44:07 +02:00
}
2019-07-24 20:15:07 +03:00
void Inter::Local::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 *var_name = InterSymbolsTable::symbol_from_ID_in_package(pack, P->W.instruction[DEFN_LOCAL_IFLD]);
inter_symbol *var_kind = InterSymbolsTable::symbol_from_ID_at_node(P, KIND_LOCAL_IFLD);
2022-02-11 12:48:26 +02:00
if ((var_name) && (var_kind)) {
WRITE("local %S ", InterSymbol::identifier(var_name));
2022-02-11 12:48:26 +02:00
TextualInter::write_symbol_from(OUT, P, KIND_LOCAL_IFLD);
SymbolAnnotation::write_annotations(OUT, P, var_name);
2020-05-11 17:21:29 +03:00
} else { *E = Inode::error(P, I"cannot write local", NULL); return; }
2019-02-05 02:44:07 +02:00
}
inter_symbol *Inter::Local::kind_of(inter_symbol *con_symbol) {
if (con_symbol == NULL) return NULL;
inter_tree_node *D = InterSymbol::definition(con_symbol);
if (D == NULL) return NULL;
2022-01-30 15:32:38 +02:00
if (D->W.instruction[ID_IFLD] != LOCAL_IST) return NULL;
2022-02-03 17:51:44 +02:00
return InterSymbolsTable::symbol_from_ID_at_node(D, KIND_LOCAL_IFLD);
2019-02-05 02:44:07 +02:00
}