static void builtin_var_loader(lily_parse_state *parser, lily_var *var) { char *name = var->name; FILE *source; char mode; if (strcmp(name, "stdin") == 0) { source = stdin; mode = 'w'; } else if (strcmp(name, "stdout") == 0) { source = stdout; mode = 'r'; } else { source = stderr; mode = 'w'; } lily_raw_value raw = {.file = lily_new_file_val(source, mode)}; lily_value v; v.flags = 0; v.type = var->type; v.value = raw; lily_tie_value(parser->symtab, var, &v); } void lily_init_builtin_package(lily_symtab *symtab, lily_import_entry *builtin) { symtab->integer_class = lily_integer_init(symtab); symtab->double_class = lily_double_init(symtab); symtab->string_class = lily_string_init(symtab); symtab->bytestring_class = lily_bytestring_init(symtab); symtab->function_class = lily_new_class_by_seed(symtab, &function_seed); symtab->any_class = lily_new_class_by_seed(symtab, &any_seed); symtab->list_class = lily_list_init(symtab); symtab->hash_class = lily_hash_init(symtab); symtab->tuple_class = lily_new_class_by_seed(symtab, &tuple_seed); symtab->optarg_class = lily_new_class_by_seed(symtab, &optarg_seed); lily_file_init(symtab); symtab->generic_class = lily_new_class_by_seed(symtab, &generic_seed); symtab->any_class->type->flags |= TYPE_MAYBE_CIRCULAR; /* This needs to be set because symtab's type finalize bubbles this unresolved flag upward. */ symtab->generic_class->type->flags |= TYPE_IS_UNRESOLVED; symtab->generic_type_start = symtab->generic_class->type; symtab->next_class_id = 12; builtin->dynaload_table = &seed_stdin; builtin->var_load_fn = builtin_var_loader; }
void lily_init_builtin_package(lily_symtab *symtab, lily_import_entry *builtin) { symtab->integer_class = lily_integer_init(symtab); symtab->double_class = lily_double_init(symtab); symtab->string_class = lily_string_init(symtab); symtab->bytestring_class = lily_bytestring_init(symtab); symtab->boolean_class = lily_boolean_init(symtab); symtab->function_class = lily_new_class_by_seed(symtab, &function_seed); symtab->dynamic_class = lily_new_class_by_seed(symtab, &dynamic_seed); symtab->list_class = lily_list_init(symtab); symtab->hash_class = lily_hash_init(symtab); symtab->tuple_class = lily_new_class_by_seed(symtab, &tuple_seed); symtab->optarg_class = lily_new_class_by_seed(symtab, &optarg_seed); lily_class *file_class = lily_file_init(symtab); symtab->generic_class = lily_new_class_by_seed(symtab, &generic_seed); symtab->question_class = lily_new_class_by_seed(symtab, &question_seed); symtab->integer_class->flags |= CLS_VALID_OPTARG | CLS_VALID_HASH_KEY; symtab->double_class->flags |= CLS_VALID_OPTARG; symtab->string_class->flags |= CLS_VALID_OPTARG | CLS_VALID_HASH_KEY; symtab->bytestring_class->flags |= CLS_VALID_OPTARG; symtab->boolean_class->flags |= CLS_VALID_OPTARG; symtab->integer_class->move_flags = VAL_IS_INTEGER; symtab->double_class->move_flags = VAL_IS_DOUBLE; symtab->string_class->move_flags = VAL_IS_STRING; symtab->bytestring_class->move_flags = VAL_IS_BYTESTRING; symtab->boolean_class->move_flags = VAL_IS_BOOLEAN; symtab->function_class->move_flags = VAL_IS_FUNCTION; symtab->dynamic_class->move_flags = VAL_IS_DYNAMIC; symtab->list_class->move_flags = VAL_IS_LIST; symtab->hash_class->move_flags = VAL_IS_HASH; symtab->tuple_class->move_flags = VAL_IS_TUPLE; file_class->move_flags = VAL_IS_FILE; /* These need to be set here so type finalization can bubble them up. */ symtab->generic_class->type->flags |= TYPE_IS_UNRESOLVED; symtab->question_class->type->flags |= TYPE_IS_INCOMPLETE; /* HACK: This ensures that there is space to dynaload builtin classes and enums into. */ symtab->next_class_id = START_CLASS_ID; builtin->dynaload_table = &seed_stdin; builtin->var_load_fn = builtin_var_loader; }