CompiledBlocks are fascinating

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

CompiledBlocks are fascinating

Christoph Thiede

class := Object newSubclass.

class addSelector: #foo: withMethod: (

[:x | x squared * 2] method as: CompiledMethod).

class new foo: 3. "18"


And you can even debug it :D




This one is really crazy:


class := Object newUniqueClassInstVars: 'state' classInstVars: ''.
class addSelector: #foo withMethod: (
[:x | gate] method as: CompiledMethod).
class new foo "-1.2045729113346377e-38"


What the ...? Am I accessing any private method literals here?


Then we only need a mechanism that translates the #pushRcvr: bytecodes to another class.


Best,

Christoph



Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: CompiledBlocks are fascinating

Eliot Miranda-2


On Sat, Apr 18, 2020 at 10:31 AM Thiede, Christoph <[hidden email]> wrote:

class := Object newSubclass.

class addSelector: #foo: withMethod: (

[:x | x squared * 2] method as: CompiledMethod).

class new foo: 3. "18"

And you can even debug it :D


This one is really crazy

class := Object newUniqueClassInstVars: 'state' classInstVars: ''.
class addSelector: #foo withMethod: (
[:x | gate] method as: CompiledMethod).
class new foo "-1.2045729113346377e-38"

What the ...? Am I accessing any private method literals here?


This may be a return address.  If you ran this in the simulator you'd be able to see.  Also try running it on the StackInterpreter and see what you get.
 

 

Then we only need a mechanism that translates the #pushRcvr: bytecodes to another class.


I don't see you jumping to the metacircular interpreter in the above.  What do you mean by "translates the #pushRcvr: bytecodes to another class"?
 

Best,

Christoph



--
_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: CompiledBlocks are fascinating

Christoph Thiede

Hi Eliot,


This may be a return address.  If you ran this in the simulator you'd be able to see.  Also try running it on the StackInterpreter and see what you get.


Ah, this could be an explanation! I finally need to check out the VMMaker :-)
Wouldn't this be a memory leak vulnerability in the VM? Or don't we care about vulnerability issues in completely open systems such as Smalltalk at all?

What do you mean by "translates the #pushRcvr: bytecodes to another class"?

Well, that's actually another issue. Since instance variable accesses are encoded into the bytecode by index, not by name, you cannot reuse the bytecodes for different kinds of objects:

c := Object newUniqueClassInstVars: 'foo bar' classInstVars: ''.
d := Object newUniqueClassInstVars: 'bar baz' classInstVars: ''.
c compile: 'bar ^ bar'.
o := c new.
p := d new.
o instVarNamed: 'bar' put: 42.
o bar. "42"
p instVarNamed: 'bar' put: 42.
p executeMethod: c >> #bar. "expected 42, but got nil"

You always need to recompile the methods first ... This makes it impossible to add instance variables to traits, for example.

Best,
Christoph


Von: Squeak-dev <[hidden email]> im Auftrag von Eliot Miranda <[hidden email]>
Gesendet: Samstag, 18. April 2020 21:05 Uhr
An: The general-purpose Squeak developers list
Betreff: Re: [squeak-dev] CompiledBlocks are fascinating
 


On Sat, Apr 18, 2020 at 10:31 AM Thiede, Christoph <[hidden email]> wrote:

class := Object newSubclass.

class addSelector: #foo: withMethod: (

[:x | x squared * 2] method as: CompiledMethod).

class new foo: 3. "18"

And you can even debug it :D


This one is really crazy

class := Object newUniqueClassInstVars: 'state' classInstVars: ''.
class addSelector: #foo withMethod: (
[:x | gate] method as: CompiledMethod).
class new foo "-1.2045729113346377e-38"

What the ...? Am I accessing any private method literals here?


This may be a return address.  If you ran this in the simulator you'd be able to see.  Also try running it on the StackInterpreter and see what you get.
 

 

Then we only need a mechanism that translates the #pushRcvr: bytecodes to another class.


I don't see you jumping to the metacircular interpreter in the above.  What do you mean by "translates the #pushRcvr: bytecodes to another class"?
 

Best,

Christoph



--
_,,,^..^,,,_
best, Eliot


Carpe Squeak!