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

81 lines
3.5 KiB
OpenEdge ABL
Raw Normal View History

2019-02-05 02:44:07 +02:00
[Inter::Ref::] The Ref Construct.
Defining the ref construct.
@
@e REF_IST
=
void Inter::Ref::define(void) {
inter_construct *IC = Inter::Defn::create_construct(
REF_IST,
L"ref (%i+) (%C+)",
I"ref", I"refs");
IC->min_level = 1;
IC->max_level = 100000000;
IC->usage_permissions = INSIDE_CODE_PACKAGE;
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Ref::read);
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, Inter::Ref::verify);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Ref::write);
2019-02-05 02:44:07 +02:00
}
@
@d BLOCK_REF_IFLD 2
@d KIND_REF_IFLD 3
@d VAL1_REF_IFLD 4
@d VAL2_REF_IFLD 5
@d EXTENT_REF_IFR 6
=
2019-07-14 12:44:07 +03:00
void Inter::Ref::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
2019-07-26 10:59:23 +03:00
if (Inter::Annotations::exist(&(ilp->set))) { *E = Inter::Errors::plain(I"__annotations are not allowed", eloc); return; }
2019-02-05 02:44:07 +02:00
2019-07-14 12:44:07 +03:00
*E = Inter::Defn::vet_level(IBM, REF_IST, ilp->indent_level, eloc);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
inter_package *routine = Inter::Defn::get_latest_block_package();
2019-07-09 08:45:46 +03:00
if (routine == NULL) { *E = Inter::Errors::plain(I"'ref' used outside function", eloc); return; }
inter_symbols_table *locals = Inter::Packages::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
2019-07-23 01:34:28 +03:00
inter_symbol *ref_kind = Inter::Textual::find_symbol(Inter::Bookmarks::tree(IBM), eloc, Inter::Bookmarks::scope(IBM), ilp->mr.exp[0], KIND_IST, E);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
2020-07-01 02:58:55 +03:00
inter_ti var_val1 = 0;
inter_ti var_val2 = 0;
2019-07-23 01:34:28 +03:00
*E = Inter::Types::read(ilp->line, eloc, Inter::Bookmarks::tree(IBM), Inter::Bookmarks::package(IBM), ref_kind, ilp->mr.exp[1], &var_val1, &var_val2, locals);
2019-07-09 08:45:46 +03:00
if (*E) return;
2019-02-05 02:44:07 +02:00
2019-07-27 13:16:22 +03:00
*E = Inter::Ref::new(IBM, ref_kind, ilp->indent_level, var_val1, var_val2, eloc);
2019-02-05 02:44:07 +02:00
}
2020-07-01 02:58:55 +03:00
inter_error_message *Inter::Ref::new(inter_bookmark *IBM, inter_symbol *ref_kind, int level, inter_ti val1, inter_ti val2, inter_error_location *eloc) {
inter_tree_node *P = Inode::fill_4(IBM, REF_IST, 0, Inter::SymbolsTables::id_from_IRS_and_symbol(IBM, ref_kind), val1, val2, eloc, (inter_ti) level);
2019-07-14 12:44:07 +03:00
inter_error_message *E = Inter::Defn::verify_construct(Inter::Bookmarks::package(IBM), P); if (E) return E;
Inter::Bookmarks::insert(IBM, P);
2019-02-05 02:44:07 +02:00
return NULL;
}
2019-07-24 20:15:07 +03:00
void Inter::Ref::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_REF_IFR) { *E = Inode::error(P, I"extent wrong", NULL); return; }
inter_symbols_table *locals = Inter::Packages::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-24 20:15:07 +03:00
*E = Inter::Verify::symbol(owner, P, P->W.data[KIND_REF_IFLD], KIND_IST); if (*E) return;
inter_symbol *ref_kind = Inter::SymbolsTables::symbol_from_id(Inter::Packages::scope(owner), P->W.data[KIND_REF_IFLD]);;
2019-07-09 08:45:46 +03:00
*E = Inter::Verify::local_value(P, VAL1_REF_IFLD, ref_kind, locals); if (*E) return;
2019-02-05 02:44:07 +02:00
}
2019-07-24 20:15:07 +03:00
void Inter::Ref::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
2019-02-05 02:44:07 +02:00
inter_package *pack = Inter::Packages::container(P);
2019-07-26 21:20:27 +03:00
inter_symbols_table *locals = Inter::Packages::scope(pack);
2020-05-11 17:21:29 +03:00
if (locals == NULL) { *E = Inode::error(P, I"function has no symbols table", NULL); return; }
2019-02-05 02:44:07 +02:00
inter_symbol *ref_kind = Inter::SymbolsTables::symbol_from_frame_data(P, KIND_REF_IFLD);
if (ref_kind) {
WRITE("ref %S ", ref_kind->symbol_name);
2019-07-24 20:15:07 +03:00
Inter::Types::write(OUT, P, ref_kind, P->W.data[VAL1_REF_IFLD], P->W.data[VAL2_REF_IFLD], locals, FALSE);
2020-05-11 17:21:29 +03:00
} else { *E = Inode::error(P, I"cannot write ref", NULL); return; }
2019-02-05 02:44:07 +02:00
}