Joyce (programming language)

Last updated

Joyce
Paradigm concurrent, imperative, structured
Family Wirth Pascal
Designed by Per Brinch Hansen
First appeared1987;36 years ago (1987)
Stable release
1 / 1987;36 years ago (1987)
Typing discipline Strong
Influenced by
Communicating sequential processes, Pascal, Concurrent Pascal
Influenced
SuperPascal

Joyce is a secure programming language for concurrent computing designed by Per Brinch Hansen in the 1980s. [1] It is based on the sequential language Pascal and the principles of communicating sequential processes (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 system implementation.

Contents

The language is based around the concept of agents; concurrently executed processes that communicate only by the use of channels and message passing. Agents may activate subagents dynamically and recursively. The development of Joyce formed the foundation of the language SuperPascal, also developed by Hansen around 1993.

Features

Joyce is based on a small subset of Pascal, extended with features inspired from CSP for concurrency. [2] 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:

agentprocess1(x,y:integer);begin...end;agentprocess2();useprocess1;beginprocess1(9,17);end;

The activation of an agent creates new instances of all local variables 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 conditions.

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=[int(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:integerin?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, [1] 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.

agentsieve(inp,out:stream);varmore:boolean;x,y:integer;succ:stream;beginpollinp?int(x)->+succ;sieve(succ,out);more:=true|inp?eos->out!eos;more:=falseend;whilemoredopollinp?int(y)->ifymodx<>0thensucc!int(y)|inp?eos->out!int(x);succ!eos;more:=falseend;end;

The following agent initialises the set of sieve agents and inputs into them a stream of integers between 3 and 9999.

agentprimes;usegenerate,sieve,print;vara,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 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. [3] 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.

Related Research Articles

<span class="mw-page-title-main">Erlang (programming language)</span> Programming language

Erlang is a general-purpose, concurrent, functional high-level programming language, and a garbage-collected runtime system. The term Erlang is used interchangeably with Erlang/OTP, or Open Telecom Platform (OTP), which consists of the Erlang runtime system, several ready-to-use components (OTP) mainly written in Erlang, and a set of design principles for Erlang programs.

occam (programming language)

occam is a programming language which is concurrent and builds on the communicating sequential processes (CSP) process algebra, and shares many of its features. It is named after philosopher William of Ockham after whom Occam's razor is named.

<span class="mw-page-title-main">Pascal (programming language)</span> Programming language

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named in honour of the French mathematician, philosopher and physicist Blaise Pascal.

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 process calculi, based on message passing via channels. CSP was highly influential in the design of the occam programming language and also influenced the design of programming languages such as Limbo, RaftLib, Erlang, Go, Crystal, and Clojure's core.async.

Oz is a multiparadigm programming language, developed in the Programming Systems Lab at Université catholique de Louvain, for programming language education. It has a canonical textbook: Concepts, Techniques, and Models of Computer Programming.

<span class="mw-page-title-main">ALGOL 68</span> Programming language

ALGOL 68 is an imperative programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously defined syntax and semantics.

In computer science, the process calculi are a diverse family of related approaches for formally modelling concurrent systems. Process calculi provide a tool for the high-level description of interactions, communications, and synchronizations between a collection of independent agents or processes. They also provide algebraic laws that allow process descriptions to be manipulated and analyzed, and permit formal reasoning about equivalences between processes. Leading examples of process calculi include CSP, CCS, ACP, and LOTOS. More recent additions to the family include the π-calculus, the ambient calculus, PEPA, the fusion calculus and the join-calculus.

<span class="mw-page-title-main">Per Brinch Hansen</span> Danish-American computer scientist

Per Brinch Hansen was a Danish-American computer scientist known for his work in operating systems, concurrent programming and parallel and distributed computing.

<span class="mw-page-title-main">Action! (programming language)</span> Atari 8-bit family programming language

Action! is a procedural programming language and integrated development environment written by Clinton Parker for the Atari 8-bit family. The language, which is similar to ALGOL, compiles to high-performance code for the MOS Technologies 6502 of the Atari computers. Action! was distributed on ROM cartridge by Optimized Systems Software starting in 1983. It was one of the company's first bank-switched 16 kB "Super Cartridges".

In concurrent programming, a monitor is a synchronization construct that allows threads to have both mutual exclusion and the ability to wait (block) for a certain condition to become false. Monitors also have a mechanism for signaling other threads that their condition has been met. A monitor consists of a mutex (lock) object and condition variables. A condition variable essentially is a container of threads that are waiting for a certain condition. Monitors provide a mechanism for threads to temporarily give up exclusive access in order to wait for some condition to be met, before regaining exclusive access and resuming their task.

The actor model in computer science is a mathematical model of concurrent computation that treats an actor as the basic building block of concurrent computation. In response to a message it receives, an actor can: make local decisions, create more actors, send more messages, and determine how to respond to the next message received. Actors may modify their own private state, but can only affect each other indirectly through messaging.

The computer programming languages C and Pascal have similar times of origin, influences, and purposes. Both were used to design their own compilers early in their lifetimes. The original Pascal definition appeared in 1969 and a first compiler in 1970. The first version of C appeared in 1972.

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.

In computer programming, an enumerated type is a data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language. An enumerated type can be seen as a degenerate tagged union of unit type. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value. In other words, an enumerated type has values that are different from each other, and that can be compared and assigned, but are not specified by the programmer as having any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.

In computing, the producer-consumer problem is a family of problems described by Edsger W. Dijkstra since 1965.

Concurrent Pascal is a programming language designed by Per Brinch Hansen for writing concurrent computing programs such as operating systems and real-time computing monitoring systems on shared memory computers.

PROMELA is a verification modeling language introduced by Gerard J. Holzmann. The language allows for the dynamic creation of concurrent processes to model, for example, distributed systems. In PROMELA models, communication via message channels can be defined to be synchronous, or asynchronous. PROMELA models can be analyzed with the SPIN model checker, to verify that the modeled system produces the desired behavior. An implementation verified with Isabelle/HOL is also available, as part of the Computer Aided Verification of Automata (CAVA) project. Files written in Promela traditionally have a .pml file extension.

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 programming. This is in contrast with implementation languages which are often complicated with machine details and historical conventions. It was created to address the need at the time for a parallel publication language. Arguably, few languages today are expressive and concise enough to be used as thinking tools.

Pic Micro Pascala.k.a. PMP is a free Pascal cross compiler for PIC microcontrollers. It is intended to work with the Microchip Technology MPLAB suite installed; it has its own IDE (Scintilla-based) and it is a highly optimized compiler.

Join-patterns provides a way to write concurrent, parallel and distributed computer programs by message passing. Compared to the use of threads and locks, this is a high level programming model using communication constructs model to abstract the complexity of concurrent environment and to allow scalability. Its focus is on the execution of a chord between messages atomically consumed from a group of channels.

References

  1. 1 2 Hansen, Brinch (2002). "Joyce: A programming language for distributed systems". In Hansen, Per Brinch (ed.). The Origin of Concurrent Programming: From Semaphores to Remote Procedure Calls. New York, New York: Springer. pp. 464–492. doi:10.1007/978-1-4757-3472-0. ISBN   978-1-4419-2986-0. S2CID   44909506.
  2. Hansen, Brinch (June 1989). "The Joyce language report". Software: Practice and Experience. John Wiley & Sons. 19 (6): 553–578. doi:10.1002/spe.4380190606. S2CID   30474491.
  3. Hansen, Brinch (June 1989). "A multiprocessor implementation of Joyce". Software: Practice and Experience. John Wiley & Sons. 19 (6): 579–592. doi:10.1002/spe.4380190606. S2CID   30474491.

Official website , Brinch Hansen Archive, a set of his papers