at:tutorial:symbiosis
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
at:tutorial:symbiosis [2007/07/27 10:25] – changes tvcutsem | at:tutorial:symbiosis [2008/10/22 16:52] – updated tvcutsem | ||
---|---|---|---|
Line 2: | Line 2: | ||
====== Symbiosis with Java ====== | ====== Symbiosis with Java ====== | ||
- | AmbientTalk is fully implemented in Java and runs on top of the JVM. Java provides an extensive class library that can be accessed from within AmbientTalk. | + | AmbientTalk is entirely |
- | The reverse, | + | The reverse, |
- | This chapter explains how both sides of this symbiotic relationship between Java and AmbientTalk can be leveraged. The goal of this symbiotic relationship is to complement the advantages of both languages and to alleviate their disadvantages. | + | This chapter explains how to program using this "symbiotic relationship" |
===== Symbiosis Architecture ===== | ===== Symbiosis Architecture ===== | ||
+ | |||
AmbientTalk has been implemented in Java. Because of this, Java plays two roles: it is both a symbiont language and the implementation language of AmbientTalk (and hence of the linguistic symbiosis itself). The figure below illustrates the different objects that play a part in the AmbientTalk/ | AmbientTalk has been implemented in Java. Because of this, Java plays two roles: it is both a symbiont language and the implementation language of AmbientTalk (and hence of the linguistic symbiosis itself). The figure below illustrates the different objects that play a part in the AmbientTalk/ | ||
Line 125: | Line 126: | ||
< | < | ||
>def test := / | >def test := / | ||
- | >>< | + | >>< |
> | > | ||
ping! | ping! | ||
Line 131: | Line 132: | ||
>>42 | >>42 | ||
</ | </ | ||
+ | |||
+ | ==== Starting an AmbientTalk interpreter from Java ==== | ||
+ | So far, the examples have illustrated how to reuse Java code from within AmbientTalk. They have shown how to access Java classes, instantiate them and invoke methods on the resulting objects. Moreover, | ||
+ | |||
+ | Embedding AmbientTalk in an application, | ||
+ | |||
+ | < | ||
+ | EmbeddedAmbientTalk vm = new EmbeddedAmbientTalk(); | ||
+ | vm.initialize( | ||
+ | NATParser.parse( | ||
+ | initFile.getName(), | ||
+ | Evaluator.loadContentOfFile(initFile)), | ||
+ | new SharedActorField[] { | ||
+ | vm.computeSystemObject(arguments), | ||
+ | vm.computeWorkingDirectory(), | ||
+ | vm.computeObjectPath(objectPath) }, | ||
+ | " | ||
+ | </ | ||
+ | The code excerpt also illustrates that the EmbeddableAmbientTalk class provides methods to create definitions for fields such as '' | ||
+ | |||
+ | Once the virtual machine is properly initialized, | ||
+ | |||
+ | < | ||
+ | public interface Controller { | ||
+ | public void executeEvent(ApplicationEvent evt); | ||
+ | public void executeEventWithoutUndo(ApplicationEvent evt); | ||
+ | public void undo(); | ||
+ | } | ||
+ | ... | ||
+ | private Controller controller = | ||
+ | (Controller) vm.evalAndWrap( | ||
+ | Evaluator.loadContentsOfFile(" | ||
+ | Controller.class); | ||
+ | </ | ||
+ | |||
+ | The corresponding AmbientTalk code should then return an object which implements the three methods to modify the model, and can be used to detect other reachable controllers with which it can exchange ApplicationEvents. | ||
+ | |||
+ | < | ||
+ | When starting an AmbientTalk virtual machine from a Java application, | ||
+ | </ |
at/tutorial/symbiosis.txt · Last modified: 2013/05/17 20:25 by tvcutsem