*/ REBINT PD_File(REBPVS *pvs) /* ***********************************************************************/ { REBSER *ser; REB_MOLD mo = {0}; REBCNT n; REBUNI c; REBSER *arg; if (pvs->setval) return PE_BAD_SET; ser = Copy_Series_Value(pvs->value); n = SERIES_TAIL(ser); if (n > 0) c = GET_ANY_CHAR(ser, n-1); if (n == 0 || c != '/') Append_Byte(ser, '/'); if (ANY_STR(pvs->select)) arg = VAL_SERIES(pvs->select); else { Reset_Mold(&mo); Mold_Value(&mo, pvs->select, 0); arg = mo.series; } c = GET_ANY_CHAR(arg, 0); n = (c == '/' || c == '\\') ? 1 : 0; Append_String(ser, arg, n, arg->tail-n); Set_Series(VAL_TYPE(pvs->value), pvs->store, ser); return PE_USE; }
*/ void Make_Error_Object(REBVAL *arg, REBVAL *value) /* ** Creates an error object from arg and puts it in value. ** The arg can be a string or an object body block. ** This function is called by MAKE ERROR!. ** ***********************************************************************/ { REBSER *err; // Error object ERROR_OBJ *error; // Error object values REBINT code = 0; // Create a new error object from another object, including any non-standard fields: if (IS_ERROR(arg) || IS_OBJECT(arg)) { err = Merge_Frames(VAL_OBJ_FRAME(ROOT_ERROBJ), IS_ERROR(arg) ? VAL_OBJ_FRAME(arg) : VAL_ERR_OBJECT(arg)); error = ERR_VALUES(err); // if (!IS_INTEGER(&error->code)) { if (!Find_Error_Info(error, &code)) code = RE_INVALID_ERROR; SET_INTEGER(&error->code, code); // } SET_ERROR(value, VAL_INT32(&error->code), err); return; } // Make a copy of the error object template: err = CLONE_OBJECT(VAL_OBJ_FRAME(ROOT_ERROBJ)); error = ERR_VALUES(err); SET_NONE(&error->id); SET_ERROR(value, 0, err); // If block arg, evaluate object values (checking done later): // If user set error code, use it to setup type and id fields. if (IS_BLOCK(arg)) { DISABLE_GC; Do_Bind_Block(err, arg); // GC-OK (disabled) ENABLE_GC; if (IS_INTEGER(&error->code) && VAL_INT64(&error->code)) { Set_Error_Type(error); } else { if (Find_Error_Info(error, &code)) { SET_INTEGER(&error->code, code); } } // The error code is not valid: if (IS_NONE(&error->id)) { SET_INTEGER(&error->code, RE_INVALID_ERROR); Set_Error_Type(error); } if (VAL_INT64(&error->code) < 100 || VAL_INT64(&error->code) > 1000) Trap_Arg(arg); } // If string arg, setup other fields else if (IS_STRING(arg)) { SET_INTEGER(&error->code, RE_USER); // user error Set_String(&error->arg1, Copy_Series_Value(arg)); Set_Error_Type(error); } // No longer allowed: // else if (IS_INTEGER(arg)) { // error->code = *arg; // Set_Error_Type(error); // } else Trap_Arg(arg); if (!(VAL_ERR_NUM(value) = VAL_INT32(&error->code))) { Trap_Arg(arg); } }