Defining the Lab construct.

§1.

enum LAB_IST
void Inter::Lab::define(void) {
    inter_construct *IC = Inter::Defn::create_construct(
        LAB_IST,
        L"lab (%C+)",
        I"lab", I"labs");
    IC->min_level = 1;
    IC->max_level = 100000000;
    IC->usage_permissions = INSIDE_CODE_PACKAGE;
    METHOD_ADD(IC, CONSTRUCT_READ_MTID, Inter::Lab::read);
    METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, Inter::Lab::verify);
    METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, Inter::Lab::write);
}

§2.

define BLOCK_LAB_IFLD 2
define LABEL_LAB_IFLD 3
define EXTENT_LAB_IFR 4
void Inter::Lab::read(inter_construct *IC, inter_bookmark *IBM, inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
    if (Inter::Annotations::exist(&(ilp->set))) { *E = Inter::Errors::plain(I"__annotations are not allowed", eloc); return; }

    *E = Inter::Defn::vet_level(IBM, LAB_IST, ilp->indent_level, eloc);
    if (*E) return;

    inter_package *routine = Inter::Defn::get_latest_block_package();
    if (routine == NULL) { *E = Inter::Errors::plain(I"'lab' used outside function", eloc); return; }
    inter_symbols_table *locals = Inter::Packages::scope(routine);
    if (locals == NULL) { *E = Inter::Errors::plain(I"function has no symbols table", eloc); return; }

    inter_symbol *label = Inter::SymbolsTables::symbol_from_name(locals, ilp->mr.exp[0]);
    if (Inter::Symbols::is_label(label) == FALSE) { *E = Inter::Errors::plain(I"not a label", eloc); return; }

    *E = Inter::Lab::new(IBM, label, (inter_t) ilp->indent_level, eloc);
}

inter_error_message *Inter::Lab::new(inter_bookmark *IBM, inter_symbol *label, inter_t level, inter_error_location *eloc) {
    inter_tree_node *P = Inter::Node::fill_2(IBM, LAB_IST, 0, Inter::SymbolsTables::id_from_IRS_and_symbol(IBM, label), eloc, (inter_t) level);
    inter_error_message *E = Inter::Defn::verify_construct(Inter::Bookmarks::package(IBM), P); if (E) return E;
    Inter::Bookmarks::insert(IBM, P);
    return NULL;
}

void Inter::Lab::verify(inter_construct *IC, inter_tree_node *P, inter_package *owner, inter_error_message **E) {
    if (P->W.extent != EXTENT_LAB_IFR) { *E = Inter::Node::error(P, I"extent wrong", NULL); return; }
    inter_symbol *label = Inter::SymbolsTables::local_symbol_from_id(owner, P->W.data[LABEL_LAB_IFLD]);
    if (Inter::Symbols::is_label(label) == FALSE) { *E = Inter::Node::error(P, I"no such label", NULL); return; }
}

void Inter::Lab::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P, inter_error_message **E) {
    inter_package *pack = Inter::Packages::container(P);
    inter_symbol *label = Inter::SymbolsTables::local_symbol_from_id(pack, P->W.data[LABEL_LAB_IFLD]);
    if (label) {
        WRITE("lab %S", label->symbol_name);
    } else { *E = Inter::Node::error(P, I"cannot write lab", NULL); return; }
}

inter_symbol *Inter::Lab::label_symbol(inter_tree_node *P) {
    inter_package *pack = Inter::Packages::container(P);
    inter_symbol *lab = Inter::SymbolsTables::local_symbol_from_id(pack, P->W.data[LABEL_LAB_IFLD]);
    if (lab == NULL) internal_error("bad lab");
    return lab;
}