1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-07-08 18:14:21 +03:00
inform7/inter/inter-module/Chapter 5/The Code Construct.w

66 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 = Inter::Defn::create_construct(
CODE_IST,
2019-03-22 13:06:13 +02:00
L"code",
2019-02-05 02:44:07 +02:00
I"code", I"codes");
IC->min_level = 0;
2019-02-05 02:44:07 +02:00
IC->max_level = 100000000;
IC->usage_permissions = INSIDE_CODE_PACKAGE + CAN_HAVE_CHILDREN;
2019-07-09 08:45:46 +03:00
METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Code::read);
METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, Inter::Code::verify);
METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Code::write);
METHOD_ADD(IC, VERIFY_INTER_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) {
2019-07-09 08:45:46 +03:00
if (ilp->no_annotations > 0) { *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, 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
inter_symbol *routine = Inter::Defn::get_latest_block_symbol();
2019-07-09 08:45:46 +03:00
if (routine == NULL) { *E = Inter::Errors::plain(I"'code' used outside function", eloc); return; }
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) {
inter_frame *P = Inter::Frame::fill_1(IBM, CODE_IST, 0, eloc, (inter_t) 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::Frame::insert(P, IBM);
2019-02-05 02:44:07 +02:00
return NULL;
}
void Inter::Code::verify(inter_construct *IC, inter_frame *P, inter_package *owner, inter_error_message **E) {
if (P->node->W.extent != EXTENT_CODE_IFR) *E = Inter::Frame::error(P, I"extent wrong", NULL);
2019-02-05 02:44:07 +02:00
}
void Inter::Code::write(inter_construct *IC, OUTPUT_STREAM, inter_frame *P, inter_error_message **E) {
2019-03-22 13:06:13 +02:00
WRITE("code");
2019-02-05 02:44:07 +02:00
}
void Inter::Code::verify_children(inter_construct *IC, inter_frame *P, inter_error_message **E) {
LOOP_THROUGH_INTER_CHILDREN(C, P) {
if ((C->node->W.data[0] != INV_IST) && (C->node->W.data[0] != SPLAT_IST) && (C->node->W.data[0] != EVALUATION_IST) && (C->node->W.data[0] != LABEL_IST) && (C->node->W.data[0] != VAL_IST) && (C->node->W.data[0] != COMMENT_IST) && (C->node->W.data[0] != NOP_IST)) {
*E = Inter::Frame::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
}