How to create a 'Hello world' example for environments

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

How to create a 'Hello world' example for environments

Chris Cunnington-4
I not sure if I've gone off the rails here, but it keeps working for me.

Chris


"acquire a Squeak6.0alpha and create an Environment"
env := Environment withName: 'WbSrvr'.
env importSelf.

"load WebClient-Core into Environment"
chunkcode := ReadWriteStream on: (String new: 1000).
SystemOrganizer default fileOutCategory: 'WebClient-Core' on: chunkcode
initializing: true.
chunkcode reset.
env fileIn: chunkcode announcing: 'Load Environment'.

"start WebServer in environment"
Compiler evaluate: 'WebServer exampleBrowse' environment: env.

"go to WebServer class>exampleBrowse in a Browser and change port to
8888, then start"
WebServer exampleBrowse

"open tabs in"
http://localhost:9999
http://localhost:8888

"to see the port in the Environment is still 9999"
env explore.
"highlight WebServer in #declarations and explore"
self class methodDictionary
"toggle #exampleBrowse and see the port is 9999"

"for added fun, go to Process class>>#forContext:priority: and add"
newProcess env: Environment current.

"start again from the top, this time, explore the WebServer processes in
ProcessBrowser to see both Environments are Smalltalk. I have no idea
what that means. I would have thought the WebServer instance started
with WbSrvr environment would be in a WbSrvr process."



Reply | Threaded
Open this post in threaded view
|

Re: How to create a 'Hello world' example for environments

Jakob Reschke
Hi Chris,

I can confirm that this works. Curious, it seems like
#evaluate:environment: implicitly looks up names in the default
Environment as a fallback. The created WbSrvr Environment does not
have a binding for Object:

   env valueOf: #Object => nil.

But:

   Compiler evaluate: 'Object' environment: env => Object
   Compiler evaluate: 'Object environment' environment: env => Smalltalk
   Compiler evaluate: 'WebServer environment' environment: env => WbSrvr

That is probably the kind of stuff that must be documented.

As for the "for added fun" part: In my image there is no accessor for
the Process environment (and it is not a fully-fledged Environment
instance, but a Dictionary, when you use Process>>environmentAt: and
friends), so I had to add that accessor myself. Anyway, while the
names in the compiled string are evaluated in the given Environment
(including the implicit fallback), the `Environment current` placed in
Process class>>forContext:priority: will search the dynamic
environment. But #evaluate:environment: does not seem to install an
appropriate Exception handler for CurrentEnvironment, so Environment
current will return the default Smalltalk Envirionment.

If I change the invocation in Compiler>>evaluteCue:ifFail: to

    [value := cue receiver
            withArgs: (cue context ifNil: [#()] ifNotNil: [{cue context}])
            executeMethod: method]
        on: CurrentEnvironment do: [:n | n resume: aCue environment].

then the WbSrvr process does get WbSrvr as its environment.

Best regards,
Jakob

2016-10-03 0:07 GMT+02:00 Chris Cunnington <[hidden email]>:

> I not sure if I've gone off the rails here, but it keeps working for me.
>
> Chris
>
>
> "acquire a Squeak6.0alpha and create an Environment"
> env := Environment withName: 'WbSrvr'.
> env importSelf.
>
> "load WebClient-Core into Environment"
> chunkcode := ReadWriteStream on: (String new: 1000).
> SystemOrganizer default fileOutCategory: 'WebClient-Core' on: chunkcode
> initializing: true.
> chunkcode reset.
> env fileIn: chunkcode announcing: 'Load Environment'.
>
> "start WebServer in environment"
> Compiler evaluate: 'WebServer exampleBrowse' environment: env.
>
> "go to WebServer class>exampleBrowse in a Browser and change port to
> 8888, then start"
> WebServer exampleBrowse
>
> "open tabs in"
> http://localhost:9999
> http://localhost:8888
>
> "to see the port in the Environment is still 9999"
> env explore.
> "highlight WebServer in #declarations and explore"
> self class methodDictionary
> "toggle #exampleBrowse and see the port is 9999"
>
> "for added fun, go to Process class>>#forContext:priority: and add"
> newProcess env: Environment current.
>
> "start again from the top, this time, explore the WebServer processes in
> ProcessBrowser to see both Environments are Smalltalk. I have no idea
> what that means. I would have thought the WebServer instance started
> with WbSrvr environment would be in a WbSrvr process."
>
>
>