*/ REBVAL *Find_In_Contexts(REBCNT sym, REBVAL *where) /* ** Search a block of objects for a given word symbol and ** return the value for the word. NULL if not found. ** ***********************************************************************/ { REBVAL *val; for (; NOT_END(where); where++) { if (IS_WORD(where)) { val = Get_Var(where); } else if (IS_PATH(where)) { Do_Path(&where, 0); val = DS_TOP; // only safe for short time! } else val = where; if (IS_OBJECT(val)) { val = Find_Word_Value(VAL_OBJ_FRAME(val), sym); if (val) return val; } } return 0; }
*/ static REBVAL *Do_Parse_Path(REBVAL *item, REBPARSE *parse, REBCNT *index) /* ** Handle a PATH, including get and set, that's found in a rule. ** ***********************************************************************/ { REBVAL *path = item; REBVAL tmp; if (IS_PATH(item)) { if (Do_Path(&path, 0)) return item; // found a function item = DS_TOP; } else if (IS_SET_PATH(item)) { Set_Series(parse->type, &tmp, parse->series); VAL_INDEX(&tmp) = *index; if (Do_Path(&path, &tmp)) return item; // found a function return 0; } else if (IS_GET_PATH(item)) { if (Do_Path(&path, 0)) return item; // found a function item = DS_TOP; // CureCode #1263 change // if (parse->type != VAL_TYPE(item) || VAL_SERIES(item) != parse->series) if (!ANY_SERIES(item)) Trap1(RE_PARSE_SERIES, path); *index = Set_Parse_Series(parse, item); return 0; } return item; }
*/ static REBFLG Get_Index_Var(REBVAL *item, REBSER *series, REBINT *index) /* ** Get the series index from a word or path or integer. ** ** Returns: TRUE if value was a series. FALSE if integer. ** ***********************************************************************/ { REBVAL *hold = item; if (IS_END(item)) Trap1(RE_PARSE_END, item); if (IS_WORD(item)) { if (!VAL_CMD(item)) item = Get_Var(item); } else if (IS_PATH(item)) { REBVAL *path = item; Do_Path(&path, 0); //!!! function! item = DS_TOP; } else if (!IS_INTEGER(item)) Trap1(RE_PARSE_VARIABLE, hold); if (IS_INTEGER(item)) { *index = Int32(item); return FALSE; } if (!ANY_SERIES(item) || VAL_SERIES(item) != series) Trap1(RE_PARSE_SERIES, hold); *index = VAL_INDEX(item); return TRUE; }
bool WriteRegistryTreeToFile(const TCHAR *key, const TCHAR *filename) { TRACE(_T("in WriteRegistryTreeToFile\n")); ASSERT(key && key[0] != 0); ASSERT(filename && filename[0] != 0); if (key == NULL || key[0] == 0) return false; if (filename == NULL || filename[0] == 0) return false; TRACE(_T("key=<%s> filename=<%s>\n"), key, filename); TCHAR *cp = _tcschr(const_cast<LPTSTR>(key), _T('\\')); if (cp == NULL) { TRACE(_T("ERROR - bad registry key %s\n"), key); return false; } int len = cp - key; HKEY hKey = NULL; #define IS_PATH(id, short_id) \ (_tcsncmp(key, _T(#id), len) == 0 || _tcsncmp(key, _T(#short_id), len) == 0) hKey = id if IS_PATH(HKEY_CLASSES_ROOT, HKCR); else if IS_PATH(HKEY_CURRENT_USER, HKCU);
bool WriteRegistryTreeToFile(const char *key, const char *filename) { char *cp = strchr(key, '\\'); if (cp == NULL) { return false; } int len = cp - key; HKEY hKey = 0; #define IS_PATH(id, short_id) if (strncmp(key, #id, len) == 0 || strncmp(key, #short_id, len) == 0) hKey = id IS_PATH(HKEY_CLASSES_ROOT, HKCR); else IS_PATH(HKEY_CURRENT_USER, HKCU);
// // Get_Simple_Value_Into: C // // Does easy lookup, else just returns the value as is. // void Get_Simple_Value_Into(REBVAL *out, const REBVAL *val) { if (IS_WORD(val) || IS_GET_WORD(val)) { *out = *GET_OPT_VAR_MAY_FAIL(val); } else if (IS_PATH(val) || IS_GET_PATH(val)) { if (Do_Path_Throws(out, NULL, val, NULL)) fail (Error_No_Catch_For_Throw(out)); } else { *out = *val; } }
// // Get_Simple_Value_Into: C // // Does easy lookup, else just returns the value as is. // void Get_Simple_Value_Into(REBVAL *out, const RELVAL *val, REBCTX *specifier) { if (IS_WORD(val) || IS_GET_WORD(val)) { *out = *GET_OPT_VAR_MAY_FAIL(val, specifier); } else if (IS_PATH(val) || IS_GET_PATH(val)) { if (Do_Path_Throws_Core(out, NULL, val, specifier, NULL)) fail (Error_No_Catch_For_Throw(out)); } else { COPY_VALUE(out, val, specifier); } }
*/ REBVAL *Get_Any_Var(REBVAL *item) /* ** Works for words and paths. For paths, return value is ** volatile on top of stack. ** ***********************************************************************/ { if (IS_WORD(item)) return Get_Var(item); if (IS_PATH(item)) { REBVAL *path = item; if (Do_Path(&path, 0)) return item; // found a function item = DS_TOP; } return item; }
*/ static REBVAL *Get_Parse_Value(REBVAL *item) /* ** Get the value of a word (when not a command) or path. ** Returns all other values as-is. ** ***********************************************************************/ { if (IS_WORD(item)) { if (!VAL_CMD(item)) item = Get_Var(item); } else if (IS_PATH(item)) { REBVAL *path = item; if (Do_Path(&path, 0)) return item; // found a function item = DS_TOP; } return item; }
int ft_trans_to_print(int pos, t_map *map, int pos_col, int pos_row) { if (pos_col == map->entrance_x && pos_row == map->entrance_y) ft_putchar(map->entrance); else if (IS_WALL(pos)) ft_putchar(map->wall); else if (IS_EXIT(pos)) ft_putchar(map->exit); else if (IS_SPACE(pos)) ft_putchar(map->space); else if (IS_PATH(pos)) ft_putchar(map->path); else { map->error = UNRECOGNISED_MAP_CHAR; return (0); } return (1); }
bool WriteRegistryTreeToFile(const TCHAR *key, const TCHAR *filename) { ASSERT(key && key[0] != 0); ASSERT(filename && filename[0] != 0); if (key == NULL || key[0] == 0) return false; if (filename == NULL || filename[0] == 0) return false; TCHAR *cp = lstrchr(key, _T('\\')); if (cp == NULL) return false; int len = cp - key; HKEY hKey = NULL; #define IS_PATH(id, short_id) \ (lstrcmpn(key, _T(#id), len) == 0 || lstrcmpn(key, _T(#short_id), len) == 0) hKey = id if IS_PATH(HKEY_CLASSES_ROOT, HKCR); else if IS_PATH(HKEY_CURRENT_USER, HKCU);
*/ void Do_Commands(REBSER *cmds, void *context) /* ** Evaluate a block of commands as efficiently as possible. ** The arguments to each command must already be reduced or ** use only variable lookup. ** ** Returns the last evaluated value, if provided. ** ***********************************************************************/ { REBVAL *blk; REBCNT index = 0; REBVAL *set_word = 0; REBVAL *cmd_word; REBSER *words; REBVAL *args; REBVAL *val; REBVAL *func; RXIFRM frm; // args stored here REBCNT n; REBEXT *ext; REBCEC *ctx; if ((ctx = context)) ctx->block = cmds; blk = BLK_HEAD(cmds); while (NOT_END(blk)) { // var: command result if IS_SET_WORD(blk) { set_word = blk++; index++; }; // get command function if (IS_WORD(cmd_word = blk)) { // Optimized var fetch: n = VAL_WORD_INDEX(blk); if (n > 0) func = FRM_VALUES(VAL_WORD_FRAME(blk)) + n; else func = Get_Var(blk); // fallback } else func = blk; if (!IS_COMMAND(func)) Trap2(RE_EXPECT_VAL, Get_Type_Word(REB_COMMAND), blk); // Advance to next value blk++; if (ctx) ctx->index = index; // position of function index++; // get command arguments and body words = VAL_FUNC_WORDS(func); RXA_COUNT(&frm) = SERIES_TAIL(VAL_FUNC_ARGS(func))-1; // not self // collect each argument (arg list already validated on MAKE) n = 0; for (args = BLK_SKIP(words, 1); NOT_END(args); args++) { //Debug_Type(args); val = blk++; index++; if (IS_END(val)) Trap2(RE_NO_ARG, cmd_word, args); //Debug_Type(val); // actual arg is a word, lookup? if (VAL_TYPE(val) >= REB_WORD) { if (IS_WORD(val)) { if (IS_WORD(args)) val = Get_Var(val); } else if (IS_PATH(val)) { if (IS_WORD(args)) val = Get_Any_Var(val); // volatile value! } else if (IS_PAREN(val)) { val = Do_Blk(VAL_SERIES(val), 0); // volatile value! } // all others fall through } // check datatype if (!TYPE_CHECK(args, VAL_TYPE(val))) Trap3(RE_EXPECT_ARG, cmd_word, args, Of_Type(val)); // put arg into command frame n++; RXA_TYPE(&frm, n) = Reb_To_RXT[VAL_TYPE(val)]; frm.args[n] = Value_To_RXI(val); } // Call the command (also supports different extension modules): func = BLK_HEAD(VAL_FUNC_BODY(func)); n = (REBCNT)VAL_INT64(func + 1); ext = &Ext_List[VAL_I32(VAL_OBJ_VALUE(func, 1))]; // Handler n = ext->call(n, &frm, context); val = DS_RETURN; switch (n) { case RXR_VALUE: RXI_To_Value(val, frm.args[1], RXA_TYPE(&frm, 1)); break; case RXR_BLOCK: RXI_To_Block(&frm, val); break; case RXR_UNSET: SET_UNSET(val); break; case RXR_NONE: SET_NONE(val); break; case RXR_TRUE: SET_TRUE(val); break; case RXR_FALSE: SET_FALSE(val); break; case RXR_ERROR: default: SET_UNSET(val); } if (set_word) { Set_Var(set_word, val); set_word = 0; } } }
*/ static REBCNT Do_Eval_Rule(REBPARSE *parse, REBCNT index, REBVAL **rule) /* ** Evaluate the input as a code block. Advance input if ** rule succeeds. Return new index or failure. ** ** Examples: ** do skip ** do end ** do "abc" ** do 'abc ** do [...] ** do variable ** do datatype! ** do quote 123 ** do into [...] ** ** Problem: cannot write: set var do datatype! ** ***********************************************************************/ { REBVAL value; REBVAL *item = *rule; REBCNT n; REBPARSE newparse; // First, check for end of input: if (index >= parse->series->tail) { if (IS_WORD(item) && VAL_CMD(item) == SYM_END) return index; else return NOT_FOUND; } // Evaluate next N input values: index = Do_Next(parse->series, index, FALSE); // Value is on top of stack (volatile!): value = *DS_POP; if (THROWN(&value)) Throw_Break(&value); // Get variable or command: if (IS_WORD(item)) { n = VAL_CMD(item); if (n == SYM_SKIP) return (IS_SET(&value)) ? index : NOT_FOUND; if (n == SYM_QUOTE) { item = item + 1; (*rule)++; if (IS_END(item)) Trap1(RE_PARSE_END, item-2); if (IS_PAREN(item)) { item = Do_Block_Value_Throw(item); // might GC } } else if (n == SYM_INTO) { item = item + 1; (*rule)++; if (IS_END(item)) Trap1(RE_PARSE_END, item-2); item = Get_Parse_Value(item); // sub-rules if (!IS_BLOCK(item)) Trap1(RE_PARSE_RULE, item-2); if (!ANY_BINSTR(&value) && !ANY_BLOCK(&value)) return NOT_FOUND; return (Parse_Series(&value, VAL_BLK_DATA(item), parse->flags, 0) == VAL_TAIL(&value)) ? index : NOT_FOUND; } else if (n > 0) Trap1(RE_PARSE_RULE, item); else item = Get_Parse_Value(item); // variable } else if (IS_PATH(item)) { item = Get_Parse_Value(item); // variable } else if (IS_SET_WORD(item) || IS_GET_WORD(item) || IS_SET_PATH(item) || IS_GET_PATH(item)) Trap1(RE_PARSE_RULE, item); if (IS_NONE(item)) { return (VAL_TYPE(&value) > REB_NONE) ? NOT_FOUND : index; } // Copy the value into its own block: newparse.series = Make_Block(1); SAVE_SERIES(newparse.series); Append_Val(newparse.series, &value); newparse.type = REB_BLOCK; newparse.flags = parse->flags; newparse.result = 0; n = (Parse_Next_Block(&newparse, 0, item, 0) != NOT_FOUND) ? index : NOT_FOUND; UNSAVE_SERIES(newparse.series); return n; }
*/ static To_Thru(REBPARSE *parse, REBCNT index, REBVAL *block, REBFLG is_thru) /* ***********************************************************************/ { REBSER *series = parse->series; REBCNT type = parse->type; REBVAL *blk; REBVAL *item; REBCNT cmd; REBCNT i; REBCNT len; for (; index <= series->tail; index++) { for (blk = VAL_BLK(block); NOT_END(blk); blk++) { item = blk; // Deal with words and commands if (IS_WORD(item)) { if (cmd = VAL_CMD(item)) { if (cmd == SYM_END) { if (index >= series->tail) { index = series->tail; goto found; } goto next; } else if (cmd == SYM_QUOTE) { item = ++blk; // next item is the quoted value if (IS_END(item)) goto bad_target; if (IS_PAREN(item)) { item = Do_Block_Value_Throw(item); // might GC } } else goto bad_target; } else { item = Get_Var(item); } } else if (IS_PATH(item)) { item = Get_Parse_Value(item); } // Try to match it: if (type >= REB_BLOCK) { if (ANY_BLOCK(item)) goto bad_target; i = Parse_Next_Block(parse, index, item, 0); if (i != NOT_FOUND) { if (!is_thru) i--; index = i; goto found; } } else if (type == REB_BINARY) { REBYTE ch1 = *BIN_SKIP(series, index); // Handle special string types: if (IS_CHAR(item)) { if (VAL_CHAR(item) > 0xff) goto bad_target; if (ch1 == VAL_CHAR(item)) goto found1; } else if (IS_BINARY(item)) { if (ch1 == *VAL_BIN_DATA(item)) { len = VAL_LEN(item); if (len == 1) goto found1; if (0 == Compare_Bytes(BIN_SKIP(series, index), VAL_BIN_DATA(item), len, 0)) { if (is_thru) index += len; goto found; } } } else if (IS_INTEGER(item)) { if (VAL_INT64(item) > 0xff) goto bad_target; if (ch1 == VAL_INT32(item)) goto found1; } else goto bad_target; } else { // String REBCNT ch1 = GET_ANY_CHAR(series, index); REBCNT ch2; if (!HAS_CASE(parse)) ch1 = UP_CASE(ch1); // Handle special string types: if (IS_CHAR(item)) { ch2 = VAL_CHAR(item); if (!HAS_CASE(parse)) ch2 = UP_CASE(ch2); if (ch1 == ch2) goto found1; } else if (ANY_STR(item)) { ch2 = VAL_ANY_CHAR(item); if (!HAS_CASE(parse)) ch2 = UP_CASE(ch2); if (ch1 == ch2) { len = VAL_LEN(item); if (len == 1) goto found1; i = Find_Str_Str(series, 0, index, SERIES_TAIL(series), 1, VAL_SERIES(item), VAL_INDEX(item), len, AM_FIND_MATCH | parse->flags); if (i != NOT_FOUND) { if (is_thru) i += len; index = i; goto found; } } } else if (IS_INTEGER(item)) { ch1 = GET_ANY_CHAR(series, index); // No casing! if (ch1 == (REBCNT)VAL_INT32(item)) goto found1; } else goto bad_target; } next: // Check for | (required if not end) blk++; if (IS_PAREN(blk)) blk++; if (IS_END(blk)) break; if (!IS_OR_BAR(blk)) { item = blk; goto bad_target; } } } return NOT_FOUND; found: if (IS_PAREN(blk+1)) Do_Block_Value_Throw(blk+1); return index; found1: if (IS_PAREN(blk+1)) Do_Block_Value_Throw(blk+1); return index + (is_thru ? 1 : 0); bad_target: Trap1(RE_PARSE_RULE, item); return 0; }
*/ static REBCNT Parse_Next_Block(REBPARSE *parse, REBCNT index, REBVAL *item, REBCNT depth) /* ** Used for parsing blocks to match the next item in the ruleset. ** If it matches, return the index just past it. Otherwise, return zero. ** ***********************************************************************/ { // !!! THIS CODE NEEDS CLEANUP AND REWRITE BASED ON OTHER CHANGES REBSER *series = parse->series; REBVAL *blk = BLK_SKIP(series, index); if (Trace_Level) { Trace_Value(7, item); Trace_Value(8, blk); } switch (VAL_TYPE(item)) { // Look for specific datattype: case REB_DATATYPE: index++; if (VAL_TYPE(blk) == (REBYTE)VAL_DATATYPE(item)) break; goto no_result; // Look for a set of datatypes: case REB_TYPESET: index++; if (TYPE_CHECK(item, VAL_TYPE(blk))) break; goto no_result; // 'word case REB_LIT_WORD: index++; if (IS_WORD(blk) && (VAL_WORD_CANON(blk) == VAL_WORD_CANON(item))) break; goto no_result; case REB_LIT_PATH: index++; if (IS_PATH(blk) && !Cmp_Block(blk, item, 0)) break; goto no_result; case REB_NONE: break; // Parse a sub-rule block: case REB_BLOCK: index = Parse_Rules_Loop(parse, index, VAL_BLK_DATA(item), depth); break; // Do an expression: case REB_PAREN: item = Do_Block_Value_Throw(item); // might GC // old: if (IS_ERROR(item)) Throw_Error(VAL_ERR_OBJECT(item)); index = MIN(index, series->tail); // may affect tail break; // Match with some other value: default: index++; if (Cmp_Value(blk, item, (REBOOL)HAS_CASE(parse))) goto no_result; } return index; no_result: return NOT_FOUND; }