Hello,

The logging of sources is not part of the compiler. It is part of the
behavior API.

Something like that would work :

ATMinimalLearningObject >> addFromObjectSelector: aSelector
    self class compile: (Object >> aSelector) sourceCode classified: #foo

Now it is strange that the decompiler can't decompile instVarAt: . It looks
like it is a bug related to primitive error code decompilation. This is
something I should look at during the sprint...


2016-01-27 20:42 GMT+01:00 stepharo <[email protected]>:

> Hi guys
>
> I'm on holidays (no book no mooc no bugs just playing magic good music and
> hacking a bit)
> and I wanted to implemented a fun object that learn from Object by copying
> the methods.
>
> ProtoObject subclass: #ATMinimalLearningObject
>     instanceVariableNames: ''
>     classVariableNames: ''
>     package: 'MiniActalk2'
>
>
> ATMinimalLearningObject >> doesNotUnderstand: aMessage
>
>     | sel |
>     sel := aMessage selector.
>     Transcript show: 'Does not understand ',  sel printString ; cr.
>     ^ (Object includesSelector: sel)
>         ifTrue: [
>                 self addFromObjectSelector: sel.
>                 aMessage sendTo: self ]
>         ifFalse: [ super doesNotUnderstand: aMessage ].
>
> ATMinimalLearningObject >> addFromObjectSelector: aSelector
>
>     | method |
>     method := OpalCompiler new
>                     class: self class;
>                     source: (Object sourceCodeAt: aSelector);
>                     compile.
>     self class addSelector: aSelector withMethod: method.
>
> ATMinimalLearningObject subclass: #ATProtozoid
>     instanceVariableNames: 'ff'
>     classVariableNames: ''
>     package: 'MiniActalk2'
>
>
> Now it is working but I have the impression that we may have a problem.
>
> When I do
> ATProtozoid new instVarAt: 1
>
>
> I get the following definition for instVarAt:
>
> instVarAt: t1
>     self error: 'Decompilation failed'
>
>
> but
>
> Object sourceCodeAt: #instVarAt: returns the correct string.
>
>  'instVarAt: index
>     "Primitive. Answer a fixed variable in an object. The numbering of the
> variables
>      corresponds to the named instance variables, followed by the indexed
> instance
>      variables. Fail if the index is not an Integer or is not the index of
> a fixed variable.
>      Essential. See Object documentation whatIsAPrimitive."
>
>     <primitive: 173 error: ec>
>     self primitiveFailed'
>
> May be the compile is not logging the method body.
> But since the compiler is full uncommented this is super nice to learn and
> get empowered.
>
> Stef
>
>
>

Reply via email to