diff --git a/.gitmodules b/.gitmodules index ef5a55c7c7..937c5ee48c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -866,3 +866,6 @@ [submodule "vendor/grammars/language-reason"] path = vendor/grammars/language-reason url = https://github.com/reasonml-editor/language-reason +[submodule "vendor/grammars/sarl-textmate"] + path = vendor/grammars/sarl-textmate + url = https://github.com/sarl/sarl-textmate diff --git a/grammars.yml b/grammars.yml index 0e70b51f7b..a9dde63ba8 100755 --- a/grammars.yml +++ b/grammars.yml @@ -713,3 +713,6 @@ vendor/grammars/xml.tmbundle: - text.xml.xsl vendor/grammars/zephir-sublime: - source.php.zephir +vendor/grammars/sarl-textmate: +- source.sarl + diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 3f2f20704c..063481aca6 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -5034,6 +5034,7 @@ Xtend: - ".xtend" ace_mode: text language_id: 406 + YAML: type: data tm_scope: source.yaml @@ -5183,3 +5184,11 @@ xBase: tm_scope: source.harbour ace_mode: text language_id: 421 +sarl: + type: programming + ace_mode: text + codemirror_mime_type: text/x-sarl + extensions: + - ".sarl" + language_id: 422 + diff --git a/samples/sarl/behaviors.sarl b/samples/sarl/behaviors.sarl new file mode 100644 index 0000000000..ed586855ee --- /dev/null +++ b/samples/sarl/behaviors.sarl @@ -0,0 +1,72 @@ +package io.sarl.demos.basic.behaviors + +import io.sarl.core.Behaviors +import io.sarl.core.Destroy +import io.sarl.core.Initialize +import io.sarl.core.Lifecycle +import io.sarl.core.Logging + +/* + * Declaration of a simple Factorial event with two internal variables + */ +event Factorial { + var number : Long + var value : Long +} + +/* + * Declaration of a simple BehaviorInitialize event without any data + */ +event BehaviorInitialize {} + +/* + * Declaration of a new behavior + */ +behavior FactorialBehavior { + uses Lifecycle, Behaviors, Logging /* the list of capacities used by this behavior */ + + var upto : Long = 5l /* A behavior attribute */ + + on BehaviorInitialize { + this.upto = new Long(16) + info("Received Calculate for " + this.upto) + wake(new Factorial => [ number = 0l ; value = 1l ]) /* Wake function send a new factorial event within the internal context of an agent (could be listen by the agent itself, its collections of behaviors and its sub-members) */ + } + + on Factorial [ occurrence.number < upto ] { + wake(new Factorial => [ number = increment(occurrence.number) ; value = occurrence.value * (increment(occurrence.number)) ]) + } + + on Factorial [occurrence.number == upto] { + info("Factorial of " + upto + " is " + occurrence.value) + + killMe + } + + def increment(nb: Long) : Long { + return nb+1 + } +} + +/* + * A simple agent executing/adopting a externally defined behavior. + */ +agent BehaviorPlayer { + + uses Behaviors + + var myFactorialBehavior : FactorialBehavior + + + on Initialize { + myFactorialBehavior = new FactorialBehavior(this) /* instantiation of the previously declared behavior */ + registerBehavior(myFactorialBehavior); /* registration of this behavior as one of the agent's behaviors */ + wake(new BehaviorInitialize) /* send the BehaviorInitialize event in the agent internal context */ + } + + on Destroy { + unregisterBehavior(myFactorialBehavior); /* WARNING: never forget to unregister a behavior before dying */ + } + +} + diff --git a/samples/sarl/countdown.sarl b/samples/sarl/countdown.sarl new file mode 100644 index 0000000000..0a58ec6c4c --- /dev/null +++ b/samples/sarl/countdown.sarl @@ -0,0 +1,36 @@ +package io.sarl.demos.basic.countdown + +import io.sarl.core.Destroy +import io.sarl.core.Initialize +import io.sarl.core.Lifecycle +import io.sarl.core.Logging +import io.sarl.core.Schedules +import java.util.concurrent.atomic.AtomicInteger + +event Element + +agent CountDownAgent { + uses Lifecycle, Schedules, Logging + + val counter = new AtomicInteger(5) + + on Initialize { + info("Initialize") + + every(2000) [ /* Decrement counter every 2 sec until v = 0, then kill itself*/ + var v = counter.decrementAndGet; + info("Counter=" + v) + if (v <= 0) { + killMe + } + ] + + + } + + on Destroy { + info("Goodbye World!") + } + +} + diff --git a/samples/sarl/distributedfactorial.sarl b/samples/sarl/distributedfactorial.sarl new file mode 100644 index 0000000000..c36f99679a --- /dev/null +++ b/samples/sarl/distributedfactorial.sarl @@ -0,0 +1,112 @@ +package io.sarl.demos.factorial.distributed + +import io.sarl.core.Behaviors +import io.sarl.core.DefaultContextInteractions +import io.sarl.core.Initialize +import io.sarl.core.Lifecycle +import io.sarl.core.Logging +import io.sarl.core.Schedules + +event Factorial { + var number : Long + var value : Long +} + +event Calculate { + var number : Long +} + +event ComputationDone { + var result : Long +} + +event Hello + +event Die + +agent DistributedFactorialBootAgent { + uses DefaultContextInteractions, Lifecycle + + on Initialize { + spawn(FactorialAgent) + spawn(FactorialQueryAgent,10l) + killMe + } +} + +agent FactorialQueryAgent { + uses Lifecycle, DefaultContextInteractions, Schedules, Logging + + var factValue : Long + + var started = false + + on Initialize { + loggingName = "QueryAgent" + if (occurrence.parameters.length > 0) { + factValue = new Long(occurrence.parameters.get(0) as Long) + + info("Auto-detecting Factorial") + task("discovery-task").every(1000) [ + emit(new Hello) + ] + } else { + info("Bad parameter settings, you must specify an integer value to compute the corresponding factorial") + emit(new Die) + killMe + } + + } + + on Hello [!isFromMe && !started] { + started = true + task("discovery-task").cancel + info("Found Factorial") + info("Query sent with number " + factValue) + emit(new Calculate => [number = factValue]) + } + + on ComputationDone { + info(factValue + "! = " + occurrence.result) + emit(new Die) + info("Killing") + killMe + } +} + +agent FactorialAgent { + uses Lifecycle, Behaviors, Logging, DefaultContextInteractions + + var upto : Long + + on Initialize { + loggingName = "FactorialAgent" + info("Factorial initialized") + } + + on Hello [!isFromMe] { + emit(new Hello) + } + + on Factorial [occurrence.number < upto] { + wake(new Factorial => [number = occurrence.number + 1; value = occurrence.value * (occurrence.number + 1)]) + } + + on Factorial [occurrence.number == upto] { + info(this.upto + "! = " + occurrence.value) + emit(new ComputationDone => [result = occurrence.value]) + } + + on Calculate { + this.upto = new Long(occurrence.number); + info("Query for " + this.upto + "!") + wake(new Factorial => [number = 0l; value = 1l]) + } + + on Die { + info("Killing") + killMe + } + +} + diff --git a/samples/sarl/helloworld.sarl b/samples/sarl/helloworld.sarl new file mode 100644 index 0000000000..210deb1d7a --- /dev/null +++ b/samples/sarl/helloworld.sarl @@ -0,0 +1,63 @@ +package io.sarl.demos.basic.helloworld + +import io.sarl.core.AgentKilled +import io.sarl.core.AgentSpawned +import io.sarl.core.ContextJoined +import io.sarl.core.ContextLeft +import io.sarl.core.Destroy +import io.sarl.core.Initialize +import io.sarl.core.Lifecycle +import io.sarl.core.Logging +import io.sarl.core.MemberJoined +import io.sarl.core.MemberLeft +import io.sarl.core.Schedules + +/* + * A "Hello World" Agent. + */ +agent HelloAgent { + uses Lifecycle, Schedules, Logging + + /* Print "Hello World" when spawned and wait 2 seconds to kill itself */ + on Initialize { + info("Hello World!") + in(2000) [killMe] + } + + /* Event trigger before agent dies, Print "Goodbye World" before dying */ + on Destroy { + /* the Destroy event is automatically */ + info("Goodbye World!") + } + + /* Event trigger when an agent of the level joins a shared context, sent to agent of the same level*/ + on ContextJoined { + info("ContextJoined, contextID:" + occurrence.holonContextID + " SpaceID: " + occurrence.defaultSpaceID) + } + + /* Event trigger when an agent of the level leaves a shared context, sent to agent of the same level */ + on ContextLeft { + info("ContextLeft, contextID:" + occurrence.holonContextID) + } + + /* Event trigger when an agent joins one of our shared super-holons, sent to all members of the considered super-holon */ + on MemberJoined { + info("MemberJoined, agentID:" + occurrence.agentID) + } + + /* Event trigger when an agent leaves one of our shared super-holons, sent to all members of the considered super-holon */ + on MemberLeft { + info("MemberLeft, agentID:" + occurrence.agentID) + } + + /* A new agent has been spawn in our context */ + on AgentSpawned { + info("AgentSpawned, agentID:" + occurrence.agentID + " AgentType: " + occurrence.agentType) + } + + /* An agent has been killed in our context */ + on AgentKilled { + info("AgentKilled, agentID:" + occurrence.agentID) + } +} + diff --git a/vendor/grammars/sarl-textmate b/vendor/grammars/sarl-textmate new file mode 160000 index 0000000000..b086c0665f --- /dev/null +++ b/vendor/grammars/sarl-textmate @@ -0,0 +1 @@ +Subproject commit b086c0665f3e85b39182a846a661b95d147d0e2f