/*
* ZRE - A lightweight, portable programming language for permacomputing.
* Copyright (C) 2025 zongor
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "debug.h"
#include "vm.h"
#ifdef __EMSCRIPTEN__
#include
#endif
/* #define MEMORY_SIZE 65536 /\* 64KB memory (adjustable) *\/ */
#define MEMORY_SIZE 1024
Word memory[MEMORY_SIZE] = {0}; /* Memory array */
uint32_t pc = 1; /* Program counter */
void mainloop() {
pc = step_vm(memory, MEMORY_SIZE, pc);
if (pc == 0) {
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop(); /* this should "kill" the app. */
#else
core_dump(memory, MEMORY_SIZE);
exit(0);
#endif
}
}
int main() {
int i = 1;
memory[0].c[0] = 'z';
memory[0].c[1] = 'r';
memory[0].c[2] = 'e';
memory[0].c[3] = '0';
memory[i++].u = OP_ADD_REAL;
memory[i++].u = 102;
memory[i++].u = 103;
memory[i++].u = 103;
memory[i++].u = OP_SUB_UINT;
memory[i++].u = 100;
memory[i++].u = 101;
memory[i++].u = 100;
memory[i++].u = OP_JGT_UINT;
memory[i++].u = 100;
memory[i++].u = 99;
memory[i++].u = 1;
memory[i++].u = OP_REAL_TO_STRING;
memory[i++].u = 103;
memory[i++].u = 1;
memory[i++].u = 200;
memory[i++].u = OP_PRINT_STRING;
memory[i++].u = 201;
memory[i++].u = 1;
memory[i++].u = 1;
memory[i++].u = OP_REAL_TO_UINT;
memory[i++].u = 103;
memory[i++].u = 1;
memory[i++].u = 103;
memory[i++].u = OP_UINT_TO_STRING;
memory[i++].u = 103;
memory[i++].u = 1;
memory[i++].u = 104;
memory[i++].u = OP_PRINT_STRING;
memory[i++].u = 105;
memory[i++].u = 1;
memory[i++].u = 1;
memory[i++].u = OP_READ_STRING;
memory[i++].u = 1;
memory[i++].u = 1;
memory[i++].u = 109;
memory[i++].u = OP_PRINT_STRING;
memory[i++].u = 110;
memory[i++].u = 1;
memory[i++].u = 1;
memory[i++].u = OP_HALT;
memory[i++].u = 0;
memory[i++].u = 0;
memory[i++].u = 0;
memory[99].u = 0;
memory[100].u = 5;
memory[101].u = 1;
memory[102].q = FLOAT_TO_Q16_16(5.0f);
memory[103].q = FLOAT_TO_Q16_16(5.0f);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(mainloop, 0, 1);
#else
while (1) {
mainloop();
}
#endif
}