Hi,
The current thing I am working on for Reflectivity is to allow to pass data to the meta level. Simple things where already working (like #object, #node). 50096 now adds the first more complex feature: passing the new value to the meta for stores into variables. Imagine you have code like this: exampleAssignment | temp | temp := (1 + 2). ^temp The temp is assigned a new value. Now you can pass that to the meta level, here is a simpel example: varNode := (ReflectivityExamples>>#exampleAssignment) ast body statements first variable. link := MetaLink new metaObject: self; selector: #tagExec:; arguments: #(newValue). varNode link: link. self assert: varNode hasMetalink. self assert: (tag isNil). instance := ReflectivityExamples new . self assert: (instance exampleAssignment = 3). self assert: (tag = 3). The byte code generated is: 21 <76> pushConstant: 1 22 <77> pushConstant: 2 23 <B0> send: + 24 <81 41> storeIntoTemp: 1 26 <20> pushConstant: ReflectiveMethodTest>>#testReifyNewValue 27 <11> pushTemp: 1 28 <E1> send: tagExec: 29 <87> pop 30 <68> popIntoTemp: 0 31 <10> pushTemp: 0 32 <7C> returnTop Next: - #name, oldValue for all variables, #offset for temps and ivars, #binding for Globals - #arguments and #receiver for message send and methodNode - #after needs to wrap in ensure: - #use literal Variable instead of literal for referencing the meta object - …. Marcus |
Hi Marcus
I'm sure this is great. Just a quick question on your example code: where is tag being defined? Is it an instance variable from ReflectiveMethodTest? Thanks - Francisco (iPhone) > On 9 Jun 2015, at 08:56, Marcus Denker <[hidden email]> wrote: > > Hi, > > The current thing I am working on for Reflectivity is to allow to pass data to the meta level. > Simple things where already working (like #object, #node). > > 50096 now adds the first more complex feature: passing the new value to the meta for stores into > variables. > > Imagine you have code like this: > > exampleAssignment > | temp | > temp := (1 + 2). > ^temp > > > The temp is assigned a new value. Now you can pass that to the meta level, here is a simpel example: > > varNode := (ReflectivityExamples>>#exampleAssignment) ast body statements first variable. > link := MetaLink new > metaObject: self; > selector: #tagExec:; > arguments: #(newValue). > varNode link: link. > self assert: varNode hasMetalink. > self assert: (tag isNil). > instance := ReflectivityExamples new . > self assert: (instance exampleAssignment = 3). > self assert: (tag = 3). > > > The byte code generated is: > > > 21 <76> pushConstant: 1 > 22 <77> pushConstant: 2 > 23 <B0> send: + > 24 <81 41> storeIntoTemp: 1 > 26 <20> pushConstant: ReflectiveMethodTest>>#testReifyNewValue > 27 <11> pushTemp: 1 > 28 <E1> send: tagExec: > 29 <87> pop > 30 <68> popIntoTemp: 0 > 31 <10> pushTemp: 0 > 32 <7C> returnTop > > > Next: > - #name, oldValue for all variables, #offset for temps and ivars, #binding for Globals > - #arguments and #receiver for message send and methodNode > - #after needs to wrap in ensure: > - #use literal Variable instead of literal for referencing the meta object > - …. > > Marcus |
> On 09 Jun 2015, at 14:55, Francisco Garau <[hidden email]> wrote: > > Hi Marcus > > I'm sure this is great. Just a quick question on your example code: where is tag being defined? Is it an instance variable from ReflectiveMethodTest? > Yes, The test instance is put as the meta-object and we call #tagExec: there. This is just: tagExec: aTag tag := aTag. So we just call it with an argument, in this case the new value of the variable. This is in the image #testReifyNewValue. >> >> varNode := (ReflectivityExamples>>#exampleAssignment) ast body statements first variable. >> link := MetaLink new >> metaObject: self; >> selector: #tagExec:; >> arguments: #(newValue). >> varNode link: link. >> self assert: varNode hasMetalink. >> self assert: (tag isNil). >> instance := ReflectivityExamples new . >> self assert: (instance exampleAssignment = 3). >> self assert: (tag = 3). >> >> Marcus |
there is still an issue that one can not run this test twice… I added it to the backlog: Marcus |
> On 09 Jun 2015, at 15:23, Marcus Denker <[hidden email]> wrote: > >> >> On 09 Jun 2015, at 15:12, Marcus Denker <[hidden email]> wrote: >> >> >>> On 09 Jun 2015, at 14:55, Francisco Garau <[hidden email]> wrote: >>> >>> Hi Marcus >>> >>> I'm sure this is great. Just a quick question on your example code: where is tag being defined? Is it an instance variable from ReflectiveMethodTest? >>> >> >> Yes, The test instance is put as the meta-object and we call #tagExec: there. This is just: >> >> tagExec: aTag >> tag := aTag. >> >> So we just call it with an argument, in this case the new value of the variable. >> >> This is in the image #testReifyNewValue. > > there is still an issue that one can not run this test twice… I added it to the backlog: > > Fixed: https://pharo.fogbugz.com/f/cases/15730/t - tests for #value (Global, Temp) - fix for #value reification - fix: allow tests to be run multiple times - untested: add #receiver reification for message send Marcus |
Free forum by Nabble | Edit this page |