// // Min_Max_Pair: C // void Min_Max_Pair(REBVAL *out, const REBVAL *a, const REBVAL *b, REBOOL maxed) { REBXYF aa; if (IS_PAIR(a)) { aa.x = VAL_PAIR_X(a); aa.y = VAL_PAIR_Y(a); } else if (IS_INTEGER(a)) aa.x = aa.y = cast(REBDEC, VAL_INT64(a)); else fail (Error_Invalid_Arg(a)); REBXYF bb; if (IS_PAIR(b)) { bb.x = VAL_PAIR_X(b); bb.y = VAL_PAIR_Y(b); } else if (IS_INTEGER(b)) bb.x = bb.y = cast(REBDEC, VAL_INT64(b)); else fail (Error_Invalid_Arg(b)); if (maxed) SET_PAIR(out, MAX(aa.x, bb.x), MAX(aa.y, bb.y)); else SET_PAIR(out, MIN(aa.x, bb.x), MIN(aa.y, bb.y)); }
*/ REBSER *Gob_To_Block(REBGOB *gob) /* ** Used by MOLD to create a block. ** ***********************************************************************/ { REBSER *ser = Make_Block(10); REBVAL *val; REBINT words[6] = {SYM_OFFSET, SYM_SIZE, SYM_ALPHA, 0}; REBVAL *vals[6]; REBINT n = 0; REBVAL *val1; REBCNT sym; for (n = 0; words[n]; n++) { val = Append_Value(ser); Init_Word(val, words[n]); VAL_SET(val, REB_SET_WORD); vals[n] = Append_Value(ser); } SET_PAIR(vals[0], GOB_X(gob), GOB_Y(gob)); SET_PAIR(vals[1], GOB_W(gob), GOB_H(gob)); SET_INTEGER(vals[2], GOB_ALPHA(gob)); if (!GOB_TYPE(gob)) return ser; if (GOB_CONTENT(gob)) { val1 = Append_Value(ser); val = Append_Value(ser); switch (GOB_TYPE(gob)) { case GOBT_COLOR: sym = SYM_COLOR; break; case GOBT_IMAGE: sym = SYM_IMAGE; break; case GOBT_STRING: case GOBT_TEXT: sym = SYM_TEXT; break; case GOBT_DRAW: sym = SYM_DRAW; break; case GOBT_EFFECT: sym = SYM_EFFECT; break; } Init_Word(val1, sym); VAL_SET(val1, REB_SET_WORD); Get_GOB_Var(gob, val1, val); } return ser; }
*/ static REBFLG Get_GOB_Var(REBGOB *gob, REBVAL *word, REBVAL *val) /* ***********************************************************************/ { switch (VAL_WORD_CANON(word)) { case SYM_OFFSET: SET_PAIR(val, GOB_X(gob), GOB_Y(gob)); break; case SYM_SIZE: SET_PAIR(val, GOB_W(gob), GOB_H(gob)); break; case SYM_IMAGE: if (GOB_TYPE(gob) == GOBT_IMAGE) { // image } else goto is_none; break; case SYM_DRAW: if (GOB_TYPE(gob) == GOBT_DRAW) { Set_Block(val, GOB_CONTENT(gob)); // Note: compiler optimizes SET_BLOCKs below } else goto is_none; break; case SYM_TEXT: if (GOB_TYPE(gob) == GOBT_TEXT) { Set_Block(val, GOB_CONTENT(gob)); } else if (GOB_TYPE(gob) == GOBT_STRING) { Set_String(val, GOB_CONTENT(gob)); } else goto is_none; break; case SYM_EFFECT: if (GOB_TYPE(gob) == GOBT_EFFECT) { Set_Block(val, GOB_CONTENT(gob)); } else goto is_none; break; case SYM_COLOR: if (GOB_TYPE(gob) == GOBT_COLOR) { Set_Tuple_Pixel((REBYTE*)&GOB_CONTENT(gob), val); } else goto is_none; break; case SYM_ALPHA: SET_INTEGER(val, GOB_ALPHA(gob)); break; case SYM_PANE: if (GOB_PANE(gob)) Set_Block(val, Pane_To_Block(gob, 0, -1)); else Set_Block(val, Make_Block(0)); break; case SYM_PARENT: if (GOB_PARENT(gob)) { SET_GOB(val, GOB_PARENT(gob)); } else is_none: SET_NONE(val); break; case SYM_DATA: if (GOB_DTYPE(gob) == GOBD_OBJECT) { SET_OBJECT(val, GOB_DATA(gob)); } else if (GOB_DTYPE(gob) == GOBD_BLOCK) { Set_Block(val, GOB_DATA(gob)); } else if (GOB_DTYPE(gob) == GOBD_STRING) { Set_String(val, GOB_DATA(gob)); } else if (GOB_DTYPE(gob) == GOBD_BINARY) { SET_BINARY(val, GOB_DATA(gob)); } else if (GOB_DTYPE(gob) == GOBD_INTEGER) { SET_INTEGER(val, (REBIPT)GOB_DATA(gob)); } else goto is_none; break; case SYM_FLAGS: Set_Block(val, Flags_To_Block(gob)); break; default: return FALSE; } return TRUE; }
*/ REBSER *Gob_To_Block(REBGOB *gob) /* ** Used by MOLD to create a block. ** ***********************************************************************/ { REBSER *ser = Make_Block(10); REBVAL *val; REBVAL *val1; REBCNT sym; val = Append_Value(ser); Init_Word(val, SYM_OFFSET); VAL_SET(val, REB_SET_WORD); val = Append_Value(ser); SET_PAIR(val, GOB_X(gob), GOB_Y(gob)); val = Append_Value(ser); Init_Word(val, SYM_SIZE); VAL_SET(val, REB_SET_WORD); val = Append_Value(ser); SET_PAIR(val, GOB_W(gob), GOB_H(gob)); if (!GET_GOB_FLAG(gob, GOBF_OPAQUE) && GOB_ALPHA(gob) < 255) { val = Append_Value(ser); Init_Word(val, SYM_ALPHA); VAL_SET(val, REB_SET_WORD); val = Append_Value(ser); SET_INTEGER(val, 255 - GOB_ALPHA(gob)); } if (!GOB_TYPE(gob)) return ser; if (GOB_CONTENT(gob)) { val1 = Append_Value(ser); val = Append_Value(ser); switch (GOB_TYPE(gob)) { case GOBT_COLOR: sym = SYM_COLOR; break; case GOBT_IMAGE: sym = SYM_IMAGE; break; #ifdef HAS_WIDGET_GOB case GOBT_WIDGET: sym = SYM_WIDGET; break; #endif case GOBT_STRING: case GOBT_TEXT: sym = SYM_TEXT; break; case GOBT_DRAW: sym = SYM_DRAW; break; case GOBT_EFFECT: sym = SYM_EFFECT; break; } Init_Word(val1, sym); VAL_SET(val1, REB_SET_WORD); Get_GOB_Var(gob, val1, val); } return ser; }
*/ static REBFLG Get_GOB_Var(REBGOB *gob, REBVAL *word, REBVAL *val) /* ***********************************************************************/ { REBSER *data; switch (VAL_WORD_CANON(word)) { case SYM_OFFSET: SET_PAIR(val, GOB_X(gob), GOB_Y(gob)); break; case SYM_SIZE: SET_PAIR(val, GOB_W(gob), GOB_H(gob)); break; case SYM_IMAGE: if (GOB_TYPE(gob) == GOBT_IMAGE) { // image } else goto is_none; break; #ifdef HAS_WIDGET_GOB case SYM_WIDGET: data = VAL_SERIES(GOB_WIDGET_SPEC(gob)); Init_Word(val, VAL_WORD_CANON(BLK_HEAD(data))); VAL_SET(val, REB_LIT_WORD); break; #endif case SYM_DRAW: if (GOB_TYPE(gob) == GOBT_DRAW) { Set_Block(val, GOB_CONTENT(gob)); // Note: compiler optimizes SET_BLOCKs below } else goto is_none; break; case SYM_TEXT: if (GOB_TYPE(gob) == GOBT_TEXT) { Set_Block(val, GOB_CONTENT(gob)); } else if (GOB_TYPE(gob) == GOBT_STRING) { Set_String(val, GOB_CONTENT(gob)); } else goto is_none; break; case SYM_EFFECT: if (GOB_TYPE(gob) == GOBT_EFFECT) { Set_Block(val, GOB_CONTENT(gob)); } else goto is_none; break; case SYM_COLOR: if (GOB_TYPE(gob) == GOBT_COLOR) { Set_Tuple_Pixel((REBYTE*)&GOB_CONTENT(gob), val); } else goto is_none; break; case SYM_ALPHA: SET_INTEGER(val, GOB_ALPHA(gob)); break; case SYM_PANE: if (GOB_PANE(gob)) Set_Block(val, Pane_To_Block(gob, 0, -1)); else Set_Block(val, Make_Block(0)); break; case SYM_PARENT: if (GOB_PARENT(gob)) { SET_GOB(val, GOB_PARENT(gob)); } else is_none: SET_NONE(val); break; case SYM_DATA: #ifdef HAS_WIDGET_GOB if (GOB_TYPE(gob) == GOBT_WIDGET) { return OS_GET_WIDGET_DATA(gob, val); } #endif data = GOB_DATA(gob); if (GOB_DTYPE(gob) == GOBD_OBJECT) { SET_OBJECT(val, data); } else if (GOB_DTYPE(gob) == GOBD_BLOCK) { Set_Block(val, data); } else if (GOB_DTYPE(gob) == GOBD_STRING) { Set_String(val, data); } else if (GOB_DTYPE(gob) == GOBD_BINARY) { SET_BINARY(val, data); } else if (GOB_DTYPE(gob) == GOBD_INTEGER) { SET_INTEGER(val, (REBIPT)data); } else goto is_none; break; case SYM_FLAGS: Set_Block(val, Flags_To_Block(gob)); break; default: return FALSE; } return TRUE; }
// // MAKE_Pair: C // void MAKE_Pair(REBVAL *out, enum Reb_Kind type, const REBVAL *arg) { if (IS_PAIR(arg)) { *out = *arg; return; } if (IS_STRING(arg)) { // // -1234567890x-1234567890 // REBCNT len; REBYTE *bp = Temp_Byte_Chars_May_Fail(arg, VAL_LEN_AT(arg), &len, FALSE); if (!Scan_Pair(bp, len, out)) goto bad_make; return; } REBDEC x; REBDEC y; if (IS_INTEGER(arg)) { x = VAL_INT32(arg); y = VAL_INT32(arg); } else if (IS_DECIMAL(arg)) { x = VAL_DECIMAL(arg); y = VAL_DECIMAL(arg); } else if (IS_BLOCK(arg) && VAL_LEN_AT(arg) == 2) { RELVAL *item = VAL_ARRAY_AT(arg); if (IS_INTEGER(item)) x = cast(REBDEC, VAL_INT64(item)); else if (IS_DECIMAL(item)) x = cast(REBDEC, VAL_DECIMAL(item)); else goto bad_make; ++item; if (IS_END(item)) goto bad_make; if (IS_INTEGER(item)) y = cast(REBDEC, VAL_INT64(item)); else if (IS_DECIMAL(item)) y = cast(REBDEC, VAL_DECIMAL(item)); else goto bad_make; } else goto bad_make; SET_PAIR(out, x, y); return; bad_make: fail (Error_Bad_Make(REB_PAIR, arg)); }