~crc_/retroforth

1eec7ab446e926ef6647e8977f4e9d56af7d8c66 — crc 16 days ago 0317b90
Change mem:* API to make memory offset calculation easier (from Rick C)

FossilOrigin-Name: 47687a00c3c0e398b7b2baf279ed91c2b236a06b1bf5bbc79fd9bee69d83d456
3 files changed, 11 insertions(+), 6 deletions(-)

A .gitignore
M tests/malloc.retro
M vm/nga-c/retro.c
A .gitignore => .gitignore +1 -0
@@ 0,0 1,1 @@
bin/

M tests/malloc.retro => tests/malloc.retro +4 -0
@@ 36,6 36,7 @@ n:random
random-value n:print
'Storing_value_to_`region1`... print
region1 random-value mem:set
region1 #8 + random-value mem:set
'===OK print nl nl
```



@@ 45,6 46,9 @@ region1 random-value mem:set
'===TEST3:_mem:get print
'Expect_ s:put 'to_contain_ s:put random-value n:put nl
'Actual_value:_____ s:put region1 mem:get n:put nl
'Calculating_memory_offset_should_not_segfault...
region1 #8 + mem:get
'Contents_of_(region1_+_1)_=_ s:put n:put nl
'===OK print nl nl
```


M vm/nga-c/retro.c => vm/nga-c/retro.c +6 -6
@@ 241,29 241,29 @@ typedef union {
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);
  stack_push(vm, addr.msw);
}

void malloc_free(NgaState *vm) {
  double_cell addr;
  addr.lsw = stack_pop(vm);
  addr.msw = stack_pop(vm);
  addr.lsw = 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);
  addr.lsw = 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);
  addr.lsw = stack_pop(vm);
  CELL value = *(CELL *)addr.val;
  stack_push(vm, value);
}


@@ 271,13 271,13 @@ void malloc_fetch(NgaState *vm) {
void malloc_realloc(NgaState *vm) {
  CELL bytes = stack_pop(vm);
  double_cell addr1;
  addr1.lsw = stack_pop(vm);
  addr1.msw = stack_pop(vm);
  addr1.lsw = stack_pop(vm);

  double_cell addr2;
  addr2.val = realloc(addr1.val, bytes);
  stack_push(vm, addr2.msw);
  stack_push(vm, addr2.lsw);
  stack_push(vm, addr2.msw);
}

void query_malloc(NgaState *vm) {