🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4832

CH Language Environment

#4832
From: Harry H. Cheng
Date: Tue, 27 Feb 1996 00:54
220 lines
8269 bytes
 

I would like to announce that the CH language environment
is available users of SunOS, Solaris, LynxOS.
CH is designed as a superset of C interpreter.
It can be used for Unix shell programming, WWW Common
Gateway Interface, WWW Common Client Interface, ...
The differences between CH and C are highlighted as follows:


EXTENSIONS TO C (some features are currently debated by 
C Standard Committee ANSI/X3J11 and ISO/SC22/WG14 as new 
features
of the next version of C standard called C9x)

(1) CH is an interpretive implementation of ANSI C as Unix shell.
    It can be used as login shell. Here are some differences between 
    CH and C shells.

          CH shell                           C shell
    _path = "/usr/bin /bin"            set path = (/usr/bin /bin)
    printf("%s\n", getenv("PATH"))
    putenv("PATH=/usr/bin /bin")       setenv PATH "/usr/bin /bin" 
    printf("%s\n", getenv("PATH"))     echo $PATH
    echo $(getenv("PATH"))             echo $PATH
    printf("%s\n", _path)              echo $path
    remenv("PATH")                     unsetenv PATH
    emvar("_path")                     unset path 
    int i = 90                         set i =90
    i = 91                             set i =91
    string hostnam =`hostname`         set hostnam =`hostname`
    alias("rm", "rm -i")               alias rm 'rm -r' 
    unalias("rm")                      unalias rm 
    _histsize = 100                    history = 100
    history                            history 
    ls ~ *                             ls ~ *
    ls > output                        ls > output
    ls $(getenv("PATH"))               ls $PATH
    ls $_path                          ls $path
    $l -agl                            !l -agl
    $3                                 !3 
    $-1                                !-1
    $$                                 !!
    more .chshrc .chlogin .chlogout    more .cshrc .login .logout
    more .rchshrc .chlogin .chlogout   more .cshrc .login .logout
    more .schshrc .chlogin .chlogout   more .cshrc .login .logout
 
    restricted shell                    restricted shell


There is safe shell in CH for internet computing.
In addition to restrictions imposed by conventional restricted shell,
the following features are disallowed for across-network internet computing
in safe CH shell.
    (a) declaration of pointers.
    (b) built-in functions remove(), rename(), unlink(), open(), and fopen().
The restrictions above are enforced after .schshrc is interpreted.
If CH is invoked with option -S, options -r and -f will be ignored.

(2) Complex is a built-in data type 
handled similar to that in Fortran.
For example,
      float f=90;
      complex z=complex(1,2);
      z = 2*f*z*sin(z)*atan(z);

(3) String is a first-class object for across-network computing.
For example,
      string s, a[3];
      s = "great string"
      strcpy(a[0], s);
      strcat(s, s);
      printf("s = %s\n", s);

(4) Functions can be nested and recursively nested
similar to implementation in GNU gcc.
For example,
      int func1() {
         void func2() {
            int func3() { ...}
         }
         ...
         func2();
      }  

(5) Arrays of variable length. They include
deferred-shape arrays, assumed-shape arrays, and pointer
to assumed-shape arrays.
The following example will clarify the concepts of these
various array definitions.
  void funct(int a[:][:], (*b)[:], c[], n, m){
  /* a: assumed-shape array */
  /* b: pointer to array of assumed-shape */
  /* c: incomplete array completed by function call */
    int d[4][5];     /* d: fixed-length array */
    int e[n][m];     /* e: deferred-shape array */
    int (*f)[:];     /* f: pointer to array of assumed-shape */
    extern int g[];  /* g: incomplete array completed by external linkage */
    int h[] = {1,2}; /* h: incomplete array completed by initialization */
    e[1][2] = a[2][3];
  }
  int A[3][4], B[5][6], C[3];
  funct(A, B, C, 10, 20);
  funct(B, A, C, 85, 85);

