Change mem:* API to make memory offset calculation easier (from Rick C)
FossilOrigin-Name: 47687a00c3c0e398b7b2baf279ed91c2b236a06b1bf5bbc79fd9bee69d83d456
This commit is contained in:
parent
0317b9074c
commit
1eec7ab446
3 changed files with 11 additions and 6 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
bin/
|
|
@ -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
|
||||
```
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue