llst icon indicating copy to clipboard operation
llst copied to clipboard

Provide convenient interface for native methods

Open 0x7CFE opened this issue 11 years ago • 0 comments

Current implementation uses primitives to provide native implementation of a code that may be invoked from managed code. One should register a primitive and then invoke it from the Smalltalk stub method.

This is not convenient and not portable. Much attention should be payed in order to prevent id collisions and so on...

We should provide a way to register pieces of C++ code that should be treated as native methods. Call to such native method should be completely transparent as it happens with primitive stub methods.

Since the validation is performed in the constructor it looks like every object of type TInteger always maintains the correct state. However, if we create a pointer inside the VM, and then reinterpret the data as TInteger - then the constructor will not be invoked and the validation will not be done.

// If the instance was created from smalltalk, then field1 contains null.
// And interpreting this null as TInteger is illegal.
struct MyClass : public TObject {
    TInteger field1;

    // native method
    void inc() { field1 = feild1 + 1; } // UB
};

0x7CFE avatar Oct 26 '13 13:10 0x7CFE