aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/runtime.cpp11
-rw-r--r--src/runtime.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/src/runtime.cpp b/src/runtime.cpp
index 7519ea9..d4c9154 100644
--- a/src/runtime.cpp
+++ b/src/runtime.cpp
@@ -22,6 +22,9 @@ void Runtime::runCommand(const Token& token) {
else if (lexeme == "O") {
doPrintAscii();
}
+ else if (lexeme == ":") {
+ doSplice();
+ }
}
void Runtime::run(std::vector<Token>& tokens) {
@@ -52,3 +55,11 @@ void Runtime::doSum() {
m_values.push_back(sum);
}
+
+void Runtime::doSplice() {
+ int count = m_values.back();
+ m_values.pop_back();
+
+ std::vector<int> spliced(m_values.begin(), m_values.begin() + count);
+ m_values = spliced;
+}
diff --git a/src/runtime.h b/src/runtime.h
index 2a32220..a3aa139 100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -11,6 +11,7 @@ class Runtime {
void doSum();
void doPrint() const;
void doPrintAscii() const;
+ void doSplice();
public:
Runtime();