summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-12-01 13:03:03 -0800
committerBen Longbons <b.r.longbons@gmail.com>2013-12-01 13:03:03 -0800
commit1458563f00deebbbcf3e8049dc90157fb825fae3 (patch)
treebc50379e732fe594f163ffd14d541cb99a1173d5 /src
parent6af0112e304be73e7e4ee9332c8280bd46ea0fd0 (diff)
downloadtmwa-1458563f00deebbbcf3e8049dc90157fb825fae3.tar.gz
tmwa-1458563f00deebbbcf3e8049dc90157fb825fae3.tar.bz2
tmwa-1458563f00deebbbcf3e8049dc90157fb825fae3.tar.xz
tmwa-1458563f00deebbbcf3e8049dc90157fb825fae3.zip
Add some debug printers for scripts
Diffstat (limited to 'src')
-rw-r--r--src/common/io.hpp26
-rw-r--r--src/map/script.py56
2 files changed, 56 insertions, 26 deletions
diff --git a/src/common/io.hpp b/src/common/io.hpp
deleted file mode 100644
index 27bf4e2..0000000
--- a/src/common/io.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef TMWA_COMMON_IO_HPP
-#define TMWA_COMMON_IO_HPP
-
-#include <istream>
-#include <ostream>
-
-#include "../strings/fstring.hpp"
-
-namespace io
-{
- inline
- std::istream& getline(std::istream& in, FString& line)
- {
- std::string s;
- if (std::getline(in, s))
- {
- std::string::const_iterator begin = s.cbegin(), end = s.cend();
- if (begin != end && end[-1] == '\r')
- --end;
- line = FString(begin, end);
- }
- return in;
- }
-} // namespace io
-
-#endif //TMWA_COMMON_IO_HPP
diff --git a/src/map/script.py b/src/map/script.py
new file mode 100644
index 0000000..ba0198c
--- /dev/null
+++ b/src/map/script.py
@@ -0,0 +1,56 @@
+class ByteCode:
+ ''' print a ByteCode
+ (workaround for gcc bug 58150)
+ '''
+ __slots__ = ('_value')
+ name = 'ByteCode'
+ enabled = True
+
+ def __init__(self, value):
+ self._value = value
+
+ def to_string(self):
+ val = int(self._value)
+ try:
+ return 'ByteCode::' + self.types[val]
+ except IndexError:
+ return 'ByteCode(%x)' % val
+
+ types = [
+ 'NOP', 'POS', 'INT', 'PARAM', 'FUNC', 'STR', 'CONSTSTR', 'ARG',
+ 'VARIABLE', 'EOL', 'RETINFO',
+
+ 'LOR', 'LAND', 'LE', 'LT', 'GE', 'GT', 'EQ', 'NE',
+ 'XOR', 'OR', 'AND', 'ADD', 'SUB', 'MUL', 'DIV', 'MOD',
+ 'NEG', 'LNOT', 'NOT', 'R_SHIFT', 'L_SHIFT',
+
+ 'FUNC_REF',
+ ]
+for i, n in enumerate(ByteCode.types):
+ setattr(ByteCode, n, i)
+del i, n
+
+class script_data(object):
+ ''' print a script_data
+ '''
+ __slots__ = ('_value')
+ name = 'script_data'
+ enabled = True
+
+ def __init__(self, value):
+ self._value = value
+
+ def children(self):
+ v = self._value
+ t = v['type']
+ yield 'type', ByteCode(t).to_string() # why does this not work?
+ v = v['u']
+ t = int(t)
+ if t == ByteCode.PARAM:
+ yield 'reg', v['reg']
+ elif t == ByteCode.RETINFO:
+ yield 'script', v['script']
+ elif t in (ByteCode.STR, ByteCode.CONSTSTR):
+ yield 'str', v['str']
+ else:
+ yield 'numi', v['numi']