|
373 | 373 | DROP 0 \ drop the result, return 0 |
374 | 374 | ; |
375 | 375 |
|
376 | | -0 BUFFER: DATASPACE \ create a buffer starting at size 0 to hold the data space |
| 376 | +VARIABLE DATASPACE \ create a variable to hold the currently allocated data space |
377 | 377 | VARIABLE DATAPOINTER \ create a variable to keep track of the data space pointer |
378 | | -DATASPACE DATAPOINTER ! \ set the data space pointer |
| 378 | + |
| 379 | +: NEW-DATASPACE ( ) \ set up a new data space |
| 380 | + 0 ALLOCATE DROP DUP ( addr addr ) |
| 381 | + DATASPACE ! \ save this new address to the dataspace |
| 382 | + DATAPOINTER ! \ also to the pointer |
| 383 | +; |
| 384 | +NEW-DATASPACE \ run it right away |
379 | 385 |
|
380 | 386 | : HERE ( -- addr ) |
381 | | - DATAPOINTER @ \ return the dataspace pointer plus the size |
| 387 | + DATAPOINTER @ \ return the dataspace pointed address |
382 | 388 | ; |
383 | 389 |
|
384 | 390 | : DATASIZE |
385 | | - DATAPOINTER @ DATASPACE - \ find the size difference |
386 | | - 0x7FFF AND |
| 391 | + DATAPOINTER @ DATASPACE @ - \ find the size difference |
| 392 | + 0x7FFF AND \ remove any alignment bits |
387 | 393 | ; |
388 | 394 |
|
389 | 395 | : ALLOT ( n -- ) |
|
395 | 401 | EXIT |
396 | 402 | THEN ( n newSize ) |
397 | 403 | SWAP DATAPOINTER +! ( newSize ) \ update the data space pointer |
398 | | - DATASPACE SWAP ( dataspace newSize ) |
| 404 | + DATASPACE @ SWAP ( dataspace newSize ) |
399 | 405 | RESIZE ( newaddress 0 ) \ resize the dataspace |
400 | 406 | 2DROP \ remove the extra values from the resize |
401 | 407 | ; |
|
407 | 413 | ; |
408 | 414 |
|
409 | 415 | : C, ( char -- ) |
410 | | - HERE DATASPACE - \ find the size difference |
| 416 | + HERE DATASPACE @ - \ find the size difference |
411 | 417 | 0< IF \ if the upper bit is set then we don't need to allocate |
412 | 418 |
|
413 | 419 | ELSE |
|
450 | 456 | ; |
451 | 457 |
|
452 | 458 | : CREATE |
453 | | - ALIGN \ align the data space pointer |
| 459 | + NEW-DATASPACE \ create a fresh section of aligned data space |
454 | 460 | HERE \ get the data space pointer |
455 | 461 | : \ parse the next input, create a word with that name |
456 | 462 | POSTPONE LITERAL \ create a literal of the previous data space pointer |
|
0 commit comments