(6) Arrays of adjustable range.
The range of subscript for an index of array can be adjusted.
For example,
  int a[1:10], b[-5:5], c[0:10][1:10], d[10][1:10], e[n:m], f[n1:m1][1:m2];
  extern int a[1:], b[-5:], c[0:][1:10];
  int funct(int a[1:], int b[1:10], int c[1:][3], int d[1:10][0:20]);
  a[10] = a[1]+2; /* OK */
  a[0] = 90;      /* Error: index out of range */

(7) Computational array.
An array qualified by type qualifier {array} is
called  computational array.
A computational array is treated as  a first-class object
as in Fortran 90. For example,
       array float a[10][10], b[10][10];
       a += b+inverse(a)*transpose(a)+sin(a);

(8) Fortran arrays.
An array qualified by type qualifier {fortran} is
called fortran-style array.
Unlike a C array,
elements of a fortran-style array are stored column-wise.
For example,
  fortran array float A[10][10], B[10][10];
  fortran float a[10][10], b[10][10];
  float *p;   
  p = &a[0][0];
  *(p+1) = 90; /* <==> a[1][0] = 90; not a[0][1] = 90 */
  funct((float [10])&A[5][10]); /* pass column 6 to function funct() */

Fortran code can be ported to CH easily.
We have ported over 10,000 lines of LAPACK package to CH.


(9)Reference for internet computing.
Reference for basic data types char, short, int,
float, double, as well as data types qualified
by signed, unsigned, long, complex, and dual
can be declared.
Functions can be called by reference.
The same syntax in C++ is used in CH.
For example,
  int i;
  int &j = i;
  int A, B;
  void swap(int &n, int &m); /* the same as in C++ */
  swap(A, B);                /* pass by reference as in Fortran */

(10) Many high-level toolboxes and function files such as
    plotxy(), plotxyz(), plotxyf(), plotxyzf() for plotting.



MISSING C FEATURES
(1) struct/union/bit-fields.
(2) pointer to functions.
These features will be implemented in CH in the future.


WHY CH?
 
(1) Like Java, CH can be used for across network
world-wide distributed computing.
It can be used for WWW Common Gateway Interface (CGI), 
WWW Common Client Interface (CCI).
Toolboxes for CGI and CCI are available.
They are easy to use. Examples of World-Wide
Distributed Computing in the CH language environment
can be found on the WWW at the URL address
   http://iel.ucdavis.edu/CH/tutor/wwdc/

(2) If you use common set of C and CH, 
your CH code can be compiled in native C compiler.
Your C programs without structure and pointer to functions
can run in the CH language environment
without compilation. 
Normally, CH is 1.xx% to 100% slower than compiled C code, 
depending on applications. But,
if your code takes advantage of high-level features of CH,
such as inverse(A) for computing inverse of matrix A,
CH code can be 
just as fast as your C program.


(3) It can be used for rapid prototyping of real-time applications.
It can be used to test your device drivers and hardware setup.

(4) Like Basic and C shell, CH is interactive.
If you are not sure a C feature, you can verify it
easily under the CH language environment. For example,

   prompt> hello.c
   Hello, world!
   (execute hello.c program without compilation)
   prompt> int i, *p;
   prompt> p = &i; 
   prompt> *p = 90;
   prompt> printf("i = %d\n", i);
   i = 90
   prompt> int **p2
   prompt> p2 = &p
   prompt> printf("**p2 = %d\n", **p2)
   **p2 = 90
   prompt> ls * > junkfile
   (all file names go to junkfile)
   prompt> 


CH runs on SunOS, Solaris, MVME167/LynxOS 2.2.1.
It is available free for downloading
on the WWW at the URL address 
   http://iel.ucdavis.edu/CH/
 

Harry Cheng
Technical Details
Message-ID: <3132563C.3BA5@ucdavis.edu>
Path: arc1-ca.pugleaf.net!news.ucdavis.edu!usenet

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.ucdavis.edu!usenet
From: "Harry H. Cheng" <hhcheng@ucdavis.edu>
Newsgroups: comp.std.c
Subject: CH Language Environment
Date: Mon, 26 Feb 1996 16:54:20 -0800
Organization: University of California, Davis
Message-ID: <3132563C.3BA5@ucdavis.edu>
NNTP-Posting-Host: dragon.engr.ucdavis.edu
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.3 sun4m)
Content-Disposition: inline; filename="l4"