1 #include "memorywatch.hpp"
2 #include "memorymanip.hpp"
9 std::string
evaluate_watch(const std::string
& expr
) throw(std::bad_alloc
)
13 std::string _expr
= expr
;
18 for(size_t i
= 0; i
< expr
.length(); i
++) {
21 y
= expr
.find_first_of("z", i
);
23 return "#syntax (noterm)";
24 t
= _expr
.substr(i
+ 1, y
- i
- 1);
25 if(t
.length() > 2 && t
.substr(0, 2) == "0x") {
27 s
.push(strtoull(t
.c_str() + 2, &end
, 16));
29 return "#syntax (badhex)";
32 s
.push(strtod(t
.c_str(), &end
));
34 return "#syntax (badnum)";
39 if(i
+ 1 == expr
.length())
40 return "#syntax (noparam)";
45 s
.push(floor(b
* a
+ 0.5) / b
);
49 return "#syntax (underflow)";
56 return "#syntax (underflow)";
65 return "#syntax (underflow)";
72 return "#syntax (underflow)";
79 return "#syntax (underflow)";
86 return "#syntax (underflow)";
93 return "#syntax (underflow)";
101 return "#syntax (underflow)";
110 return "#syntax (underflow)";
119 return "#syntax (underflow)";
128 return "#syntax (underflow)";
137 return "#syntax (underflow)";
142 s
.push(static_cast<int64_t>(a
/ b
));
146 return "#syntax (underflow)";
151 s
.push(a
- static_cast<int64_t>(a
/ b
) * b
);
155 return "#syntax (underflow)";
158 s
.push(static_cast<int8_t>(memory_read_byte(a
)));
162 return "#syntax (underflow)";
165 s
.push(static_cast<uint8_t>(memory_read_byte(a
)));
169 return "#syntax (underflow)";
172 s
.push(static_cast<int16_t>(memory_read_word(a
)));
176 return "#syntax (underflow)";
179 s
.push(static_cast<uint16_t>(memory_read_word(a
)));
183 return "#syntax (underflow)";
186 s
.push(static_cast<int32_t>(memory_read_dword(a
)));
190 return "#syntax (underflow)";
193 s
.push(static_cast<uint32_t>(memory_read_dword(a
)));
197 return "#syntax (underflow)";
200 s
.push(static_cast<int64_t>(memory_read_qword(a
)));
204 return "#syntax (underflow)";
207 s
.push(static_cast<uint64_t>(memory_read_qword(a
)));
210 return "#syntax (illchar)";
217 sprintf(buffer
, "%f", s
.top());