jas:technicaldescriptionofoverlays
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
jas:technicaldescriptionofoverlays [2009/12/15 11:08] – jwarrior | jas:technicaldescriptionofoverlays [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== How Overlays Work ===== | ||
+ | |||
+ | ==== Method Source Overlays ==== | ||
+ | |||
+ | |||
+ | There are four kinds of overlays: | ||
+ | |||
+ | This article deals with method source overlays (MSO) only. | ||
+ | |||
+ | Method source overlays allow the JAS user to store Smalltalk code (methods) in scenario data as overlays to existing or new methods. When the simulation starts to run, JAS reads the overlay data, compiles it, and then replaces the old method code with the overlaid code. Overlays are possible because Smalltalk supports [[http:// | ||
+ | |||
+ | ==== A Trivial Example ==== | ||
+ | |||
+ | The class Circle implements a method called area, which allows Circle objects to answer their area when they are sent the area message. | ||
+ | < | ||
+ | area | ||
+ | |||
+ | ^Float pi * radius * radius | ||
+ | |||
+ | </ | ||
+ | |||
+ | But let us suppose that you, for whatever reason, want your circles to have a slightly larger area. You could create a MSO for method Circle>> | ||
+ | < | ||
+ | area | ||
+ | |||
+ | ^(Float pi * radius * radius) + 1 | ||
+ | |||
+ | </ | ||
+ | Now all your circles are 1 unit bigger! A triumph of modeling! | ||
+ | |||
+ | ==== A Detailed Technical Explanation ==== | ||
+ | |||
+ | |||
+ | As mentioned above, MSOs are only possible because Smalltalk supports [[http:// | ||
+ | |||
+ | We will use the infamous Hello, World program as an example. In C, it is: | ||
+ | < | ||
+ | main() | ||
+ | { | ||
+ | print_Hello_World(); | ||
+ | } | ||
+ | |||
+ | print_Hello_World() | ||
+ | { | ||
+ | printf(“Hello, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This C source code is compiled by a C compiler, which checks for syntactical correctness, | ||
+ | |||
+ | If we wanted to change the implementation of print_Hello_World to also print "Hi, Mom", we would have to edit the source code | ||
+ | < | ||
+ | print_Hello_World() | ||
+ | { | ||
+ | printf(“Hello, | ||
+ | printf(“Hi, | ||
+ | } | ||
+ | </ | ||
+ | and then recompile, relink, and recreate the executable hello.exe. Because hello.exe is staticly linked, there is no way to change what the function print_Hello_World does at runtime. | ||
+ | |||
+ | Let's explore a similar example in Smalltalk. Because we are conscientious, | ||
+ | < | ||
+ | main | ||
+ | |||
+ | self read_Overlays. | ||
+ | self print_Hello_World. | ||
+ | |||
+ | print_Hello_World | ||
+ | |||
+ | Transcript show: “Hello, World"; | ||
+ | |||
+ | </ | ||