summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-10-07 00:05:57 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-10-07 00:31:42 -0700
commit0c2de8979105e6b5a24be18d3241a609f9bfed8f (patch)
tree4634ed919e246374bf22a0ce2a47e0dd3686d1e1 /src
parentc9ff0496aec665b6bda7d145c4705caa4f500da1 (diff)
downloadtmwa-0c2de8979105e6b5a24be18d3241a609f9bfed8f.tar.gz
tmwa-0c2de8979105e6b5a24be18d3241a609f9bfed8f.tar.bz2
tmwa-0c2de8979105e6b5a24be18d3241a609f9bfed8f.tar.xz
tmwa-0c2de8979105e6b5a24be18d3241a609f9bfed8f.zip
Minimize script header
Diffstat (limited to 'src')
-rw-r--r--src/map/fwd.hpp5
-rw-r--r--src/map/magic-v2.cpp2
-rw-r--r--src/map/npc.hpp2
-rw-r--r--src/map/script.cpp92
-rw-r--r--src/map/script.hpp101
5 files changed, 118 insertions, 84 deletions
diff --git a/src/map/fwd.hpp b/src/map/fwd.hpp
index 79bbbcd..b73d36a 100644
--- a/src/map/fwd.hpp
+++ b/src/map/fwd.hpp
@@ -20,6 +20,8 @@
#include "../sanity.hpp"
+#include <cstdint>
+
namespace tmwa
{
@@ -40,6 +42,9 @@ struct NpcEvent;
struct item_data;
+enum class SP : uint16_t;
+struct ScriptLabel;
+
namespace magic
{
struct fun_t;
diff --git a/src/map/magic-v2.cpp b/src/map/magic-v2.cpp
index 5b375b2..b299279 100644
--- a/src/map/magic-v2.cpp
+++ b/src/map/magic-v2.cpp
@@ -24,6 +24,8 @@
#include <map>
#include <set>
+#include "../range/slice.hpp"
+
#include "../strings/rstring.hpp"
#include "../strings/literal.hpp"
diff --git a/src/map/npc.hpp b/src/map/npc.hpp
index 33dd378..3870a39 100644
--- a/src/map/npc.hpp
+++ b/src/map/npc.hpp
@@ -24,6 +24,8 @@
#include <cstdint>
+#include "../range/slice.hpp"
+
#include "../strings/fwd.hpp"
#include "../generic/fwd.hpp"
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 04fc11a..61233b8 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -80,6 +80,35 @@ namespace tmwa
constexpr bool DEBUG_DISP = false;
constexpr bool DEBUG_RUN = false;
+enum class VariableCode : uint8_t
+{
+ PARAM,
+ VARIABLE,
+};
+
+enum class StringCode : uint8_t
+{
+ NOP, POS, INT, PARAM, FUNC,
+ VARIABLE,
+};
+
+enum class ByteCode : uint8_t
+{
+ // types and specials
+ // Note that 'INT' is synthetic, and does not occur in the data stream
+ NOP, POS, INT, PARAM, FUNC, STR, ARG,
+ VARIABLE, EOL,
+
+ // unary and binary operators
+ LOR, LAND, LE, LT, GE, GT, EQ, NE,
+ XOR, OR, AND, ADD, SUB, MUL, DIV, MOD,
+ NEG, LNOT, NOT, R_SHIFT, L_SHIFT,
+
+ // additions
+ // needed because FUNC is used for the actual call
+ FUNC_REF,
+};
+
struct str_data_t
{
StringCode type;
@@ -88,6 +117,69 @@ struct str_data_t
int label_;
int val;
};
+
+class ScriptBuffer
+{
+ typedef ZString::iterator ZSit;
+
+ std::vector<ByteCode> script_buf;
+public:
+ // construction methods used only by script.cpp
+ void add_scriptc(ByteCode a);
+ void add_scriptb(uint8_t a);
+ void add_scripti(uint32_t a);
+ void add_scriptl(str_data_t *a);
+ void set_label(str_data_t *ld, int pos_);
+ ZSit parse_simpleexpr(ZSit p);
+ ZSit parse_subexpr(ZSit p, int limit);
+ ZSit parse_expr(ZSit p);
+ ZSit parse_line(ZSit p, bool *canstep);
+ void parse_script(ZString src, int line, bool implicit_end);
+
+ // consumption methods used only by script.cpp
+ ByteCode operator[](size_t i) const { return script_buf[i]; }
+ ZString get_str(size_t i) const
+ {
+ return ZString(strings::really_construct_from_a_pointer, reinterpret_cast<const char *>(&script_buf[i]), nullptr);
+ }
+};
+} // namespace tmwa
+
+void std::default_delete<const tmwa::ScriptBuffer>::operator()(const tmwa::ScriptBuffer *sd)
+{
+ really_delete1 sd;
+}
+
+namespace tmwa
+{
+ByteCode ScriptPointer::peek() const { return (*code)[pos]; }
+ByteCode ScriptPointer::pop() { return (*code)[pos++]; }
+ZString ScriptPointer::pops()
+{
+ ZString rv = code->get_str(pos);
+ pos += rv.size();
+ ++pos;
+ return rv;
+}
+
+struct script_stack
+{
+ std::vector<struct script_data> stack_datav;
+};
+
+enum class ScriptEndState;
+// future improvements coming!
+class ScriptState
+{
+public:
+ struct script_stack *stack;
+ int start, end;
+ ScriptEndState state;
+ BlockId rid, oid;
+ ScriptPointer scriptp, new_scriptp;
+ int defsp, new_defsp;
+};
+
static
Map<RString, str_data_t> str_datam;
static
diff --git a/src/map/script.hpp b/src/map/script.hpp
index 96e14fc..19dbcd0 100644
--- a/src/map/script.hpp
+++ b/src/map/script.hpp
@@ -24,9 +24,10 @@
#include <cstdint>
+#include <memory>
#include <vector>
-#include "../range/slice.hpp"
+#include "../range/fwd.hpp"
#include "../strings/zstring.hpp"
@@ -36,71 +37,27 @@
#include "../mmo/ids.hpp"
-#include "clif.t.hpp"
-#include "map.t.hpp"
-
namespace tmwa
{
-enum class VariableCode : uint8_t
-{
- PARAM,
- VARIABLE,
-};
+enum class ByteCode : uint8_t;
-enum class StringCode : uint8_t
-{
- NOP, POS, INT, PARAM, FUNC,
- VARIABLE,
-};
+class ScriptBuffer;
+} // namespace tmwa
-enum class ByteCode : uint8_t
+namespace std
{
- // types and specials
- // Note that 'INT' is synthetic, and does not occur in the data stream
- NOP, POS, INT, PARAM, FUNC, STR, ARG,
- VARIABLE, EOL,
-
- // unary and binary operators
- LOR, LAND, LE, LT, GE, GT, EQ, NE,
- XOR, OR, AND, ADD, SUB, MUL, DIV, MOD,
- NEG, LNOT, NOT, R_SHIFT, L_SHIFT,
-
- // additions
- // needed because FUNC is used for the actual call
- FUNC_REF,
-};
-
-struct str_data_t;
-
-class ScriptBuffer
+template<>
+struct default_delete<const tmwa::ScriptBuffer>
{
- typedef ZString::iterator ZSit;
-
- std::vector<ByteCode> script_buf;
-public:
- // construction methods used only by script.cpp
- void add_scriptc(ByteCode a);
- void add_scriptb(uint8_t a);
- void add_scripti(uint32_t a);
- void add_scriptl(str_data_t *a);
- void set_label(str_data_t *ld, int pos_);
- ZSit parse_simpleexpr(ZSit p);
- ZSit parse_subexpr(ZSit p, int limit);
- ZSit parse_expr(ZSit p);
- ZSit parse_line(ZSit p, bool *canstep);
- void parse_script(ZString src, int line, bool implicit_end);
-
- // consumption methods used only by script.cpp
- ByteCode operator[](size_t i) const { return script_buf[i]; }
- ZString get_str(size_t i) const
- {
- return ZString(strings::really_construct_from_a_pointer, reinterpret_cast<const char *>(&script_buf[i]), nullptr);
- }
-
- // method used elsewhere
+ default_delete() {}
+ default_delete(default_delete<tmwa::ScriptBuffer>) {}
+ void operator()(const tmwa::ScriptBuffer *sd);
};
+} // namespace std
+namespace tmwa
+{
struct ScriptPointer
{
const ScriptBuffer *code;
@@ -116,15 +73,9 @@ struct ScriptPointer
, pos(p)
{}
- ByteCode peek() const { return (*code)[pos]; }
- ByteCode pop() { return (*code)[pos++]; }
- ZString pops()
- {
- ZString rv = code->get_str(pos);
- pos += rv.size();
- ++pos;
- return rv;
- }
+ ByteCode peek() const;
+ ByteCode pop();
+ ZString pops();
};
// internal
@@ -216,24 +167,6 @@ struct script_data : ScriptDataVariantBase
script_data(ScriptDataFuncRef v) : ScriptDataVariantBase(std::move(v)) {}
};
-struct script_stack
-{
- std::vector<struct script_data> stack_datav;
-};
-
-enum class ScriptEndState;
-// future improvements coming!
-class ScriptState
-{
-public:
- struct script_stack *stack;
- int start, end;
- ScriptEndState state;
- BlockId rid, oid;
- ScriptPointer scriptp, new_scriptp;
- int defsp, new_defsp;
-};
-
std::unique_ptr<const ScriptBuffer> parse_script(ZString, int, bool implicit_end);
struct argrec_t