merge in malloc device (thanks to Rick C for this!) and start of a double: vocabulary (create variables, constants; fetch/store variables)

FossilOrigin-Name: 302e5bc9cfcb2b5a46f3e4384e307c47831b23c299dd25e4385e8ed79bdb9558
This commit is contained in:
crc 2022-07-25 12:15:34 +00:00
parent de4a28c43c
commit f32c3c57e6
6 changed files with 165 additions and 111 deletions

View file

@ -59,6 +59,7 @@ ENABLED += -DENABLE_SIGNALS
ENABLED += -DENABLE_MULTICORE
ENABLED += -DENABLE_FFI
ENABLED += -DENABLE_UNSIGNED
ENABLED += -DENABLE_MALLOC
ENABLED += -DNEEDS_STRL
@ -77,6 +78,8 @@ DEVICES += interface/ffi.retro
DEVICES += interface/retro-napia.retro
DEVICES += interface/block.retro
DEVICES += interface/deprecated.retro
DEVICES += interface/double.retro
DEVICES += interface/malloc.retro
# -------------------------------------------------------------

View file

@ -42,6 +42,7 @@ Portions of the code derive from RETRO 11, which was:
Copyright (c) 2011, Remy Moueza
Copyright (c) 2012, John M Harrison
Copyright (c) 2012, Todd Thomas
Copyright (c) 2022, Rick Carlino
The Free Pascal implementation in vm/nga-pascal is:

View file

@ -46,6 +46,7 @@ ENABLED += -DENABLE_SIGNALS
ENABLED += -DENABLE_MULTICORE
ENABLED += -DENABLE_FFI
ENABLED += -DENABLE_UNSIGNED
ENABLED += -DENABLE_MALLOC
DEVICES ?=
DEVICES += interface/floatingpoint.retro
@ -62,6 +63,8 @@ DEVICES += interface/unsigned.retro
DEVICES += interface/retro-napia.retro
DEVICES += interface/block.retro
DEVICES += interface/deprecated.retro
DEVICES += interface/double.retro
DEVICES += interface/malloc.retro
# -------------------------------------------------------------

13
interface/double.retro Normal file
View file

@ -0,0 +1,13 @@
~~~
:double:var (nns-)
d:create swap , , ;
:double:fetch (a-nn)
fetch-next swap fetch ;
:double:store (nna-)
&swap dip store-next store ;
:double:const (nns-)
double:var &double:fetch does ;
~~~

View file

