~crc_/rx

187ce418d449168daa59965c06b31047db58a8d5 — crc 3 years ago 55a5e95
update vm
3 files changed, 127 insertions(+), 106 deletions(-)

A find-tags
A programs
M src,vm.c
A find-tags => find-tags +9 -0
@@ 0,0 1,9 @@
~~~
:has-tag? [ ${ s:contains-char? ] [ $} s:contains-char? ] bi and ;
:text? 't, s:begins-with? ;

:display-tag s:put nl ;
:scan [ dup has-tag? [ display-tag ] [ drop ] choose ] file:for-each-line ;

file-list [ dup text? [ scan ] [ drop ] choose ] a:for-each


A programs => programs +12 -0
@@ 0,0 1,12 @@
~~~
file-list
[ dup ', s:contains-string? [ drop ] if;
  dup 'README s:eq? [ drop ] if;
  dup 'rx.c s:eq? [ drop ] if;
  dup 'retro.muri s:eq? [ drop ] if;
  dup 'retro.forth s:eq? [ drop ] if;
  dup 'Makefile s:eq? [ drop ] if;
  s:put sp
] a:for-each
~~~


M src,vm.c => src,vm.c +106 -106
@@ 1,8 1,4 @@
/*---------------------------------------------------------------------
  RETRO is a clean, elegant, and pragmatic dialect of Forth. It
  provides a simple alternative for those willing to make a break
  from legacy systems.

  Copyright (c) 2008 - 2021, Charles Childers

  The virtual machine is based on the C implementation of Ngaro and


@@ 25,20 21,17 @@
#define CELL int32_t
#define CELL_MIN INT_MIN + 1
#define CELL_MAX INT_MAX - 1

#define IMAGE_SIZE 64000000      /* Amount of RAM, in cells           */
#define ADDRESSES    128000       /* Depth of address stack            */
#define STACK_DEPTH  128000       /* Depth of data stack               */

#define TIB            1024       /* Location of TIB                   */
#define IMAGE_SIZE  32000000      /* Amount of RAM, in cells           */
#define ADDRESSES    256          /* Depth of address stack            */
#define STACK_DEPTH  256          /* Depth of data stack               */
#define TIB          1024         /* Location of TIB                   */

#define D_OFFSET_LINK     0       /* Dictionary Format Info. Update if */
#define D_OFFSET_XT       1       /* you change the dictionary fields. */
#define D_OFFSET_CLASS    2
#define D_OFFSET_NAME     3

#define NUM_DEVICES       6       /* Set the number of I/O devices     */

#define MAX_DEVICES      32
#define MAX_OPEN_FILES   32

CELL stack_pop();


@@ 48,18 41,19 @@ char *string_extract(CELL at);
CELL d_xt_for(char *Name, CELL Dictionary);
void update_rx();
void include_file(char *fname);
void io_output_handler();
void io_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_scripting_handler();
void io_scripting_query();
void io_random();
void io_random_query();
void register_device(void *handler, void *query);
void io_output();
void query_output();
void io_keyboard();
void query_keyboard();
void query_filesystem();
void io_filesystem();
void query_unix();
void io_unix();
void io_scripting();
void query_scripting();
void io_rng();
void query_rng();

CELL load_image();
void prepare_vm();


@@ 78,17 72,9 @@ CELL memory[IMAGE_SIZE + 1];      /* The memory for the image          */

typedef void (*Handler)(void);

Handler IO_deviceHandlers[] = {
  io_output_handler,      io_keyboard_handler,
  io_filesystem_handler,  io_unix_handler,
  io_scripting_handler,   io_random,
};

Handler IO_queryHandlers[] = {
  io_output_query,       io_keyboard_query,
  io_filesystem_query,   io_unix_query,
  io_scripting_query,    io_random_query,
};
Handler IO_deviceHandlers[MAX_DEVICES];
Handler IO_queryHandlers[MAX_DEVICES];
int devices;

CELL Dictionary;
CELL interpret;


@@ 97,6 83,13 @@ char string_data[8192];
char **sys_argv;
int sys_argc;

