2019-02-05 02:44:07 +02:00
|
|
|
[Inter::Val::] The Val Construct.
|
|
|
|
|
|
|
|
Defining the val construct.
|
|
|
|
|
|
|
|
@
|
|
|
|
|
|
|
|
@e VAL_IST
|
|
|
|
|
|
|
|
=
|
|
|
|
void Inter::Val::define(void) {
|
2022-02-08 01:30:40 +02:00
|
|
|
inter_construct *IC = InterConstruct::create_construct(VAL_IST, I"val");
|
2022-02-15 01:45:34 +02:00
|
|
|
InterConstruct::specify_syntax(IC, I"val TOKENS");
|
2022-02-24 01:37:43 +02:00
|
|
|
InterConstruct::fix_instruction_length_between(IC, EXTENT_VAL_IFR, EXTENT_VAL_IFR);
|
2022-02-08 01:30:40 +02:00
|
|
|
InterConstruct::allow_in_depth_range(IC, 1, INFINITELY_DEEP);
|
|
|
|
InterConstruct::permit(IC, INSIDE_CODE_PACKAGE_ICUP);
|
2019-07-09 08:45:46 +03:00
|
|
|
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Val::read);
|
2019-09-07 03:28:18 +03:00
|
|
|
METHOD_ADD(IC, CONSTRUCT_TRANSPOSE_MTID, Inter::Val::transpose);
|
2019-07-09 08:45:46 +03:00
|
|
|
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, Inter::Val::verify);
|
|
|
|
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Val::write);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@
|
|
|
|
|
|
|
|
@d BLOCK_VAL_IFLD 2
|
|
|
|
@d KIND_VAL_IFLD 3
|
|
|
|
@d VAL1_VAL_IFLD 4
|
|
|
|
@d VAL2_VAL_IFLD 5
|
|
|
|
|
|
|
|
@d EXTENT_VAL_IFR 6
|
|
|
|
|
|
|
|
=
|
2019-07-14 12:44:07 +03:00
|
|
|
void Inter::Val::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
|
2022-03-01 00:24:58 +02:00
|
|
|
if (SymbolAnnotation::nonempty(&(ilp->set))) { *E = InterErrors::plain(I"__annotations are not allowed", eloc); return; }
|
2019-02-05 02:44:07 +02:00
|
|
|
|
2022-02-09 12:33:49 +02:00
|
|
|
*E = InterConstruct::check_level_in_package(IBM, VAL_IST, ilp->indent_level, eloc);
|
2019-07-09 08:45:46 +03:00
|
|
|
if (*E) return;
|
2019-02-05 02:44:07 +02:00
|
|
|
|
2022-02-14 01:44:50 +02:00
|
|
|
inter_package *routine = InterBookmark::package(IBM);
|
2022-03-01 00:24:58 +02:00
|
|
|
if (routine == NULL) { *E = InterErrors::plain(I"'val' used outside function", eloc); return; }
|
2022-01-31 01:49:12 +02:00
|
|
|
inter_symbols_table *locals = InterPackage::scope(routine);
|
2022-03-01 00:24:58 +02:00
|
|
|
if (locals == NULL) { *E = InterErrors::plain(I"function has no symbols table", eloc); return; }
|
2019-02-05 02:44:07 +02:00
|
|
|
|
2022-02-15 01:45:34 +02:00
|
|
|
text_stream *kind_text = NULL, *value_text = ilp->mr.exp[0];
|
|
|
|
match_results mr2 = Regexp::create_mr();
|
|
|
|
if (Regexp::match(&mr2, value_text, L"%((%c+)%) (%c+)")) {
|
|
|
|
kind_text = mr2.exp[0];
|
|
|
|
value_text = mr2.exp[1];
|
|
|
|
}
|
|
|
|
|
2022-02-21 15:05:50 +02:00
|
|
|
inter_type val_type = InterTypes::parse_simple(InterBookmark::scope(IBM), eloc, kind_text, E);
|
2022-02-17 12:38:00 +02:00
|
|
|
if (*E) return;
|
2019-02-05 02:44:07 +02:00
|
|
|
|
2022-02-25 01:53:40 +02:00
|
|
|
inter_pair val = InterValuePairs::undef();
|
2019-02-05 02:44:07 +02:00
|
|
|
|
2022-02-23 01:31:47 +02:00
|
|
|
inter_symbol *kind_as_value = TextualInter::find_symbol(IBM, eloc, value_text, TYPENAME_IST, E);
|
2019-02-05 02:44:07 +02:00
|
|
|
if (kind_as_value) {
|
2022-02-15 01:45:34 +02:00
|
|
|
*E = NULL;
|
2022-02-28 01:52:33 +02:00
|
|
|
val = InterValuePairs::symbolic(IBM, kind_as_value);
|
2019-02-05 02:44:07 +02:00
|
|
|
} else {
|
2022-02-28 01:52:33 +02:00
|
|
|
*E = TextualInter::parse_pair(ilp->line, eloc, IBM, val_type, value_text, &val);
|
2019-07-09 08:45:46 +03:00
|
|
|
if (*E) return;
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
|
2022-02-25 01:53:40 +02:00
|
|
|
*E = Inter::Val::new(IBM, val_type, ilp->indent_level, val, eloc);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
|
2022-02-17 12:38:00 +02:00
|
|
|
inter_error_message *Inter::Val::new(inter_bookmark *IBM, inter_type val_type,
|
2022-02-25 01:53:40 +02:00
|
|
|
int level, inter_pair val, inter_error_location *eloc) {
|
2022-03-01 00:24:58 +02:00
|
|
|
inter_tree_node *P = Inode::new_with_4_data_fields(IBM, VAL_IST, 0, InterTypes::to_TID_at(IBM, val_type),
|
2022-02-25 01:53:40 +02:00
|
|
|
InterValuePairs::to_word1(val), InterValuePairs::to_word2(val), eloc, (inter_ti) 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;
|
|
|
|
}
|
|
|
|
|
2020-07-01 02:58:55 +03:00
|
|
|
void Inter::Val::transpose(inter_construct *IC, inter_tree_node *P, inter_ti *grid, inter_ti grid_extent, inter_error_message **E) {
|
2022-02-27 20:14:05 +02:00
|
|
|
InterValuePairs::set(P, VAL1_VAL_IFLD,
|
|
|
|
InterValuePairs::transpose(InterValuePairs::get(P, VAL1_VAL_IFLD), grid, grid_extent, E));
|
2019-09-07 03:28:18 +03:00
|
|
|
}
|
|
|
|
|
2019-07-24 20:15:07 +03:00
|
|
|
void Inter::Val::verify(inter_construct *IC, inter_tree_node *P, inter_package *owner, inter_error_message **E) {
|
2022-02-24 01:37:43 +02:00
|
|
|
*E = Inter::Verify::TID_field(owner, P, KIND_VAL_IFLD);
|
|
|
|
if (*E) return;
|
|
|
|
inter_type type = InterTypes::from_TID_in_field(P, KIND_VAL_IFLD);
|
|
|
|
*E = Inter::Verify::data_pair_fields(owner, P, VAL1_VAL_IFLD, type);
|
|
|
|
if (*E) return;
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|
|
|
|
|
2019-07-24 20:15:07 +03:00
|
|
|
void Inter::Val::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
|
2022-02-15 01:45:34 +02:00
|
|
|
WRITE("val ");
|
2022-03-01 00:24:58 +02:00
|
|
|
TextualInter::write_optional_type_marker(OUT, P, KIND_VAL_IFLD);
|
2022-02-28 01:52:33 +02:00
|
|
|
TextualInter::write_pair(OUT, P, InterValuePairs::get(P, VAL1_VAL_IFLD), FALSE);
|
2019-02-05 02:44:07 +02:00
|
|
|
}
|