check in current work on error handling device

FossilOrigin-Name: a094776a8890c56a8d3ad05e44e4216acde44d04f9df0b1f781699dbaf77c272
This commit is contained in:
crc 2023-06-27 00:20:12 +00:00
parent 4c90b3bf8c
commit a147144fde
5 changed files with 123 additions and 70 deletions

View file

@ -13,6 +13,7 @@
* removed words deprecated in 2022.8
* new example: konilo-wiki.retro
* GNUmakefile fix from drakonis
* addition of an i/o device for handling some errors
================================================================

View file

@ -1,2 +1,16 @@
~~~
:err:set-handler (nn-)
#1234 io:scan-for
dup n:negative? [ drop 'Error:_device_(1234)_not_found s:put nl ] if;
#0 swap io:invoke ;
:err:dsu (-)
reset nl 'ERROR:_DSU:_DATA_STACK_UNDERFLOW s:put nl bye ;
:err:dso (-)
reset nl 'ERROR:_DSO:_DATA_STACK_OVERFLOW s:put nl bye ;
:err:set-defaults
&err:dsu #1 err:set-handler
&err:dso #2 err:set-handler ;
~~~

View file

@ -12,21 +12,32 @@
*/
#ifdef ENABLE_ERROR
void execute(NgaState *vm, CELL cell);
void handle_error(NgaState *vm, CELL error) {
CELL saved_ip = vm->cpu[vm->active].ip;
if (vm->ErrorHandlers[error] != 0) {
printf("\nHandling %lld\n", error);
execute(vm, vm->ErrorHandlers[error]);
}
vm->cpu[vm->active].ip = saved_ip;
}
void register_error_handler(NgaState *vm) {
CELL ErrorID = stack_pop(vm);
CELL ErrorHandler = stack_pop(vm);
vm->ErrorHandlers[ErrorID] = ErrorHandler;
printf("Assigned %lld to %lld\n", ErrorID, ErrorHandler);
}
void io_error(NgaState *vm) {
switch (stack_pop(vm)) {
case 0: register_error_handler(vm);
case 0: register_error_handler(vm); break;
default: break;
}
}
void query_err(NgaState *vm) {
void query_error(NgaState *vm) {
stack_push(vm, 0);
stack_push(vm, 1234);
}

View file

@ -10,8 +10,8 @@
#define CELL_MAX LLONG_MAX - 1
#endif
#endif
CELL ngaImageCells = 19932;
CELL ngaImage[] = { 1793,19438,19887,19931,202309,417,389,1249,1535,0,11254,0,10,1,10,2,10,3,10,
CELL ngaImageCells = 20169;
CELL ngaImage[] = { 1793,19675,20124,20168,202309,417,389,1249,1535,0,11254,0,10,1,10,2,10,3,10,
4,10,5,10,6,10,7,10,8,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,68223234,
1,2575,85000450,1,656912,163,180,268505089,65,64,285281281,0,65,2063,10,101384453,0,9,10,68485378,
@ -20,8 +20,8 @@ CELL ngaImage[] = { 1793,19438,19887,19931,202309,417,389,1249,1535,0,11254,0,10
1,251790353,101777669,1,17565186,109,524545,113,66,167838467,-1,134287105,3,61,659457,3,459023,130,2049,58,
25,2049,130,1793,137,2049,137,117506307,0,130,0,524545,28,135,168820993,0,149,1642241,149,134283523,
13,135,1793,130,524545,2049,130,1793,130,16846593,149,163,180,1793,66,16846593,149,135,180,1793,
66,7,10,659713,1,659713,2,659713,3,659713,4,659713,5,1793,19684,17108737,3,2,524559,130,
2049,130,2049,130,524545,0,130,524545,0,130,2049,144,1048838,2,1642241,10,7,18697,8246457295145463473,167841793,
66,7,10,659713,1,659713,2,659713,3,659713,4,659713,5,1793,19921,17108737,3,2,524559,130,
2049,130,2049,130,524545,0,130,524545,0,130,2049,144,1048838,2,1642241,10,7,18934,8246457295145463473,167841793,
216,11,17826049,0,216,2,15,25,524546,18035,134287105,217,29,2305,218,459023,226,2049,4875,134287361,
217,221,659201,216,10,659969,7,2049,58,25,17694978,58,244,9,84152833,48,319750404,243,117507601,246,
184618754,45,25,16974851,-1,168886532,1,134284289,1,259,134284289,0,246,660227,32,0,0,115,105,103,
@ -74,8 +74,8 @@ CELL ngaImage[] = { 1793,19438,19887,19931,202309,417,389,1249,1535,0,11254,0,10
110,112,97,99,107,0,1193,186,168,504,7572226160734292,100,58,115,111,117,114,99,101,0,
1205,188,168,504,6953375310887,100,58,104,97,115,104,0,1219,389,168,504,-3366153855364863819,101,114,114,
58,110,111,116,102,111,117,110,100,0,105,109,97,103,101,58,115,97,118,101,
0,103,101,0,65,68,77,69,46,114,101,116,114,111,0,0,111,0,117,110,
100,0,99,107,101,116,115,46,0,50,46,49,47,83,79,67,75,69,84,83,
0,103,101,0,65,68,77,69,46,114,101,116,114,111,0,0,111,0,70,76,
79,87,0,0,101,116,115,46,0,50,46,49,47,83,79,67,75,69,84,83,
46,109,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,
@ -170,7 +170,7 @@ CELL ngaImage[] = { 1793,19438,19887,19931,202309,417,389,1249,1535,0,11254,0,10
110,58,105,110,99,0,659713,1,10,3114,3139,168,12041,210720197721,110,58,100,101,99,0,
659969,1,10,3128,3158,168,12041,8246617666422322998,110,58,98,101,116,119,101,101,110,63,0,67503109,
1793,3166,67503109,67503109,2049,3106,10,1,3161,2049,2241,11,10,3142,3187,168,12041,249861296566813883,83,99,
111,112,101,76,105,115,116,0,19789,19843,10,3172,3198,168,12041,5864091,123,123,0,2049,
111,112,101,76,105,115,116,0,20026,20080,10,3172,3198,168,12041,5864091,123,123,0,2049,
1576,2,1,3187,2049,61,16,10,3190,3225,168,12041,-6305314778776785742,45,45,45,114,101,118,101,
97,108,45,45,45,0,2049,1576,1,3187,2049,3125,16,10,3207,3241,168,12041,5864159,125,
125,0,1,3187,2049,58,4,15,11,1793,3255,3841,3187,4097,2,10,1,3250,1793,3281,
@ -228,7 +228,7 @@ CELL ngaImage[] = { 1793,19438,19887,19931,202309,417,389,1249,1535,0,11254,0,10
10,4239,4297,156,12041,-4600587576916820603,84,101,109,112,83,116,114,105,110,103,115,0,32,4280,
4317,156,12041,7474516786580364824,84,101,109,112,83,116,114,105,110,103,77,97,120,0,512,4298,
4331,168,12041,229440420829967,83,84,82,73,78,71,83,0,2049,1545,3841,4297,3841,4317,19,18,
10,4318,4353,156,0,0,67,117,114,114,101,110,116,0,30,10,4340,4370,168,0,
10,4318,4353,156,0,0,67,117,114,114,101,110,116,0,1,10,4340,4370,168,0,
0,115,58,112,111,105,110,116,101,114,0,3841,4353,3841,4317,19,2049,4331,17,10,
4355,4391,168,0,0,115,58,110,101,120,116,0,1,4353,2049,3864,3841,4353,3841,4297,
11,1793,4407,1,0,4097,4353,10,1,4402,9,10,4318,4423,168,12041,6953962777192,115,58,116,
@ -533,7 +533,7 @@ CELL ngaImage[] = { 1793,19438,19887,19931,202309,417,389,1249,1535,0,11254,0,10
1793,10393,2,2049,104,2049,2740,1,417,1,17,2049,66,10,1,10381,2049,2229,2049,3125,
10,1,10374,2049,2449,2049,417,10,10250,10423,168,12041,8246849872898570441,115,58,101,118,97,108,117,
97,116,101,0,2049,10315,2049,5573,2049,10315,2,2049,10339,2049,10372,10,10407,10443,156,0,
0,76,80,0,0,10435,10455,156,0,0,73,110,100,101,120,0,0,13,0,0,
0,76,80,0,0,10435,10455,156,0,0,73,110,100,101,120,0,0,14,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,10444,10497,168,0,0,110,101,120,116,0,3841,10443,
1,10455,17,2049,3864,10,10487,10515,168,0,0,112,114,101,112,0,1,10443,2049,3864,
@ -944,67 +944,79 @@ CELL ngaImage[] = { 1793,19438,19887,19931,202309,417,389,1249,1535,0,11254,0,10
58,102,101,116,99,104,45,100,111,117,98,108,101,0,2,1,1,2049,18586,15,
5,2049,18526,6,10,18591,18646,168,0,1730340976492540563,109,101,109,58,115,116,111,114,101,45,
100,111,117,98,108,101,0,5,5,2049,2217,1,1,2049,18586,6,2049,18506,6,2049,
18506,10,1793,18682,1,192,1,2,17,8,2049,1576,2049,190,3841,11239,8,2049,1576,2049,
188,16,10,1,18663,18624,18693,168,19448,193470948,84,73,66,0,1,7,15,10,18684,18713,
168,19448,8246457295145463473,105,109,97,103,101,58,115,97,118,101,0,1,1000,2049,10812,2049,10793,
10,18697,18731,168,0,210711039690,101,100,105,116,63,0,2,1793,18738,1,8,11,10,1,
18734,1793,18746,1,127,11,10,1,18742,2049,2255,22,10,18720,18764,168,0,6953539406400,103,97,
116,104,101,114,0,2049,18731,1,17,1,4134,2049,66,10,18752,18784,168,0,210709415765,99,
121,99,108,101,0,2049,11123,2049,2217,4,8,2049,2644,25,3,2049,18764,1,18784,7,
10,18697,18817,168,19448,-4557881830897049127,112,97,114,115,101,45,117,110,116,105,108,0,1793,18829,
2049,4451,2049,4234,2049,18784,771,2049,4096,10,1,18819,2049,4260,10,18800,18845,168,19448,210726130610,
115,58,103,101,116,0,1793,18867,1793,18853,1,13,11,10,1,18849,1793,18861,1,10,
11,10,1,18857,2049,2255,22,10,1,18847,2049,18817,10,18834,18883,168,19448,210708950412,99,108,
101,97,114,0,2049,4472,92,94,91,50,74,92,94,91,48,59,48,72,0,1,
18885,2049,8246,2049,10918,10,18872,18914,156,0,193454829,69,79,84,0,0,18905,18929,156,0,
7571133383038306,73,103,110,111,114,105,110,103,0,0,18915,18945,168,0,249892406716047873,105,103,110,111,
114,105,110,103,63,0,3841,18929,10,18930,18961,168,0,229486327000139,118,101,114,115,105,111,
110,0,3841,4,1,100,20,10,18948,18978,168,0,210710254026,100,111,110,101,63,0,2,
4097,18914,1793,18987,1,13,11,10,1,18983,1793,18995,1,10,11,10,1,18991,1793,19003,
1,32,11,10,1,18999,2049,2298,22,22,10,18967,19020,168,0,6385195044,101,111,108,63,
0,3841,18914,1793,19028,1,13,11,10,1,19024,1793,19036,1,10,11,10,1,19032,2049,
2255,22,10,19010,19054,168,0,6954126150804,118,97,108,105,100,63,0,2,2049,104,2049,2812,
10,19042,19075,168,0,249883998779477802,99,104,101,99,107,45,101,111,102,0,2,1793,19082,1,
-1,11,10,1,19078,1793,19090,1,4,11,10,1,19086,2049,2255,22,1,11190,9,10,
19060,19107,168,0,5863258,98,115,0,2049,4212,1,2,2049,2675,1793,19119,2049,4160,3,10,
1,19115,9,2049,4160,3,10,19099,19140,168,0,7572242387256805,99,104,101,99,107,45,98,115,
0,2,1793,19147,1,8,11,10,1,19143,1793,19155,1,127,11,10,1,19151,2049,2255,
22,1,19107,9,10,19126,19175,168,0,210708806723,99,104,101,99,107,0,2049,19075,2049,19140,
10,19164,19195,168,0,249883994190734226,99,104,97,114,97,99,116,101,114,0,2049,11123,2,2049,
4134,10,19180,19213,168,0,6953366942559,98,117,102,102,101,114,0,1793,19223,2049,18693,2049,4234,
8,2049,4096,10,1,19215,2049,4260,10,19201,19244,168,0,8246863741238799215,114,101,97,100,45,116,
111,107,101,110,0,1793,19260,1793,19255,2049,19195,2049,19175,2049,18978,10,1,19248,2049,2397,
10,1,19246,2049,19213,2049,4587,10,19228,19278,168,0,210716150453,105,110,112,117,116,0,2049,
19244,2049,19054,10,19267,19296,168,0,229479082815460,112,114,111,99,101,115,115,0,2049,18945,1793,
19314,771,2049,19020,1793,19310,1,18929,2049,3931,10,1,19305,9,10,1,19300,2049,2862,1,
417,1,17,2049,66,10,18872,19333,180,19448,5861507,47,47,0,2049,16613,1,18929,2049,3916,
10,19325,19352,168,19448,6953343520347,98,97,110,110,101,114,0,2049,18961,2049,4472,82,69,84,
82,79,32,49,50,32,40,37,110,46,37,110,41,92,110,0,1,19356,2049,8246,
2049,10918,2049,9335,2049,1545,2049,9335,18,2049,1545,2049,4472,37,110,32,77,97,120,44,
32,37,110,32,85,115,101,100,44,32,37,110,32,70,114,101,101,92,110,0,
1,19392,2049,8246,2049,10918,10,19340,19438,168,19448,6953744547860,108,105,115,116,101,110,0,2049,
19352,2049,19278,2049,19296,1,19440,7,10,105,110,116,101,114,102,97,99,101,47,114,
101,116,114,111,45,117,110,105,120,46,114,101,116,114,111,0,19426,19488,156,0,
229441520490121,83,111,117,114,99,101,115,0,1,19737,0,0,0,0,0,0,0,0,0,
18506,10,18624,18682,168,0,4283726481136624767,101,114,114,58,115,101,116,45,104,97,110,100,108,
101,114,0,1,1234,2049,10812,2,2049,2761,1793,18732,3,2049,4472,69,114,114,111,114,
58,32,100,101,118,105,99,101,32,40,49,50,51,52,41,32,110,111,116,32,
102,111,117,110,100,0,1,18694,2049,10918,2049,10875,10,1,18691,2049,2862,1,0,4,
2049,10793,10,18661,18755,168,0,229464878751060,101,114,114,58,100,115,117,0,2049,10950,2049,10875,
2049,4472,69,82,82,79,82,58,32,68,83,85,58,32,68,65,84,65,32,83,
84,65,67,75,32,85,78,68,69,82,70,76,79,87,0,1,18761,2049,10918,2049,
10875,2049,11190,10,18742,18816,168,0,229464878751054,101,114,114,58,100,115,111,0,2049,10950,2049,
10875,2049,4472,69,82,82,79,82,58,32,68,83,79,58,32,68,65,84,65,32,
83,84,65,67,75,32,79,86,69,82,70,76,79,87,0,1,18822,2049,10918,2049,
10875,2049,11190,10,18803,18885,168,0,-6210978877792005319,101,114,114,58,115,101,116,45,100,101,102,
97,117,108,116,115,0,1,18755,1,1,2049,18682,1,18816,1,2,2049,18682,10,1793,
18919,1,192,1,2,17,8,2049,1576,2049,190,3841,11239,8,2049,1576,2049,188,16,10,
1,18900,18863,18930,168,19685,193470948,84,73,66,0,1,7,15,10,18921,18950,168,19685,8246457295145463473,
105,109,97,103,101,58,115,97,118,101,0,1,1000,2049,10812,2049,10793,10,18934,18968,
168,0,210711039690,101,100,105,116,63,0,2,1793,18975,1,8,11,10,1,18971,1793,18983,
1,127,11,10,1,18979,2049,2255,22,10,18957,19001,168,0,6953539406400,103,97,116,104,101,
114,0,2049,18968,1,17,1,4134,2049,66,10,18989,19021,168,0,210709415765,99,121,99,108,
101,0,2049,11123,2049,2217,4,8,2049,2644,25,3,2049,19001,1,19021,7,10,18934,19054,
168,19685,-4557881830897049127,112,97,114,115,101,45,117,110,116,105,108,0,1793,19066,2049,4451,2049,
4234,2049,19021,771,2049,4096,10,1,19056,2049,4260,10,19037,19082,168,19685,210726130610,115,58,103,
101,116,0,1793,19104,1793,19090,1,13,11,10,1,19086,1793,19098,1,10,11,10,1,
19094,2049,2255,22,10,1,19084,2049,19054,10,19071,19120,168,19685,210708950412,99,108,101,97,114,
0,2049,4472,92,94,91,50,74,92,94,91,48,59,48,72,0,1,19122,2049,8246,
2049,10918,10,19109,19151,156,0,193454829,69,79,84,0,0,19142,19166,156,0,7571133383038306,73,103,
110,111,114,105,110,103,0,0,19152,19182,168,0,249892406716047873,105,103,110,111,114,105,110,
103,63,0,3841,19166,10,19167,19198,168,0,229486327000139,118,101,114,115,105,111,110,0,3841,
4,1,100,20,10,19185,19215,168,0,210710254026,100,111,110,101,63,0,2,4097,19151,1793,
19224,1,13,11,10,1,19220,1793,19232,1,10,11,10,1,19228,1793,19240,1,32,11,
10,1,19236,2049,2298,22,22,10,19204,19257,168,0,6385195044,101,111,108,63,0,3841,19151,
1793,19265,1,13,11,10,1,19261,1793,19273,1,10,11,10,1,19269,2049,2255,22,10,
19247,19291,168,0,6954126150804,118,97,108,105,100,63,0,2,2049,104,2049,2812,10,19279,19312,
168,0,249883998779477802,99,104,101,99,107,45,101,111,102,0,2,1793,19319,1,-1,11,10,
1,19315,1793,19327,1,4,11,10,1,19323,2049,2255,22,1,11190,9,10,19297,19344,168,
0,5863258,98,115,0,2049,4212,1,2,2049,2675,1793,19356,2049,4160,3,10,1,19352,9,
2049,4160,3,10,19336,19377,168,0,7572242387256805,99,104,101,99,107,45,98,115,0,2,1793,
19384,1,8,11,10,1,19380,1793,19392,1,127,11,10,1,19388,2049,2255,22,1,19344,
9,10,19363,19412,168,0,210708806723,99,104,101,99,107,0,2049,19312,2049,19377,10,19401,19432,
168,0,249883994190734226,99,104,97,114,97,99,116,101,114,0,2049,11123,2,2049,4134,10,19417,
19450,168,0,6953366942559,98,117,102,102,101,114,0,1793,19460,2049,18930,2049,4234,8,2049,4096,
10,1,19452,2049,4260,10,19438,19481,168,0,8246863741238799215,114,101,97,100,45,116,111,107,101,
110,0,1793,19497,1793,19492,2049,19432,2049,19412,2049,19215,10,1,19485,2049,2397,10,1,19483,
2049,19450,2049,4587,10,19465,19515,168,0,210716150453,105,110,112,117,116,0,2049,19481,2049,19291,
10,19504,19533,168,0,229479082815460,112,114,111,99,101,115,115,0,2049,19182,1793,19551,771,2049,
19257,1793,19547,1,19166,2049,3931,10,1,19542,9,10,1,19537,2049,2862,1,417,1,17,
2049,66,10,19109,19570,180,19685,5861507,47,47,0,2049,16613,1,19166,2049,3916,10,19562,19589,
168,19685,6953343520347,98,97,110,110,101,114,0,2049,19198,2049,4472,82,69,84,82,79,32,
49,50,32,40,37,110,46,37,110,41,92,110,0,1,19593,2049,8246,2049,10918,2049,
9335,2049,1545,2049,9335,18,2049,1545,2049,4472,37,110,32,77,97,120,44,32,37,110,
32,85,115,101,100,44,32,37,110,32,70,114,101,101,92,110,0,1,19629,2049,
8246,2049,10918,10,19577,19675,168,19685,6953744547860,108,105,115,116,101,110,0,2049,19589,2049,19515,
2049,19533,1,19677,7,10,105,110,116,101,114,102,97,99,101,47,114,101,116,114,
111,45,117,110,105,120,46,114,101,116,114,111,0,19663,19725,156,0,229441520490121,83,111,
117,114,99,101,115,0,1,19974,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19475,19628,168,
0,6953711201841,107,110,111,119,110,63,0,2,1,19488,2049,9099,10,19616,19645,168,0,210716136861,
105,110,100,101,120,0,1,19488,4,2049,9775,1,19488,4,2049,9245,10,19634,19668,168,
0,6953974036516,114,101,99,111,114,100,0,2049,4500,2,1,19488,2049,3864,3841,19488,1,19488,
17,16,10,1793,19735,2049,16548,2049,19628,1793,19693,2049,19645,10,1,19690,1793,19700,2049,19668,
10,1,19697,2049,66,1793,19713,1,192,1,2,17,8,10,1,19706,2049,2229,2049,1576,
2049,186,16,2049,1576,2049,190,3841,11239,8,2049,1576,2049,188,16,10,1,19684,100,105,
99,116,45,119,111,114,100,115,45,108,105,115,116,105,110,103,46,102,111,114,
116,104,0,19426,19775,168,19737,229461403550098,100,58,119,111,114,100,115,0,1793,19784,2049,190,
2049,10918,2049,10888,10,1,19777,2049,8491,10,19762,19807,168,19737,-3502157631813457253,100,58,119,111,114,
100,115,45,119,105,116,104,0,2049,1977,2049,5573,1793,19838,2049,190,2,2049,1977,2049,
5286,1793,19827,2049,10918,2049,10888,10,1,19822,1793,19833,3,10,1,19831,2049,66,10,1,
19813,2049,8491,10,19789,19864,168,19737,2818131571306626127,100,105,115,112,108,97,121,45,105,102,45,
108,101,102,116,0,2,2049,1977,2049,5519,1793,19876,2049,10918,2049,10888,10,1,19871,1793,
19882,3,10,1,19880,2049,66,10,19789,19915,168,19737,2947807019553410009,100,58,119,111,114,100,115,
45,98,101,103,105,110,110,105,110,103,45,119,105,116,104,0,2049,1977,2049,5573,
1793,19926,2049,190,2049,19864,10,1,19921,2049,8491,10,0 };
0,0,0,0,0,0,0,0,0,0,0,0,0,0,19712,19865,168,0,6953711201841,107,
110,111,119,110,63,0,2,1,19725,2049,9099,10,19853,19882,168,0,210716136861,105,110,100,
101,120,0,1,19725,4,2049,9775,1,19725,4,2049,9245,10,19871,19905,168,0,6953974036516,114,
101,99,111,114,100,0,2049,4500,2,1,19725,2049,3864,3841,19725,1,19725,17,16,10,
1793,19972,2049,16548,2049,19865,1793,19930,2049,19882,10,1,19927,1793,19937,2049,19905,10,1,19934,
2049,66,1793,19950,1,192,1,2,17,8,10,1,19943,2049,2229,2049,1576,2049,186,16,
2049,1576,2049,190,3841,11239,8,2049,1576,2049,188,16,10,1,19921,100,105,99,116,45,
119,111,114,100,115,45,108,105,115,116,105,110,103,46,102,111,114,116,104,0,
19663,20012,168,19974,229461403550098,100,58,119,111,114,100,115,0,1793,20021,2049,190,2049,10918,2049,
10888,10,1,20014,2049,8491,10,19999,20044,168,19974,-3502157631813457253,100,58,119,111,114,100,115,45,
119,105,116,104,0,2049,1977,2049,5573,1793,20075,2049,190,2,2049,1977,2049,5286,1793,20064,
2049,10918,2049,10888,10,1,20059,1793,20070,3,10,1,20068,2049,66,10,1,20050,2049,8491,
10,20026,20101,168,19974,2818131571306626127,100,105,115,112,108,97,121,45,105,102,45,108,101,102,
116,0,2,2049,1977,2049,5519,1793,20113,2049,10918,2049,10888,10,1,20108,1793,20119,3,10,
1,20117,2049,66,10,20026,20152,168,19974,2947807019553410009,100,58,119,111,114,100,115,45,98,101,
103,105,110,110,105,110,103,45,119,105,116,104,0,2049,1977,2049,5573,1793,20163,2049,
190,2049,20101,10,1,20158,2049,8491,10,0 };

View file

@ -146,6 +146,8 @@ struct NgaState {
/* Function Prototypes ----------------------------------------------- */
void handle_error(NgaState *, CELL);
CELL stack_pop(NgaState *);
void stack_push(NgaState *, CELL);
CELL string_inject(NgaState *, char *, CELL);
@ -226,6 +228,7 @@ void guard(NgaState *vm, int n, int m, int diff) {
if (vm->cpu[vm->active].sp < n) {
#ifdef ENABLE_ERROR
if (vm->ErrorHandlers[1] != 0) {
handle_error(vm, 1);
}
#else
printf("E: Data Stack Underflow");
@ -236,6 +239,7 @@ void guard(NgaState *vm, int n, int m, int diff) {
if (((vm->cpu[vm->active].sp + m) - n) > (STACK_DEPTH - 1)) {
#ifdef ENABLE_ERROR
if (vm->ErrorHandlers[2] != 0) {
handle_error(vm, 2);
}
#else
printf("E: Data Stack Overflow");
@ -247,6 +251,7 @@ void guard(NgaState *vm, int n, int m, int diff) {
if (vm->cpu[vm->active].rp + diff < 0) {
#ifdef ENABLE_ERROR
if (vm->ErrorHandlers[3] != 0) {
handle_error(vm, 3);
}
#else
return;
@ -255,6 +260,7 @@ void guard(NgaState *vm, int n, int m, int diff) {
if (vm->cpu[vm->active].rp + diff > (ADDRESSES - 1)) {
#ifdef ENABLE_ERROR
if (vm->ErrorHandlers[1] != 4) {
handle_error(vm, 4);
}
#else
return;
@ -270,6 +276,10 @@ void guard(NgaState *vm, int n, int m, int diff) {
#endif
#endif
#ifdef ENABLE_ERROR
#include "dev-error.c"
#endif
/* Block Storage -------------------------------------------- */
#ifdef ENABLE_BLOCKS
void io_blocks(NgaState *vm) {
@ -562,6 +572,7 @@ void execute(NgaState *vm, CELL cell) {
} else {
invalid_opcode(vm, opcode);
}
#ifndef ENABLE_ERROR
if (vm->cpu[vm->active].sp < 0 || vm->cpu[vm->active].sp > STACK_DEPTH) {
printf("\nERROR (nga/execute): Stack Limits Exceeded!\n");
printf("At %lld, opcode %lld. sp = %lld, core = %lld\n", (long long)vm->cpu[vm->active].ip, (long long)opcode, (long long)vm->cpu[vm->active].sp, (long long)vm->active);
@ -572,6 +583,7 @@ void execute(NgaState *vm, CELL cell) {
printf("At %lld, opcode %lld. rp = %lld\n", (long long)vm->cpu[vm->active].ip, (long long)opcode, (long long)vm->cpu[vm->active].rp);
exit(1);
}
#endif
vm->cpu[vm->active].ip++;
#ifdef ENABLE_MULTICORE
switch_core(vm);
@ -924,6 +936,9 @@ int main(int argc, char **argv) {
#ifdef ENABLE_UNSIGNED
register_device(vm, io_unsigned, query_unsigned);
#endif
#ifdef ENABLE_ERROR
register_device(vm, io_error, query_error);
#endif
strcpy(vm->code_start, "~~~");
strcpy(vm->code_end, "~~~");