Create an object at a given address: Difference between revisions

Content added Content deleted
(Initial FutureBasic task solution added)
m (→‎{{header|Wren}}: Minor tidy)
Line 1,110: Line 1,110:
Note that it is not possible to specify the address at which the embedding API function ''wrenSetSlotNewForeign'' allocates new objects and any attempt to allocate a new object at the same address as an old one by juggling with pointers will almost certainly lead to a seg fault. So all we can sensibly do is to change the value of the current object.
Note that it is not possible to specify the address at which the embedding API function ''wrenSetSlotNewForeign'' allocates new objects and any attempt to allocate a new object at the same address as an old one by juggling with pointers will almost certainly lead to a seg fault. So all we can sensibly do is to change the value of the current object.


<syntaxhighlight lang="ecmascript">/* create_object_at_given_address.wren */
<syntaxhighlight lang="wren">/* Create_an_object_at_a_given_address.wren */


import "./fmt" for Fmt
import "./fmt" for Fmt
Line 1,132: Line 1,132:
<br>
<br>
We now embed this in the following C program, compile and run it.
We now embed this in the following C program, compile and run it.
<syntaxhighlight lang="c">/* gcc create_object_at_given_address.c -o create_object_at_given_address -lwren -lm */
<syntaxhighlight lang="c">/* gcc Create_an_object_at_a_given_address.c -o Create_an_object_at_a_given_address -lwren -lm */


#include <stdio.h>
#include <stdio.h>
Line 1,247: Line 1,247:
WrenVM* vm = wrenNewVM(&config);
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* module = "main";
const char* fileName = "create_object_at_given_address.wren";
const char* fileName = "Create_an_object_at_a_given_address.wren";
char *script = readFile(fileName);
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 1,272: Line 1,272:
Integer object value changed to: 43 but still at address 0x55a56e0f2dd8.
Integer object value changed to: 43 but still at address 0x55a56e0f2dd8.
</pre>
</pre>

=={{header|Z80 Assembly}}==
=={{header|Z80 Assembly}}==
When writing assembly yourself, you'll know any object's memory location in advance.
When writing assembly yourself, you'll know any object's memory location in advance.