void register_device(void *handler, void *query) {
  IO_deviceHandlers[devices] = handler;
  IO_queryHandlers[devices] = query;
  devices++;
}


FILE *OpenFileHandles[MAX_OPEN_FILES];

CELL files_get_handle() {


@@ 195,12 188,12 @@ Handler FileActions[10] = {
  file_flush
};

void io_filesystem_query() {
void query_filesystem() {
  stack_push(0);
  stack_push(4);
}

void io_filesystem_handler() {
void io_filesystem() {
  FileActions[stack_pop()]();
}



@@ 269,12 262,12 @@ Handler UnixActions[] = {
  unix_system, unix_dir
};

void io_unix_query() {
void query_unix() {
  stack_push(1);
  stack_push(8);
}

void io_unix_handler() {
void io_unix() {
  UnixActions[stack_pop()]();
}



@@ 292,27 285,27 @@ void io_random() {
  stack_push(llabs(r));
}

void io_random_query() {
void query_rng() {
  stack_push(0);
  stack_push(10);
}

void io_output_handler() {
void io_output() {
  putc(stack_pop(), stdout);
  fflush(stdout);
}

void io_output_query() {
void query_output() {
  stack_push(0);
  stack_push(0);
}

void io_keyboard_handler() {
void io_keyboard() {
  stack_push(getc(stdin));
  if (TOS == 127) TOS = 8;
}

void io_keyboard_query() {
void query_keyboard() {
  stack_push(0);
  stack_push(1);
}


@@ 341,12 334,12 @@ Handler ScriptingActions[] = {
  scripting_include,    scripting_name,
};

void io_scripting_query() {
void query_scripting() {
  stack_push(2);
  stack_push(9);
}

void io_scripting_handler() {
void io_scripting() {
  ScriptingActions[stack_pop()]();
}



@@ 523,8 516,14 @@ int main(int argc, char **argv) {
  int modes[16];
  char *files[16];

  initialize();                           /* Initialize Nga & image    */
  initialize();
  update_rx();
  register_device(io_output, query_output);
  register_device(io_keyboard, query_keyboard);
  register_device(io_filesystem, query_filesystem);
  register_device(io_unix, query_unix);
  register_device(io_scripting, query_scripting);


  /* Setup variables related to the scripting device */
  sys_argc = argc;                        /* Point the global argc and */


@@ 651,6 650,7 @@ void prepare_vm() {
    data[ip] = 0;
  for (ip = 0; ip < ADDRESSES; ip++)
    address[ip] = 0;
  devices = 0;
}

void inst_no() {


@@ 823,7 823,7 @@ void inst_ha() {

void inst_ie() {
  sp++;
  TOS = NUM_DEVICES;
  TOS = devices;
}

void inst_iq() {


@@ 874,9 874,9 @@ void process_opcode_bundle(CELL opcode) {
  }
}

int32_t ngaImageCells = 1017;
int32_t ngaImageCells = 1011;
int32_t ngaImage[] = {
1793,-1,1001,1536,202104,0,10,1,10,2,10,3,10,4,10,5,10,6,10,7,
1793,-1,995,1536,202104,0,10,1,10,2,10,3,10,4,10,5,10,6,10,7,
10,8,10,9,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,68223234,1,2575,85000450,
1,656912,0,0,268505089,63,62,285281281,0,63,2063,10,101384453,0,9,10,2049,56,25,459011,


@@ 887,62 887,62 @@ int32_t ngaImage[] = {
659713,1,659713,2,659713,3,1793,168,17108737,3,2,524559,107,2049,107,2049,107,2049,121,168820998,
2,0,0,167841793,181,5,17826049,0,181,2,15,25,524546,164,134287105,182,95,2305,183,459023,
191,134287361,182,186,659201,181,2049,56,25,84152833,48,286458116,10,459014,206,184618754,45,25,16974851,-1,
168886532,1,134284289,1,215,134284289,0,206,660227,32,0,0,112,114,101,102,105,120,58,95,
0,285278479,232,7,2576,524546,81,1641217,1,167838467,229,2049,245,2049,241,524545,232,201,17826050,231,
0,2572,2563,2049,222,1793,133,459023,133,17760513,146,3,166,8,251727617,3,2,2049,160,16,
168820993,-1,126,2049,201,2049,160,459023,133,285282049,3,2,134287105,126,280,524545,1793,107,16846593,3,
0,107,8,659201,3,524545,25,112,17043201,3,7,2049,112,2049,107,268505092,126,1642241,126,656131,
659201,3,524545,7,112,2049,107,459009,19,112,459009,54,112,459009,15,112,459009,17,112,1793,
5,10,524546,160,134284303,162,1807,0,0,0,1642241,231,285282049,347,1,459012,342,117509889,181,342,
134287105,347,201,16845825,0,357,339,1793,64,1793,371,17826050,347,251,8,117506305,348,360,64,2116,
11340,11700,11400,13685,13104,12432,12402,9603,9801,11514,11413,11110,12528,11948,10302,13340,9700,13455,12753,10500,
10670,12654,13320,11960,13908,10088,10605,11865,11025,0,2049,201,987393,1,1793,107,524546,447,2049,445,
2049,445,17891588,2,447,8,17045505,-24,-16,17043736,-8,1118488,1793,107,17043202,1,169021201,2049,56,25,
33883396,101450758,6404,459011,437,34668804,2,2049,434,524545,379,437,302056196,379,659969,1,0,9,152,100,
117,112,0,456,11,152,100,114,111,112,0,463,13,152,115,119,97,112,0,471,
21,152,99,97,108,108,0,479,26,152,101,113,63,0,487,28,152,45,101,113,
63,0,494,30,152,108,116,63,0,502,32,152,103,116,63,0,509,34,152,102,
101,116,99,104,0,516,36,152,115,116,111,114,101,0,525,38,152,43,0,534,
40,152,45,0,539,42,152,42,0,544,44,152,47,109,111,100,0,549,46,152,
97,110,100,0,557,48,152,111,114,0,564,50,152,120,111,114,0,570,52,152,
115,104,105,102,116,0,577,333,158,112,117,115,104,0,586,336,158,112,111,112,
0,594,330,158,48,59,0,601,56,146,102,101,116,99,104,45,110,101,120,116,
0,607,59,146,115,116,111,114,101,45,110,101,120,116,0,621,222,146,115,58,
116,111,45,110,117,109,98,101,114,0,635,95,146,115,58,101,113,63,0,650,
81,146,115,58,108,101,110,103,116,104,0,659,64,146,99,104,111,111,115,101,
0,671,74,152,105,102,0,681,72,146,45,105,102,0,687,262,158,112,114,101,
102,105,120,58,40,0,694,126,133,67,111,109,112,105,108,101,114,0,706,3,
133,72,101,97,112,0,718,107,146,44,0,726,121,146,115,44,0,731,127,158,
59,0,737,289,158,91,0,742,305,158,93,0,747,2,133,68,105,99,116,105,
111,110,97,114,121,0,752,159,146,100,58,108,105,110,107,0,766,160,146,100,
58,120,116,0,776,162,146,100,58,99,108,97,115,115,0,784,164,146,100,58,
110,97,109,101,0,795,146,146,99,108,97,115,115,58,119,111,114,100,0,805,
158,146,99,108,97,115,115,58,109,97,99,114,111,0,819,133,146,99,108,97,
115,115,58,100,97,116,97,0,834,166,146,100,58,97,100,100,45,104,101,97,
100,101,114,0,848,263,158,112,114,101,102,105,120,58,35,0,864,269,158,112,
114,101,102,105,120,58,58,0,876,283,158,112,114,101,102,105,120,58,38,0,
888,267,158,112,114,101,102,105,120,58,36,0,900,320,158,114,101,112,101,97,
116,0,912,322,158,97,103,97,105,110,0,922,369,146,105,110,116,101,114,112,
114,101,116,0,931,201,146,100,58,108,111,111,107,117,112,0,944,152,146,99,
108,97,115,115,58,112,114,105,109,105,116,105,118,101,0,956,4,133,86,101,
114,115,105,111,110,0,975,416,146,105,0,986,107,146,100,0,991,410,146,114,
0,996,339,146,101,114,114,58,110,111,116,102,111,117,110,100,0,0,0,0,
0,0,0,0,284430,285470,133,70,73,68,0,1,285463,285484,146,114,101,97,100,45,
98,121,116,101,0,3841,285470,2049,9462,1,255,21,10,285471,285505,146,114,101,97,100,
45,99,101,108,108,0,2049,285484,2049,285484,2049,285484,2049,285484,1,-8,24,17,1,-8,
24,17,1,-8,24,17,10,285492,285535,133,67,101,108,108,115,0,1017,285526,285544,146,
115,105,122,101,0,3841,285470,2049,9535,1,4,197652,2,4097,285535,10,285536,285569,146,108,
111,97,100,45,105,109,97,103,101,0,1,0,2049,9425,4097,285470,1,284439,2049,285544,
1793,285588,2049,285505,67502597,16,2049,2890,10,1,285581,2049,2275,3,3841,285470,2049,9444,10,285555,
285607,133,67,111,117,110,116,0,8,285598,285616,146,69,79,76,63,0,1,285607,2049,
2988,3841,285607,1,20,11,1793,285634,2049,9211,1,0,4097,285607,10,1,285627,9,10,1793,
285753,3841,285535,2049,3646,105,110,116,51,50,92,32,116,32,110,103,97,73,109,97,
103,101,67,101,108,108,115,32,61,32,37,110,59,0,1,285644,2049,7225,2049,9248,
2049,9211,2049,3646,105,110,116,51,50,92,32,116,32,110,103,97,73,109,97,103,
101,91,93,32,61,32,123,0,1,285683,2049,7225,2049,9248,2049,9211,1,284439,1,284439,
1,3,17,15,1793,285736,2049,56,2049,9262,1,44,2049,9198,2049,285616,10,1,285725,2049,
2275,3,2049,3646,125,59,0,1,285743,2049,9248,2049,9211,10,1,285640,48,52,0,53,
56,50,0,54,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
168886532,1,134284289,1,215,134284289,0,206,660227,32,0,0,115,105,103,105,108,58,95,0,
285278479,232,6,2576,524546,81,1641217,1,167838467,229,2049,244,2049,240,524545,232,201,17826050,231,0,
2572,2563,2049,222,1793,133,459023,133,17760513,146,3,166,8,251727617,3,2,2049,160,16,168820993,
-1,126,2049,201,2049,160,459023,133,285282049,3,2,134287105,126,279,524545,1793,107,16846593,3,0,
107,8,659201,3,524545,25,112,17043201,3,7,2049,112,2049,107,268505092,126,1642241,126,656131,659201,
3,524545,7,112,2049,107,459009,19,112,459009,54,112,459009,15,112,459009,17,112,1793,5,
10,524546,160,134284303,162,1807,0,0,0,1642241,231,285282049,346,1,459012,341,117509889,181,341,134287105,
346,201,16845825,0,356,338,1793,64,1793,370,17826050,346,250,8,117506305,347,359,64,2116,11340,
11700,11400,13685,13104,12432,12402,9603,9801,11514,11413,11110,12528,11948,10302,13340,9700,13455,12753,10500,10670,
12654,13320,11960,13908,10088,10605,11865,11025,0,2049,201,987393,1,1793,107,524546,446,2049,444,2049,
444,17891588,2,446,8,17045505,-24,-16,17043736,-8,1118488,1793,107,17043202,1,169021201,2049,56,25,33883396,
101450758,6404,459011,436,34668804,2,2049,433,524545,378,436,302056196,378,659969,1,0,9,152,100,117,
112,0,455,11,152,100,114,111,112,0,462,13,152,115,119,97,112,0,470,21,
152,99,97,108,108,0,478,26,152,101,113,63,0,486,28,152,45,101,113,63,
0,493,30,152,108,116,63,0,501,32,152,103,116,63,0,508,34,152,102,101,
116,99,104,0,515,36,152,115,116,111,114,101,0,524,38,152,43,0,533,40,
152,45,0,538,42,152,42,0,543,44,152,47,109,111,100,0,548,46,152,97,
110,100,0,556,48,152,111,114,0,563,50,152,120,111,114,0,569,52,152,115,
104,105,102,116,0,576,332,158,112,117,115,104,0,585,335,158,112,111,112,0,
593,329,158,48,59,0,600,56,146,102,101,116,99,104,45,110,101,120,116,0,
606,59,146,115,116,111,114,101,45,110,101,120,116,0,620,222,146,115,58,116,
111,45,110,117,109,98,101,114,0,634,95,146,115,58,101,113,63,0,649,81,
146,115,58,108,101,110,103,116,104,0,658,64,146,99,104,111,111,115,101,0,
670,74,152,105,102,0,680,72,146,45,105,102,0,686,261,158,115,105,103,105,
108,58,40,0,693,126,133,67,111,109,112,105,108,101,114,0,704,3,133,72,
101,97,112,0,716,107,146,44,0,724,121,146,115,44,0,729,127,158,59,0,
735,288,158,91,0,740,304,158,93,0,745,2,133,68,105,99,116,105,111,110,
97,114,121,0,750,159,146,100,58,108,105,110,107,0,764,160,146,100,58,120,
116,0,774,162,146,100,58,99,108,97,115,115,0,782,164,146,100,58,110,97,
109,101,0,793,146,146,99,108,97,115,115,58,119,111,114,100,0,803,158,146,
99,108,97,115,115,58,109,97,99,114,111,0,817,133,146,99,108,97,115,115,
58,100,97,116,97,0,832,166,146,100,58,97,100,100,45,104,101,97,100,101,
114,0,846,262,158,115,105,103,105,108,58,35,0,862,268,158,115,105,103,105,
108,58,58,0,873,282,158,115,105,103,105,108,58,38,0,884,266,158,115,105,
103,105,108,58,36,0,895,319,158,114,101,112,101,97,116,0,906,321,158,97,
103,97,105,110,0,916,368,146,105,110,116,101,114,112,114,101,116,0,925,201,
146,100,58,108,111,111,107,117,112,0,938,152,146,99,108,97,115,115,58,112,
114,105,109,105,116,105,118,101,0,950,4,133,86,101,114,115,105,111,110,0,
969,415,146,105,0,980,107,146,100,0,985,409,146,114,0,990,338,146,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,288898,289938,133,70,73,68,0,1,289931,289952,146,114,101,97,100,45,
98,121,116,101,0,3841,289938,2049,9522,1,255,21,10,289939,289973,146,114,101,97,100,
45,99,101,108,108,0,2049,289952,2049,289952,2049,289952,2049,289952,1,-8,24,17,1,-8,
24,17,1,-8,24,17,10,289960,290003,133,67,101,108,108,115,0,1011,289994,290012,146,
115,105,122,101,0,3841,289938,2049,9595,1,4,197652,2,4097,290003,10,290004,290037,146,108,
111,97,100,45,105,109,97,103,101,0,1,0,2049,9485,4097,289938,1,288907,2049,290012,
1793,290056,2049,289973,67502597,16,2049,2884,10,1,290049,2049,2270,3,3841,289938,2049,9504,10,290023,
290075,133,67,111,117,110,116,0,8,290066,290084,146,69,79,76,63,0,1,290075,2049,
2982,3841,290075,1,20,11,1793,290102,2049,9203,1,0,4097,290075,10,1,290095,9,10,1793,
290221,3841,290003,2049,3640,105,110,116,51,50,92,32,116,32,110,103,97,73,109,97,
103,101,67,101,108,108,115,32,61,32,37,110,59,0,1,290112,2049,7217,2049,9240,
2049,9203,2049,3640,105,110,116,51,50,92,32,116,32,110,103,97,73,109,97,103,
101,91,93,32,61,32,123,0,1,290151,2049,7217,2049,9240,2049,9203,1,288907,1,288907,
1,3,17,15,1793,290204,2049,56,2049,9254,1,44,2049,9190,2049,290084,10,1,290193,2049,
2270,3,2049,3640,125,59,0,1,290211,2049,9240,2049,9203,10,1,290108,56,53,0,48,
57,50,0,54,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,