|
@@ -6,12 +6,12 @@ static u8 code[MAX_CODE];
|
|
|
static size_t codeIndex = 0;
|
|
static size_t codeIndex = 0;
|
|
|
static size_t codeExecutionIndex = 0;
|
|
static size_t codeExecutionIndex = 0;
|
|
|
|
|
|
|
|
-void resetCode() {
|
|
|
|
|
|
|
+void codeReset() {
|
|
|
codeIndex = 0;
|
|
codeIndex = 0;
|
|
|
codeExecutionIndex = 0;
|
|
codeExecutionIndex = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static bool pushU8(u8 u) {
|
|
|
|
|
|
|
+static bool codePushU8(u8 u) {
|
|
|
if(codeIndex >= MAX_CODE) {
|
|
if(codeIndex >= MAX_CODE) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -19,7 +19,7 @@ static bool pushU8(u8 u) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static bool push(const void* p, size_t n) {
|
|
|
|
|
|
|
+static bool codePush(const void* p, size_t n) {
|
|
|
if(codeIndex + n >= MAX_CODE) {
|
|
if(codeIndex + n >= MAX_CODE) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -28,48 +28,48 @@ static bool push(const void* p, size_t n) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool pushInstruction(Instruction i) {
|
|
|
|
|
- return pushU8(i);
|
|
|
|
|
|
|
+bool codePushInstruction(Instruction i) {
|
|
|
|
|
+ return codePushU8(i);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool pushI64(i64 i) {
|
|
|
|
|
- return push(&i, sizeof(i));
|
|
|
|
|
|
|
+bool codePushI64(i64 i) {
|
|
|
|
|
+ return codePush(&i, sizeof(i));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool pushSize(size_t i) {
|
|
|
|
|
- return push(&i, sizeof(i));
|
|
|
|
|
|
|
+bool codePushSize(size_t i) {
|
|
|
|
|
+ return codePush(&i, sizeof(i));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool pushConstantString(const char* c) {
|
|
|
|
|
|
|
+bool codePushConstantString(const char* c) {
|
|
|
size_t n = strlen(c) + 1;
|
|
size_t n = strlen(c) + 1;
|
|
|
- return pushSize(n) || push(c, n);
|
|
|
|
|
|
|
+ return codePushSize(n) || codePush(c, n);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-Instruction readInstruction() {
|
|
|
|
|
|
|
+Instruction codeReadInstruction() {
|
|
|
return codeExecutionIndex < codeIndex ? code[codeExecutionIndex++] : STOP;
|
|
return codeExecutionIndex < codeIndex ? code[codeExecutionIndex++] : STOP;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void read(void* p, size_t n) {
|
|
|
|
|
|
|
+static void codeRead(void* p, size_t n) {
|
|
|
if(codeExecutionIndex + n <= codeIndex) {
|
|
if(codeExecutionIndex + n <= codeIndex) {
|
|
|
memcpy(p, code + codeExecutionIndex, n);
|
|
memcpy(p, code + codeExecutionIndex, n);
|
|
|
codeExecutionIndex += n;
|
|
codeExecutionIndex += n;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-i64 readI64() {
|
|
|
|
|
|
|
+i64 codeReadI64() {
|
|
|
i64 i = 0;
|
|
i64 i = 0;
|
|
|
- read(&i, sizeof(i));
|
|
|
|
|
|
|
+ codeRead(&i, sizeof(i));
|
|
|
return i;
|
|
return i;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-size_t readSize() {
|
|
|
|
|
|
|
+size_t codeReadSize() {
|
|
|
size_t i = 0;
|
|
size_t i = 0;
|
|
|
- read(&i, sizeof(i));
|
|
|
|
|
|
|
+ codeRead(&i, sizeof(i));
|
|
|
return i;
|
|
return i;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const char* readConstantString() {
|
|
|
|
|
- size_t n = readSize();
|
|
|
|
|
|
|
+const char* codeReadConstantString() {
|
|
|
|
|
+ size_t n = codeReadSize();
|
|
|
if(codeExecutionIndex + n <= codeIndex &&
|
|
if(codeExecutionIndex + n <= codeIndex &&
|
|
|
code[codeExecutionIndex + n - 1] == '\0') {
|
|
code[codeExecutionIndex + n - 1] == '\0') {
|
|
|
const char* s = (char*)(code + codeExecutionIndex);
|
|
const char* s = (char*)(code + codeExecutionIndex);
|