Add stack linker

This commit is contained in:
Nikiroy78 2023-06-23 17:03:50 +03:00
parent a2d4b08d98
commit 86b067a606
4 changed files with 34 additions and 21 deletions

View File

@ -1,3 +1,3 @@
Start testing: May 09 20:48 RTZ 2 (çèìà)
Start testing: Jun 23 16:16 RTZ 2 (çèìà)
----------------------------------------------------------
End testing: May 09 20:48 RTZ 2 (çèìà)
End testing: Jun 23 16:16 RTZ 2 (çèìà)

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 9.0.0, 2023-05-09T01:33:09. -->
<!-- Written by QtCreator 9.0.0, 2023-06-23T17:03:21. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -375,23 +375,6 @@
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="QString">0</value>
<value type="QString">1</value>
<value type="QString">2</value>
<value type="QString">3</value>
<value type="QString">4</value>
<value type="QString">5</value>
<value type="QString">6</value>
<value type="QString">7</value>
<value type="QString">8</value>
<value type="QString">9</value>
<value type="QString">10</value>
<value type="QString">11</value>
<value type="QString">12</value>
<value type="QString">13</value>
<value type="QString">14</value>
</valuelist>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>

View File

@ -1,6 +1,11 @@
#include "stack.h"
#include <iostream>
int bytesToInt (vector<vector<std::byte>> bytes) {
// (!) Сделать потом
return 0;
}
Stack::Stack() {
this->stackStorage.clear();
this->stackPointer = -1;
@ -11,11 +16,31 @@ Stack::~Stack () {
vector<byte> Stack::get () {
if (this->stackStorage.size() == 0) return {};
else return this->stackStorage[this->stackPointer];
vector<byte> result = this->stackStorage[this->stackPointer];
if (this->stackLinker[this->stackPointer] != -1) {
if (
this->stackLinker.size() < bytesToInt(this->stackStorage[this->stackPointer])
) {
// (!) Выдать ошибку: такого элемента не существует
}
else if (
bytesToInt(this->stackStorage[this->stackPointer]) == this->stackPointer
) {
// (!) Выдать ошибку: ссылочный элемент не может ссылаться на самого себя
}
else {
this->stackPointer = bytesToInt(this->stackStorage[this->stackPointer]);
return this->get();
}
}
else {
return result;
}
}
void Stack::push (vector<byte> data) {
this->stackStorage.push_back(data);
this->stackLinker.push_back(-1);
this->stackPointer = this->stackStorage.size() - 1;
/*if (this->readMode) {
// (!) Выдать ошибку: стек открыт только для чтения
@ -35,6 +60,7 @@ void Stack::rm (byte removeMode) {
else {
// (!) Вот тут очистить по индексу
this->stackStorage.pop_back();
this->stackLinker.pop_back();
if (this->stackStorage.size() <= this->stackPointer) {
this->stackPointer--;
}

View File

@ -5,6 +5,8 @@
using std::byte;
using std::vector;
int bytesToInt (vector<vector<byte>> bytes);
class Stack {
public:
Stack();
@ -20,6 +22,8 @@ private:
int stackPointer = -1;
int stackSize = 0;
vector<vector<byte>> stackStorage = {};
// Link: -1 - Not Link; 0 - Link to stack; 1 - Link to heap
vector<int> stackLinker = {};
};
#endif // STACK_H