XC (programming language)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
XC
Paradigm(s) Concurrent programming, multi-core, imperative
Appeared in 2005
Typing discipline strong, static
Major implementations xcc
Influenced by C, Communicating Sequential Processes, Occam
Filename extension(s) .xc
Website http://www.xmos.com/published/programming-xc-xmos-devices

The XC Programming Language is a computer programming language developed in 2005 by Douglas Watt and David May at XMOS.

XC is an imperative programming language with a computational framework based on C. XC programs consist of functions that execute statements that act upon values stored in variables. Control-flow statements express decisions, and looping statements express iteration.[1]

The language was designed to exploit the XMOS processor architecture,[2] but is a general-purpose language and implementations for other architectures are in construction[citation needed]. Running XC on other platforms is currently supported by highly-optimised interpretation of the XMOS instruction set.

New features[edit]

One of the most unusual features of XC is the inclusion of timers and ports in a high-level programming language.

Introduction[edit]

The following is the XC source for the Hello World program.

#include <stdio.h>
 
main ( void ) {
   printf ( "Hello, world!\n" );
}

The language permits explicit parallelism, as well as parallel replication.

#include <platform.h>
on   stdcore [0] :  out  port tx         =  XS1_PORT_1A ;
on   stdcore [0] :  in   port rx         =  XS1_PORT_1B ;
on   stdcore [1] :  out  port lcdData    =  XS1_PORT_32A ;
on   stdcore [2] :  in   port keys       =  XS1_PORT_8B ;
int main ( void ) {
   par {
      on stdcore [0]   : uartTX ( tx );
      on stdcore [0]   : uartRX ( rx );
      on stdcore [1]   : lcdDrive ( lcdData );
      on stdcore [2]   : kbListen ( keys );
   }
}

Concurrent processes can communicate using channels.

#include <platform.h>
on stdcore [0] : out port tx      = XS1_PORT_1A ;
on stdcore [1] : in port keys     = XS1_PORT_8B ;
void uartTX ( chanend dataIn , port tx ) {
   char data ;
   while (1) {
     dataIn :> data ;
     transmitByte ( tx , data );
   }
}
void kbListen ( chanend c , port keys ) {
   char data ;
   while (1) {
     data = waitForKeyStroke ( keys );
     c <: data ;
   }
}
int main ( void ) {
   chan c ;
   par {
     on stdcore [0] : uartTX (c , tx );     // Thread X
     on stdcore [1] : kbListen (c , keys ); // Thread Y
   }
}

More unconventionally, the language includes the use of ports - which can be used to directly control hardware pins from high-level software.

#include <xs1.h>
out port p = XS1_PORT_1A ;
int main ( void ) {
   p <: 1;
   p <: 0;
}

Historical influences[edit]

The language design was heavily influenced[3] by Communicating Sequential Processes - a process algebra developed by Tony Hoare, and therefore includes explicit parallelism and channel communication. Edsger Dijkstra can also claim an influence with the inclusion of guarded commands.

Because of its relations to CSP, the framework for modelling from CSP can be used to reason about XC programs.[4]

As a result the language bears semantic (though not structural) similarities to languages such as occam. This is not surprising as one of the XC language designers was David May who also created occam.

References[edit]

  1. ^ Douglas R. Watt. Programming XC on XMOS Devices. XMOS Limited. ISBN 978-1-907361-03-6. Retrieved 2012-03-01. 
  2. ^ David May. The XMOS XS1 Architecture. ISBN 1-907361-01-4. Retrieved 2012-03-01. 
  3. ^ http://www.cs.bris.ac.uk/~dave/
  4. ^ Oliver Fausta, Rajendra Acharya Ub, Bernhard H.C. Sputha and Lim Choo Minb (June 2010). "Systems engineering principles for the design of biomedical signal processing systems". Computer Methods and Programs in Biomedicine 102 (3): 267–276. doi:10.1016/j.cmpb.2010.05.002. ISSN 0169-2607. PMID 20576311. 

External links[edit]