|
| 1 | +/*********************************************************************** |
| 2 | +** |
| 3 | +** REBOL [R3] Language Interpreter and Run-time Environment |
| 4 | +** |
| 5 | +** Copyright 2012 REBOL Technologies |
| 6 | +** Copyright 2012-2021 Rebol Open Source Contributors |
| 7 | +** REBOL is a trademark of REBOL Technologies |
| 8 | +** |
| 9 | +** Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +** you may not use this file except in compliance with the License. |
| 11 | +** You may obtain a copy of the License at |
| 12 | +** |
| 13 | +** http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +** |
| 15 | +** Unless required by applicable law or agreed to in writing, software |
| 16 | +** distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +** See the License for the specific language governing permissions and |
| 19 | +** limitations under the License. |
| 20 | +** |
| 21 | +************************************************************************ |
| 22 | +** |
| 23 | +** Module: t-handle.c |
| 24 | +** Summary: handle datatype |
| 25 | +** Section: datatypes |
| 26 | +** Author: Oldes |
| 27 | +** Notes: |
| 28 | +** |
| 29 | +***********************************************************************/ |
| 30 | + |
| 31 | +#include "sys-core.h" |
| 32 | + |
| 33 | +/*********************************************************************** |
| 34 | +** |
| 35 | +*/ REBINT Cmp_Handle(REBVAL *a, REBVAL *b) |
| 36 | +/* |
| 37 | +***********************************************************************/ |
| 38 | +{ |
| 39 | + REBYTE *sp; |
| 40 | + REBYTE *tp; |
| 41 | + if (IS_CONTEXT_HANDLE(a)) { |
| 42 | + if (IS_CONTEXT_HANDLE(b)) { |
| 43 | + if (VAL_HANDLE_SYM(a) != VAL_HANDLE_SYM(b)) { |
| 44 | + // comparing 2 context handles of different types |
| 45 | + sp = VAL_HANDLE_NAME(a); |
| 46 | + tp = VAL_HANDLE_NAME(b); |
| 47 | + return Compare_UTF8(sp, tp, (REBCNT)LEN_BYTES(tp)) + 2; |
| 48 | + } |
| 49 | + } |
| 50 | + else { |
| 51 | + // comparing context-handle with data-handle |
| 52 | + return -1; |
| 53 | + } |
| 54 | + } |
| 55 | + else if (IS_CONTEXT_HANDLE(b)) { |
| 56 | + // comparing data-handle with context-handle |
| 57 | + return 1; |
| 58 | + } |
| 59 | + // same ctx-handle types or both data handles |
| 60 | + return (VAL_HANDLE_I32(a) - VAL_HANDLE_I32(b)); |
| 61 | +} |
| 62 | + |
| 63 | +/*********************************************************************** |
| 64 | +** |
| 65 | +*/ REBINT CT_Handle(REBVAL *a, REBVAL *b, REBINT mode) |
| 66 | +/* |
| 67 | +***********************************************************************/ |
| 68 | +{ |
| 69 | + REBINT diff; |
| 70 | + if (mode > 0) { |
| 71 | + return ((VAL_HANDLE_FLAGS(a) == VAL_HANDLE_FLAGS(b)) |
| 72 | + && (VAL_HANDLE_DATA(a) == VAL_HANDLE_DATA(b))); |
| 73 | + } |
| 74 | + else if (mode == 0) { |
| 75 | + return (IS_CONTEXT_HANDLE(a) && IS_CONTEXT_HANDLE(b) |
| 76 | + && (VAL_HANDLE_SYM(a) == VAL_HANDLE_SYM(b))); |
| 77 | + } |
| 78 | + else { |
| 79 | + diff = Cmp_Handle(a, b); |
| 80 | + if (mode == -1) return (diff >= 0); |
| 81 | + return (diff > 0); |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | + |
| 86 | +/*********************************************************************** |
| 87 | +** |
| 88 | +*/ REBFLG MT_Handle(REBVAL *out, REBVAL *data, REBCNT type) |
| 89 | +/* |
| 90 | +***********************************************************************/ |
| 91 | +{ |
| 92 | + return FALSE; |
| 93 | +} |
| 94 | + |
| 95 | + |
| 96 | +/*********************************************************************** |
| 97 | +** |
| 98 | +*/ REBTYPE(Handle) |
| 99 | +/* |
| 100 | +** |
| 101 | +***********************************************************************/ |
| 102 | +{ |
| 103 | + REBVAL *val = D_ARG(1); |
| 104 | + |
| 105 | + switch (action) { |
| 106 | + |
| 107 | + default: |
| 108 | + Trap_Action(VAL_TYPE(val), action); |
| 109 | + } |
| 110 | + |
| 111 | + return R_RET; |
| 112 | +} |
0 commit comments