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

121 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-02-03 17:51:44 +02:00
inter_symbol *md = InterSymbolsTable::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-02-03 17:51:44 +02:00
inter_symbol *md = InterSymbolsTable::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-02-27 20:14:05 +02:00
inter_pair val = InterValuePairs::get(D, DATA_CONST_IFLD);
2022-02-28 01:52:33 +02:00
if (InterValuePairs::is_symbolic(val) == FALSE) Metadata::err("not symbol", pack, key);
2022-02-28 01:52:33 +02:00
inter_symbol *s = InterValuePairs::to_symbol_in(val, pack);
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-02-03 17:51:44 +02:00
inter_symbol *md = InterSymbolsTable::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-02-27 20:14:05 +02:00
inter_pair val = InterValuePairs::get(D, DATA_CONST_IFLD);
2022-02-28 01:52:33 +02:00
if (InterValuePairs::is_symbolic(val) == FALSE) Metadata::err("not symbol", pack, key);
2021-04-27 16:01:34 +03:00
2022-02-28 01:52:33 +02:00
inter_symbol *s = InterValuePairs::to_symbol_in(val, pack);
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-02-03 17:51:44 +02:00
inter_symbol *md = InterSymbolsTable::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-02-03 17:51:44 +02:00
inter_symbol *md = InterSymbolsTable::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);
2022-02-27 20:14:05 +02:00
inter_pair val = InterValuePairs::get(D, DATA_CONST_IFLD);
if (InterValuePairs::is_number(val) == FALSE) Metadata::err("not literal", pack, key);
return InterValuePairs::to_number(val);
2021-04-27 16:01:34 +03:00
}
inter_ti Metadata::read_optional_numeric(inter_package *pack, text_stream *key) {
2022-02-03 17:51:44 +02:00
inter_symbol *md = InterSymbolsTable::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);
2022-02-27 20:14:05 +02:00
inter_pair val = InterValuePairs::get(D, DATA_CONST_IFLD);
if (InterValuePairs::is_number(val) == FALSE) Metadata::err("not literal", pack, key);
return InterValuePairs::to_number(val);
}
text_stream *Metadata::read_textual(inter_package *pack, text_stream *key) {
2022-02-03 17:51:44 +02:00
inter_symbol *md = InterSymbolsTable::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-02-03 17:51:44 +02:00
inter_symbol *md = InterSymbolsTable::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-02-03 17:51:44 +02:00
InterPackage::write_URL(STDERR, pack);
2021-05-01 12:46:37 +03:00
WRITE_TO(STDERR, "\n");
internal_error(err);
}