Skip to content

Commit

Permalink
ACTIONSCRIPT: Add stacked registers
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Feb 23, 2019
1 parent c63240c commit 406a565
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/aurora/actionscript/avm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ namespace ActionScript {

AVM::AVM() {
_registers.resize(256);
for (size_t i = 0; i < _registers.size(); ++i)
_registers[i].push(Variable());

_stopFlag = false;

_variables["_global"] = ObjectPtr(new Object());
Expand All @@ -66,12 +69,24 @@ void AVM::setFSCommandCallback(FSCommandFunction fscommand) {
_fscommand = fscommand;
}

void AVM::pushRegisters(uint8 n) {
for (unsigned int i = 1; i < n; ++i) {
_registers[i].push(Variable());
}
}

void AVM::popRegisters(uint8 n) {
for (unsigned int i = 1; i < n; ++i) {
_registers[i].pop();
}
}

void AVM::storeRegister(Variable value, byte index) {
_registers[index] = value;
_registers[index].top() = value;
}

Variable AVM::getRegister(byte index) {
return _registers[index];
return _registers[index].top();
}

void AVM::fsCommand(const Common::UString &name, const Common::UString &value) {
Expand Down
7 changes: 6 additions & 1 deletion src/aurora/actionscript/avm.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef AURORA_ACTIONSCRIPT_AVM_H
#define AURORA_ACTIONSCRIPT_AVM_H

#include <stack>

#include <boost/function.hpp>

#include "src/common/ustring.h"
Expand Down Expand Up @@ -61,6 +63,9 @@ class AVM {
*/
void fsCommand(const Common::UString &name, const Common::UString &value);

void pushRegisters(uint8 n);
void popRegisters(uint8 n);

void storeRegister(Variable value, byte index);
Variable getRegister(byte index);

Expand All @@ -85,7 +90,7 @@ class AVM {
RegisterClassFunction _registerClass;
FSCommandFunction _fscommand;

std::vector<Variable> _registers;
std::vector<std::stack<Variable>> _registers;
std::map<Common::UString, Variable> _variables;

bool _stopFlag;
Expand Down

0 comments on commit 406a565

Please sign in to comment.