@ -10,8 +10,8 @@
#define CELL_MAX LLONG_MAX - 1
#endif
#endif
CELL ngaImageCells = 19596;
CELL ngaImage[] = { 1793,18193,19551,19595,202207,410,382,1242,1535,0,10,1,10,2,10,3,10,4,10,
CELL ngaImageCells = 18925;
CELL ngaImage[] = { 1793,18432,18880,18924,202207,410,382,1242,1535,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,161,178,268505089,63,62,285281281,0,63,2063,10,101384453,0,9,10,68485378,255,18350338,
@ -20,8 +20,8 @@ CELL ngaImage[] = { 1793,18193,19551,19595,202207,410,382,1242,1535,0,10,1,10,2,
101777669,1,17565186,107,524545,111,64,167838467,-1,134287105,3,59,659457,3,459023,128,2049,56,25,2049,
128,1793,135,2049,135,117506307,0,128,0,524545,26,133,168820993,0,147,1642241,147,134283523,11,133,
1793,128,524545,2049,128,1793,128,16846593,147,161,178,1793,64,16846593,147,133,178,1793,64,7,
10,659713,1,659713,2,659713,3,659713,4,659713,5,1793,19358,17108737,3,2,524559,128,2049,128,
2049,128,524545,0,128,524545,0,128,2049,142,168820998,2,17429,1242,167841793,211,9,17826049,0,211,
10,659713,1,659713,2,659713,3,659713,4,659713,5,1793,18687,17108737,3,2,524559,128,2049,128,
2049,128,524545,0,128,524545,0,128,2049,142,168820998,2,17668,1242,167841793,211,9,17826049,0,211,
2,15,25,524546,188,134287105,212,116,2305,213,459023,221,134287361,212,216,659201,211,10,659969,7,
2049,56,25,17694978,58,237,9,84152833,48,319750404,236,117507601,239,184618754,45,25,16974851,-1,168886532,1,
134284289,1,252,134284289,0,239,660227,32,0,0,115,105,103,105,108,58,105,0,285278479,269,
@ -170,7 +170,7 @@ CELL ngaImage[] = { 1793,18193,19551,19595,202207,410,382,1242,1535,0,10,1,10,2,
110,58,105,110,99,0,659713,1,10,3114,3139,166,16136,266800217,110,58,100,101,99,0,
659969,1,10,3128,3158,166,16136,1032861494,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,166,16136,-2130983749,83,99,
111,112,101,76,105,115,116,0,19453,19507,10,3172,3198,166,16136,5864091,123,123,0,2049,
111,112,101,76,105,115,116,0,18782,18836,10,3172,3198,166,16136,5864091,123,123,0,2049,
1576,2,1,3187,2049,59,16,10,3190,3225,166,16136,-1644352334,45,45,45,114,101,118,101,
97,108,45,45,45,0,2049,1576,1,3187,2049,3125,16,10,3207,3241,166,16136,5864159,125,
125,0,1,3187,2049,56,4,15,11,1793,3255,3841,3187,4097,2,10,1,3250,1793,3281,
@ -228,7 +228,7 @@ CELL ngaImage[] = { 1793,18193,19551,19595,202207,410,382,1242,1535,0,10,1,10,2,
10,4239,4297,154,16136,1204567429,84,101,109,112,83,116,114,105,110,103,115,0,32,4280,
4317,154,16136,1808866840,84,101,109,112,83,116,114,105,110,103,77,97,120,0,512,4298,
4331,166,16136,-1027089649,83,84,82,73,78,71,83,0,2049,1545,3841,4297,3841,4317,19,18,
10,4318,4353,154,0,0,67,117,114,114,101,110,116,0,10,10,4340,4370,166,0,
10,4318,4353,154,0,0,67,117,114,114,101,110,116,0,14,10,4340,4370,166,0,
0,115,58,112,111,105,110,116,101,114,0,3841,4353,3841,4317,19,2049,4331,17,10,
4355,4391,166,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,166,16136,410724968,115,58,116,
@ -526,7 +526,7 @@ CELL ngaImage[] = { 1793,18193,19551,19595,202207,410,382,1242,1535,0,10,1,10,2,
2229,2049,3125,10,1,10217,2049,2449,2049,410,10,10093,10266,166,16136,102250697,115,58,101,118,
97,108,117,97,116,101,0,2049,10158,2049,5573,2049,10158,2,2049,10182,2049,10215,10,10250,
10286,154,0,0,76,80,0,0,10278,10298,154,0,0,73,110,100,101,120,0,0,
13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,10287,10340,166,0,0,110,101,120,116,
0,3841,10286,1,10298,17,2049,3864,10,10330,10358,166,0,0,112,114,101,112,0,1,
10286,2049,3864,1,0,3841,10286,1,10298,17,16,10,10348,10381,166,0,0,100,111,110,
@ -881,113 +881,80 @@ CELL ngaImage[] = { 1793,18193,19551,19595,202207,410,382,1242,1535,0,10,1,10,2,
111,102,0,2049,9195,10,17326,17368,166,0,420384638,97,58,105,110,100,101,120,45,111,
102,45,115,116,114,105,110,103,0,2049,9320,10,17345,17387,166,0,1439644652,115,58,105,
110,100,101,120,45,111,102,0,2049,4779,10,17371,17413,166,0,1818260368,115,58,105,110,
100,101,120,45,111,102,45,115,116,114,105,110,103,0,2049,5069,10,17390,17425,166,
18212,193470948,84,73,66,0,1,7,15,10,17416,17445,166,18212,-460132687,105,109,97,103,101,
58,115,97,118,101,0,1,1000,2049,10655,2049,10636,10,17429,17463,166,0,0,101,100,
105,116,63,0,2,1793,17470,1,8,11,10,1,17466,1793,17478,1,127,11,10,1,
17474,2049,2255,22,10,17452,17496,166,0,0,103,97,116,104,101,114,0,2049,17463,1,
15,1,4134,2049,64,10,17484,17516,166,0,0,99,121,99,108,101,0,2049,10985,2049,
2217,4,8,2049,2644,25,3,2049,17496,1,17516,7,10,17429,17549,166,18212,-1658019367,112,97,
114,115,101,45,117,110,116,105,108,0,1793,17561,2049,4451,2049,4234,2049,17516,771,2049,
4096,10,1,17551,2049,4260,10,17532,17577,166,18212,272733106,115,58,103,101,116,0,1793,17599,
1793,17585,1,13,11,10,1,17581,1793,17593,1,10,11,10,1,17589,2049,2255,22,10,
1,17579,2049,17549,10,17566,17615,166,18212,255552908,99,108,101,97,114,0,2049,4472,92,94,
91,50,74,92,94,91,48,59,48,72,0,1,17617,2049,8246,2049,10761,10,17604,17649,
154,18212,-976122143,78,111,69,99,104,111,0,0,17637,17659,154,0,0,69,79,84,0,
0,17650,17674,154,0,0,73,103,110,111,114,105,110,103,0,0,17660,17690,166,0,
0,105,103,110,111,114,105,110,103,63,0,3841,17674,10,17675,17706,166,0,0,118,
101,114,115,105,111,110,0,3841,4,1,100,20,10,17693,17723,166,0,0,100,111,
110,101,63,0,2,4097,17659,1793,17732,1,13,11,10,1,17728,1793,17740,1,10,11,
10,1,17736,1793,17748,1,32,11,10,1,17744,2049,2298,22,22,10,17712,17765,166,0,
0,101,111,108,63,0,3841,17659,1793,17773,1,13,11,10,1,17769,1793,17781,1,10,
11,10,1,17777,2049,2255,22,10,17755,17799,166,0,0,118,97,108,105,100,63,0,
2,2049,102,2049,2812,10,17787,17820,166,0,0,99,104,101,99,107,45,101,111,102,
0,2,1793,17827,1,-1,11,10,1,17823,1793,17835,1,4,11,10,1,17831,2049,2255,
22,1793,17845,2049,11052,10,1,17842,9,10,17805,17857,166,0,0,98,115,0,2049,4212,
1,2,2049,2675,1793,17869,2049,4160,3,10,1,17865,9,2049,4160,3,10,17849,17890,166,
0,0,99,104,101,99,107,45,98,115,0,2,1793,17897,1,8,11,10,1,17893,
1793,17905,1,127,11,10,1,17901,2049,2255,22,1793,17915,2049,17857,10,1,17912,9,10,
17876,17930,166,0,0,99,104,101,99,107,0,2049,17820,2049,17890,10,17919,17950,166,0,
0,99,104,97,114,97,99,116,101,114,0,2049,10985,2,2049,4134,10,17935,17968,166,
0,0,98,117,102,102,101,114,0,1793,17978,2049,17425,2049,4234,8,2049,4096,10,1,
17970,2049,4260,10,17956,17999,166,0,0,114,101,97,100,45,116,111,107,101,110,0,
1793,18015,1793,18010,2049,17950,2049,17930,2049,17723,10,1,18003,2049,2397,10,1,18001,2049,17968,
2049,4587,10,17983,18033,166,0,0,105,110,112,117,116,0,2049,17999,2049,17799,10,18022,
18051,166,0,0,112,114,111,99,101,115,115,0,2049,17690,1793,18069,771,2049,17765,1793,
18065,1,17674,2049,3931,10,1,18060,9,10,1,18055,2049,2862,1,410,1,15,2049,64,
10,17637,18088,178,18212,5861507,47,47,0,2049,15624,1,17674,2049,3916,10,18080,18107,166,18212,
-208531877,98,97,110,110,101,114,0,2049,17706,2049,4472,82,69,84,82,79,32,49,50,
32,40,37,110,46,37,110,41,92,110,0,1,18111,2049,8246,2049,10761,2049,10837,2049,
1545,2049,10837,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,18147,2049,8246,2049,
10761,10,18095,18193,166,18212,192495636,108,105,115,116,101,110,0,3841,17649,1793,18200,2049,18107,
10,1,18197,2049,72,2049,18033,2049,18051,1,18204,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,
18181,18252,154,0,0,83,111,117,114,99,101,115,0,2,18489,18683,0,0,0,0,
100,101,120,45,111,102,45,115,116,114,105,110,103,0,2049,5069,10,17390,17432,166,
0,-1059603453,100,111,117,98,108,101,58,118,97,114,0,2049,2075,4,2049,128,2049,128,
10,17416,17458,166,0,1419216868,100,111,117,98,108,101,58,102,101,116,99,104,0,2049,
56,4,15,10,17440,17481,166,0,1435167943,100,111,117,98,108,101,58,115,116,111,114,
101,0,1,17,2049,2229,2049,59,16,10,17463,17507,166,0,1416012481,100,111,117,98,108,
101,58,99,111,110,115,116,0,2049,17432,1,17458,2049,8460,10,17489,17530,166,0,0,
109,101,109,58,105,110,118,111,107,101,0,1,15,2049,10655,2049,10636,10,17514,0,
154,0,0,65,76,76,79,67,0,17537,1,154,0,0,70,82,69,69,0,17548,
2,154,0,0,83,84,79,82,69,0,17558,3,154,0,0,70,69,84,67,72,
0,17489,17595,166,0,369169257,109,101,109,58,97,108,108,111,99,0,1,0,2049,17530,
10,17580,17613,166,0,-1111837014,109,101,109,58,115,101,116,0,1,2,2049,17530,10,17600,
17631,166,0,-1111850082,109,101,109,58,103,101,116,0,1,3,2049,17530,10,17618,17650,166,
0,1963630784,109,101,109,58,102,114,101,101,0,1,1,2049,17530,10,17636,17664,166,18451,
193470948,84,73,66,0,1,7,15,10,17655,17684,166,18451,-460132687,105,109,97,103,101,58,
115,97,118,101,0,1,1000,2049,10655,2049,10636,10,17668,17702,166,0,0,101,100,105,
116,63,0,2,1793,17709,1,8,11,10,1,17705,1793,17717,1,127,11,10,1,17713,
2049,2255,22,10,17691,17735,166,0,0,103,97,116,104,101,114,0,2049,17702,1,15,
1,4134,2049,64,10,17723,17755,166,0,0,99,121,99,108,101,0,2049,10985,2049,2217,
4,8,2049,2644,25,3,2049,17735,1,17755,7,10,17668,17788,166,18451,-1658019367,112,97,114,
115,101,45,117,110,116,105,108,0,1793,17800,2049,4451,2049,4234,2049,17755,771,2049,4096,
10,1,17790,2049,4260,10,17771,17816,166,18451,272733106,115,58,103,101,116,0,1793,17838,1793,
17824,1,13,11,10,1,17820,1793,17832,1,10,11,10,1,17828,2049,2255,22,10,1,
17818,2049,17788,10,17805,17854,166,18451,255552908,99,108,101,97,114,0,2049,4472,92,94,91,
50,74,92,94,91,48,59,48,72,0,1,17856,2049,8246,2049,10761,10,17843,17888,154,
18451,-976122143,78,111,69,99,104,111,0,0,17876,17898,154,0,0,69,79,84,0,0,
17889,17913,154,0,0,73,103,110,111,114,105,110,103,0,0,17899,17929,166,0,0,
105,103,110,111,114,105,110,103,63,0,3841,17913,10,17914,17945,166,0,0,118,101,
114,115,105,111,110,0,3841,4,1,100,20,10,17932,17962,166,0,0,100,111,110,
101,63,0,2,4097,17898,1793,17971,1,13,11,10,1,17967,1793,17979,1,10,11,10,
1,17975,1793,17987,1,32,11,10,1,17983,2049,2298,22,22,10,17951,18004,166,0,0,
101,111,108,63,0,3841,17898,1793,18012,1,13,11,10,1,18008,1793,18020,1,10,11,
10,1,18016,2049,2255,22,10,17994,18038,166,0,0,118,97,108,105,100,63,0,2,
2049,102,2049,2812,10,18026,18059,166,0,0,99,104,101,99,107,45,101,111,102,0,
2,1793,18066,1,-1,11,10,1,18062,1793,18074,1,4,11,10,1,18070,2049,2255,22,
1793,18084,2049,11052,10,1,18081,9,10,18044,18096,166,0,0,98,115,0,2049,4212,1,
2,2049,2675,1793,18108,2049,4160,3,10,1,18104,9,2049,4160,3,10,18088,18129,166,0,
0,99,104,101,99,107,45,98,115,0,2,1793,18136,1,8,11,10,1,18132,1793,
18144,1,127,11,10,1,18140,2049,2255,22,1793,18154,2049,18096,10,1,18151,9,10,18115,
18169,166,0,0,99,104,101,99,107,0,2049,18059,2049,18129,10,18158,18189,166,0,0,
99,104,97,114,97,99,116,101,114,0,2049,10985,2,2049,4134,10,18174,18207,166,0,
0,98,117,102,102,101,114,0,1793,18217,2049,17664,2049,4234,8,2049,4096,10,1,18209,
2049,4260,10,18195,18238,166,0,0,114,101,97,100,45,116,111,107,101,110,0,1793,
18254,1793,18249,2049,18189,2049,18169,2049,17962,10,1,18242,2049,2397,10,1,18240,2049,18207,2049,
4587,10,18222,18272,166,0,0,105,110,112,117,116,0,2049,18238,2049,18038,10,18261,18290,
166,0,0,112,114,111,99,101,115,115,0,2049,17929,1793,18308,771,2049,18004,1793,18304,
1,17913,2049,3931,10,1,18299,9,10,1,18294,2049,2862,1,410,1,15,2049,64,10,
17876,18327,178,18451,5861507,47,47,0,2049,15624,1,17913,2049,3916,10,18319,18346,166,18451,-208531877,
98,97,110,110,101,114,0,2049,17945,2049,4472,82,69,84,82,79,32,49,50,32,
40,37,110,46,37,110,41,92,110,0,1,18350,2049,8246,2049,10761,2049,10837,2049,1545,
2049,10837,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,18386,2049,8246,2049,10761,
10,18334,18432,166,18451,192495636,108,105,115,116,101,110,0,3841,17888,1793,18439,2049,18346,10,
1,18436,2049,72,2049,18272,2049,18290,1,18443,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,18420,
18491,154,0,0,83,111,117,114,99,101,115,0,1,18730,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,18239,18392,166,0,0,107,110,111,119,110,63,0,2,1,18252,2049,9003,10,18380,
18409,166,0,0,105,110,100,101,120,0,1,18252,4,2049,9320,1,18252,4,2049,9140,
10,18398,18432,166,0,0,114,101,99,111,114,100,0,2049,4500,2,1,18252,2049,3864,
3841,18252,1,18252,17,16,10,1793,18487,2049,15559,2049,18392,1793,18457,2049,18409,10,1,18454,
1793,18464,2049,18432,10,1,18461,2049,64,1793,18477,1,190,1,2,17,8,10,1,18470,
2049,2229,2049,1576,2049,184,16,10,1,18448,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,18181,18527,166,18489,-1519205998,
100,58,119,111,114,100,115,0,1793,18536,2049,188,2049,10761,2049,10731,10,1,18529,2049,
8491,10,18514,18559,166,18489,1750461083,100,58,119,111,114,100,115,45,119,105,116,104,0,
2049,1977,2049,5573,1793,18590,2049,188,2,2049,1977,2049,5286,1793,18579,2049,10761,2049,10731,10,
1,18574,1793,18585,3,10,1,18583,2049,64,10,1,18565,2049,8491,10,18541,18616,166,18489,
0,100,105,115,112,108,97,121,45,105,102,45,108,101,102,116,0,2,2049,1977,
2049,5519,1793,18628,2049,10761,2049,10731,10,1,18623,1793,18634,3,10,1,18632,2049,64,10,
18541,18667,166,18489,-1159574567,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,18678,2049,188,2049,18616,10,1,
18673,2049,8491,10,108,105,115,116,46,102,111,114,116,104,0,18639,18707,154,18683,0,
83,111,117,114,99,101,115,0,2,18944,19138,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18694,18847,166,18683,
0,107,110,111,119,110,63,0,2,1,18707,2049,9003,10,18835,18864,166,18683,0,105,
110,100,101,120,0,1,18707,4,2049,9320,1,18707,4,2049,9140,10,18853,18887,166,18683,
0,114,101,99,111,114,100,0,2049,4500,2,1,18707,2049,3864,3841,18707,1,18707,17,
16,10,1793,18942,2049,15559,2049,18847,1793,18912,2049,18864,10,1,18909,1793,18919,2049,18887,10,
1,18916,2049,64,1793,18932,1,190,1,2,17,8,10,1,18925,2049,2229,2049,1576,2049,
184,16,10,1,18903,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,18639,18982,166,18944,-1519205998,100,58,119,111,114,
100,115,0,1793,18991,2049,188,2049,10761,2049,10731,10,1,18984,2049,8491,10,18969,19014,166,
18944,1750461083,100,58,119,111,114,100,115,45,119,105,116,104,0,2049,1977,2049,5573,1793,
19045,2049,188,2,2049,1977,2049,5286,1793,19034,2049,10761,2049,10731,10,1,19029,1793,19040,3,
10,1,19038,2049,64,10,1,19020,2049,8491,10,18996,19071,166,18944,0,100,105,115,112,
108,97,121,45,105,102,45,108,101,102,116,0,2,2049,1977,2049,5519,1793,19083,2049,
10761,2049,10731,10,1,19078,1793,19089,3,10,1,19087,2049,64,10,18996,19122,166,18944,-1159574567,
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,19133,2049,188,2049,19071,10,1,19128,2049,8491,10,108,
105,115,116,46,102,111,114,116,104,0,19094,19162,154,19138,0,83,111,117,114,99,
101,115,0,1,19401,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,19149,19302,166,19138,0,107,110,111,119,
110,63,0,2,1,19162,2049,9003,10,19290,19319,166,19138,0,105,110,100,101,120,0,
1,19162,4,2049,9320,1,19162,4,2049,9140,10,19308,19342,166,19138,0,114,101,99,111,
114,100,0,2049,4500,2,1,19162,2049,3864,3841,19162,1,19162,17,16,10,1793,19399,2049,
15559,2049,19302,1793,19367,2049,19319,10,1,19364,1793,19374,2049,19342,10,1,19371,2049,64,1793,
19387,1,190,1,2,17,8,10,1,19380,2049,2229,2049,1576,2049,184,16,2049,11116,10,
1,19358,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,19094,19439,166,19401,-1519205998,100,58,119,111,114,100,115,0,
1793,19448,2049,188,2049,10761,2049,10731,10,1,19441,2049,8491,10,19426,19471,166,19401,1750461083,100,
58,119,111,114,100,115,45,119,105,116,104,0,2049,1977,2049,5573,1793,19502,2049,188,
2,2049,1977,2049,5286,1793,19491,2049,10761,2049,10731,10,1,19486,1793,19497,3,10,1,19495,
2049,64,10,1,19477,2049,8491,10,19453,19528,166,19401,-1509196721,100,105,115,112,108,97,121,
45,105,102,45,108,101,102,116,0,2,2049,1977,2049,5519,1793,19540,2049,10761,2049,10731,
10,1,19535,1793,19546,3,10,1,19544,2049,64,10,19453,19579,166,19401,-1159574567,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,19590,2049,188,2049,19528,10,1,19585,2049,8491,10,0 };
18478,18631,166,0,0,107,110,111,119,110,63,0,2,1,18491,2049,9003,10,18619,18648,
166,0,0,105,110,100,101,120,0,1,18491,4,2049,9320,1,18491,4,2049,9140,10,
18637,18671,166,0,0,114,101,99,111,114,100,0,2049,4500,2,1,18491,2049,3864,3841,
18491,1,18491,17,16,10,1793,18728,2049,15559,2049,18631,1793,18696,2049,18648,10,1,18693,1793,
18703,2049,18671,10,1,18700,2049,64,1793,18716,1,190,1,2,17,8,10,1,18709,2049,
2229,2049,1576,2049,184,16,2049,11116,10,1,18687,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,18420,18768,166,18730,
-1519205998,100,58,119,111,114,100,115,0,1793,18777,2049,188,2049,10761,2049,10731,10,1,18770,
2049,8491,10,18755,18800,166,18730,1750461083,100,58,119,111,114,100,115,45,119,105,116,104,
0,2049,1977,2049,5573,1793,18831,2049,188,2,2049,1977,2049,5286,1793,18820,2049,10761,2049,10731,
10,1,18815,1793,18826,3,10,1,18824,2049,64,10,1,18806,2049,8491,10,18782,18857,166,
18730,-1509196721,100,105,115,112,108,97,121,45,105,102,45,108,101,102,116,0,2,2049,
1977,2049,5519,1793,18869,2049,10761,2049,10731,10,1,18864,1793,18875,3,10,1,18873,2049,64,
10,18782,18908,166,18730,-1159574567,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,18919,2049,188,2049,18857,10,
1,18914,2049,8491,10,0 };

View file

@ -190,6 +190,10 @@ void io_floatingpoint(NgaState *); void query_floatingpoint(NgaState *);
void io_socket(NgaState *); void query_socket(NgaState *);
#endif
#ifdef ENABLE_MALLOC
void io_malloc(NgaState *); void query_malloc(NgaState *);
#endif
void io_image(NgaState *); void query_image(NgaState *);
void load_embedded_image(NgaState *);
@ -229,6 +233,66 @@ void inst_iq(NgaState *); void inst_ii(NgaState *);
/* Global Variables -------------------------------------------------- */
/* Dynamic Memory / `malloc` support --------------------------------- */
#ifdef ENABLE_MALLOC
typedef union {
void* val;
struct {
CELL msw;
CELL lsw;
};
} double_cell;
void malloc_allocate(NgaState *vm) {
// TODO: Conditionally compile based on host word size?
double_cell addr = { .val = malloc(stack_pop(vm)) };
stack_push(vm, addr.msw);
stack_push(vm, addr.lsw);
}
void malloc_free(NgaState *vm) {
double_cell addr;
addr.lsw = stack_pop(vm);
addr.msw = stack_pop(vm);
free(addr.val);
}
void malloc_store(NgaState *vm) {
CELL value = stack_pop(vm);
double_cell addr;
addr.lsw = stack_pop(vm);
addr.msw = stack_pop(vm);
*(CELL *) addr.val = value;
}
void malloc_fetch(NgaState *vm) {
double_cell addr;
addr.lsw = stack_pop(vm);
addr.msw = stack_pop(vm);
CELL value = *(CELL *)addr.val;
stack_push(vm, value);
}
// TODO: realloc() support
// void malloc_realloc(NgaState *vm) { }
void query_malloc(NgaState *vm) {
stack_push(vm, 0);
stack_push(vm, 15);
}
void io_malloc(NgaState *vm) {
int i = stack_pop(vm);
switch (i) {
case 0: malloc_allocate(vm); return;
case 1: malloc_free(vm); return;
case 2: malloc_store(vm); return;
case 3: malloc_fetch(vm); return;
}
stack_push(vm, -1);
}
#endif
/* Multi Core Support ------------------------------------------------ */
#ifdef ENABLE_MULTICORE
void init_core(NgaState *vm, CELL x) {
@ -1816,6 +1880,9 @@ int main(int argc, char **argv) {
#ifdef ENABLE_UNIX
register_device(vm, io_unix, query_unix);
#endif
#ifdef ENABLE_MALLOC
register_device(vm, io_malloc, query_malloc);
#endif
#ifdef ENABLE_CLOCK
register_device(vm, io_clock, query_clock);
#endif