From 8a08606aff1025dc246b17cba4f985e097b0e7f3 Mon Sep 17 00:00:00 2001 From: crc Date: Fri, 4 Jan 2019 05:07:15 +0000 Subject: [PATCH] rre: begin work on the new windows version FossilOrigin-Name: eba21e68ce89a7a51bf35f24cff10a032877aff6d09816033e14b26b06a97172 --- interfaces/rre_windows.c | 1007 +++++++++++++++++++++++ interfaces/windows/rre_image_windows.c | 524 ------------ interfaces/windows/rre_windows.c | 1016 ------------------------ interfaces/windows/rre_windows.forth | 265 ------ 4 files changed, 1007 insertions(+), 1805 deletions(-) create mode 100644 interfaces/rre_windows.c delete mode 100644 interfaces/windows/rre_image_windows.c delete mode 100644 interfaces/windows/rre_windows.c delete mode 100644 interfaces/windows/rre_windows.forth diff --git a/interfaces/rre_windows.c b/interfaces/rre_windows.c new file mode 100644 index 0000000..aa34a85 --- /dev/null +++ b/interfaces/rre_windows.c @@ -0,0 +1,1007 @@ +/* RETRO ------------------------------------------------------ + A personal, minimalistic forth + Copyright (c) 2016 - 2019 Charles Childers + + This is `rre`, short for `run retro and exit`. It's the basic + interface layer for Retro on FreeBSD, Linux and macOS. + + rre embeds the image file into the binary, so the compiled + version of this is all you need to have a functional system. + + I'll include commentary throughout the source, so read on. + ---------------------------------------------------------- */ + +/* ------------------------------------------------------------ + Begin by including the various C headers needed. + ---------------------------------------------------------- */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef USE_TERMIOS +#include +#include +#endif + + +void generic_output(); +void generic_output_query(); +void io_keyboard_handler(); +void io_keyboard_query(); +void io_filesystem_query(); +void io_filesystem_handler(); +//void io_unix_query(); +//void io_unix_handler(); +void io_floatingpoint_query(); +void io_floatingpoint_handler(); +//void io_gopher_query(); +//void io_gopher_handler(); +void io_scripting_handler(); +void io_scripting_query(); + +#define NUM_DEVICES 5 + +typedef void (*Handler)(void); + +Handler IO_deviceHandlers[NUM_DEVICES + 1] = { + generic_output, + io_keyboard_handler, + io_filesystem_handler, + io_floatingpoint_handler, + io_scripting_handler, +// io_unix_handler, +// io_gopher_handler +}; + +Handler IO_queryHandlers[NUM_DEVICES + 1] = { + generic_output_query, + io_keyboard_query, + io_filesystem_query, + io_floatingpoint_query, + io_scripting_query, +// io_unix_query, +// io_gopher_query +}; + +/* ------------------------------------------------------------ + First, a few constants relating to the image format and + memory layout. If you modify the kernel (Rx.md), these will + need to be altered to match your memory layout. + ---------------------------------------------------------- */ + +#define TIB 1025 +#define D_OFFSET_LINK 0 +#define D_OFFSET_XT 1 +#define D_OFFSET_CLASS 2 +#define D_OFFSET_NAME 3 + + +/* ------------------------------------------------------------ + Next we get into some things that relate to the Nga virtual + machine that RETRO runs on. + ---------------------------------------------------------- */ + +#define CELL int32_t /* Cell size (32 bit, signed integer */ +#define IMAGE_SIZE 524288 * 8 /* Amount of RAM. 4MiB by default. */ +#define STACK_DEPTH 4096 /* Depth of data stack */ +#define ADDRESSES STACK_DEPTH * 3 /* Depth of address stack */ + +CELL sp, rp, ip; /* Data, address, instruction pointers */ +CELL data[STACK_DEPTH]; /* The data stack */ +CELL address[ADDRESSES]; /* The address stack */ +CELL memory[IMAGE_SIZE + 1]; /* The memory for the image */ + +#define TOS data[sp] /* Shortcut for top item on stack */ +#define NOS data[sp-1] /* Shortcut for second item on stack */ +#define TORS address[rp] /* Shortcut for top item on address stack */ + +/* ------------------------------------------------------------ + RRE embeds the image into the binary. This includes the image + data (converted to a .c file by an external tool). + ---------------------------------------------------------- */ + +#include "rre_image_unix.c" + + +/* ------------------------------------------------------------ + Moving forward, a few variables. These are updated to point + to the latest values in the image. + ---------------------------------------------------------- */ + +CELL Dictionary; +CELL NotFound; +CELL interpret; + + +/* ------------------------------------------------------------ + Function prototypes. + ---------------------------------------------------------- */ + +CELL stack_pop(); +void stack_push(CELL value); +CELL string_inject(char *str, CELL buffer); +char *string_extract(CELL at); +CELL d_link(CELL dt); +CELL d_xt(CELL dt); +CELL d_class(CELL dt); +CELL d_name(CELL dt); +CELL d_lookup(CELL Dictionary, char *name); +CELL d_xt_for(char *Name, CELL Dictionary); +void update_rx(); +void execute(CELL cell, int silent); +void evaluate(char *s, int silent); +int not_eol(int ch); +void read_token(FILE *file, char *token_buffer, int echo); +void include_file(char *fname, int run_tests); +CELL ngaLoadImage(char *imageFile); +void ngaPrepare(); +void ngaProcessOpcode(CELL opcode); +void ngaProcessPackedOpcodes(CELL opcode); +int ngaValidatePackedOpcodes(CELL opcode); + + +/* ------------------------------------------------------------ + Declare global variables related to I/O. + ---------------------------------------------------------- */ + +char **sys_argv; +int sys_argc; +int silence_input; + +/* ------------------------------------------------------------ + Now to the fun stuff: interfacing with the virtual machine. + There are a things I like to have here: + + - push a value to the stack + - pop a value off the stack + - extract a string from the image + - inject a string into the image. + - lookup dictionary headers and access dictionary fields + ---------------------------------------------------------- */ + + +/*--------------------------------------------------------------------- + Stack push/pop is easy. I could avoid these, but it aids in keeping + the code readable, so it's worth the slight overhead. + ---------------------------------------------------------------------*/ + +CELL stack_pop() { + sp--; + if (sp < 0) { + printf("Data stack underflow.\n"); + exit(1); + } + return data[sp + 1]; +} + +void stack_push(CELL value) { + sp++; + if (sp >= STACK_DEPTH) { + printf("Data stack overflow.\n"); + exit(1); + } + data[sp] = value; +} + + +/*--------------------------------------------------------------------- + Strings are next. RETRO uses C-style NULL terminated strings. So I + can easily inject or extract a string. Injection iterates over the + string, copying it into the image. This also takes care to ensure + that the NULL terminator is added. + ---------------------------------------------------------------------*/ + +CELL string_inject(char *str, CELL buffer) { + CELL m, i; + if (!str) { + memory[buffer] = 0; + return 0; + } + m = strlen(str); + i = 0; + while (m > 0) { + memory[buffer + i] = (CELL)str[i]; + memory[buffer + i + 1] = 0; + m--; i++; + } + return buffer; +} + + +/*--------------------------------------------------------------------- + Extracting a string is similar, but I have to iterate over the VM + memory instead of a C string and copy the charaters into a buffer. + This uses a static buffer (`string_data`) as I prefer to avoid using + `malloc()`. + ---------------------------------------------------------------------*/ + +char string_data[8192]; +char *string_extract(CELL at) { + CELL starting = at; + CELL i = 0; + while(memory[starting] && i < 8192) + string_data[i++] = (char)memory[starting++]; + string_data[i] = 0; + return (char *)string_data; +} + + +/*--------------------------------------------------------------------- + Continuing along, I now define functions to access the dictionary. + + RETRO's dictionary is a linked list. Each entry is setup like: + + 0000 Link to previous entry (NULL if this is the root entry) + 0001 Pointer to definition start + 0002 Pointer to class handler + 0003 Start of a NULL terminated string with the word name + + First, functions to access each field. The offsets were defineed at + the start of the file. + ---------------------------------------------------------------------*/ + +CELL d_link(CELL dt) { + return dt + D_OFFSET_LINK; +} + +CELL d_xt(CELL dt) { + return dt + D_OFFSET_XT; +} + +CELL d_class(CELL dt) { + return dt + D_OFFSET_CLASS; +} + +CELL d_name(CELL dt) { + return dt + D_OFFSET_NAME; +} + + +/*--------------------------------------------------------------------- + Next, a more complext word. This will walk through the entries to + find one with a name that matches the specified name. This is *slow*, + but works ok unless you have a really large dictionary. (I've not + run into issues with this in practice). + ---------------------------------------------------------------------*/ + +CELL d_lookup(CELL Dictionary, char *name) { + CELL dt = 0; + CELL i = Dictionary; + char *dname; + while (memory[i] != 0 && i != 0) { + dname = string_extract(d_name(i)); + if (strcmp(dname, name) == 0) { + dt = i; + i = 0; + } else { + i = memory[i]; + } + } + return dt; +} + + +/*--------------------------------------------------------------------- + My last dictionary related word returns the `xt` pointer for a word. + This is used to help keep various important bits up to date. + ---------------------------------------------------------------------*/ + +CELL d_xt_for(char *Name, CELL Dictionary) { + return memory[d_xt(d_lookup(Dictionary, Name))]; +} + + +/*--------------------------------------------------------------------- + This interface tracks a few words and variables in the image. These + are: + + Dictionary - the latest dictionary header + NotFound - called when a word is not found + interpret - the heart of the interpreter/compiler + + I have to call this periodically, as the Dictionary will change as + new words are defined, and the user might write a new error handler + or interpreter. + ---------------------------------------------------------------------*/ + +void update_rx() { + Dictionary = memory[2]; + interpret = d_xt_for("interpret", Dictionary); + NotFound = d_xt_for("err:notfound", Dictionary); +} + + +/*--------------------------------------------------------------------- + Now on to I/O and extensions! + + RRE provides a lot of additional functionality over the base RETRO + system. First up is support for files. + + The RRE file model is intended to be similar to that of the standard + C libraries and wraps fopen(), fclose(), etc. + ---------------------------------------------------------------------*/ + +void generic_output() { + putc(stack_pop(), stdout); + fflush(stdout); +} + +void generic_output_query() { + stack_push(0); + stack_push(0); +} + +void io_keyboard_handler() { + stack_push(getc(stdin)); + if (TOS == 127) TOS = 8; +#ifdef USE_TERMIOS + if (silence_input != -1) { + putc(TOS, stdout); + fflush(stdout); + } +#endif +} + +void io_keyboard_query() { + stack_push(0); + stack_push(1); +} + + +/*--------------------------------------------------------------------- + ---------------------------------------------------------------------*/ + +#ifdef USE_TERMIOS +struct termios new_termios, old_termios; + +void prepare_term() { + tcgetattr(0, &old_termios); + new_termios = old_termios; + new_termios.c_iflag &= ~(BRKINT+ISTRIP+IXON+IXOFF); + new_termios.c_iflag |= (IGNBRK+IGNPAR); + new_termios.c_lflag &= ~(ICANON+ISIG+IEXTEN+ECHO); + new_termios.c_cc[VMIN] = 1; + new_termios.c_cc[VTIME] = 0; + tcsetattr(0, TCSANOW, &new_termios); +} + +void restore_term() { + tcsetattr(0, TCSANOW, &old_termios); +} +#endif + + +void scripting_arg() { + CELL a, b; + a = stack_pop(); + b = stack_pop(); + stack_push(string_inject(sys_argv[a + 2], b)); +} + +void scripting_arg_count() { + stack_push(sys_argc - 2); +} + +void scripting_include() { + include_file(string_extract(stack_pop()), 0); +} + +Handler ScriptingActions[] = { + scripting_arg_count, + scripting_arg, + scripting_include +}; + +void io_scripting_query() { + stack_push(0); + stack_push(9); +} + +void io_scripting_handler() { + ScriptingActions[stack_pop()](); +} + +/*--------------------------------------------------------------------- + With these out of the way, I implement `execute`, which takes an + address and runs the code at it. This has a couple of interesting + bits. + + Nga uses packed instruction bundles, with up to four instructions per + bundle. Since RETRO requires an additional instruction to handle + displaying a character, I define the handler for that here. + + This will also exit if the address stack depth is zero (meaning that + the word being run, and it's dependencies) are finished. + ---------------------------------------------------------------------*/ + +void execute(CELL cell, int silent) { + CELL a, b, token; + CELL opcode; + silence_input = silent; + rp = 1; + ip = cell; + token = TIB; + while (ip < IMAGE_SIZE) { + if (ip == NotFound) { + printf("\nERROR: Word Not Found: "); + printf("`%s`\n\n", string_extract(token)); + } + if (ip == interpret) { + token = TOS; + } + opcode = memory[ip]; + if (ngaValidatePackedOpcodes(opcode) != 0) { + ngaProcessPackedOpcodes(opcode); + } else { + printf("Invalid instruction!\n"); + printf("At %d, opcode %d\n", ip, opcode); +#ifdef USE_TERMIOS + restore_term(); +#endif + exit(1); + } + ip++; + if (rp == 0) + ip = IMAGE_SIZE; + } +} + + + +/*--------------------------------------------------------------------- + RETRO's `interpret` word expects a token on the stack. This next + function copies a token to the `TIB` (text input buffer) and then + calls `interpret` to process it. + ---------------------------------------------------------------------*/ + +void evaluate(char *s, int silent) { + if (strlen(s) == 0) + return; + update_rx(); + string_inject(s, TIB); + stack_push(TIB); + execute(interpret, silent); +} + + +/*--------------------------------------------------------------------- + `read_token` reads a token from the specified file. It will stop on + a whitespace or newline. It also tries to handle backspaces, though + the success of this depends on how your terminal is configured. + ---------------------------------------------------------------------*/ + +int not_eol(int ch) { + return (ch != (char)10) && (ch != (char)13) && (ch != (char)32) && (ch != EOF) && (ch != 0); +} + +void read_token(FILE *file, char *token_buffer, int echo) { + int ch = getc(file); + int count = 0; + if (echo != 0) + putchar(ch); + while (not_eol(ch)) + { + if ((ch == 8 || ch == 127) && count > 0) { + count--; + if (echo != 0) { + putchar(8); + putchar(32); + putchar(8); + } + } else { + token_buffer[count++] = ch; + } + ch = getc(file); + if (echo != 0) + putchar(ch); + } + token_buffer[count] = '\0'; +} + + +/*--------------------------------------------------------------------- + ---------------------------------------------------------------------*/ +void dump_stack() { + CELL i; + if (sp == 0) + return; + printf("\nStack: "); + for (i = 1; i <= sp; i++) { + if (i == sp) + printf("[ TOS: %d ]", data[i]); + else + printf("%d ", data[i]); + } + printf("\n"); +} + + +/*--------------------------------------------------------------------- + RRE is primarily intended to be used in a batch or scripting model. + The `include_file()` function will be used to read the code in the + file, evaluating it as encountered. + + I enforce a literate model, with code in fenced blocks. E.g., + + # This is a test + + Display "Hello, World!" + + ~~~ + 'Hello,_World! puts nl + ~~~ + + RRE will ignore anything outside the `~~~` blocks. To identify if the + current token is the start or end of a block, I provide a `fenced()` + function. + ---------------------------------------------------------------------*/ + +int fenced(char *s) +{ + int a = strcmp(s, "```"); + int b = strcmp(s, "~~~"); + if (a == 0) return 2; + if (b == 0) return 1; + return 0; +} + + +/*--------------------------------------------------------------------- + And now for the actual `include_file()` function. + ---------------------------------------------------------------------*/ + +void include_file(char *fname, int run_tests) { + int inBlock = 0; /* Tracks status of in/out of block */ + char source[64 * 1024]; /* Line buffer [about 64K] */ + char fence[4]; /* Used with `fenced()` */ + + FILE *fp; /* Open the file. If not found, */ + fp = fopen(fname, "r"); /* exit. */ + if (fp == NULL) + return; + + while (!feof(fp)) /* Loop through the file */ + { + read_token(fp, source, 0); + strncpy(fence, source, 3); /* Copy the first three characters */ + fence[3] = '\0'; /* into `fence` to see if we are in */ + if (fenced(fence) > 0) { /* a code block. */ + if (fenced(fence) == 2 && run_tests == 0) { + } else { + if (inBlock == 0) + inBlock = 1; + else + inBlock = 0; + } + } else { + if (inBlock == 1) /* If we are, evaluate token */ + evaluate(source, -1); + } + } + + fclose(fp); +} + + +/*--------------------------------------------------------------------- + `help()` displays a summary of the command line arguments RRE allows. + + This is invoked using `rre -h` + ---------------------------------------------------------------------*/ + +void help(char *exename) { + printf("Scripting Usage: %s filename\n\n", exename); + printf("Interactive Usage: %s [-h] [-i] [-c] [-s] [-f filename] [-t]\n\n", exename); + printf("Valid Arguments:\n\n"); + printf(" -h\n"); + printf(" Display this help text\n\n"); + printf(" -i\n"); + printf(" Launches in interactive mode (line buffered)\n\n"); + printf(" -c\n"); + printf(" Launches in interactive mode (character buffered)\n\n"); + printf(" -s\n"); + printf(" Suppress the 'ok' prompt and keyboard echo in interactive mode\n\n"); + printf(" -f filename\n"); + printf(" Run the contents of the specified file\n\n"); + printf(" -t\n"); + printf(" Run tests (in ``` blocks) in any loaded files\n\n"); +} + + +/*--------------------------------------------------------------------- + `initialize()` sets up Nga and loads the image (from the array in + `image.c`) to memory. + ---------------------------------------------------------------------*/ + +void initialize() { + CELL i; + ngaPrepare(); + for (i = 0; i < ngaImageCells; i++) + memory[i] = ngaImage[i]; + update_rx(); +} + + +/*--------------------------------------------------------------------- + `arg_is()` exists to aid in readability. It compares the first actual + command line argument to a string and returns a boolean flag. + ---------------------------------------------------------------------*/ + +int arg_is(char *t) { + return strcmp(sys_argv[1], t) == 0; +} + + +/*--------------------------------------------------------------------- + ---------------------------------------------------------------------*/ + +enum flags { + FLAG_HELP, FLAG_RUN_TESTS, FLAG_INCLUDE, FLAG_INTERACTIVE, FLAG_CBREAK, FLAG_SILENT +}; + +int main(int argc, char **argv) { + int i; + int modes[32]; + char *files[16]; + int fsp; + + int run_tests; + + if (argc <= 1) return 0; /* Guard clause: exit if no */ + /* arguments are passed. */ + + initialize(); /* Initialize Nga & image */ + + sys_argc = argc; /* Point the global argc and */ + sys_argv = argv; /* argv to the actual ones */ + + if (argc >= 2 && argv[1][0] != '-') { + include_file(argv[1], 0); /* If no flags were passed, */ + if (sp >= 1) dump_stack(); /* load the file specified, */ + exit(0); /* and exit */ + } + + for (i = 0; i < 32; i++) + modes[i] = 0; + + for (i = 0; i < 16; i++) + files[i] = "\0"; + + run_tests = 0; + fsp = 0; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-h") == 0) { + help(argv[0]); + exit(0); + } else if (strcmp(argv[i], "-i") == 0) { + modes[FLAG_INTERACTIVE] = 1; + } else if (strcmp(argv[i], "-c") == 0) { + modes[FLAG_INTERACTIVE] = 1; + modes[FLAG_CBREAK] = 1; + } else if (strcmp(argv[i], "-s") == 0) { + modes[FLAG_SILENT] = 1; + } else if (strcmp(argv[i], "-f") == 0) { + files[fsp] = argv[i + 1]; + fsp++; + i++; + } else if (strcmp(argv[i], "-t") == 0) { + modes[FLAG_RUN_TESTS] = 1; + run_tests = 1; + } + } + + for (i = 0; i < fsp; i++) { + if (strcmp(files[i], "\0") != 0) + include_file(files[i], run_tests); + } + + + if (modes[FLAG_SILENT] == 1) { + memory[d_xt_for("NoEcho", Dictionary)] = -1; + } + + if (modes[FLAG_INTERACTIVE] == 1) { + execute(d_xt_for("banner", Dictionary), 0); +#ifdef USE_TERMIOS + if (modes[FLAG_CBREAK] == 1) prepare_term(); +#endif + if (modes[FLAG_CBREAK] == 1) while (1) execute(d_xt_for("listen", Dictionary), 0); + if (modes[FLAG_CBREAK] == 0) while (1) execute(d_xt_for("listen", Dictionary), -1); +#ifdef USE_TERMIOS + if (modes[FLAG_CBREAK] == 1) restore_term(); +#endif + exit(0); + } +} + + +/* Nga ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Copyright (c) 2008 - 2018, Charles Childers + Copyright (c) 2009 - 2010, Luke Parrish + Copyright (c) 2010, Marc Simpson + Copyright (c) 2010, Jay Skeer + Copyright (c) 2011, Kenneth Keating + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + +enum vm_opcode { + VM_NOP, VM_LIT, VM_DUP, VM_DROP, VM_SWAP, VM_PUSH, VM_POP, + VM_JUMP, VM_CALL, VM_CCALL, VM_RETURN, VM_EQ, VM_NEQ, VM_LT, + VM_GT, VM_FETCH, VM_STORE, VM_ADD, VM_SUB, VM_MUL, VM_DIVMOD, + VM_AND, VM_OR, VM_XOR, VM_SHIFT, VM_ZRET, VM_END, VM_IE, + VM_IQ, VM_II +}; +#define NUM_OPS VM_II + 1 + +#ifndef NUM_DEVICES +#define NUM_DEVICES 0 +#endif + +//Handler IO_deviceHandlers[NUM_DEVICES + 1]; +//Handler IO_queryHandlers[NUM_DEVICES + 1]; + +CELL ngaLoadImage(char *imageFile) { + FILE *fp; + CELL imageSize; + long fileLen; + CELL i; + if ((fp = fopen(imageFile, "rb")) != NULL) { + /* Determine length (in cells) */ + fseek(fp, 0, SEEK_END); + fileLen = ftell(fp) / sizeof(CELL); + rewind(fp); + /* Read the file into memory */ + imageSize = fread(&memory, sizeof(CELL), fileLen, fp); + fclose(fp); + } + else { + for (i = 0; i < ngaImageCells; i++) + memory[i] = ngaImage[i]; + imageSize = i; + } + return imageSize; +} + +void ngaPrepare() { + ip = sp = rp = 0; + for (ip = 0; ip < IMAGE_SIZE; ip++) + memory[ip] = VM_NOP; + for (ip = 0; ip < STACK_DEPTH; ip++) + data[ip] = 0; + for (ip = 0; ip < ADDRESSES; ip++) + address[ip] = 0; +} + +void inst_nop() { +} + +void inst_lit() { + sp++; + ip++; + TOS = memory[ip]; +} + +void inst_dup() { + sp++; + data[sp] = NOS; +} + +void inst_drop() { + data[sp] = 0; + if (--sp < 0) + ip = IMAGE_SIZE; +} + +void inst_swap() { + CELL a; + a = TOS; + TOS = NOS; + NOS = a; +} + +void inst_push() { + rp++; + TORS = TOS; + inst_drop(); +} + +void inst_pop() { + sp++; + TOS = TORS; + rp--; +} + +void inst_jump() { + ip = TOS - 1; + inst_drop(); +} + +void inst_call() { + rp++; + TORS = ip; + ip = TOS - 1; + inst_drop(); +} + +void inst_ccall() { + CELL a, b; + a = TOS; inst_drop(); /* False */ + b = TOS; inst_drop(); /* Flag */ + if (b != 0) { + rp++; + TORS = ip; + ip = a - 1; + } +} + +void inst_return() { + ip = TORS; + rp--; +} + +void inst_eq() { + NOS = (NOS == TOS) ? -1 : 0; + inst_drop(); +} + +void inst_neq() { + NOS = (NOS != TOS) ? -1 : 0; + inst_drop(); +} + +void inst_lt() { + NOS = (NOS < TOS) ? -1 : 0; + inst_drop(); +} + +void inst_gt() { + NOS = (NOS > TOS) ? -1 : 0; + inst_drop(); +} + +void inst_fetch() { + switch (TOS) { + case -1: TOS = sp - 1; break; + case -2: TOS = rp; break; + case -3: TOS = IMAGE_SIZE; break; + default: TOS = memory[TOS]; break; + } +} + +void inst_store() { + if (TOS <= IMAGE_SIZE && TOS >= 0) { + memory[TOS] = NOS; + inst_drop(); + inst_drop(); + } else { + ip = IMAGE_SIZE; + } +} + +void inst_add() { + NOS += TOS; + inst_drop(); +} + +void inst_sub() { + NOS -= TOS; + inst_drop(); +} + +void inst_mul() { + NOS *= TOS; + inst_drop(); +} + +void inst_divmod() { + CELL a, b; + a = TOS; + b = NOS; + TOS = b / a; + NOS = b % a; +} + +void inst_and() { + NOS = TOS & NOS; + inst_drop(); +} + +void inst_or() { + NOS = TOS | NOS; + inst_drop(); +} + +void inst_xor() { + NOS = TOS ^ NOS; + inst_drop(); +} + +void inst_shift() { + CELL y = TOS; + CELL x = NOS; + if (TOS < 0) + NOS = NOS << (TOS * -1); + else { + if (x < 0 && y > 0) + NOS = x >> y | ~(~0U >> y); + else + NOS = x >> y; + } + inst_drop(); +} + +void inst_zret() { + if (TOS == 0) { + inst_drop(); + ip = TORS; + rp--; + } +} + +void inst_end() { + ip = IMAGE_SIZE; +} + +void inst_ie() { + sp++; + TOS = NUM_DEVICES; +} + +void inst_iq() { + CELL Device = TOS; + inst_drop(); + IO_queryHandlers[Device](); +} + +void inst_ii() { + CELL Device = TOS; + inst_drop(); + IO_deviceHandlers[Device](); +} + +Handler instructions[NUM_OPS] = { + inst_nop, inst_lit, inst_dup, inst_drop, inst_swap, inst_push, inst_pop, + inst_jump, inst_call, inst_ccall, inst_return, inst_eq, inst_neq, inst_lt, + inst_gt, inst_fetch, inst_store, inst_add, inst_sub, inst_mul, inst_divmod, + inst_and, inst_or, inst_xor, inst_shift, inst_zret, inst_end, inst_ie, + inst_iq, inst_ii +}; + +void ngaProcessOpcode(CELL opcode) { + if (opcode != 0) + instructions[opcode](); +} + +int ngaValidatePackedOpcodes(CELL opcode) { + CELL raw = opcode; + CELL current; + int valid = -1; + int i; + for (i = 0; i < 4; i++) { + current = raw & 0xFF; + if (!(current >= 0 && current <= 29)) + valid = 0; + raw = raw >> 8; + } + return valid; +} + +void ngaProcessPackedOpcodes(CELL opcode) { + CELL raw = opcode; + int i; + for (i = 0; i < 4; i++) { + ngaProcessOpcode(raw & 0xFF); + raw = raw >> 8; + } +} diff --git a/interfaces/windows/rre_image_windows.c b/interfaces/windows/rre_image_windows.c deleted file mode 100644 index 4313b2e..0000000 --- a/interfaces/windows/rre_image_windows.c +++ /dev/null @@ -1,524 +0,0 @@ -#include -int32_t ngaImageCells = 10434; -int32_t ngaImage[] = { 1793,-1,10398,10433,201804,0,10,1,10,2,10,3,10,4,10,5,10,6,10, - 7,10,8,10,9,10,10,10,11,10,12,10,13,10,14,10,15,10,16,10, - 17,10,18,10,19,10,20,10,21,10,22,10,23,10,24,10,25,10,26,10, - 68223234,1,2575,85000450,1,656912,354,339,268505089,66,65,135205121,66,10,101384453,0,9,10,2049,59, - 25,459011,77,524546,77,302256641,1,10,16974595,0,50529798,10,25,524547,96,50529798,10,17108738,1,251790353, - 101777669,1,17565186,87,524545,91,67,167838467,-1,134287105,3,62,659457,3,459023,108,2049,59,25,2049, - 108,1793,115,2049,115,117506307,0,108,0,524545,25,113,168820993,0,127,1642241,127,134283523,7,113, - 1793,108,7,524545,2049,108,1793,108,16846593,127,142,141,1793,67,16846593,127,113,141,1793,67, - 7,10,659713,1,659713,2,659713,3,17108737,3,2,524559,108,2049,108,2049,108,2049,122,168820998, - 2,655,1025,167841793,180,5,17826049,0,180,2,15,25,524546,165,134287105,181,96,2305,182,459023, - 190,134287361,181,185,659201,180,2049,59,25,84152833,48,286458116,10,459014,205,184618754,45,25,16974851,-1, - 168886532,1,134284289,1,214,134284289,0,205,660227,32,0,0,112,114,101,102,105,120,58,32, - 0,285278479,231,7,2576,524546,82,1641217,1,167838467,228,2049,244,2049,240,524545,231,200,17826050,230, - 0,2572,2563,2049,221,1793,134,459023,134,17760513,147,3,167,8,251727617,3,2,2049,161,268501264, - -1,127,10,2049,200,2049,161,459023,134,285282049,3,2,16846593,127,-1,127,134283536,1793,108,16846593, - 3,0,108,8,659201,3,524545,25,113,17043201,3,7,2049,113,2049,108,268505092,127,1642241,127, - 656131,659201,3,524545,7,113,2049,108,459009,19,113,459009,55,113,459009,15,113,459009,17,113, - 1793,5,524546,161,134284303,163,1807,1025,1642241,230,285282049,346,1,459012,341,117509889,180,341,134287105,346, - 200,16845825,0,354,339,1793,67,17826050,346,250,8,117506305,347,357,67,0,9,153,100,117, - 112,0,374,11,153,100,114,111,112,0,381,13,153,115,119,97,112,0,389,21, - 153,99,97,108,108,0,397,27,153,101,113,63,0,405,29,153,45,101,113,63, - 0,412,31,153,108,116,63,0,420,33,153,103,116,63,0,427,35,153,102,101, - 116,99,104,0,434,37,153,115,116,111,114,101,0,443,39,153,43,0,452,41, - 153,45,0,457,43,153,42,0,462,45,153,47,109,111,100,0,467,47,153,97, - 110,100,0,475,49,153,111,114,0,482,51,153,120,111,114,0,488,53,153,115, - 104,105,102,116,0,495,333,159,112,117,115,104,0,504,336,159,112,111,112,0, - 512,330,159,48,59,0,519,59,147,102,101,116,99,104,45,110,101,120,116,0, - 525,62,147,115,116,111,114,101,45,110,101,120,116,0,539,221,147,115,58,116, - 111,45,110,117,109,98,101,114,0,553,96,147,115,58,101,113,63,0,568,82, - 147,115,58,108,101,110,103,116,104,0,577,67,147,99,104,111,111,115,101,0, - 589,75,147,105,102,0,599,73,147,45,105,102,0,605,261,159,112,114,101,102, - 105,120,58,40,0,612,127,134,67,111,109,112,105,108,101,114,0,624,3,134, - 72,101,97,112,0,636,108,147,44,0,644,122,147,115,44,0,649,128,159,59, - 0,655,288,159,91,0,660,305,159,93,0,665,2,134,68,105,99,116,105,111, - 110,97,114,121,0,670,160,147,100,58,108,105,110,107,0,684,161,147,100,58, - 120,116,0,694,163,147,100,58,99,108,97,115,115,0,702,165,147,100,58,110, - 97,109,101,0,713,147,147,99,108,97,115,115,58,119,111,114,100,0,723,159, - 147,99,108,97,115,115,58,109,97,99,114,111,0,737,134,147,99,108,97,115, - 115,58,100,97,116,97,0,752,167,147,100,58,97,100,100,45,104,101,97,100, - 101,114,0,766,262,159,112,114,101,102,105,120,58,35,0,782,268,159,112,114, - 101,102,105,120,58,58,0,794,282,159,112,114,101,102,105,120,58,38,0,806, - 266,159,112,114,101,102,105,120,58,36,0,818,320,159,114,101,112,101,97,116, - 0,830,322,159,97,103,97,105,110,0,840,366,147,105,110,116,101,114,112,114, - 101,116,0,849,200,147,100,58,108,111,111,107,117,112,0,862,153,147,99,108, - 97,115,115,58,112,114,105,109,105,116,105,118,101,0,874,4,134,86,101,114, - 115,105,111,110,0,893,339,147,101,114,114,58,110,111,116,102,111,117,110,100, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,59,0,114,115,101,45,117,110,116,105,108,0,114,118, - 101,0,53,44,95,72,101,97,112,95,64,95,0,94,96,123,124,125,126,0, - 72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,904,1543,147, - 69,79,77,0,1,-3,15,10,1536,1557,147,100,58,108,97,115,116,0,1,2, - 15,10,1547,1575,147,100,58,108,97,115,116,60,120,116,62,0,2049,1557,2049,161, - 15,10,1561,1598,147,100,58,108,97,115,116,60,99,108,97,115,115,62,0,2049, - 1557,2049,163,15,10,1581,1620,147,100,58,108,97,115,116,60,110,97,109,101,62, - 0,2049,1557,2049,165,10,1604,1636,147,114,101,99,108,97,115,115,0,2049,1557,2049, - 163,16,10,1625,1655,147,105,109,109,101,100,105,97,116,101,0,1,159,2049,1636, - 10,1642,1668,147,100,97,116,97,0,1,134,2049,1636,10,1660,1682,147,100,101,112, - 116,104,0,1,-1,15,10,1673,1701,147,99,111,109,112,105,108,101,58,108,105, - 116,0,1,1,2049,108,2049,108,10,1686,1724,147,99,111,109,112,105,108,101,58, - 106,117,109,112,0,1,1793,2049,108,2049,108,10,1708,1747,147,99,111,109,112,105, - 108,101,58,99,97,108,108,0,1,2049,2049,108,2049,108,10,1731,1769,147,99,111, - 109,112,105,108,101,58,114,101,116,0,1,10,2049,108,10,1754,1788,147,99,111, - 109,112,105,108,105,110,103,63,0,1,127,15,10,1774,1804,159,112,114,101,102, - 105,120,58,64,0,2049,200,2049,161,15,2049,1788,1793,1820,1,3841,2049,108,2049,108, - 10,1,1813,1793,1826,15,10,1,1824,2049,67,10,1792,1843,159,112,114,101,102,105, - 120,58,33,0,2049,200,2049,161,15,2049,1788,1793,1859,1,4097,2049,108,2049,108,10, - 1,1852,1793,1865,16,10,1,1863,2049,67,10,1831,1882,159,112,114,101,102,105,120, - 58,96,0,2049,1788,1793,1891,2049,221,2049,108,10,1,1886,1793,1897,3,10,1,1895, - 2049,67,10,1870,1910,147,104,101,114,101,0,3841,3,10,1902,1925,147,100,58,99, - 114,101,97,116,101,0,1,134,1,0,2049,167,2049,1910,2049,1557,2049,161,16,10, - 1913,1946,147,118,97,114,0,2049,1925,1,0,2049,108,10,1939,1963,147,118,97,114, - 60,110,62,0,2049,1925,2049,108,10,1953,1977,147,99,111,110,115,116,0,2049,1925, - 2049,1557,2049,161,16,10,1968,1993,147,116,117,99,107,0,2,5,4,6,10,1985, - 2006,147,111,118,101,114,0,5,2,6,4,10,1998,2023,147,100,117,112,45,112, - 97,105,114,0,2049,2006,2049,2006,10,2011,2035,147,110,105,112,0,4,3,10,2028, - 2051,147,100,114,111,112,45,112,97,105,114,0,3,3,10,2038,2062,147,63,100, - 117,112,0,2,25,10,2054,2072,147,100,105,112,0,4,5,8,6,10,2065,2084, - 147,115,105,112,0,5,2,6,4,1,21,2049,2072,10,2077,2099,147,98,105,0, - 1,2084,2049,2072,8,10,2093,2112,147,98,105,42,0,1,2072,2049,2072,8,10,2105, - 2125,147,98,105,64,0,2,2049,2112,10,2118,2136,147,116,114,105,0,1793,2145,1, - 2084,2049,2072,2049,2084,10,1,2138,2049,2072,8,10,2129,2159,147,116,114,105,42,0, - 1793,2176,1793,2169,4,1,2072,2049,2072,10,1,2163,2049,2072,2049,2072,10,1,2161,2049, - 2072,8,10,2151,2190,147,116,114,105,64,0,2,2,2049,2159,10,2182,2204,147,119, - 104,105,108,101,0,1793,2216,2,2049,2072,4,25,3,1,2206,7,10,1,2206,8, - 3,10,2195,2230,147,117,110,116,105,108,0,1793,2245,2,2049,2072,4,1,-1,23, - 25,3,1,2232,7,10,1,2232,8,3,10,2221,2259,147,116,105,109,101,115,0, - 4,1793,2276,25,1,1,18,5,1,21,2049,2084,6,1,2262,7,10,1,2262,8, - 3,10,2250,2289,147,84,82,85,69,0,1,-1,10,2281,2301,147,70,65,76,83, - 69,0,1,0,10,2292,2313,147,108,116,101,113,63,0,2049,2023,11,1793,2320,13, - 10,1,2318,2049,2072,22,10,2304,2335,147,103,116,101,113,63,0,2049,2023,11,1793, - 2342,14,10,1,2340,2049,2072,22,10,2326,2357,147,110,58,77,65,88,0,1,2147483647, - 10,2348,2369,147,110,58,77,73,78,0,1,-2147483648,10,2360,2383,147,110,58,122,101, - 114,111,63,0,1,0,11,10,2372,2399,147,110,58,45,122,101,114,111,63,0, - 1,0,12,10,2387,2418,147,110,58,110,101,103,97,116,105,118,101,63,0,1, - 0,13,10,2403,2437,147,110,58,112,111,115,105,116,105,118,101,63,0,1,-1, - 14,10,2422,2465,147,110,58,115,116,114,105,99,116,108,121,45,112,111,115,105, - 116,105,118,101,63,0,1,0,14,10,2441,2480,147,110,58,101,118,101,110,63, - 0,1,2,20,3,2049,2383,10,2469,2497,147,110,58,111,100,100,63,0,1,2, - 20,3,2049,2399,10,2487,2512,147,99,97,115,101,0,1793,2518,2049,2006,11,10,1, - 2514,2049,2072,4,1793,2531,2049,2035,8,2049,2289,10,1,2525,1793,2539,3,2049,2301,10, - 1,2535,2049,67,25,6,3,3,10,2504,2558,147,115,58,99,97,115,101,0,1793, - 2565,2049,2006,2049,96,10,1,2560,2049,2072,4,1793,2578,2049,2035,8,2049,2289,10,1, - 2572,1793,2586,3,2049,2301,10,1,2582,2049,67,25,6,3,3,10,2548,2602,147,114, - 111,116,0,1793,2606,4,10,1,2604,2049,2072,4,10,2595,2620,147,116,111,114,115, - 0,6,6,2,5,4,5,10,2612,2632,147,47,0,20,2049,2035,10,2627,2643,147, - 109,111,100,0,20,3,10,2636,2653,147,110,111,116,0,1,-1,23,10,2646,2666, - 147,110,58,112,111,119,0,1,1,4,1793,2675,2049,2006,19,10,1,2671,2049,2259, - 2049,2035,10,2657,2694,147,110,58,110,101,103,97,116,101,0,1,-1,19,10,2682, - 2710,147,110,58,115,113,117,97,114,101,0,2,19,10,2698,2723,147,110,58,115, - 113,114,116,0,1,1,1793,2744,2049,2023,2049,2632,2049,2006,18,1,2,2049,2632,25, - 17,1,2727,7,10,1,2727,8,2049,2035,10,2713,2759,147,110,58,109,105,110,0, - 2049,2023,13,1793,2766,3,10,1,2764,1793,2773,2049,2035,10,1,2770,2049,67,10,2750, - 2787,147,110,58,109,97,120,0,2049,2023,14,1793,2794,3,10,1,2792,1793,2801,2049, - 2035,10,1,2798,2049,67,10,2778,2815,147,110,58,97,98,115,0,2,2049,2694,2049, - 2787,10,2806,2832,147,110,58,108,105,109,105,116,0,4,5,2049,2759,6,2049,2787, - 10,2821,2849,147,110,58,105,110,99,0,1,1,17,10,2840,2862,147,110,58,100, - 101,99,0,1,1,18,10,2853,2880,147,110,58,98,101,116,119,101,101,110,63, - 0,2049,2602,1793,2891,2049,2602,2049,2602,2049,2832,10,1,2884,2049,2084,11,10,2866,2909, - 147,118,58,105,110,99,45,98,121,0,1793,2914,15,17,10,1,2911,2049,2084,16, - 10,2897,2932,147,118,58,100,101,99,45,98,121,0,1793,2938,15,4,18,10,1, - 2934,2049,2084,16,10,2920,2953,147,118,58,105,110,99,0,1,1,4,2049,2909,10, - 2944,2968,147,118,58,100,101,99,0,1,1,4,2049,2932,10,2959,2985,147,118,58, - 108,105,109,105,116,0,5,5,2,15,6,6,2049,2832,4,16,10,2974,3004,147, - 118,58,111,110,0,2049,2289,4,16,10,2996,3018,147,118,58,111,102,102,0,2049, - 2301,4,16,10,3009,3037,147,118,58,112,114,101,115,101,114,118,101,0,4,2, - 15,1793,3051,1793,3046,8,10,1,3044,2049,2072,10,1,3042,2049,2072,4,16,10,3023, - 3067,147,97,108,108,111,116,0,1,3,2049,2909,10,3058,3090,147,118,58,117,112, - 100,97,116,101,45,117,115,105,110,103,0,4,1793,3097,15,4,8,10,1,3093, - 2049,2084,16,10,3072,3111,147,99,111,112,121,0,1793,3120,1,59,2049,2072,2049,62, - 10,1,3113,2049,2259,3,3,10,3103,3140,147,83,99,111,112,101,76,105,115,116, - 0,10281,10340,10,3127,3149,147,123,123,0,2049,1557,2,1,3140,2049,62,16,10,3143, - 3174,147,45,45,45,114,101,118,101,97,108,45,45,45,0,2049,1557,1,3140,2049, - 2849,16,10,3158,3188,147,125,125,0,1,3140,2049,59,4,15,11,1793,3202,3841,3140, - 4097,2,10,1,3197,1793,3232,3841,3140,1793,3227,1,2,15,2,15,1,3140,2049,2849, - 15,12,25,3,1,3212,7,10,1,3210,8,16,10,1,3206,2049,67,10,3182,3247, - 134,66,117,102,102,101,114,0,0,10,3237,3256,134,80,116,114,0,0,10,3249, - 3271,147,116,101,114,109,105,110,97,116,101,0,1,0,3841,3256,16,10,3182,3293, - 147,98,117,102,102,101,114,58,115,116,97,114,116,0,3841,3247,10,3277,3310,147, - 98,117,102,102,101,114,58,101,110,100,0,3841,3256,10,3296,3327,147,98,117,102, - 102,101,114,58,97,100,100,0,2049,3310,16,1,3256,2049,2953,2049,3271,10,3313,3351, - 147,98,117,102,102,101,114,58,103,101,116,0,1,3256,2049,2968,2049,3310,15,2049, - 3271,10,3337,3377,147,98,117,102,102,101,114,58,101,109,112,116,121,0,2049,3293, - 4097,3256,2049,3271,10,3361,3399,147,98,117,102,102,101,114,58,115,105,122,101,0, - 2049,3310,2049,3293,18,10,3384,3419,147,98,117,102,102,101,114,58,115,101,116,0, - 4097,3247,2049,3377,10,3405,3443,147,98,117,102,102,101,114,58,112,114,101,115,101, - 114,118,101,0,3841,3247,3841,3256,1793,3460,1793,3453,8,10,1,3451,2049,2072,4097,3247, - 10,1,3449,2049,2072,4097,3256,10,3424,3482,134,84,101,109,112,83,116,114,105,110, - 103,115,0,32,3467,3500,134,84,101,109,112,83,116,114,105,110,103,77,97,120, - 0,512,3483,3512,147,83,84,82,73,78,71,83,0,2049,1543,3841,3482,3841,3500,19, - 18,10,3501,3534,134,115,58,67,117,114,114,101,110,116,0,27,10,3521,3549,147, - 115,58,112,111,105,110,116,101,114,0,3841,3534,3841,3500,19,2049,3512,17,10,3536, - 3568,147,115,58,110,101,120,116,0,1,3534,2049,2953,3841,3534,3841,3482,11,1793,3584, - 1,0,4097,3534,10,1,3579,2049,75,10,3501,3599,147,115,58,116,101,109,112,0, - 2,2049,82,2049,2849,2049,3549,4,2049,3111,2049,3549,2049,3568,10,3589,3625,147,115,58, - 101,109,112,116,121,0,2049,3549,2049,3568,10,3614,3640,147,115,58,115,107,105,112, - 0,6,1793,3648,2049,59,2049,2399,10,1,3643,2049,2204,2049,2862,5,10,3630,3666,147, - 115,58,107,101,101,112,0,2049,1788,1793,3675,1,3640,2049,147,10,1,3670,2049,75, - 2049,1910,1793,3686,2049,122,10,1,3683,2049,2072,2049,134,10,3656,3705,159,112,114,101, - 102,105,120,58,39,0,2049,1788,1793,3712,2049,3666,10,1,3709,1793,3719,2049,3599,10, - 1,3716,2049,67,10,3693,3734,147,115,58,99,104,111,112,0,2049,3599,2,2049,82, - 2049,2006,17,2049,2862,1,0,4,16,10,3724,3762,147,115,58,114,101,118,101,114, - 115,101,0,1793,3804,2,2049,3599,2049,3419,1,82,1793,3780,2,2049,82,17,2049,2862, - 10,1,3773,2049,2099,4,1793,3794,2,15,2049,3327,2049,2862,10,1,3787,2049,2259,3, - 2049,3293,2049,3599,10,1,3764,2049,3443,10,3749,3824,147,115,58,116,114,105,109,45, - 108,101,102,116,0,2049,3599,1793,3849,2049,59,1793,3836,1,32,11,10,1,3832,1793, - 3843,2049,2399,10,1,3840,2049,2099,21,10,1,3828,2049,2204,2049,2862,10,3809,3872,147, - 115,58,116,114,105,109,45,114,105,103,104,116,0,2049,3599,2049,3762,2049,3824,2049, - 3762,10,3856,3891,147,115,58,116,114,105,109,0,2049,3872,2049,3824,10,3881,3909,147, - 115,58,112,114,101,112,101,110,100,0,2049,3599,1793,3933,2,2049,82,17,1793,3925, - 2,2049,82,2049,2849,10,1,3919,2049,2072,4,2049,3111,10,1,3913,2049,2084,10,3896, - 3950,147,115,58,97,112,112,101,110,100,0,4,2049,3909,10,3938,3968,147,115,58, - 102,111,114,45,101,97,99,104,0,1793,4013,2049,2006,15,25,3,2049,2023,1793,3996, - 1793,3991,1793,3985,15,10,1,3983,2049,2072,8,10,1,3981,2049,2072,10,1,3979,2049, - 2072,1793,4005,2049,2849,10,1,4002,2049,2072,1,3970,7,10,1,3970,8,2049,2051,10, - 3954,4033,147,115,58,105,110,100,101,120,45,111,102,0,4,1793,4057,2049,59,25, - 4,1793,4046,2049,2006,12,10,1,4042,2049,2072,4,25,3,1,4036,7,10,1,4036, - 2049,2084,1793,4069,18,2049,2862,2049,2035,10,1,4063,2049,2084,2049,82,2049,2006,11,1793, - 4084,3,1,-1,10,1,4080,2049,75,10,4019,4109,147,115,58,99,111,110,116,97, - 105,110,115,45,99,104,97,114,63,0,2049,4033,1,-1,12,10,4089,4122,134,83, - 114,99,0,0,4115,4130,134,84,97,114,0,0,4123,4138,134,80,97,100,0,0, - 4131,4144,134,73,0,0,4139,4150,134,70,0,0,4145,4157,134,65,116,0,0,4151, - 4171,147,116,101,114,109,105,110,97,116,101,0,1,0,3841,4138,3841,4130,2049,82, - 17,16,10,4158,4193,147,101,120,116,114,97,99,116,0,3841,4122,3841,4144,17,3841, - 4138,3841,4130,2049,82,2049,3111,10,4182,4218,147,99,111,109,112,97,114,101,0,3841, - 4138,3841,4130,2049,96,3841,4150,22,4097,4150,3841,4150,1793,4238,3841,4144,4097,4157,10,1, - 4233,2049,73,10,4207,4251,147,110,101,120,116,0,1,4144,2049,2953,10,4089,4278,147, - 115,58,99,111,110,116,97,105,110,115,45,115,116,114,105,110,103,63,0,4097, - 4130,4097,4122,2049,3625,4097,4138,1,0,4097,4144,1,0,4097,4150,3841,4122,2049,82,1793, - 4309,2049,4193,2049,4171,2049,4218,2049,4251,10,1,4300,2049,2259,3841,4150,10,4256,4337,147, - 115,58,105,110,100,101,120,45,111,102,45,115,116,114,105,110,103,0,4097,4130, - 4097,4122,2049,3625,4097,4138,1,0,4097,4144,1,0,4097,4150,1,-1,4097,4157,3841,4122, - 2049,82,1793,4372,2049,4193,2049,4171,2049,4218,2049,4251,10,1,4363,2049,2259,3841,4150,1793, - 4383,3841,4157,10,1,4380,1793,4390,1,-1,10,1,4387,2049,67,10,4316,4407,147,115, - 58,102,105,108,116,101,114,0,1793,4444,2049,3625,2049,3419,4,1793,4436,2049,2023,4, - 8,1793,4425,2049,3327,10,1,4422,1793,4431,3,10,1,4429,2049,67,10,1,4416,2049, - 3968,3,2049,3293,10,1,4409,2049,3443,10,4395,4458,147,115,58,109,97,112,0,1793, - 4481,2049,3625,2049,3419,4,1793,4473,2049,2006,8,2049,3327,10,1,4467,2049,3968,3,2049, - 3293,10,1,4460,2049,3443,10,4449,4498,147,115,58,115,117,98,115,116,114,0,1793, - 4504,17,2049,3625,10,1,4500,2049,2072,1793,4522,2049,2006,1793,4517,2049,3111,10,1,4514, - 2049,2072,10,1,4510,2049,2084,2049,2006,1793,4536,17,1,0,4,16,10,1,4530,2049, - 2072,10,4486,4552,147,115,58,114,105,103,104,116,0,2049,2006,2049,82,2049,2006,18, - 4,2049,4498,10,4541,4573,147,115,58,108,101,102,116,0,1,0,4,2049,4498,10, - 4563,4589,147,115,58,104,97,115,104,0,1,5381,4,1793,4600,4,1,33,19,17, - 10,1,4594,2049,3968,10,4579,4615,147,115,58,99,111,112,121,0,2049,2006,2049,82, - 2049,2849,2049,3111,10,4605,4636,147,115,58,68,73,71,73,84,83,0,2049,3640,48, - 49,50,51,52,53,54,55,56,57,0,1,4638,10,4624,4673,147,115,58,65,83, - 67,73,73,45,76,79,87,69,82,67,65,83,69,0,2049,3640,97,98,99,100, - 101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120, - 121,122,0,1,4675,10,4652,4726,147,115,58,65,83,67,73,73,45,85,80,80, - 69,82,67,65,83,69,0,2049,3640,65,66,67,68,69,70,71,72,73,74,75, - 76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,0,1,4728,10,4705, - 4777,147,115,58,65,83,67,73,73,45,76,69,84,84,69,82,83,0,2049,3640, - 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116, - 117,118,119,120,121,122,65,66,67,68,69,70,71,72,73,74,75,76,77,78, - 79,80,81,82,83,84,85,86,87,88,89,90,0,1,4779,10,4758,4852,147,115, - 58,80,85,78,67,84,85,65,84,73,79,78,0,2049,3640,95,33,34,35,36, - 37,38,39,40,41,42,43,44,45,46,47,58,59,60,61,62,63,64,91,92, - 93,94,96,123,124,125,126,0,1,4854,1,95,2049,2006,16,10,4835,4911,134,115, - 58,87,72,73,84,69,83,80,65,67,69,0,9,10,13,0,4895,0,134,65, - 83,67,73,73,58,78,85,76,0,4915,1,134,65,83,67,73,73,58,83,79, - 72,0,4928,2,134,65,83,67,73,73,58,83,84,88,0,4941,3,134,65,83, - 67,73,73,58,69,84,88,0,4954,4,134,65,83,67,73,73,58,69,79,84, - 0,4967,5,134,65,83,67,73,73,58,69,78,81,0,4980,6,134,65,83,67, - 73,73,58,65,67,75,0,4993,7,134,65,83,67,73,73,58,66,69,76,0, - 5006,8,134,65,83,67,73,73,58,66,83,0,5019,9,134,65,83,67,73,73, - 58,72,84,0,5031,10,134,65,83,67,73,73,58,76,70,0,5043,11,134,65, - 83,67,73,73,58,86,84,0,5055,12,134,65,83,67,73,73,58,70,70,0, - 5067,13,134,65,83,67,73,73,58,67,82,0,5079,14,134,65,83,67,73,73, - 58,83,79,0,5091,15,134,65,83,67,73,73,58,83,73,0,5103,16,134,65, - 83,67,73,73,58,68,76,69,0,5115,17,134,65,83,67,73,73,58,68,67, - 49,0,5128,18,134,65,83,67,73,73,58,68,67,50,0,5141,19,134,65,83, - 67,73,73,58,68,67,51,0,5154,20,134,65,83,67,73,73,58,68,67,52, - 0,5167,21,134,65,83,67,73,73,58,78,65,75,0,5180,22,134,65,83,67, - 73,73,58,83,89,78,0,5193,23,134,65,83,67,73,73,58,69,84,66,0, - 5206,24,134,65,83,67,73,73,58,67,65,78,0,5219,25,134,65,83,67,73, - 73,58,69,77,0,5232,26,134,65,83,67,73,73,58,83,85,66,0,5244,27, - 134,65,83,67,73,73,58,69,83,67,0,5257,28,134,65,83,67,73,73,58, - 70,83,0,5270,29,134,65,83,67,73,73,58,71,83,0,5282,30,134,65,83, - 67,73,73,58,82,83,0,5294,31,134,65,83,67,73,73,58,85,83,0,5306, - 32,134,65,83,67,73,73,58,83,80,65,67,69,0,5318,127,134,65,83,67, - 73,73,58,68,69,76,0,5333,5359,147,99,58,108,101,116,116,101,114,63,0, - 1,65,1,122,2049,2880,10,5346,5382,147,99,58,108,111,119,101,114,99,97,115, - 101,63,0,1,97,1,122,2049,2880,10,5366,5405,147,99,58,117,112,112,101,114, - 99,97,115,101,63,0,1,65,1,90,2049,2880,10,5389,5424,147,99,58,100,105, - 103,105,116,63,0,1,48,1,57,2049,2880,10,5412,5437,134,87,83,0,32,9, - 10,13,0,5412,5459,147,99,58,119,104,105,116,101,115,112,97,99,101,63,0, - 1,5437,4,2049,4109,10,5442,5479,147,99,58,118,105,115,105,98,108,101,63,0, - 1,31,1,126,2049,2880,10,5465,5498,147,99,58,118,111,119,101,108,63,0,2049, - 3640,97,101,105,111,117,65,69,73,79,85,0,1,5500,4,2049,4109,10,5486,5533, - 147,99,58,99,111,110,115,111,110,97,110,116,63,0,2,2049,5359,1793,5543,2049, - 5498,2049,2653,10,1,5538,1793,5551,3,2049,2301,10,1,5547,2049,67,10,5517,5573,147, - 99,58,45,108,111,119,101,114,99,97,115,101,63,0,2049,5382,2049,2653,10,5556, - 5595,147,99,58,45,117,112,112,101,114,99,97,115,101,63,0,2049,5405,2049,2653, - 10,5578,5613,147,99,58,45,100,105,103,105,116,63,0,2049,5424,2049,2653,10,5600, - 5636,147,99,58,45,119,104,105,116,101,115,112,97,99,101,63,0,2049,5459,2049, - 2653,10,5618,5656,147,99,58,45,118,105,115,105,98,108,101,63,0,2049,5479,2049, - 2653,10,5641,5674,147,99,58,45,118,111,119,101,108,63,0,2049,5498,2049,2653,10, - 5661,5696,147,99,58,45,99,111,110,115,111,110,97,110,116,63,0,2049,5533,2049, - 2653,10,5679,5715,147,99,58,116,111,45,117,112,112,101,114,0,2,2049,5382,25, - 3,1,32,18,10,5701,5738,147,99,58,116,111,45,108,111,119,101,114,0,2, - 2049,5405,25,3,1,32,17,10,5724,5764,147,99,58,116,111,103,103,108,101,45, - 99,97,115,101,0,2,2049,5382,1793,5772,2049,5715,10,1,5769,1793,5779,2049,5738,10, - 1,5776,2049,67,10,5747,5799,147,99,58,116,111,45,115,116,114,105,110,103,0, - 2049,3640,46,0,1,5801,2049,3599,1793,5811,16,10,1,5809,2049,2084,10,5784,5830,147, - 115,58,116,111,45,117,112,112,101,114,0,1793,5835,2049,5715,10,1,5832,2049,4458, - 10,5816,5854,147,115,58,116,111,45,108,111,119,101,114,0,1793,5859,2049,5738,10, - 1,5856,2049,4458,10,5840,5873,134,86,97,108,117,101,0,0,5864,5885,147,99,111, - 114,114,101,99,116,0,2,1,48,13,1793,5901,1,48,2049,2006,18,1,2,19, - 17,10,1,5891,2049,75,10,5840,5921,147,110,58,116,111,45,115,116,114,105,110, - 103,0,1793,5976,2049,1910,2049,3419,2,4097,5873,2049,2815,1793,5949,1,10,20,4,1, - 48,17,2049,5885,2049,3327,2,2049,2399,10,1,5934,2049,2204,3,3841,5873,2049,2418,1793, - 5965,1,45,2049,3327,10,1,5960,2049,75,2049,3293,2049,3762,2049,3599,10,1,5923,2049, - 3443,10,5906,6003,134,82,101,119,114,105,116,101,85,110,100,101,114,115,99,111, - 114,101,115,0,-1,5981,6011,147,115,117,98,0,1,95,1793,6018,1,32,10,1, - 6015,2049,2512,10,6004,6034,147,114,101,119,114,105,116,101,0,3841,6003,1793,6048,1793, - 6043,2049,6011,10,1,6040,2049,4458,10,1,6038,2049,75,1,3705,8,10,5981,6068,159, - 112,114,101,102,105,120,58,39,0,2049,6034,10,6056,6082,147,115,58,115,112,108, - 105,116,0,2049,2023,2049,4033,2049,2035,2049,2023,2049,4573,1793,6096,17,10,1,6094,2049, - 2072,10,6071,6122,147,115,58,115,112,108,105,116,45,111,110,45,115,116,114,105, - 110,103,0,2049,2023,2049,4337,2049,2849,2049,2035,2049,2023,2049,4573,1793,6138,17,10,1, - 6136,2049,2072,10,6101,6148,134,76,0,0,6101,6162,147,115,58,114,101,112,108,97, - 99,101,0,2049,2006,2049,82,4097,6148,1793,6177,2049,6122,4,3841,6148,17,10,1,6170, - 2049,2072,2049,3909,2049,3950,10,6149,6198,134,83,112,108,105,116,45,79,110,0,0, - 6186,6209,147,109,97,116,99,104,63,0,3841,6198,11,10,6199,6226,147,116,101,114, - 109,105,110,97,116,101,0,1,0,2049,2006,2049,2862,16,10,6213,6242,147,115,116, - 101,112,0,1793,6247,2049,2849,10,1,6244,2049,2072,2049,6209,1793,6261,2,2049,108,2049, - 6226,10,1,6255,2049,75,10,6149,6280,147,115,58,116,111,107,101,110,105,122,101, - 0,4097,6198,2049,3666,2049,1910,1,0,2049,108,1793,6307,2,2049,108,2,1793,6301,2049, - 6242,10,1,6298,2049,3968,3,10,1,6292,2049,2072,2049,1910,2049,2006,18,2049,2862,2049, - 2006,16,10,6266,6332,134,84,111,107,101,110,115,0,0,6322,6343,134,78,101,101, - 100,108,101,0,0,6333,6355,147,45,109,97,116,99,104,63,0,2,3841,6343,2049, - 4278,10,6344,6375,147,115,97,118,101,45,116,111,107,101,110,0,3841,6343,2049,6122, - 2049,3666,2049,3327,2049,2849,10,6361,6403,147,116,111,107,101,110,115,45,116,111,45, - 115,101,116,0,2049,1910,3841,6332,2049,3399,2,2049,108,1793,6419,2049,59,2049,108,10, - 1,6414,2049,2259,3,10,6266,6449,147,115,58,116,111,107,101,110,105,122,101,45, - 111,110,45,115,116,114,105,110,103,0,1793,6488,2049,3666,4097,6343,2049,1910,1,8192, - 17,4097,6332,3841,6332,2049,3419,1793,6478,2049,6355,25,3,2049,6375,1,6468,7,10,1, - 6468,8,2049,3666,2049,3327,2049,6403,10,1,6451,2049,3443,10,6425,6503,134,86,97,108, - 117,101,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,6493,6539,147,102,114,111,109,0, - 2049,82,2,1793,6558,1793,6551,1,6503,17,16,10,1,6546,2049,2084,2049,2862,10,1, - 6544,2049,2259,3,10,6531,6570,147,116,111,0,2,2049,82,1793,6588,2049,59,1,97, - 18,2049,2849,1,6503,17,15,4,10,1,6575,2049,2259,3,10,6425,6605,147,114,101, - 111,114,100,101,114,0,1793,6610,2049,6539,10,1,6607,2049,2072,2049,6570,10,6594,6626, - 147,99,117,114,114,121,0,2049,1910,1793,6638,4,2049,1701,2049,1747,2049,1769,10,1, - 6630,2049,2072,10,6617,6651,147,100,111,101,115,0,2049,1575,4,2049,6626,2049,1557,2049, - 161,16,1,147,2049,1636,10,6643,6680,147,100,58,102,111,114,45,101,97,99,104, - 0,1,2,1793,6708,15,25,2049,2023,1793,6700,1793,6695,4,8,10,1,6692,2049,2072, - 10,1,6690,2049,2072,1,6684,7,10,1,6684,8,3,10,6666,6728,147,100,58,108, - 111,111,107,117,112,45,120,116,0,1,0,4,1793,6763,2049,2023,2049,161,15,11, - 1793,6752,4,1793,6747,2049,2035,10,1,6744,2049,2072,10,1,6741,1793,6758,3,10,1, - 6756,2049,67,10,1,6733,2049,6680,3,10,6713,6777,147,99,104,97,114,0,1,32, - 1793,6786,1,95,2049,3327,10,1,6781,2049,2512,1,114,1793,6799,1,13,2049,3327,10, - 1,6794,2049,2512,1,110,1793,6812,1,10,2049,3327,10,1,6807,2049,2512,1,116,1793, - 6825,1,9,2049,3327,10,1,6820,2049,2512,2049,3327,10,6769,6842,147,115,116,114,105, - 110,103,0,2049,59,25,2049,3327,1,6842,7,10,6832,6859,147,116,121,112,101,0, - 1,99,1793,6867,4,2049,3327,10,1,6863,2049,2512,1,115,1793,6880,4,2049,6842,3, - 10,1,6875,2049,2512,1,110,1793,6895,4,2049,5921,2049,6842,3,10,1,6888,2049,2512, - 3,10,6851,6911,147,104,97,110,100,108,101,0,1,92,1793,6920,2049,59,2049,6777, - 10,1,6915,2049,2512,1,37,1793,6933,2049,59,2049,6859,10,1,6928,2049,2512,2049,3327, - 10,6713,6957,147,115,58,119,105,116,104,45,102,111,114,109,97,116,0,1793,6986, - 2049,3625,1793,6981,2049,3419,1793,6976,2049,59,25,2049,6911,1,6967,7,10,1,6967,8, - 3,10,1,6963,2049,2084,10,1,6959,2049,3443,10,6940,7002,147,115,58,99,111,110, - 115,116,0,1793,7007,2049,3666,10,1,7004,2049,2072,2049,1977,10,6991,7028,147,115,101, - 116,58,108,101,110,103,116,104,0,15,10,7014,7050,147,115,101,116,58,102,114, - 111,109,45,114,101,115,117,108,116,115,0,2049,1682,1793,7056,8,10,1,7054,2049, - 2072,2049,1682,4,18,2049,1910,1793,7081,2,2049,108,1793,7076,2049,108,10,1,7073,2049, - 2259,10,1,7068,2049,2072,10,7030,7105,147,115,101,116,58,102,114,111,109,45,115, - 116,114,105,110,103,0,2049,3762,1793,7117,1793,7112,10,1,7111,2049,3968,10,1,7109, - 2049,6626,2049,7050,10,7086,7129,134,81,0,0,7086,7146,147,115,101,116,58,102,111, - 114,45,101,97,99,104,0,1,7129,1793,7176,4097,7129,2049,59,1793,7170,2049,59,4, - 1793,7165,3841,7129,8,10,1,7161,2049,2072,10,1,7156,2049,2259,3,10,1,7150,2049, - 3037,10,7130,7192,147,115,101,116,58,100,117,112,0,2049,1910,1793,7210,2,15,2049, - 108,1793,7205,2049,108,10,1,7202,2049,7146,10,1,7196,2049,2072,10,7181,7229,147,115, - 101,116,58,102,105,108,116,101,114,0,1793,7258,2049,2006,1793,7237,8,10,1,7235, - 2049,2072,4,1793,7247,2049,108,10,1,7244,1793,7253,3,10,1,7251,2049,67,10,1, - 7231,2049,6626,2049,1910,1793,7274,2049,2006,15,2049,108,2049,7146,10,1,7266,2049,2072,2049, - 1910,2049,2006,18,2049,2862,2049,2006,16,10,7215,7294,134,70,0,0,7215,7312,147,115, - 101,116,58,99,111,110,116,97,105,110,115,63,0,1,7294,2049,3018,1793,7327,2049, - 2006,11,3841,7294,22,4097,7294,10,1,7318,2049,7146,3,3841,7294,10,7295,7359,147,115, - 101,116,58,99,111,110,116,97,105,110,115,45,115,116,114,105,110,103,63,0, - 1,7294,2049,3018,1793,7375,2049,2006,2049,96,3841,7294,22,4097,7294,10,1,7365,2049,7146, - 3,3841,7294,10,7335,7394,147,115,101,116,58,109,97,112,0,1793,7400,8,2049,108, - 10,1,7396,2049,6626,2049,1910,1793,7416,2049,2006,15,2049,108,2049,7146,10,1,7408,2049, - 2072,10,7383,7436,147,115,101,116,58,114,101,118,101,114,115,101,0,2049,1910,1793, - 7470,2049,59,1793,7448,17,2049,2862,10,1,7444,2049,2084,2,2049,108,1793,7464,2,15, - 2049,108,2049,2862,10,1,7457,2049,2259,3,10,1,7440,2049,2072,10,7421,7486,147,115, - 101,116,58,110,116,104,0,17,2049,2849,10,7475,7504,147,115,101,116,58,114,101, - 100,117,99,101,0,1793,7508,4,10,1,7506,2049,2072,2049,7146,10,7490,7521,134,73, - 48,0,0,0,0,7515,7530,134,73,49,0,0,0,0,7524,7539,134,73,50,0, - 0,0,0,7533,7548,134,73,51,0,0,0,0,7542,7561,147,111,112,99,111,100, - 101,0,2049,3640,46,46,0,1,7563,1793,7573,1,0,10,1,7570,2049,2558,2049,3640, - 108,105,0,1,7579,1793,7589,1,1,10,1,7586,2049,2558,2049,3640,100,117,0,1, - 7595,1793,7605,1,2,10,1,7602,2049,2558,2049,3640,100,114,0,1,7611,1793,7621,1, - 3,10,1,7618,2049,2558,2049,3640,115,119,0,1,7627,1793,7637,1,4,10,1,7634, - 2049,2558,2049,3640,112,117,0,1,7643,1793,7653,1,5,10,1,7650,2049,2558,2049,3640, - 112,111,0,1,7659,1793,7669,1,6,10,1,7666,2049,2558,2049,3640,106,117,0,1, - 7675,1793,7685,1,7,10,1,7682,2049,2558,2049,3640,99,97,0,1,7691,1793,7701,1, - 8,10,1,7698,2049,2558,2049,3640,99,99,0,1,7707,1793,7717,1,9,10,1,7714, - 2049,2558,2049,3640,114,101,0,1,7723,1793,7733,1,10,10,1,7730,2049,2558,2049,3640, - 101,113,0,1,7739,1793,7749,1,11,10,1,7746,2049,2558,2049,3640,110,101,0,1, - 7755,1793,7765,1,12,10,1,7762,2049,2558,2049,3640,108,116,0,1,7771,1793,7781,1, - 13,10,1,7778,2049,2558,2049,3640,103,116,0,1,7787,1793,7797,1,14,10,1,7794, - 2049,2558,2049,3640,102,101,0,1,7803,1793,7813,1,15,10,1,7810,2049,2558,2049,3640, - 115,116,0,1,7819,1793,7829,1,16,10,1,7826,2049,2558,2049,3640,97,100,0,1, - 7835,1793,7845,1,17,10,1,7842,2049,2558,2049,3640,115,117,0,1,7851,1793,7861,1, - 18,10,1,7858,2049,2558,2049,3640,109,117,0,1,7867,1793,7877,1,19,10,1,7874, - 2049,2558,2049,3640,100,105,0,1,7883,1793,7893,1,20,10,1,7890,2049,2558,2049,3640, - 97,110,0,1,7899,1793,7909,1,21,10,1,7906,2049,2558,2049,3640,111,114,0,1, - 7915,1793,7925,1,22,10,1,7922,2049,2558,2049,3640,120,111,0,1,7931,1793,7941,1, - 23,10,1,7938,2049,2558,2049,3640,115,104,0,1,7947,1793,7957,1,24,10,1,7954, - 2049,2558,2049,3640,122,114,0,1,7963,1793,7973,1,25,10,1,7970,2049,2558,2049,3640, - 101,110,0,1,7979,1793,7989,1,26,10,1,7986,2049,2558,3,1,0,10,7551,8005, - 147,112,97,99,107,0,1,7521,2049,7561,1,7530,2049,7561,1,7539,2049,7561,1,7548, - 2049,7561,1,-24,24,4,1,-16,24,17,4,1,-8,24,17,4,17,10,7490,8042, - 147,105,0,2,1,7521,1,2,2049,3111,1,2,17,2,1,7530,1,2,2049,3111, - 1,2,17,2,1,7539,1,2,2049,3111,1,2,17,1,7548,1,2,2049,3111,2049, - 8005,2049,108,10,8037,8088,147,100,0,2049,108,10,8083,8096,147,114,0,2049,200,2049, - 161,15,2049,108,10,8091,8111,159,97,115,123,0,3841,127,1,127,2049,3018,10,8104, - 8125,159,125,97,115,0,4097,127,10,8118,8144,147,99,117,114,114,101,110,116,45, - 108,105,110,101,0,2049,3512,1,1025,18,10,8128,8166,147,99,111,117,110,116,45, - 116,111,107,101,110,115,0,1793,8172,1,32,11,10,1,8168,2049,4407,2049,82,10, - 8150,8193,147,110,101,120,116,45,116,111,107,101,110,0,1,32,2049,6082,10,8179, - 8216,147,112,114,111,99,101,115,115,45,116,111,107,101,110,115,0,1793,8251,2049, - 8193,4,1793,8244,2,2049,82,2049,2399,1793,8233,2049,366,10,1,8230,1793,8239,3,10, - 1,8237,2049,67,10,1,8223,2049,2072,2049,2849,10,1,8218,2049,2259,2049,366,10,8118, - 8272,147,115,58,101,118,97,108,117,97,116,101,0,2049,8144,2049,4615,2049,8144,2, - 2049,8166,2049,8216,10,8258,8290,134,76,80,0,0,8284,8300,134,73,110,100,101,120, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,8291,8436,147,110,101,120,116,0,3841,8290,1, - 8300,17,2049,2953,10,8428,8452,147,112,114,101,112,0,1,8290,2049,2953,1,0,3841, - 8290,1,8300,17,16,10,8444,8473,147,100,111,110,101,0,1,8290,2049,2968,10,8258, - 8483,147,73,0,3841,8290,1,8300,17,15,10,8478,8495,147,74,0,3841,8290,1,8300, - 17,2049,2862,15,10,8490,8509,147,75,0,3841,8290,1,8300,17,1,2,18,15,10, - 8504,8540,147,116,105,109,101,115,60,119,105,116,104,45,105,110,100,101,120,62, - 0,2049,8452,4,1793,8561,25,1,1,18,5,1,21,2049,2084,6,2049,8436,1,8545, - 7,10,1,8545,8,3,2049,8473,10,8519,8576,147,112,117,116,99,0,1000,10,8568, - 8584,147,110,108,0,1,10,2049,8576,10,8578,8595,147,115,112,0,1,32,2049,8576, - 10,8589,8607,147,116,97,98,0,1,9,2049,8576,10,8600,8620,147,112,117,116,115, - 0,1793,8625,2049,8576,10,1,8622,2049,3968,10,8612,8638,147,112,117,116,110,0,2049, - 5921,2049,8620,10,8630,8652,147,119,111,114,100,115,0,1793,8661,2049,165,2049,8620,2049, - 8595,10,1,8654,2049,6680,10,8643,8675,147,114,101,115,101,116,0,2049,1682,25,5, - 3,6,1,1,18,1,8677,7,10,8666,8702,147,100,117,109,112,45,115,116,97, - 99,107,0,2049,1682,25,3,5,2049,8702,6,2,2049,8638,2049,8595,10,8688,8724,147, - 70,82,69,69,0,2049,3512,1,1025,18,2049,1910,18,10,8716,8741,147,103,101,116, - 99,0,1001,10,8733,8757,147,110,58,116,111,45,102,108,111,97,116,0,1,0, - -6000,10,8743,8775,147,115,58,116,111,45,102,108,111,97,116,0,1,1,-6000,10, - 8761,8794,147,102,58,116,111,45,115,116,114,105,110,103,0,2049,3625,2,1,2, - -6000,10,8779,8808,147,102,58,43,0,1,3,-6000,10,8801,8819,147,102,58,45,0, - 1,4,-6000,10,8812,8830,147,102,58,42,0,1,5,-6000,10,8823,8841,147,102,58, - 47,0,1,6,-6000,10,8834,8856,147,102,58,102,108,111,111,114,0,1,7,-6000, - 10,8845,8869,147,102,58,101,113,63,0,1,8,-6000,10,8860,8883,147,102,58,45, - 101,113,63,0,1,9,-6000,10,8873,8896,147,102,58,108,116,63,0,1,10,-6000, - 10,8887,8909,147,102,58,103,116,63,0,1,11,-6000,10,8900,8924,147,102,58,100, - 101,112,116,104,0,1,12,-6000,10,8913,8937,147,102,58,100,117,112,0,1,13, - -6000,10,8928,8951,147,102,58,100,114,111,112,0,1,14,-6000,10,8941,8965,147,102, - 58,115,119,97,112,0,1,15,-6000,10,8955,8978,147,102,58,108,111,103,0,1, - 16,-6000,10,8969,8993,147,102,58,112,111,119,101,114,0,1,17,-6000,10,8982,9012, - 147,102,58,116,111,45,110,117,109,98,101,114,0,1,18,-6000,10,8997,9025,147, - 102,58,115,105,110,0,1,19,-6000,10,9016,9038,147,102,58,99,111,115,0,1, - 20,-6000,10,9029,9051,147,102,58,116,97,110,0,1,21,-6000,10,9042,9065,147,102, - 58,97,115,105,110,0,1,22,-6000,10,9055,9079,147,102,58,97,99,111,115,0, - 1,23,-6000,10,9069,9093,147,102,58,97,116,97,110,0,1,24,-6000,10,9083,9107, - 147,102,58,111,118,101,114,0,2049,8794,2049,8937,2049,8775,2049,8965,10,9097,9126,147, - 102,58,116,117,99,107,0,2049,8965,2049,9107,10,9116,9146,147,102,58,112,111,115, - 105,116,105,118,101,63,0,1,0,2049,8757,2049,8909,10,9131,9168,147,102,58,110, - 101,103,97,116,105,118,101,63,0,1,0,2049,8757,2049,8896,10,9153,9187,147,102, - 58,110,101,103,97,116,101,0,1,-1,2049,8757,2049,8830,10,9175,9203,147,102,58, - 97,98,115,0,2049,8937,2049,9168,1793,9212,2049,9187,10,1,9209,2049,75,10,9194,9229, - 159,112,114,101,102,105,120,58,46,0,2049,1788,1793,9236,2049,3666,10,1,9233,1793, - 9243,2049,3599,10,1,9240,2049,67,1,8775,2049,147,10,9217,9260,147,112,117,116,102, - 0,2049,8794,2049,8620,10,9252,9273,147,102,58,80,73,0,2049,3640,51,46,49,52, - 49,53,57,50,0,1,9275,2049,8775,10,9265,9296,147,102,58,69,0,2049,3640,50, - 46,55,49,56,50,56,49,0,1,9298,2049,8775,10,9289,9324,147,115,121,115,58, - 97,114,103,99,0,-6100,10,9312,9338,147,115,121,115,58,97,114,103,118,0,2049, - 3625,4,-6101,10,9326,0,134,102,105,108,101,58,82,0,9343,1,134,102,105,108, - 101,58,87,0,9353,2,134,102,105,108,101,58,65,0,9363,3,134,102,105,108, - 101,58,82,43,0,9373,9397,147,102,105,108,101,58,111,112,101,110,0,118,10, - 9384,9413,147,102,105,108,101,58,99,108,111,115,101,0,119,10,9399,9428,147,102, - 105,108,101,58,114,101,97,100,0,120,10,9415,9444,147,102,105,108,101,58,119, - 114,105,116,101,0,121,10,9430,9459,147,102,105,108,101,58,116,101,108,108,0, - 122,10,9446,9474,147,102,105,108,101,58,115,101,101,107,0,123,10,9461,9489,147, - 102,105,108,101,58,115,105,122,101,0,124,10,9476,9506,147,102,105,108,101,58, - 100,101,108,101,116,101,0,125,10,9491,9522,147,102,105,108,101,58,102,108,117, - 115,104,0,126,10,9508,9540,147,102,105,108,101,58,101,120,105,115,116,115,63, - 0,1,0,2049,9397,2,2049,2399,1793,9554,2049,9413,2049,2289,10,1,9549,1793,9562,3, - 2049,2301,10,1,9558,2049,67,10,9524,9574,134,70,73,68,0,0,9567,9584,134,70, - 83,105,122,101,0,0,9575,9595,134,65,99,116,105,111,110,0,0,9585,9606,134, - 66,117,102,102,101,114,0,0,9596,9616,147,45,101,111,102,63,0,3841,9574,2049, - 9459,3841,9584,13,10,9607,9636,147,112,114,101,115,101,114,118,101,0,1,9574,1793, - 9651,1,9584,1793,9646,8,10,1,9644,2049,3037,10,1,9640,2049,3037,10,9524,9674,147, - 102,105,108,101,58,114,101,97,100,45,108,105,110,101,0,4097,9574,1793,9731,2049, - 1910,2,4097,9606,2049,3419,1793,9723,3841,9574,2049,9428,2,2049,3327,1793,9700,1,13,11, - 10,1,9696,1793,9708,1,10,11,10,1,9704,1793,9716,1,0,11,10,1,9712,2049, - 2136,22,22,10,1,9687,2049,2230,2049,3351,3,10,1,9678,2049,3443,3841,9606,10,9656, - 9760,147,102,105,108,101,58,102,111,114,45,101,97,99,104,45,108,105,110,101, - 0,1793,9797,4097,9595,1,0,2049,9397,4097,9574,3841,9574,2049,9489,4097,9584,1793,9788,3841, - 9574,2049,9674,3841,9595,8,2049,9616,10,1,9778,2049,2204,3841,9574,2049,9413,10,1,9762, - 2049,9636,10,9738,9809,134,70,73,68,0,0,9802,9818,134,83,105,122,101,0,0, - 9738,9833,147,102,105,108,101,58,115,108,117,114,112,0,1793,9869,1,0,2049,9397, - 4097,9809,2049,3419,3841,9809,2049,9489,4097,9818,3841,9818,1793,9860,3841,9809,2049,9428,2049,3327, - 10,1,9853,2049,2259,3841,9809,2049,9413,10,1,9835,2049,3443,10,9819,9881,134,70,73, - 68,0,0,9819,9895,147,102,105,108,101,58,115,112,101,119,0,1,1,2049,9397, - 4097,9881,1793,9908,3841,9881,2049,9444,10,1,9903,2049,3968,3841,9881,2049,9413,10,9882,9928, - 147,118,101,114,115,105,111,110,0,3841,4,1,100,20,2049,8638,1,46,2049,8576, - 2049,8638,10,9917,9950,147,101,111,108,63,0,1793,9956,1,13,11,10,1,9952,1793, - 9964,1,10,11,10,1,9960,1793,9972,1,32,11,10,1,9968,2049,2136,22,22,10, - 9942,9989,147,118,97,108,105,100,63,0,2,2049,82,2049,2399,10,9979,10001,147,111, - 107,0,2049,1788,1793,10018,2049,8584,2049,3640,79,107,32,0,1,10009,2049,8620,10,1, - 10005,2049,73,10,9995,10036,147,99,104,101,99,107,45,101,111,102,0,2,1793,10043, - 1,-1,11,10,1,10039,1793,10051,1,4,11,10,1,10047,2049,2099,22,1793,10073,2049, - 3640,98,121,101,0,1,10060,2049,200,2049,161,15,8,10,1,10058,2049,75,10,10023, - 10090,147,99,104,101,99,107,45,98,115,0,2,1793,10097,1,8,11,10,1,10093, - 1793,10105,1,127,11,10,1,10101,2049,2099,22,1793,10116,2049,3351,3,10,1,10112,2049, - 75,10,10078,10129,147,103,101,116,115,0,1793,10158,1,1025,2049,3419,1793,10149,2049,8741, - 2,2049,3327,2049,10036,2049,10090,2049,9950,10,1,10137,2049,2230,2049,3293,2049,3734,10,1, - 10131,2049,3443,10,9882,10173,147,98,97,110,110,101,114,0,2049,3640,82,69,84,82, - 79,32,49,50,32,40,114,120,45,0,1,10175,2049,8620,2049,9928,1,41,2049,8576, - 2049,8584,2049,1543,2049,8638,2049,3640,32,77,65,88,44,32,84,73,66,32,64,32, - 49,48,50,53,44,32,72,101,97,112,32,64,32,0,1,10207,2049,8620,2049,1910, - 2049,8638,2049,8584,10,10163,10254,147,108,105,115,116,101,110,0,2049,10001,2049,10129,2049, - 9989,1793,10267,2049,366,2049,10001,10,1,10262,1793,10273,3,10,1,10271,2049,67,1,10256, - 7,10,10244,10292,147,105,110,99,108,117,100,101,0,-9999,10,10281,10304,147,103,97, - 116,104,101,114,0,2,1793,10311,1,8,11,10,1,10307,1793,10319,1,127,11,10, - 1,10315,2049,2099,22,1793,10328,3,10,1,10326,1793,10335,2049,3327,10,1,10332,2049,67, - 10,10294,10349,147,99,121,99,108,101,0,2049,8741,2049,2023,4,8,2049,2653,25,3, - 2049,10304,1,10349,7,10,10281,10380,147,112,97,114,115,101,45,117,110,116,105,108, - 0,1793,10393,2049,3625,2049,3419,2049,10349,2049,2051,2049,3293,10,1,10382,2049,3443,10,10365, - 10406,147,103,101,116,115,0,1793,10428,1793,10414,1,10,11,10,1,10410,1793,10422,1, - 13,11,10,1,10418,2049,2099,22,10,1,10408,2049,10380,10,0 }; diff --git a/interfaces/windows/rre_windows.c b/interfaces/windows/rre_windows.c deleted file mode 100644 index 68f3a99..0000000 --- a/interfaces/windows/rre_windows.c +++ /dev/null @@ -1,1016 +0,0 @@ -/* RETRO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - a personal, pragmatic, minimalistic forth - Copyright (c) 2016 - 2018 Charles Childers - - This is `rre`, short for `run retro and exit`. It's the basic - interface layer for Retro on FreeBSD, Linux and macOS. - - rre embeds the image file into the binary, so the compiled version - of this is all you need to have a functional system. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -#include -#include -#include -#include -#include -#include -#include - -/* Configure Nga (the VM) Limitations */ -#define CELL int32_t -#define IMAGE_SIZE 524288 * 16 -#define ADDRESSES 2048 -#define STACK_DEPTH 512 - -/* This assumes some knowledge of the ngaImage format for the - Retro language. If things change there, these will need to - be adjusted to match. */ - -#define TIB 1025 -#define D_OFFSET_LINK 0 -#define D_OFFSET_XT 1 -#define D_OFFSET_CLASS 2 -#define D_OFFSET_NAME 3 - -/* More Nga bits. You shouldn't need to alter these */ - -enum vm_opcode { - VM_NOP, VM_LIT, VM_DUP, VM_DROP, VM_SWAP, VM_PUSH, VM_POP, - VM_JUMP, VM_CALL, VM_CCALL, VM_RETURN, VM_EQ, VM_NEQ, VM_LT, - VM_GT, VM_FETCH, VM_STORE, VM_ADD, VM_SUB, VM_MUL, VM_DIVMOD, - VM_AND, VM_OR, VM_XOR, VM_SHIFT, VM_ZRET, VM_END -}; -#define NUM_OPS VM_END + 1 - -CELL sp, rp, ip; -CELL data[STACK_DEPTH]; -CELL address[ADDRESSES]; -CELL memory[IMAGE_SIZE + 1]; -#define TOS data[sp] -#define NOS data[sp-1] -#define TORS address[rp] - -/* Function Prototypes */ - -CELL stack_pop(); -void stack_push(CELL value); -CELL string_inject(char *str, CELL buffer); -char *string_extract(CELL at); -CELL d_link(CELL dt); -CELL d_xt(CELL dt); -CELL d_class(CELL dt); -CELL d_name(CELL dt); -CELL d_lookup(CELL Dictionary, char *name); -CELL d_xt_for(char *Name, CELL Dictionary); -CELL d_class_for(char *Name, CELL Dictionary); -CELL ioGetFileHandle(); -CELL ioOpenFile(); -CELL ioReadFile(); -CELL ioWriteFile(); -CELL ioCloseFile(); -CELL ioGetFilePosition(); -CELL ioSetFilePosition(); -CELL ioGetFileSize(); -CELL ioDeleteFile(); -void ioFlushFile(); -void update_rx(); -void execute(CELL cell); -void evaluate(char *s); -int not_eol(int ch); -void read_token(FILE *file, char *token_buffer, int echo); -char *read_token_str(char *s, char *token_buffer, int echo); -void include_file(char *fname); -void ngaFloatingPointUnit(); -CELL ngaLoadImage(char *imageFile); -void ngaPrepare(); -void ngaProcessOpcode(CELL opcode); -void ngaProcessPackedOpcodes(CELL opcode); -int ngaValidatePackedOpcodes(CELL opcode); - - - -CELL Dictionary, Compiler; -CELL notfound; - -char **sys_argv; -int sys_argc; - -/* Some I/O Parameters */ - -#define MAX_OPEN_FILES 128 -#define IO_TTY_PUTC 1000 -#define IO_TTY_GETC 1001 -#define IO_FS_OPEN 118 -#define IO_FS_CLOSE 119 -#define IO_FS_READ 120 -#define IO_FS_WRITE 121 -#define IO_FS_TELL 122 -#define IO_FS_SEEK 123 -#define IO_FS_SIZE 124 -#define IO_FS_DELETE 125 -#define IO_FS_FLUSH 126 - - -/* First, a couple of functions to simplify interacting with - the stack. */ - -CELL stack_pop() { - sp--; - return data[sp + 1]; -} - -void stack_push(CELL value) { - sp++; - data[sp] = value; -} - -/* Next, functions to translate C strings to/from Retro - strings. */ - -CELL string_inject(char *str, CELL buffer) { - int m = strlen(str); - CELL i = 0; - while (m > 0) { - memory[buffer + i] = (CELL)str[i]; - memory[buffer + i + 1] = 0; - m--; i++; - } - return buffer; -} - -char string_data[8192]; -char *string_extract(CELL at) { - CELL starting = at; - CELL i = 0; - while(memory[starting] && i < 8192) - string_data[i++] = (char)memory[starting++]; - string_data[i] = 0; - return (char *)string_data; -} - -CELL d_link(CELL dt) { - return dt + D_OFFSET_LINK; -} - -CELL d_xt(CELL dt) { - return dt + D_OFFSET_XT; -} - -CELL d_class(CELL dt) { - return dt + D_OFFSET_CLASS; -} - -CELL d_name(CELL dt) { - return dt + D_OFFSET_NAME; -} - -/* With the dictionary accessors, some functions to actually - lookup headers. */ - -CELL d_lookup(CELL Dictionary, char *name) { - CELL dt = 0; - CELL i = Dictionary; - char *dname; - while (memory[i] != 0 && i != 0) { - dname = string_extract(d_name(i)); - if (strcmp(dname, name) == 0) { - dt = i; - i = 0; - } else { - i = memory[i]; - } - } - return dt; -} - -CELL d_xt_for(char *Name, CELL Dictionary) { - return memory[d_xt(d_lookup(Dictionary, Name))]; -} - -CELL d_class_for(char *Name, CELL Dictionary) { - return memory[d_class(d_lookup(Dictionary, Name))]; -} - - -/* Now for File I/O functions. These were adapted from the Ngaro VM. */ - -FILE *ioFileHandles[MAX_OPEN_FILES]; - -CELL ioGetFileHandle() { - CELL i; - for(i = 1; i < MAX_OPEN_FILES; i++) - if (ioFileHandles[i] == 0) - return i; - return 0; -} - -CELL ioOpenFile() { - CELL slot, mode, name; - slot = ioGetFileHandle(); - mode = data[sp]; sp--; - name = data[sp]; sp--; - char *request = string_extract(name); - if (slot > 0) { - if (mode == 0) ioFileHandles[slot] = fopen(request, "rb"); - if (mode == 1) ioFileHandles[slot] = fopen(request, "w"); - if (mode == 2) ioFileHandles[slot] = fopen(request, "a"); - if (mode == 3) ioFileHandles[slot] = fopen(request, "rb+"); - } - if (ioFileHandles[slot] == NULL) { - ioFileHandles[slot] = 0; - slot = 0; - } - stack_push(slot); - return slot; -} - -CELL ioReadFile() { - CELL slot = stack_pop(); - CELL c = fgetc(ioFileHandles[slot]); - return feof(ioFileHandles[slot]) ? 0 : c; -} - -CELL ioWriteFile() { - CELL slot, c, r; - slot = data[sp]; sp--; - c = data[sp]; sp--; - r = fputc(c, ioFileHandles[slot]); - return (r == EOF) ? 0 : 1; -} - -CELL ioCloseFile() { - fclose(ioFileHandles[data[sp]]); - ioFileHandles[data[sp]] = 0; - sp--; - return 0; -} - -CELL ioGetFilePosition() { - CELL slot = data[sp]; sp--; - return (CELL) ftell(ioFileHandles[slot]); -} - -CELL ioSetFilePosition() { - CELL slot, pos, r; - slot = data[sp]; sp--; - pos = data[sp]; sp--; - r = fseek(ioFileHandles[slot], pos, SEEK_SET); - return r; -} - -CELL ioGetFileSize() { - CELL slot, current, r, size; - slot = data[sp]; sp--; - struct stat buffer; - int status; - status = fstat(fileno(ioFileHandles[slot]), &buffer); - if (!S_ISDIR(buffer.st_mode)) { - current = ftell(ioFileHandles[slot]); - r = fseek(ioFileHandles[slot], 0, SEEK_END); - size = ftell(ioFileHandles[slot]); - fseek(ioFileHandles[slot], current, SEEK_SET); - } else { - r = -1; - } - return (r == 0) ? size : 0; -} - -CELL ioDeleteFile() { - CELL name = data[sp]; sp--; - char *request = string_extract(name); - return (unlink(request) == 0) ? -1 : 0; -} - -void ioFlushFile() { - CELL slot; - slot = data[sp]; sp--; - fflush(ioFileHandles[slot]); -} - -/* Retro needs to track a few variables. This function is - called as necessary to ensure that the interface stays - in sync with the image state. */ - -void update_rx() { - Dictionary = memory[2]; - Compiler = d_xt_for("Compiler", Dictionary); - notfound = d_xt_for("err:notfound", Dictionary); -} - - -/* The `execute` function runs a word in the Retro image. - It also handles the additional I/O instructions. */ - -void execute(CELL cell) { - CELL a, b, c; - CELL opcode; - char path[1024]; - char arg0[1024], arg1[1024], arg2[1024]; - char arg3[1024], arg4[1024], arg5[1024]; - rp = 1; - ip = cell; - while (ip < IMAGE_SIZE) { - if (ip == notfound) { - printf("%s ?\n", string_extract(TIB)); - } - opcode = memory[ip]; - if (ngaValidatePackedOpcodes(opcode) != 0) { - ngaProcessPackedOpcodes(opcode); - } else if (opcode >= 0 && opcode < 27) { - ngaProcessOpcode(opcode); - } else { - switch (opcode) { - case IO_TTY_PUTC: putc(stack_pop(), stdout); fflush(stdout); break; - case IO_TTY_GETC: stack_push(getc(stdin)); break; - case -9999: include_file(string_extract(stack_pop())); break; - case IO_FS_OPEN: ioOpenFile(); break; - case IO_FS_CLOSE: ioCloseFile(); break; - case IO_FS_READ: stack_push(ioReadFile()); break; - case IO_FS_WRITE: ioWriteFile(); break; - case IO_FS_TELL: stack_push(ioGetFilePosition()); break; - case IO_FS_SEEK: ioSetFilePosition(); break; - case IO_FS_SIZE: stack_push(ioGetFileSize()); break; - case IO_FS_DELETE: ioDeleteFile(); break; - case IO_FS_FLUSH: ioFlushFile(); break; - case -6000: ngaFloatingPointUnit(); break; - case -6100: stack_push(sys_argc - 2); break; - case -6101: a = stack_pop(); - b = stack_pop(); - stack_push(string_inject(sys_argv[a + 2], b)); - break; - default: printf("Invalid instruction!\n"); - printf("At %d, opcode %d\n", ip, opcode); - exit(1); - } - } - ip++; - if (rp == 0) - ip = IMAGE_SIZE; - } -} - -/* -#include - -void gopher_fetch(char *host, CELL port, char *selector, CELL dest) { - int sockfd, portno, n; - struct sockaddr_in serv_addr; - struct hostent *server; - char data[128 * 1024 + 1]; - char buffer[1025]; - portno = (int)port; - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) - error("ERROR opening socket"); - server = gethostbyname(host); - if (server == NULL) { - fprintf(stderr,"ERROR, no such host\n"); - exit(0); - } - bzero(data, 128 * 1024 + 1); - bzero((char *) &serv_addr, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - bcopy((char *)server->h_addr, - (char *)&serv_addr.sin_addr.s_addr, - server->h_length); - serv_addr.sin_port = htons(portno); - if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) - error("ERROR connecting"); - n = write(sockfd,selector,strlen(selector)); - if (n < 0) - error("ERROR writing to socket"); - n = write(sockfd,"\n",strlen("\n")); - if (n < 0) - error("ERROR writing to socket"); - n = 1; - while (n > 0) { - bzero(buffer,1025); - n = read(sockfd,buffer,1024); - strcat(data, buffer); - } - closesocket(sockfd); - string_inject(data, dest); - stack_push(strlen(data)); -} -*/ - - -/* The `evaluate` function moves a token into the Retro - token buffer, then calls the Retro `interpret` word - to process it. */ - -void evaluate(char *s) { - if (strlen(s) == 0) - return; - update_rx(); - CELL interpret = d_xt_for("interpret", Dictionary); - string_inject(s, TIB); - stack_push(TIB); - execute(interpret); -} - - -/* `read_token` reads a token from the specified file. - It will stop on a whitespace or newline. It also - tries to handle backspaces, though the success of this - depends on how your terminal is configured. */ - -int not_eol(int ch) { - return (ch != (char)10) && (ch != (char)13) && (ch != (char)32) && (ch != EOF) && (ch != 0); -} - -void read_token(FILE *file, char *token_buffer, int echo) { - int ch = getc(file); - if (echo != 0) - putchar(ch); - int count = 0; - while (not_eol(ch)) - { - if ((ch == 8 || ch == 127) && count > 0) { - count--; - if (echo != 0) { - putchar(8); - putchar(32); - putchar(8); - } - } else { - token_buffer[count++] = ch; - } - ch = getc(file); - if (echo != 0) - putchar(ch); - } - token_buffer[count] = '\0'; -} - -char *read_token_str(char *s, char *token_buffer, int echo) { - int ch = (char)*s++; - if (echo != 0) - putchar(ch); - int count = 0; - while (not_eol(ch)) - { - if ((ch == 8 || ch == 127) && count > 0) { - count--; - if (echo != 0) { - putchar(8); - putchar(32); - putchar(8); - } - } else { - token_buffer[count++] = ch; - } - ch = (char)*s++; - if (echo != 0) - putchar(ch); - } - token_buffer[count] = '\0'; - return s; -} - -double Floats[8192]; -CELL fsp; - -int is_even(double d) { - double int_part; - modf(d / 2.0, &int_part); - return 2.0 * int_part == d; -} - -void float_push(double value) { - fsp++; - Floats[fsp] = value; -} - -double float_pop() { - fsp--; - return Floats[fsp + 1]; -} - -void float_from_number() { - float_push((double)stack_pop()); -} - -void float_from_string() { - float_push(atof(string_extract(stack_pop()))); -} - -void float_to_string() { - snprintf(string_data, 8192, "%f", float_pop()); - string_inject(string_data, stack_pop()); -} - -void float_add() { - double a = float_pop(); - double b = float_pop(); - float_push(a+b); -} - -void float_sub() { - double a = float_pop(); - double b = float_pop(); - float_push(b-a); -} - -void float_mul() { - double a = float_pop(); - double b = float_pop(); - float_push(a*b); -} - -void float_div() { - double a = float_pop(); - double b = float_pop(); - float_push(b/a); -} - -void float_floor() { - float_push(floor(float_pop())); -} - -void float_eq() { - double a = float_pop(); - double b = float_pop(); - if (a == b) - stack_push(-1); - else - stack_push(0); -} - -void float_neq() { - double a = float_pop(); - double b = float_pop(); - if (a != b) - stack_push(-1); - else - stack_push(0); -} - -void float_lt() { - double a = float_pop(); - double b = float_pop(); - if (b < a) - stack_push(-1); - else - stack_push(0); -} - -void float_gt() { - double a = float_pop(); - double b = float_pop(); - if (b > a) - stack_push(-1); - else - stack_push(0); -} - -void float_depth() { - stack_push(fsp); -} - -void float_dup() { - double a = float_pop(); - float_push(a); - float_push(a); -} - -void float_drop() { - float_pop(); -} - -void float_swap() { - double a = float_pop(); - double b = float_pop(); - float_push(a); - float_push(b); -} - -void float_log() { - double a = float_pop(); - double b = float_pop(); - float_push(log(b) / log(a)); -} - -void float_pow() { - double a = float_pop(); - double b = float_pop(); - float_push(pow(b, a)); -} - -void float_to_number() { - double a = float_pop(); - if (a > 2147483647) - a = 2147483647; - if (a < -2147483648) - a = -2147483648; - stack_push((CELL)round(a)); -} - -void float_sin() { - float_push(sin(float_pop())); -} - -void float_cos() { - float_push(cos(float_pop())); -} - -void float_tan() { - float_push(tan(float_pop())); -} - -void float_asin() { - float_push(asin(float_pop())); -} - -void float_acos() { - float_push(acos(float_pop())); -} - -void float_atan() { - float_push(atan(float_pop())); -} - -void ngaFloatingPointUnit() { - switch (stack_pop()) { - case 0: float_from_number(); break; - case 1: float_from_string(); break; - case 2: float_to_string(); break; - case 3: float_add(); break; - case 4: float_sub(); break; - case 5: float_mul(); break; - case 6: float_div(); break; - case 7: float_floor(); break; - case 8: float_eq(); break; - case 9: float_neq(); break; - case 10: float_lt(); break; - case 11: float_gt(); break; - case 12: float_depth(); break; - case 13: float_dup(); break; - case 14: float_drop(); break; - case 15: float_swap(); break; - case 16: float_log(); break; - case 17: float_pow(); break; - case 18: float_to_number(); break; - case 19: float_sin(); break; - case 20: float_cos(); break; - case 21: float_tan(); break; - case 22: float_asin(); break; - case 23: float_acos(); break; - case 24: float_atan(); break; - default: break; - } -} - -void error(const char *msg) { - perror(msg); - exit(0); -} - - -/* Compile image.c and link against the image.o */ -#include "rre_image_windows.c" - -void dump_stack() { - CELL i; - if (sp == 0) - return; - printf("\nStack: "); - for (i = 1; i <= sp; i++) { - if (i == sp) - printf("[ TOS: %d ]", data[i]); - else - printf("%d ", data[i]); - } - printf("\n"); -} - - -int fenced(char *s) -{ - int a = strcmp(s, "```"); - int b = strcmp(s, "~~~"); - if (a == 0) return 1; - if (b == 0) return 1; - return 0; -} - - -void include_file(char *fname) { - int inBlock = 0; - char source[64 * 1024]; - char fence[4]; - FILE *fp; - fp = fopen(fname, "r"); - if (fp == NULL) - return; - while (!feof(fp)) - { - read_token(fp, source, 0); - strncpy(fence, source, 3); - fence[3] = '\0'; - if (fenced(fence)) { - if (inBlock == 0) - inBlock = 1; - else - inBlock = 0; - } else { - if (inBlock == 1) - evaluate(source); - } - } - fclose(fp); -} - - -int main(int argc, char **argv) { - int i, interactive; - ngaPrepare(); - for (i = 0; i < ngaImageCells; i++) - memory[i] = ngaImage[i]; - update_rx(); - - interactive = 0; - - sys_argc = argc; - sys_argv = argv; - - if (argc > 1) { - if (strcmp(argv[1], "-i") == 0) { - interactive = 1; - if (argc >= 4 && strcmp(argv[2], "-f") == 0) { - include_file(argv[3]); - } - } else if (strcmp(argv[1], "-h") == 0) { - printf("Scripting Usage: rre filename\n\n"); - printf("Interactive Usage: rre args\n\n"); - printf("Valid Arguments:\n\n"); - printf(" -h\n"); - printf(" Display this help text\n\n"); - printf(" -i\n"); - printf(" Launches in interactive mode (line buffered)\n\n"); - printf(" -i -f filename\n"); - printf(" Launches in interactive mode (line buffered) and load the contents of the\n specified file\n\n"); - } else { - include_file(argv[1]); - } - } - - if (interactive == 1) { - execute(d_xt_for("banner", Dictionary)); - while (1) execute(d_xt_for("listen", Dictionary)); - } - if (interactive == 2) { - execute(d_xt_for("banner", Dictionary)); - while (1) execute(d_xt_for("listen-cbreak", Dictionary)); - } - - if (sp >= 1) - dump_stack(); - - exit(0); -} - -/* Nga ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Copyright (c) 2008 - 2018, Charles Childers - Copyright (c) 2009 - 2010, Luke Parrish - Copyright (c) 2010, Marc Simpson - Copyright (c) 2010, Jay Skeer - Copyright (c) 2011, Kenneth Keating - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -CELL ngaLoadImage(char *imageFile) { - FILE *fp; - CELL imageSize; - long fileLen; - if ((fp = fopen(imageFile, "rb")) != NULL) { - /* Determine length (in cells) */ - fseek(fp, 0, SEEK_END); - fileLen = ftell(fp) / sizeof(CELL); - rewind(fp); - /* Read the file into memory */ - imageSize = fread(&memory, sizeof(CELL), fileLen, fp); - fclose(fp); - } - else { - printf("Unable to find the ngaImage!\n"); - exit(1); - } - return imageSize; -} - -void ngaPrepare() { - ip = sp = rp = 0; - for (ip = 0; ip < IMAGE_SIZE; ip++) - memory[ip] = VM_NOP; - for (ip = 0; ip < STACK_DEPTH; ip++) - data[ip] = 0; - for (ip = 0; ip < ADDRESSES; ip++) - address[ip] = 0; -} - -void inst_nop() { -} - -void inst_lit() { - sp++; - ip++; - TOS = memory[ip]; -} - -void inst_dup() { - sp++; - data[sp] = NOS; -} - -void inst_drop() { - data[sp] = 0; - if (--sp < 0) - ip = IMAGE_SIZE; -} - -void inst_swap() { - CELL a; - a = TOS; - TOS = NOS; - NOS = a; -} - -void inst_push() { - rp++; - TORS = TOS; - inst_drop(); -} - -void inst_pop() { - sp++; - TOS = TORS; - rp--; -} - -void inst_jump() { - ip = TOS - 1; - inst_drop(); -} - -void inst_call() { - rp++; - TORS = ip; - ip = TOS - 1; - inst_drop(); -} - -void inst_ccall() { - CELL a, b; - a = TOS; inst_drop(); /* False */ - b = TOS; inst_drop(); /* Flag */ - if (b != 0) { - rp++; - TORS = ip; - ip = a - 1; - } -} - -void inst_return() { - ip = TORS; - rp--; -} - -void inst_eq() { - NOS = (NOS == TOS) ? -1 : 0; - inst_drop(); -} - -void inst_neq() { - NOS = (NOS != TOS) ? -1 : 0; - inst_drop(); -} - -void inst_lt() { - NOS = (NOS < TOS) ? -1 : 0; - inst_drop(); -} - -void inst_gt() { - NOS = (NOS > TOS) ? -1 : 0; - inst_drop(); -} - -void inst_fetch() { - switch (TOS) { - case -1: TOS = sp - 1; break; - case -2: TOS = rp; break; - case -3: TOS = IMAGE_SIZE; break; - default: TOS = memory[TOS]; break; - } -} - -void inst_store() { - if (TOS <= IMAGE_SIZE && TOS >= 0) { - memory[TOS] = NOS; - inst_drop(); - inst_drop(); - } else { - ip = IMAGE_SIZE; - } -} - -void inst_add() { - NOS += TOS; - inst_drop(); -} - -void inst_sub() { - NOS -= TOS; - inst_drop(); -} - -void inst_mul() { - NOS *= TOS; - inst_drop(); -} - -void inst_divmod() { - CELL a, b; - a = TOS; - b = NOS; - TOS = b / a; - NOS = b % a; -} - -void inst_and() { - NOS = TOS & NOS; - inst_drop(); -} - -void inst_or() { - NOS = TOS | NOS; - inst_drop(); -} - -void inst_xor() { - NOS = TOS ^ NOS; - inst_drop(); -} - -void inst_shift() { - CELL y = TOS; - CELL x = NOS; - if (TOS < 0) - NOS = NOS << (TOS * -1); - else { - if (x < 0 && y > 0) - NOS = x >> y | ~(~0U >> y); - else - NOS = x >> y; - } - inst_drop(); -} - -void inst_zret() { - if (TOS == 0) { - inst_drop(); - ip = TORS; - rp--; - } -} - -void inst_end() { - ip = IMAGE_SIZE; -} - -typedef void (*Handler)(void); -Handler instructions[NUM_OPS] = { - inst_nop, inst_lit, inst_dup, inst_drop, inst_swap, inst_push, inst_pop, - inst_jump, inst_call, inst_ccall, inst_return, inst_eq, inst_neq, inst_lt, - inst_gt, inst_fetch, inst_store, inst_add, inst_sub, inst_mul, inst_divmod, - inst_and, inst_or, inst_xor, inst_shift, inst_zret, inst_end -}; - -void ngaProcessOpcode(CELL opcode) { - instructions[opcode](); -} - -int ngaValidatePackedOpcodes(CELL opcode) { - CELL raw = opcode; - CELL current; - int valid = -1; - int i; - for (i = 0; i < 4; i++) { - current = raw & 0xFF; - if (!(current >= 0 && current <= 26)) - valid = 0; - raw = raw >> 8; - } - return valid; -} - -void ngaProcessPackedOpcodes(CELL opcode) { - CELL raw = opcode; - int i; - for (i = 0; i < 4; i++) { - ngaProcessOpcode(raw & 0xFF); - raw = raw >> 8; - } -} - diff --git a/interfaces/windows/rre_windows.forth b/interfaces/windows/rre_windows.forth deleted file mode 100644 index f2a70e0..0000000 --- a/interfaces/windows/rre_windows.forth +++ /dev/null @@ -1,265 +0,0 @@ -# RETRO - -This is a set of extensions for RRE. - -# Console Input - -~~~ -:c:get (-c) `1001 ; -~~~ - ---------------------------------------------------------------- - -# Floating Point - -~~~ -:n:to-float (n-_f:-n) #0 `-6000 ; -:s:to-float (s-_f:-n) #1 `-6000 ; -:f:to-string (f:n-__-s) s:empty dup #2 `-6000 ; -:f:+ (f:ab-c) #3 `-6000 ; -:f:- (f:ab-c) #4 `-6000 ; -:f:* (f:ab-c) #5 `-6000 ; -:f:/ (f:ab-c) #6 `-6000 ; -:f:floor (f:ab-c) #7 `-6000 ; -:f:eq? (f:ab-c) #8 `-6000 ; -:f:-eq? (f:ab-c) #9 `-6000 ; -:f:lt? (f:ab-c) #10 `-6000 ; -:f:gt? (f:ab-c) #11 `-6000 ; -:f:depth (-n) #12 `-6000 ; -:f:dup (f:a-aa) #13 `-6000 ; -:f:drop (f:a-) #14 `-6000 ; -:f:swap (f:ab-ba) #15 `-6000 ; -:f:log (f:ab-c) #16 `-6000 ; -:f:power (f:ab-c) #17 `-6000 ; -:f:to-number (f:a-__-n) #18 `-6000 ; -:f:sin (f:f-f) #19 `-6000 ; -:f:cos (f:f-f) #20 `-6000 ; -:f:tan (f:f-f) #21 `-6000 ; -:f:asin (f:f-f) #22 `-6000 ; -:f:acos (f:f-f) #23 `-6000 ; -:f:atan (f:f-f) #24 `-6000 ; -:f:over (f:ab-aba) f:to-string f:dup s:to-float f:swap ; -:f:tuck (f:ab-bab) f:swap f:over ; -:f:positive? (-f__f:a-) #0 n:to-float f:gt? ; -:f:negative? (-f__f:a-) #0 n:to-float f:lt? ; -:f:negate (f:a-b) #-1 n:to-float f:* ; -:f:abs (f:a-b) f:dup f:negative? [ f:negate ] if ; -:prefix:. (s-__f:-a) - compiling? [ s:keep ] [ s:temp ] choose &s:to-float class:word ; immediate -:f:put (f:a-) f:to-string s:put ; -:f:PI (f:-F) .3.141592 ; -:f:E (f:-F) .2.718281 ; -~~~ - ---------------------------------------------------------------- - -# Scripting: Command Line Arguments - -~~~ -:sys:argc (-n) `-6100 ; -:sys:argv (n-s) s:empty swap `-6101 ; -~~~ - ---------------------------------------------------------------- - -# File I/O - -This implements words for interfacing with the POSIX file I/O words if -you are using an interface supporting them. All of these are in the -`file:` namespace. - -These are pretty much direct wrappers for fopen(), fclose(), etc. - -First up, constants for the file modes. - -| # | Used For | -| - | ------------------ | -| R | Mode for READING | -| W | Mode for WRITING | -| A | Mode for APPENDING | - -~~~ -#0 'file:R const -#1 'file:W const -#2 'file:A const -#3 'file:R+ const -~~~ - -For opening a file, provide the file name and mode. This will return a -number identifying the file handle. - -~~~ -:file:open (sm-h) `118 ; -~~~ - -Given a file handle, close the file. - -~~~ -:file:close (h-) `119 ; -~~~ - -Given a file handle, read a character. - -~~~ -:file:read (h-c) `120 ; -~~~ - -Write a character to an open file. - -~~~ -:file:write (ch-) `121 ; -~~~ - -Return the current pointer within a file. - -~~~ -:file:tell (h-n) `122 ; -~~~ - -Move the file pointer to the specified location. - -~~~ -:file:seek (nh-) `123 ; -~~~ - -Return the size of the opened file. - -~~~ -:file:size (h-n) `124 ; -~~~ - -Given a file name, delete the file. - -~~~ -:file:delete (s-) `125 ; -~~~ - -Flush pending writes to disk. - -~~~ -:file:flush (f-) `126 ; -~~~ - -Given a file name, return `TRUE` if it exists or `FALSE` otherwise. - -~~~ -:file:exists? (s-f) - file:R file:open dup n:-zero? - [ file:close TRUE ] - [ drop FALSE ] choose ; -~~~ - -~~~ -:file:open (s-nn) - file:R file:open dup file:size swap ; - -:file:open (s-nn) - file:A file:open dup file:size swap ; - -:file:open (s-n) - file:W file:open ; -~~~ - - -With that out of the way, we can begin building higher level functionality. - -The first of these reads a line from the file. This is read to `here`; move -it somewhere safe if you need to keep it around. - -The second goes with it. The `for-each-line` word will invoke a combinator -once for each line in a file. This makes some things trivial. E.g., a simple -'cat' implementation could be as simple as: - - 'filename [ s:put nl ] file:for-each-line - -~~~ -{{ - 'FID var - 'FSize var - 'Action var - 'Buffer var - :-eof? (-f) @FID file:tell @FSize lt? ; - :preserve (q-) &FID [ &FSize [ call ] v:preserve ] v:preserve ; ----reveal--- - :file:read-line (f-s) - !FID - [ here dup !Buffer buffer:set - [ @FID file:read dup buffer:add - [ ASCII:CR eq? ] [ ASCII:LF eq? ] [ ASCII:NUL eq? ] tri or or ] until - buffer:get drop ] buffer:preserve - @Buffer ; - - :file:for-each-line (sq-) - [ !Action - file:R file:open !FID - @FID file:size !FSize - [ @FID file:read-line @Action call -eof? ] while - @FID file:close - ] preserve ; -}} -~~~ - -`file:slurp` reads a file into a buffer. - -~~~ -{{ - 'FID var - 'Size var ----reveal--- - :file:slurp (as-) - [ file:R file:open !FID - buffer:set - @FID file:size !Size - @Size [ @FID file:read buffer:add ] times - @FID file:close - ] buffer:preserve ; -}} -~~~ - -~~~ -{{ - 'FID var ----reveal--- - :file:spew (ss-) - file:W file:open !FID [ @FID file:write ] s:for-each @FID file:close ; -}} -~~~ - -# Interactive Listener - -~~~ - -{{ - :version (-) @Version #100 /mod n:put $. c:put n:put ; - :eol? (c-f) [ ASCII:CR eq? ] [ ASCII:LF eq? ] [ ASCII:SPACE eq? ] tri or or ; - :valid? (s-sf) dup s:length n:-zero? ; - :ok (-) compiling? [ nl 'Ok_ s:put ] -if ; - :check-eof (c-c) dup [ #-1 eq? ] [ #4 eq? ] bi or [ 'bye d:lookup d:xt fetch call ] if ; - :check-bs (c-c) dup [ #8 eq? ] [ #127 eq? ] bi or [ buffer:get drop ] if ; - :s:get (-s) [ #1025 buffer:set - [ c:get dup buffer:add check-eof check-bs eol? ] until - buffer:start s:chop ] buffer:preserve ; ----reveal--- - :banner (-) 'RETRO_12_(rx- s:put version $) c:put nl - EOM n:put '_MAX,_TIB_@_1025,_Heap_@_ s:put here n:put nl ; - :listen (-) - ok repeat s:get valid? [ interpret ok ] [ drop ] choose again ; -}} -~~~ - -~~~ -:include (s-) `-9999 ; -~~~ - -~~~ -{{ - :gather (c-) - dup [ #8 eq? ] [ #127 eq? ] bi or [ drop ] [ buffer:add ] choose ; - :cycle (q-qc) repeat c:get dup-pair swap call not 0; drop gather again ; ----reveal--- - :parse-until (q-s) - [ s:empty buffer:set cycle drop-pair buffer:start ] buffer:preserve ; -}} - -:s:get (-s) [ [ ASCII:LF eq? ] [ ASCII:CR eq? ] bi or ] parse-until ; -~~~