1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef ARCHETYPE_INTERPRETER 24 #define ARCHETYPE_INTERPRETER 25 26 #include "glk/archetype/expression.h" 27 #include "common/stream.h" 28 29 namespace Glk { 30 namespace Archetype { 31 32 enum DesiredType { LVALUE, RVALUE, NAME }; 33 34 typedef ExprNode ResultType; 35 36 struct ContextType { 37 int sender, self, each, message; 38 ContextTypeContextType39 ContextType() : sender(0), self(0), each(0), message(0) {} 40 }; 41 42 extern int MainObject; 43 44 extern void interpreter_init(); 45 46 /** 47 * A short wrapper to NewDynStr which basically uses the stack as temporary string storage. 48 * If you want to use a string constructor expression as an argument, call this function, 49 * since it does not take strings by reference but by value. Expensive on the stack but 50 * only briefly; it saves cluttering eval_expr 51 */ 52 extern StringPtr MakeNewDynStr(const String &s); 53 54 /** 55 * Given a string message, returns its number in the Vocabulary list, or -1 if it was not found. 56 * At present, it simply uses a very inefficient O(N) lookup. If speed begins to become a 57 * consideration, this can be changed. 58 * @param message message to find number of 59 * @returns the number of the message in the Vocabulary list. 60 */ 61 extern int find_message(const String &message); 62 63 /** 64 * Converts a scalar expression node to a target type. Deals primarily with numeric -> string 65 * or string -> numeric conversions in their many incarnations. 66 * @param target_type type to convert to 67 * @param the_scalar scalar to convert 68 */ 69 extern bool convert_to(AclType target_type, ResultType &the_scalar); 70 71 /** 72 * Used to initialize previously unused result records. Does not expect that there might be 73 * a string pointer lurking within. 74 */ 75 extern void undefine(ResultType &result); 76 77 /** 78 * To be used on temporary result variables after their usefulness is finished. Like 'undefine' above, 79 * except that it is used only for results that have actually been used - in other words, results with 80 * their "kind" field set properly. 81 */ 82 extern void cleanup(ResultType &result); 83 84 /** 85 * Does an rvalue-like copy from r2 to r1 86 */ 87 extern void copy_result(ResultType &r1, const ResultType &r2); 88 89 /** 90 * Compares two result nodes according to the given operator. 91 * @returns true if they can; false if they cannot 92 */ 93 extern bool result_compare(short comparison, ResultType &r1, ResultType &r2); 94 95 /** 96 * Given the result of an LVALUE evaluation and a result to assign to the attribute, 97 * performs the assignment if possible. 98 * @param target hopefully points to attribute to receive assignment 99 * @param value Result to assign 100 * @returns Returns true if the assignment was successful; false otherwise 101 */ 102 extern bool assignment(ResultType &target, ResultType &value); 103 104 /** 105 * Gets a textual version of a passed result 106 */ 107 extern String get_result_string(ResultType &result); 108 109 /** 110 * Writes the given result to screen w/o terminating it with a newline 111 */ 112 extern void write_result(ResultType &result); 113 114 /** 115 * For purposes of debugging. 116 * Strings are enclosed in double quotes. 117 * Messages are enclosed in single quotes. 118 * Quote literals are preceded by >> 119 */ 120 extern void display_result(ResultType &result); 121 122 /** 123 * Given an expression tree, displays the thing on screen. 124 */ 125 extern void display_expr(ExprTree the_tree); 126 127 /** 128 * Loads a game into memory from a binary input file. Checks for errors 129 * in the header or incompatible versions. 130 * @param f_in Input file 131 */ 132 extern bool load_game(Common::ReadStream *f_in); 133 134 } // End of namespace Archetype 135 } // End of namespace Glk 136 137 #endif 138