Joyce is a secure
programming language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming ...
for
concurrent computing
Concurrent computing is a form of computing in which several computations are executed '' concurrently''—during overlapping time periods—instead of ''sequentially—''with one completing before the next starts.
This is a property of a syst ...
designed by
Per Brinch Hansen
Per Brinch Hansen (13 November 1938 – 31 July 2007) was a Danish-American computer scientist known for his work in operating systems, concurrent programming and parallel and distributed computing.
Biography
Early life and education
Per Br ...
in the 1980s.
It is based on the sequential language
Pascal
Pascal, Pascal's or PASCAL may refer to:
People and fictional characters
* Pascal (given name), including a list of people with the name
* Pascal (surname), including a list of people and fictional characters with the name
** Blaise Pascal, Fren ...
and the principles of
communicating sequential processes
In computer science, communicating sequential processes (CSP) is a formal language for describing patterns of interaction in concurrent systems. It is a member of the family of mathematical theories of concurrency known as process algebras, or pro ...
(CSP). It was created to address the shortcomings of CSP to be applied as a programming language, and to provide a tool, mainly for teaching, for
distributed computing
A distributed system is a system whose components are located on different computer network, networked computers, which communicate and coordinate their actions by message passing, passing messages to one another from any system. Distributed com ...
system implementation.
The language is based around the concept of ''agents''; concurrently executed processes that communicate only by the use of channels and
message passing
In computer science, message passing is a technique for invoking behavior (i.e., running a program) on a computer. The invoking program sends a message to a process (which may be an actor or object) and relies on that process and its supporting i ...
. Agents may activate subagents dynamically and
recursively
Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics ...
. The development of Joyce formed the foundation of the language
SuperPascal
SuperPascal is an imperative, concurrent computing programming language developed by Per Brinch Hansen. It was designed as a ''publication language'': a thinking tool to enable the clear and concise expression of concepts in parallel programmin ...
, also developed by Hansen around 1993.
Features
Joyce is based on a small subset of Pascal, extended with features inspired from CSP for concurrency.
The following sections describe some of the more novel features that were introduced.
Agents
An agent is a procedure consisting of a set of statements and possibly nested definitions of other agents. An agent may dynamically ''activate'' subagents which execute concurrently with their ''creator''. An agent can terminate only when all of its subagents have also terminated. For example, an agent
process2
activates
process1
:
agent process1(x, y: integer);
begin
...
end;
agent process2();
use process1;
begin
process1(9, 17);
end;
The activation of an agent creates new instances of all
local variable
In computer science, a local variable is a Variable (programming), variable that is given ''local scope (programming), scope''. A local variable reference in the subroutine, function or block (programming), block in which it is declared overrides ...
s and the value of each formal parameter is copied to a local variable. Hence, agents cannot access
variables of other agents and are allowed only to communicate through the use of channels. This restriction prevents problems associated with the use of shared variables such as
race condition
A race condition or race hazard is the condition of an electronics, software, or other system where the system's substantive behavior is dependent on the sequence or timing of other uncontrollable events. It becomes a bug when one or more of t ...
s.
Communication
Agents communicate through entities called ''channels''. Channels have an alphabet, defining the set of symbols which may be transmitted. Channels are created dynamically and accessed through the use of ''port'' variables. A port type is defined by a distinct set of symbols constituting its alphabet. Symbols with multiple values are defined with a specific type. For example:
stream = nt(integer), eos
The symbol
int(integer)
denotes a ''message'' symbol called
int
of any integer value. The second typeless symbol declaration
eos
(end of stream) is named a ''signal''. Once a port type has been defined, a port variable of that type can be declared:
out : stream
in : stream
And then a channel entity, internal to the agent creating it, can be activated as follows:
+out;
Symbols can then be sent and received on channels using the CSP-style input and output operators
?
and
!
respectively. A communication can occur only if there is a receiving agent matching the sending agent. The receiving agent must expect to receive the symbol type being sent. For example, the value 9 followed by the
eos
symbol is sent on port
out
:
out ! int(9)
out ! eos
And an integer message is received into a variable of a matching type, followed by the
eos
:
received : integer
in ? int(received)
in ? eos
Polling statements
Polling statements are based the CSP concept of guarded alternatives. A polling statement is made up of a set of statements, each guarded by an input channel statement. When a communication is matched between a transmitting agent and a guard, the guard is executed, followed by the corresponding statement. For example:
poll
in ? X -> x := x + 1 ,
in ? Y -> y := y + 1
end
Where the port
in
is monitored for the signals
X
or
Y
, on a matching communication, the corresponding variables
x
or
y
are incremented.
Security
Joyce was designed to be a ''secure'' language in the sense that a compiler would be able to detect all violations of the language rules.
Example program
The following is a complete example program, taken from the original paper introducing the Joyce programming language,
implementing an algorithm to generate prime numbers based on a sieving technique for
generation of primes. A
sieve
agent is sent a stream of integers from its predecessor, the first being a prime. It removes all multiples of this prime from the stream and activates a successor. This continues until the
eos
signal is propagated along the set of sieves.
agent sieve(inp, out: stream);
var more: boolean; x, y: integer;
succ: stream;
begin
poll
inp?int(x) -> +succ;
sieve(succ, out); more := true ,
inp?eos -> out!eos; more := false
end;
while more do
poll
inp?int(y) ->
if y mod x <> 0 then succ!int(y) ,
inp?eos -> out!int(x);
succ!eos; more := false
end;
end;
The following agent initialises the set of sieve agents and inputs into them a stream of integers between 3 and 9999.
agent primes;
use generate, sieve, print;
var a, b: stream;
begin
+a; +b; generate(a, 3, 2, 4999);
sieve(a, b); print(b)
end;
Implementation
Stack allocation
Due to concurrent execution of agent procedures, a conventional sequential
stack
Stack may refer to:
Places
* Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group
* Blue Stack Mountains, in Co. Donegal, Ireland
People
* Stack (surname) (including a list of people ...
allocation scheme cannot be used as the activation records of the agent calls do not follow a last-in first-out pattern. Instead, the creator-subagent relationships form a tree-structured stack. A simple scheme is used to implement this behaviour, which works by allocating new activation records at the top of the stack, and linking subagents' activation records to their creator's record. These records are freed only when the agent has terminated and they are at the top of the stack.
The effectiveness of this scheme depends on the structure and behaviour of a program, which in some cases will result in poor memory use. A more effective scheme was implemented in Hansen's language
SuperPascal
SuperPascal is an imperative, concurrent computing programming language developed by Per Brinch Hansen. It was designed as a ''publication language'': a thinking tool to enable the clear and concise expression of concepts in parallel programmin ...
.
References
External links
, Brinch Hansen Archive, a set of his papers
{{Pascal programming language family
Concurrent programming languages
Procedural programming languages
Pascal programming language family
Programming languages created in 1993