extending the BrazilMappingForWin32 and brazil classes

33 views
Skip to first unread message

Steven Marks

unread,
Jul 25, 2015, 4:29:46 PM7/25/15
to Newspeak Programming Language
I have implemented some basic keyboard and bubbling click events for my application, which required changing the BrazilMappingForWin32 and brazil classes. I would like to extend these classes so I don't have to merge the code everytime a change is made to one of these classes in the main repository.

Ideally, I would use class hierarchy inheritance inside of the top level module that contains all of my code, however, there is only one object for BrazilMappingForWin32 and brazil for the entire desktop that are initialized on startup, so class hierarchy inheritance does not work in this case. I also tried simply extending the BrazilMappingForWin32 and adding my functionality there and replacing BrazilMappingForWin32 when the platform loads. When I tried that the gui just did not load without any errors or messages of any kind even when the child class has nothing in it. So I am not sure how to proceed in that direction either.

What would be the best way to go about extending the BrazilMappingForWin32 and brazil classes?

Thanks
Steven

Gilad Bracha

unread,
Jul 26, 2015, 1:07:41 AM7/26/15
to newspeak...@googlegroups.com
Hi Steve,

I assume your extensions are not something that one would want in the normal platform. Otherwise, we'd just take them back into the platform.  


Given that you need a custom Brazil, it makes sense for you to modify RuntimeForSqueak so that it uses your version for BrazilMappingForWin32. You say that didn't work. Did you extend BrazilMappingForWin32 via inheritance or modify it directly?  I ask because if you used inheritance, that may indicate that the mixin support is buggy.  If you modified BrazilMappingForWin32 itself, it may be you need a custom bootstrap.

--
Cheers, Gilad

Steven Marks

unread,
Jul 26, 2015, 8:19:32 AM7/26/15
to Newspeak Programming Language, gi...@bracha.org, gbr...@gmail.com
Gilad,

I used inheritence to extend BrazilMappingForWin32. I just tested it on a new bootstrap image with the latest updates without any other changes and there seems to be a bug.

I added a new class:

class BrazilMappingForWin32Custom platform:platform = BrazilMappingForWin32 platform:platform (
|
|
)()

and called BrazilMappingForWin32Custom platform:platform in a workspace

It thinks that the parent is Object and tries to call Object platform: and fails.

Gilad Bracha

unread,
Jul 26, 2015, 12:06:03 PM7/26/15
to Steven Marks, Newspeak Programming Language
Hi Steven,

There are two ways you can subclass BrazilMappingForWin32.  Both have to be done in the context of an enclosing class:

Newspeak3
'Experiments'
class Mapping usingPlatform: p <Platform> mapping: m <BrazilMappingForWin32> = (
(*Describe the class in this comment.*)
|
SuperBrazilMappingForWin32 = m.
|
) (
public class BrazilMappingForWin32 platform: p = SuperBrazilMappingForWin32 platform: p (
(* Describe the class in this comment. *)

) (
) : (
)
) : (
)


The reason you need the enclosing class is that you cannot create a top level class that subclasses another class, because Newspeak has no global namespace. I would have hoped that the error in your case would be a DNU for BrazilMappingForWin32. We should look into that.  

Your real problems begin when you have this class, as there can really only be one such mapping. Newspeak doesn't do singletons, but Windows does :-( !  After all, there is just one display on a PC.

So actually creating an instance of the custom class has to be done when bringing up the platform. 

You would have to feed RuntimeForSqueak a manifest object that responded to BrazilMappingForWin32 with your modified version. I think you could do this by mutating NewspeakGlobalState namespace 
(i.e., 
NewspeakGlobalState namespace 
   at: #BrazilMappingForWin32 
   put: (Mapping usingPlatform: platform mapping: BrazilMappingForWin32) BrazilMappingForWin32 )

and then doing a #resetEverything from the Tools menu. I have not tried it - there may be more to this than meets the eye. Ryan is much more up to date on the details of bootstrap than I am. Have a look at BootstrapManifest and NewspeakGlobalState to see how things get put together.

Steven Marks

unread,
Jul 26, 2015, 9:55:52 PM7/26/15
to Newspeak Programming Language, gbr...@gmail.com
Gilad,

I was successfully able to replace the BrazilMappingForWin32 class in the platform.  In addition to what you said I also had to set the category of the class before resetting the platform in order for it to work.

Thanks for your help.

Steven

Gilad Bracha

unread,
Jul 26, 2015, 10:39:54 PM7/26/15
to Steven Marks, Newspeak Programming Language
Glad it worked out.  
--
Cheers, Gilad

Ryan Macnak

unread,
Jul 28, 2015, 9:58:24 PM7/28/15
to newspeak...@googlegroups.com
On Sun, Jul 26, 2015 at 9:05 AM, Gilad Bracha <gbr...@gmail.com> wrote:
The reason you need the enclosing class is that you cannot create a top level class that subclasses another class, because Newspeak has no global namespace. I would have hoped that the error in your case would be a DNU for BrazilMappingForWin32. We should look into that. 

In what context would #BrazilMappingForWin32 be sent? Naming a superclass at the top level is supposed to be a compile-time error. In the current implementation the superclass is ignored, but the super factory message affects the compilation of the instance initializer and we rely on this to work around the lack generalized mixin application support in classes like Win32API and Newspeak2SqueakCompilation.

Your real problems begin when you have this class, as there can really only be one such mapping. Newspeak doesn't do singletons, but Windows does :-( !  After all, there is just one display on a PC.

So actually creating an instance of the custom class has to be done when bringing up the platform. 

You would have to feed RuntimeForSqueak a manifest object that responded to BrazilMappingForWin32 with your modified version. I think you could do this by mutating NewspeakGlobalState namespace 
(i.e., 
NewspeakGlobalState namespace 
   at: #BrazilMappingForWin32 
   put: (Mapping usingPlatform: platform mapping: BrazilMappingForWin32) BrazilMappingForWin32 )

and then doing a #resetEverything from the Tools menu. I have not tried it - there may be more to this than meets the eye. Ryan is much more up to date on the details of bootstrap than I am. Have a look at BootstrapManifest and NewspeakGlobalState to see how things get put together.

Brazil supports remapping: one can dynamically switch between the native Windows and Morphic. Assuming the Windows mappings don't allocate any once-per-process resources, it should be possible to instantiation your modified bindings and have Brazil migrate all the windows over to it. However, the code that does this is quite a mess.

Gilad Bracha

unread,
Jul 28, 2015, 10:00:42 PM7/28/15
to newspeak...@googlegroups.com
BTW, the remapping is a bit broken on Windows right now because of access control changes.
--
Cheers, Gilad
Reply all
Reply to author
Forward
0 new messages