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

61 lines
2.3 KiB
OpenEdge ABL
Raw Normal View History

2019-02-05 02:44:07 +02:00
[Inter::Code::] The Code Construct.
Defining the Code construct.
@
@e CODE_IST
=
void Inter::Code::define(void) {
inter_construct *IC = InterConstruct::create_construct(CODE_IST, I"code");
InterConstruct::specify_syntax(IC, I"code");
2022-02-24 01:37:43 +02:00
InterConstruct::fix_instruction_length_between(IC, EXTENT_CODE_IFR, EXTENT_CODE_IFR);
InterConstruct::allow_in_depth_range(IC, 0, INFINITELY_DEEP);
InterConstruct::permit(IC, INSIDE_CODE_PACKAGE_ICUP);
InterConstruct::permit(IC, CAN_HAVE_CHILDREN_ICUP);
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Code::read);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Code::write);
2022-02-09 12:33:49 +02:00
METHOD_ADD(IC, CONSTRUCT_VERIFY_CHILDREN_MTID, Inter::Code::verify_children);
2019-02-05 02:44:07 +02:00
}
@
@d BLOCK_CODE_IFLD 2
@d EXTENT_CODE_IFR 3
2019-02-05 02:44:07 +02:00
=
2019-07-14 12:44:07 +03:00
void Inter::Code::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
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, CODE_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-24 01:37:43 +02:00
if (InterBookmark::package(IBM) == NULL) {
*E = InterErrors::plain(I"'code' used outside package", eloc); return;
2022-02-24 01:37:43 +02:00
}
2019-03-22 13:06:13 +02:00
*E = Inter::Code::new(IBM, ilp->indent_level, eloc);
2019-02-05 02:44:07 +02:00
}
inter_error_message *Inter::Code::new(inter_bookmark *IBM, int level, inter_error_location *eloc) {
2022-01-28 01:38:14 +02:00
inter_tree_node *P = Inode::new_with_1_data_field(IBM, CODE_IST, 0, 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;
}
2019-07-24 20:15:07 +03:00
void Inter::Code::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
2019-03-22 13:06:13 +02:00
WRITE("code");
2019-02-05 02:44:07 +02:00
}
2019-07-24 20:15:07 +03:00
void Inter::Code::verify_children(inter_construct *IC, inter_tree_node *P, inter_error_message **E) {
LOOP_THROUGH_INTER_CHILDREN(C, P) {
2022-01-30 15:32:38 +02:00
if ((C->W.instruction[0] != INV_IST) && (C->W.instruction[0] != SPLAT_IST) && (C->W.instruction[0] != EVALUATION_IST) && (C->W.instruction[0] != LABEL_IST) && (C->W.instruction[0] != VAL_IST) && (C->W.instruction[0] != COMMENT_IST) && (C->W.instruction[0] != NOP_IST)) {
2020-05-11 17:21:29 +03:00
*E = Inode::error(C, I"only an inv, a val, a splat, a concatenate or a label can be below a code", NULL);
return;
}
}
2019-02-05 02:44:07 +02:00
}