vm and compiler fixes; some work on instance system
[gaemu.git] / gaem / runner / value.d
blob22911ec02feb823c54e359673cd127f55e42bdb7
1 /* GML runner
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 module gaem.runner.value is aliced;
20 import gaem.runner.strpool;
23 // ////////////////////////////////////////////////////////////////////////// //
24 alias Real = double;
27 // value manipulation
28 bool isReal (Real v) nothrow @safe @nogc {
29 pragma(inline, true);
30 import std.math;
31 return !isNaN(v);
35 bool isString (Real v) nothrow @safe @nogc {
36 pragma(inline, true);
37 import std.math;
38 return isNaN(v);
42 bool isUndef (Real v) nothrow @safe @nogc {
43 pragma(inline, true);
44 import std.math;
45 return (isNaN(v) && getNaNPayload(v) < 0);
49 // creates "undefined" value
50 Real undefValue () nothrow @safe @nogc {
51 pragma(inline, true);
52 import std.math;
53 return NaN(-666);
57 // for invalid strings it returns 0
58 int getStrId (Real v) nothrow @safe @nogc {
59 pragma(inline, true);
60 import std.math;
61 if (isNaN(v)) {
62 auto res = getNaNPayload(v);
63 static if (Real.sizeof == 4) {
64 return (res < 0 ? 0 : cast(int)res);
65 } else {
66 return (res < 0 || res > int.max ? 0 : cast(int)res);
68 } else {
69 return 0;
74 Real buildStrId (int id) nothrow @safe @nogc {
75 pragma(inline, true);
76 import std.math;
77 static if (Real.sizeof == 4) {
78 assert(id >= 0 && id <= 0x3F_FFFF);
79 } else {
80 assert(id >= 0);
82 return NaN(id);
86 Real Value () nothrow @safe @nogc { pragma(inline, true); return undefValue(); }
88 Real Value(T) (T v) {
89 pragma(inline, true);
90 static if (is(T : const(char)[])) return buildStrId(newDynStr(v));
91 else static if (is(T : Real)) return cast(Real)v;
92 else static assert(0, "invalid value type");