- - -

Defining the defaultvalue construct.

- -
- -

§1. Definition. For what this does and why it is used, see Textual Inter (in inter). -

- -
-void DefaultValueInstruction::define_construct(void) {
-    inter_construct *IC = InterInstruction::create_construct(DEFAULTVALUE_IST, I"defaultvalue");
-    InterInstruction::specify_syntax(IC, I"defaultvalue TOKEN = TOKENS");
-    InterInstruction::fix_instruction_length_between(IC, 5, 5);
-    InterInstruction::permit(IC, INSIDE_PLAIN_PACKAGE_ICUP);
-    METHOD_ADD(IC, CONSTRUCT_READ_MTID, DefaultValueInstruction::read);
-    METHOD_ADD(IC, CONSTRUCT_VERIFY_MTID, DefaultValueInstruction::verify);
-    METHOD_ADD(IC, CONSTRUCT_WRITE_MTID, DefaultValueInstruction::write);
-}
-
-

§2. Instructions. In bytecode, the frame of an defaultvalue instruction is laid out with the -compulsory words — see Inter Nodes — followed by: -

- -
define TYPE_DEF_IFLD (DATA_IFLD + 0)
-define VAL1_DEF_IFLD (DATA_IFLD + 1)
-define VAL2_DEF_IFLD (DATA_IFLD + 2)
-
-
-inter_error_message *DefaultValueInstruction::new(inter_bookmark *IBM,
-    inter_symbol *typename, inter_pair val, inter_ti level, inter_error_location *eloc) {
-    inter_tree_node *P = Inode::new_with_3_data_fields(IBM, DEFAULTVALUE_IST,
-        /* TYPE_DEF_IFLD: */ InterSymbolsTable::id_at_bookmark(IBM, typename),
-        /* VAL1_DEF_IFLD: */ InterValuePairs::to_word1(val),
-        /* VAL2_DEF_IFLD: */ InterValuePairs::to_word2(val),
-        eloc, level);
-    inter_error_message *E = VerifyingInter::instruction(InterBookmark::package(IBM), P);
-    if (E) return E;
-    NodePlacement::move_to_moving_bookmark(P, IBM);
-    return NULL;
-}
-
-

§3. Verification consists only of sanity checks. Note that the TYPE_DEF_IFLD -field must contain a valid symbol ID — of a typename — and cannot be a more -general TID. So you cannot have an instruction setting the default value of, -say, int32. -

- -
-void DefaultValueInstruction::verify(inter_construct *IC, inter_tree_node *P,
-    inter_package *owner, inter_error_message **E) {
-    *E = VerifyingInter::SID_field(owner, P, TYPE_DEF_IFLD, TYPENAME_IST);
-}
-
-

§4. Creating from textual Inter syntax.

- -
-void DefaultValueInstruction::read(inter_construct *IC, inter_bookmark *IBM,
-    inter_line_parse *ilp, inter_error_location *eloc, inter_error_message **E) {
-    inter_symbol *typename =
-        TextualInter::find_symbol(IBM, eloc, ilp->mr.exp[0], TYPENAME_IST, E);
-    if (*E) return;
-
-    inter_pair val = InterValuePairs::undef();
-    *E = TextualInter::parse_pair(ilp->line, eloc, IBM, InterTypes::from_type_name(typename),
-        ilp->mr.exp[1], &val);
-    if (*E) return;
-
-    *E = DefaultValueInstruction::new(IBM, typename, val, (inter_ti) ilp->indent_level, eloc);
-}
-
-

§5. Writing to textual Inter syntax.

- -
-void DefaultValueInstruction::write(inter_construct *IC, OUTPUT_STREAM, inter_tree_node *P) {
-    inter_symbol *typename = InterSymbolsTable::symbol_from_ID_at_node(P, TYPE_DEF_IFLD);
-    WRITE("defaultvalue %S = ", InterSymbol::identifier(typename));
-    TextualInter::write_pair(OUT, P, InterValuePairs::get(P, VAL1_DEF_IFLD), FALSE);
-}
-
- - -