1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-01 06:24:58 +03:00
inform7/inter/bytecode-module/Chapter 3/Metadata.w

119 lines
4.9 KiB
OpenEdge ABL
Raw Normal View History

[Metadata::] Metadata.
Looking up metadata in special constants.
@ =
int Metadata::valid_key(text_stream *key) {
if (Str::get_at(key, 0) == '^') return TRUE;
return FALSE;
}
2021-05-01 17:00:44 +03:00
int Metadata::exists(inter_package *pack, text_stream *key) {
2022-01-31 01:49:12 +02:00
inter_symbol *md = InterSymbolsTables::symbol_from_name(InterPackage::scope(pack), key);
2021-05-01 17:00:44 +03:00
if (md == NULL) return FALSE;
inter_tree_node *D = md->definition;
if (D == NULL) return FALSE;
return TRUE;
}
inter_symbol *Metadata::read_symbol(inter_package *pack, text_stream *key) {
2022-01-31 01:49:12 +02:00
inter_symbol *md = InterSymbolsTables::symbol_from_name(InterPackage::scope(pack), key);
if (md == NULL) {
LOG("unable to find metadata key %S in package $6\n", key, pack);
2021-05-01 12:46:37 +03:00
Metadata::err("not found", pack, key);
}
inter_tree_node *D = md->definition;
2021-05-01 12:46:37 +03:00
if (D == NULL) Metadata::err("not defined", pack, key);
2022-01-30 15:32:38 +02:00
if (D->W.instruction[FORMAT_CONST_IFLD] != CONSTANT_DIRECT) {
LOG("%d\n", D->W.instruction[FORMAT_CONST_IFLD]);
2021-05-01 12:46:37 +03:00
Metadata::err("not direct", pack, key);
}
2022-01-30 15:32:38 +02:00
if (D->W.instruction[DATA_CONST_IFLD] != ALIAS_IVAL) Metadata::err("not symbol", pack, key);
2022-01-31 01:49:12 +02:00
inter_symbol *s = InterSymbolsTables::symbol_from_id(InterPackage::scope(pack),
2022-01-30 15:32:38 +02:00
D->W.instruction[DATA_CONST_IFLD + 1]);
2021-05-01 12:46:37 +03:00
if (s == NULL) Metadata::err("no symbol", pack, key);
return s;
}
2021-04-27 16:01:34 +03:00
inter_symbol *Metadata::read_optional_symbol(inter_package *pack, text_stream *key) {
2022-01-31 01:49:12 +02:00
inter_symbol *md = InterSymbolsTables::symbol_from_name(InterPackage::scope(pack), key);
2021-04-27 16:01:34 +03:00
if (md == NULL) return NULL;
inter_tree_node *D = md->definition;
2021-05-01 12:46:37 +03:00
if (D == NULL) Metadata::err("not defined", pack, key);
2022-01-30 15:32:38 +02:00
if (D->W.instruction[FORMAT_CONST_IFLD] != CONSTANT_DIRECT) {
LOG("%d\n", D->W.instruction[FORMAT_CONST_IFLD]);
2021-05-01 12:46:37 +03:00
Metadata::err("not direct", pack, key);
2021-04-27 16:01:34 +03:00
}
2022-01-30 15:32:38 +02:00
if (D->W.instruction[DATA_CONST_IFLD] != ALIAS_IVAL) Metadata::err("not symbol", pack, key);
2021-04-27 16:01:34 +03:00
2022-01-31 01:49:12 +02:00
inter_symbol *s = InterSymbolsTables::symbol_from_id(InterPackage::scope(pack),
2022-01-30 15:32:38 +02:00
D->W.instruction[DATA_CONST_IFLD + 1]);
2021-05-01 12:46:37 +03:00
if (s == NULL) Metadata::err("no symbol", pack, key);
2021-04-27 16:01:34 +03:00
return s;
}
2021-06-27 16:56:29 +03:00
inter_tree_node *Metadata::read_optional_list(inter_package *pack, text_stream *key) {
2022-01-31 01:49:12 +02:00
inter_symbol *md = InterSymbolsTables::symbol_from_name(InterPackage::scope(pack), key);
2021-06-27 16:56:29 +03:00
if (md == NULL) return NULL;
inter_tree_node *D = md->definition;
if (D == NULL) Metadata::err("not defined", pack, key);
2022-01-30 15:32:38 +02:00
if (D->W.instruction[FORMAT_CONST_IFLD] != CONSTANT_INDIRECT_LIST) {
LOG("%d\n", D->W.instruction[FORMAT_CONST_IFLD]);
2021-06-27 16:56:29 +03:00
Metadata::err("not a list", pack, key);
}
return D;
}
inter_ti Metadata::read_numeric(inter_package *pack, text_stream *key) {
2022-01-31 01:49:12 +02:00
inter_symbol *md = InterSymbolsTables::symbol_from_name(InterPackage::scope(pack), key);
2021-05-01 12:46:37 +03:00
if (md == NULL) Metadata::err("not found", pack, key);
inter_tree_node *D = md->definition;
2021-05-01 12:46:37 +03:00
if (D == NULL) Metadata::err("not defined", pack, key);
2022-01-30 15:32:38 +02:00
if (D->W.instruction[FORMAT_CONST_IFLD] != CONSTANT_DIRECT) Metadata::err("not direct", pack, key);
if (D->W.instruction[DATA_CONST_IFLD] != LITERAL_IVAL) Metadata::err("not literal", pack, key);
return D->W.instruction[DATA_CONST_IFLD + 1];
2021-04-27 16:01:34 +03:00
}
inter_ti Metadata::read_optional_numeric(inter_package *pack, text_stream *key) {
2022-01-31 01:49:12 +02:00
inter_symbol *md = InterSymbolsTables::symbol_from_name(InterPackage::scope(pack), key);
2021-04-27 16:01:34 +03:00
if (md == NULL) return 0;
inter_tree_node *D = md->definition;
2021-05-01 12:46:37 +03:00
if (D == NULL) Metadata::err("not defined", pack, key);
2022-01-30 15:32:38 +02:00
if (D->W.instruction[FORMAT_CONST_IFLD] != CONSTANT_DIRECT) Metadata::err("not direct", pack, key);
if (D->W.instruction[DATA_CONST_IFLD] != LITERAL_IVAL) Metadata::err("not literal", pack, key);
return D->W.instruction[DATA_CONST_IFLD + 1];
}
text_stream *Metadata::read_textual(inter_package *pack, text_stream *key) {
2022-01-31 01:49:12 +02:00
inter_symbol *md = InterSymbolsTables::symbol_from_name(InterPackage::scope(pack), key);
2021-05-01 12:46:37 +03:00
if (md == NULL) Metadata::err("not found", pack, key);
inter_tree_node *D = md->definition;
2021-05-01 12:46:37 +03:00
if (D == NULL) Metadata::err("not defined", pack, key);
2022-01-30 15:32:38 +02:00
if (D->W.instruction[FORMAT_CONST_IFLD] != CONSTANT_INDIRECT_TEXT) {
LOG("%d\n", D->W.instruction[FORMAT_CONST_IFLD]);
2021-05-01 12:46:37 +03:00
Metadata::err("not text", pack, key);
}
2022-01-30 15:32:38 +02:00
return Inode::ID_to_text(D, D->W.instruction[DATA_CONST_IFLD]);
}
text_stream *Metadata::read_optional_textual(inter_package *pack, text_stream *key) {
2022-01-31 01:49:12 +02:00
inter_symbol *md = InterSymbolsTables::symbol_from_name(InterPackage::scope(pack), key);
if (md == NULL) return NULL;
inter_tree_node *D = md->definition;
2021-05-01 12:46:37 +03:00
if (D == NULL) Metadata::err("not defined", pack, key);
2022-01-30 15:32:38 +02:00
if (D->W.instruction[FORMAT_CONST_IFLD] != CONSTANT_INDIRECT_TEXT) {
LOG("%d\n", D->W.instruction[FORMAT_CONST_IFLD]);
2021-05-01 12:46:37 +03:00
Metadata::err("not text", pack, key);
}
2022-01-30 15:32:38 +02:00
return Inode::ID_to_text(D, D->W.instruction[DATA_CONST_IFLD]);
}
2021-05-01 12:46:37 +03:00
void Metadata::err(char *err, inter_package *pack, text_stream *key) {
LOG("Error on metadata %S in $6\n", key, pack);
WRITE_TO(STDERR, "Error on metadata %S in ", key);
2022-01-31 01:49:12 +02:00
InterPackage::write_url_name(STDERR, pack);
2021-05-01 12:46:37 +03:00
WRITE_TO(STDERR, "\n");
internal_error(err);
}