Removed a couple of functions in _chpl_file that were defined over _nilType.

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@8427 3a8e244f-b0f2-452b-bcba-4c88e055c3ca

//
// Functions on _file primitive type, the C file pointer type
//

pragma "no codegen" var chpl_input_filename: string;
pragma "no codegen" var chpl_input_lineno: int;

pragma "inline" def _get_errno() return __primitive("get_errno");
pragma "inline" def _get_eof() return __primitive("get_eof");
pragma "inline" def _get_stdin() return __primitive("get_stdin");
pragma "inline" def _get_stdout() return __primitive("get_stdout");
pragma "inline" def _get_stderr() return __primitive("get_stderr");
pragma "inline" def _get_nullfile() return __primitive("get_nullfile");

pragma "inline" def _copy(x: _file) return x;
pragma "inline" def =(a: _file, b: _file) return b;
pragma "inline" def ==(a: _file, b: _file) return __primitive("==", a, b);
pragma "inline" def !=(a: _file, b: _file) return __primitive("!=", a, b);

pragma "inline" def _fopen(filename: string, mode: string)
  return __primitive("fopen", filename, mode);

pragma "inline" def _fclose(fp: _file)
  return __primitive("fclose", fp);

pragma "inline" def fprintf(fp: _file, fmt: string, val)
  return __primitive("fprintf", fp, fmt, val);

pragma "inline" def fscanf(fp: _file, fmt: string, inout val)
  return __primitive("fscanf", fp, fmt, val);

pragma "inline" def _string_fscanf(fp: _file)
  return __primitive("string_fscanf", fp);

pragma "inline" def _readLitChar(fp: _file, val: string, ignoreWhiteSpace: bool)
  return __primitive("readLit", fp, val, ignoreWhiteSpace);

pragma "rename _chpl_fflush"
def fflush(f: file) {
  fflush(f.fp);
}

pragma "rename _chpl_assert_no_args"
def assert(test: bool) {
  if (!test) {
    _writeAssertFailed();
    if (!chpl_input_lineno) {
      fwriteln(stderr);
    }
    exit(0);
  }
}

pragma "rename _chpl_assert"
def assert(test: bool, args ...?numArgs) {
  if (!test) {
    _writeAssertFailed();
    if (!chpl_input_lineno) {
      fwrite(stderr, ": ");
    }
    for param i in 1..numArgs {
      fwrite(stderr, args(i));
    }
    fwriteln(stderr);
    exit(0);
  }
}

def _writeAssertFailed() {
  fflush(stdout);
  fwrite(stderr, "Assertion failed");
  if (chpl_input_lineno) {
    fwriteln(stderr, ": ", chpl_input_filename, ":", chpl_input_lineno);
  }
}

pragma "rename _chpl_halt_no_args"
def halt() {
  _writeHaltReached();
  if(!chpl_input_lineno) {
    fwriteln(stderr);
  }
  exit(0);
}

pragma "rename _chpl_halt"
def halt(args ...?numArgs) {
  _writeHaltReached();
  if (!chpl_input_lineno) {
    fwrite(stderr, ": ");
  }
  for param i in 1..numArgs {
    fwrite(stderr, args(i));
  }
  fwriteln(stderr);
  exit(0);
}

def _writeHaltReached() {
  fflush(stdout);
  fwrite(stderr, "Halt reached");
  if (chpl_input_lineno) {
    fwriteln(stderr, ": ", chpl_input_filename, ":", chpl_input_lineno);
  }
}

class file {
  var filename : string = "";
  var mode : string = "r";
  var path : string = ".";
  var fp : _file;
  var writeLock : sync uint(64);    // for serializing fwrite output

  def open {
    if (this == stdin || this == stdout || this == stderr) {
      halt("***Error: It is not necessary to open \"", filename, "\"***");
    }

    var fullFilename = path + "/" + filename;
    fp = _fopen(fullFilename, mode);

    if (fp == _get_nullfile()) {
      halt("***Error: Unable to open \"", fullFilename, "\": ",
           _get_errno(), "***");
    }
  }

  def _checkFileStateChangeLegality(state) {
    if (isOpen) {
      halt("Cannot change ", state, " of file ", path, "/", filename,
           " while it is open");
    }
  }

  def filename {
    return filename;
  }

  def =filename(newfilename) {
    _checkFileStateChangeLegality("filename");
    filename = newfilename;
  }

  def path {
    return path;
  }

  def =path(newpath) {
    _checkFileStateChangeLegality("path");
    path = newpath;
  }

  def mode {
    return mode;
  }

  def =mode(newmode: string) {
    _checkFileStateChangeLegality("mode");
    mode = newmode;
  }

  def isOpen: bool {
    var openStatus: bool = false;
    if (fp != _get_nullfile()) {
      openStatus = true;
    }
    return openStatus;
  }

  def close {
    if (this == stdin || this == stdout || this == stderr) {
      halt("***Error: You may not close \"", filename, "\"***");
    }
    if (fp == _get_nullfile()) {
      var fullFilename = path + "/" + filename;
      halt("***Error: Trying to close \"", fullFilename,
           "\" which isn't open***");
    }
    var returnVal: int = _fclose(fp);
    if (returnVal < 0) {
      var fullFilename = path + "/" + filename;
      halt("***Error: The close of \"", fullFilename, "\" failed: ",
           _get_errno(), "***");
    }
    fp = _get_nullfile();
  }
}

const stdin  = file("stdin", "r", "/dev", _get_stdin());
const stdout = file("stdout", "w", "/dev", _get_stdout());
const stderr = file("stderr", "w", "/dev", _get_stderr());

def _fopenError(f: file, isRead: bool) {
  var fullFilename:string = f.path + "/" + f.filename;
  if (isRead) {
    halt("***Error: You must open \"", fullFilename,
         "\" before trying to read from it***");
  } else {
    halt("***Error: You must open \"", fullFilename,
         "\" before trying to write to it***");
  }
}

def _fmodeError(f: file, isRead: bool) {
  var fullFilename: string = f.path + "/" + f.filename;
  var modestring = if (isRead) then "reading" else "writing";
  halt("***Error: ", fullFilename, " not open for ", modestring, "***");
}

def _fprintfError() {
  halt("***Error: Write failed: ", _get_errno(), "***");
}

def _fscanfError() {
  halt("***Error: Read failed: ", _get_errno(), "***");
}

pragma "rename _chpl_fread_int"
def fread(f: file = stdin, inout val: int) {
  if (f.isOpen) {
    var returnVal: int = fscanf(f.fp, "%d", val);
    if (returnVal == _get_eof()) {
      halt("***Error: Read failed: EOF***");
    }
    if (returnVal < 0) {
      _fscanfError();
    } else if (returnVal == 0) {
      halt("***Error: No int was read***");
    }
  } else {
    _fopenError(f, isRead = true);
  }
}

def _fwrite_lock( f: file) {
  var me: uint(64) = __primitive( "thread_id");
  if (isFull( f.writeLock)) {
    if (readXX( f.writeLock) == me) {
      return false;
    }
  }
  f.writeLock = me;
  return true;
}

def _fwrite_unlock( f: file) {
  writeFE( f.writeLock, 0);  // writeXE works also as it should be full before
}

pragma "rename _chpl_fread_uint"
def fread(f: file = stdin, inout val: uint) {
  if (f.isOpen) {
    var returnVal: int = fscanf(f.fp, "%llu", val);
    if (returnVal == _get_eof()) {
      halt("***Error: Read failed: EOF***");
    }
    if (returnVal < 0) {
      _fscanfError();
    } else if (returnVal == 0) {
      halt("***Error: No int was read***");
    }
  } else {
    _fopenError(f, isRead = true);
  }
}

pragma "rename _chpl_fread_real"
def fread(f: file = stdin, inout val: real) {
  if (f.isOpen) {
    var returnVal: int = fscanf(f.fp, "%lg", val);
    if (returnVal == _get_eof()) {
      halt("***Error: Read failed: EOF***");
    }
    if (returnVal < 0) {
      _fscanfError();
    } else if (returnVal == 0) {
      halt("***Error: No real was read***");
    }
  } else {
    _fopenError(f, isRead = true);
  }
}

pragma "rename _chpl_fread_complex"
def fread(f: file = stdin, inout val: complex) {
  var realPart: real;
  var imagPart: real;
  var imagI: string;
  var matchingCharWasRead: int;
  var isNeg: bool;

  fread(f, realPart);
  matchingCharWasRead = _readLitChar(f.fp, "+", true);
  if (matchingCharWasRead != 1) {
    matchingCharWasRead = _readLitChar(f.fp, "-", true);
    if (matchingCharWasRead != 1) {
      halt("***Error: Incorrect format for complex numbers***");
    }
    isNeg = true;
  }

  fread(f, imagPart);
  matchingCharWasRead = _readLitChar(f.fp, "i", false);
  if (matchingCharWasRead != 1) {
    halt("***Error: Incorrect format for complex numbers***");
  }

  val.re = realPart;
  if (isNeg) {
    val.im = -imagPart;
  } else {
    val.im = imagPart;
  }
}

pragma "rename _chpl_fread_string"
def fread(f: file = stdin, inout val: string) {
  if (f.isOpen) {
    val = _string_fscanf(f.fp);
  } else {
    _fopenError(f, isRead = true);
  }
}

pragma "rename _chpl_fread_bool"
def fread(f: file = stdin, inout val: bool) {
  if (f.isOpen) {
    var valString : string = _string_fscanf(f.fp);
    if (valString == "true") {
      val = true;
    } else if (valString == "false") {
      val = false;
    } else {
      halt("***Error: Not of bool type***");
    }
  } else {
    _fopenError(f, isRead = true);
  }
}

pragma "rename _chpl_fwrite_string"
def fwrite(f: file, val: string) {
  var need_release: bool = _fwrite_lock( f);

  if (!f.isOpen) {
    _fopenError(f, isRead = false);
  }
  if (f.mode != "w") {
    _fmodeError(f, isRead = false);
  }
  var returnVal = fprintf(f.fp, "%s", val);
  if (returnVal < 0) {
    _fprintfError();
  }

  if (need_release) { _fwrite_unlock( f); }
}

def fwrite(f: file, args ...?numArgs) {
  var need_release: bool = _fwrite_lock( f);
  for param i in 1..numArgs {
    fwrite(f, args(i));
  }
  if (need_release) { _fwrite_unlock( f); }
}

def fwriteln(f: file, args ...?numArgs) {
  var need_release: bool = _fwrite_lock( f);
  fwrite(f, (...args));
  fwriteln(f);
  if (need_release) { _fwrite_unlock( f); }
}

def fwriteln(f: file) {
  var need_release: bool = _fwrite_lock( f);
  fwrite(f, "\n");
  if (need_release) { _fwrite_unlock( f); }
}

def write(args ...?numArgs) {
  fwrite(stdout, (...args));
}

def writeln(args ...?numArgs) {
  fwriteln(stdout, (...args));
}

def writeln() {
  fwriteln(stdout);
}

//
// Functions on _file primitive type, the C file pointer type
//

pragma "no codegen" var chpl_input_filename: string;
pragma "no codegen" var chpl_input_lineno: int;

pragma "inline" def _get_errno() return __primitive("get_errno");
pragma "inline" def _get_eof() return __primitive("get_eof");
pragma "inline" def _get_stdin() return __primitive("get_stdin");
pragma "inline" def _get_stdout() return __primitive("get_stdout");
pragma "inline" def _get_stderr() return __primitive("get_stderr");
pragma "inline" def _get_nullfile() return __primitive("get_nullfile");

pragma "inline" def _copy(x: _file) return x;
pragma "inline" def =(a: _file, b: _file) return b;
pragma "inline" def ==(a: _file, b: _file) return __primitive("==", a, b);
pragma "inline" def !=(a: _file, b: _file) return __primitive("!=", a, b);

pragma "inline" def _fopen(filename: string, mode: string)
  return __primitive("fopen", filename, mode);

pragma "inline" def _fclose(fp: _file)
  return __primitive("fclose", fp);

pragma "inline" def fprintf(fp: _file, fmt: string, val)
  return __primitive("fprintf", fp, fmt, val);

pragma "inline" def fscanf(fp: _file, fmt: string, inout val)
  return __primitive("fscanf", fp, fmt, val);

pragma "inline" def _string_fscanf(fp: _file)
  return __primitive("string_fscanf", fp);

pragma "inline" def _readLitChar(fp: _file, val: string, ignoreWhiteSpace: bool)
  return __primitive("readLit", fp, val, ignoreWhiteSpace);

pragma "rename _chpl_fflush"
def fflush(f: file) {
  fflush(f.fp);
}

pragma "rename _chpl_fflush_nil"
def fflush(f: _nilType) {
  halt("***Error: called fflush on nil***");
}

pragma "rename _chpl_assert_no_args"
def assert(test: bool) {
  if (!test) {
    _writeAssertFailed();
    if (!chpl_input_lineno) {
      fwriteln(stderr);
    }
    exit(0);
  }
}

pragma "rename _chpl_assert"
def assert(test: bool, args ...?numArgs) {
  if (!test) {
    _writeAssertFailed();
    if (!chpl_input_lineno) {
      fwrite(stderr, ": ");
    }
    for param i in 1..numArgs {
      fwrite(stderr, args(i));
    }
    fwriteln(stderr);
    exit(0);
  }
}

def _writeAssertFailed() {
  fflush(stdout);
  fwrite(stderr, "Assertion failed");
  if (chpl_input_lineno) {
    fwriteln(stderr, ": ", chpl_input_filename, ":", chpl_input_lineno);
  }
}

pragma "rename _chpl_halt_no_args"
def halt() {
  _writeHaltReached();
  if(!chpl_input_lineno) {
    fwriteln(stderr);
  }
  exit(0);
}

pragma "rename _chpl_halt"
def halt(args ...?numArgs) {
  _writeHaltReached();
  if (!chpl_input_lineno) {
    fwrite(stderr, ": ");
  }
  for param i in 1..numArgs {
    fwrite(stderr, args(i));
  }
  fwriteln(stderr);
  exit(0);
}

def _writeHaltReached() {
  fflush(stdout);
  fwrite(stderr, "Halt reached");
  if (chpl_input_lineno) {
    fwriteln(stderr, ": ", chpl_input_filename, ":", chpl_input_lineno);
  }
}

class file {
  var filename : string = "";
  var mode : string = "r";
  var path : string = ".";
  var fp : _file;
  var writeLock : sync uint(64);    // for serializing fwrite output

  def open {
    if (this == stdin || this == stdout || this == stderr) {
      halt("***Error: It is not necessary to open \"", filename, "\"***");
    }

    var fullFilename = path + "/" + filename;
    fp = _fopen(fullFilename, mode);

    if (fp == _get_nullfile()) {
      halt("***Error: Unable to open \"", fullFilename, "\": ",
           _get_errno(), "***");
    }
  }

  def _checkFileStateChangeLegality(state) {
    if (isOpen) {
      halt("Cannot change ", state, " of file ", path, "/", filename,
           " while it is open");
    }
  }

  def filename {
    return filename;
  }

  def =filename(newfilename) {
    _checkFileStateChangeLegality("filename");
    filename = newfilename;
  }

  def path {
    return path;
  }

  def =path(newpath) {
    _checkFileStateChangeLegality("path");
    path = newpath;
  }

  def mode {
    return mode;
  }

  def =mode(newmode: string) {
    _checkFileStateChangeLegality("mode");
    mode = newmode;
  }

  def isOpen: bool {
    var openStatus: bool = false;
    if (fp != _get_nullfile()) {
      openStatus = true;
    }
    return openStatus;
  }

  def close {
    if (this == stdin || this == stdout || this == stderr) {
      halt("***Error: You may not close \"", filename, "\"***");
    }
    if (fp == _get_nullfile()) {
      var fullFilename = path + "/" + filename;
      halt("***Error: Trying to close \"", fullFilename,
           "\" which isn't open***");
    }
    var returnVal: int = _fclose(fp);
    if (returnVal < 0) {
      var fullFilename = path + "/" + filename;
      halt("***Error: The close of \"", fullFilename, "\" failed: ",
           _get_errno(), "***");
    }
    fp = _get_nullfile();
  }
}

const stdin  = file("stdin", "r", "/dev", _get_stdin());
const stdout = file("stdout", "w", "/dev", _get_stdout());
const stderr = file("stderr", "w", "/dev", _get_stderr());

def _fopenError(f: file, isRead: bool) {
  var fullFilename:string = f.path + "/" + f.filename;
  if (isRead) {
    halt("***Error: You must open \"", fullFilename,
         "\" before trying to read from it***");
  } else {
    halt("***Error: You must open \"", fullFilename,
         "\" before trying to write to it***");
  }
}

def _fmodeError(f: file, isRead: bool) {
  var fullFilename: string = f.path + "/" + f.filename;
  var modestring = if (isRead) then "reading" else "writing";
  halt("***Error: ", fullFilename, " not open for ", modestring, "***");
}

def _fprintfError() {
  halt("***Error: Write failed: ", _get_errno(), "***");
}

def _fscanfError() {
  halt("***Error: Read failed: ", _get_errno(), "***");
}

pragma "rename _chpl_fread_int"
def fread(f: file = stdin, inout val: int) {
  if (f.isOpen) {
    var returnVal: int = fscanf(f.fp, "%d", val);
    if (returnVal == _get_eof()) {
      halt("***Error: Read failed: EOF***");
    }
    if (returnVal < 0) {
      _fscanfError();
    } else if (returnVal == 0) {
      halt("***Error: No int was read***");
    }
  } else {
    _fopenError(f, isRead = true);
  }
}

def _fwrite_lock( f: file) {
  var me: uint(64) = __primitive( "thread_id");
  if (isFull( f.writeLock)) {
    if (readXX( f.writeLock) == me) {
      return false;
    }
  }
  f.writeLock = me;
  return true;
}

def _fwrite_unlock( f: file) {
  writeFE( f.writeLock, 0);  // writeXE works also as it should be full before
}

pragma "rename _chpl_fread_uint"
def fread(f: file = stdin, inout val: uint) {
  if (f.isOpen) {
    var returnVal: int = fscanf(f.fp, "%llu", val);
    if (returnVal == _get_eof()) {
      halt("***Error: Read failed: EOF***");
    }
    if (returnVal < 0) {
      _fscanfError();
    } else if (returnVal == 0) {
      halt("***Error: No int was read***");
    }
  } else {
    _fopenError(f, isRead = true);
  }
}

pragma "rename _chpl_fread_real"
def fread(f: file = stdin, inout val: real) {
  if (f.isOpen) {
    var returnVal: int = fscanf(f.fp, "%lg", val);
    if (returnVal == _get_eof()) {
      halt("***Error: Read failed: EOF***");
    }
    if (returnVal < 0) {
      _fscanfError();
    } else if (returnVal == 0) {
      halt("***Error: No real was read***");
    }
  } else {
    _fopenError(f, isRead = true);
  }
}

pragma "rename _chpl_fread_complex"
def fread(f: file = stdin, inout val: complex) {
  var realPart: real;
  var imagPart: real;
  var imagI: string;
  var matchingCharWasRead: int;
  var isNeg: bool;

  fread(f, realPart);
  matchingCharWasRead = _readLitChar(f.fp, "+", true);
  if (matchingCharWasRead != 1) {
    matchingCharWasRead = _readLitChar(f.fp, "-", true);
    if (matchingCharWasRead != 1) {
      halt("***Error: Incorrect format for complex numbers***");
    }
    isNeg = true;
  }

  fread(f, imagPart);
  matchingCharWasRead = _readLitChar(f.fp, "i", false);
  if (matchingCharWasRead != 1) {
    halt("***Error: Incorrect format for complex numbers***");
  }

  val.re = realPart;
  if (isNeg) {
    val.im = -imagPart;
  } else {
    val.im = imagPart;
  }
}

pragma "rename _chpl_fread_string"
def fread(f: file = stdin, inout val: string) {
  if (f.isOpen) {
    val = _string_fscanf(f.fp);
  } else {
    _fopenError(f, isRead = true);
  }
}

pragma "rename _chpl_fread_bool"
def fread(f: file = stdin, inout val: bool) {
  if (f.isOpen) {
    var valString : string = _string_fscanf(f.fp);
    if (valString == "true") {
      val = true;
    } else if (valString == "false") {
      val = false;
    } else {
      halt("***Error: Not of bool type***");
    }
  } else {
    _fopenError(f, isRead = true);
  }
}

pragma "rename _chpl_fwrite_string"
def fwrite(f: file, val: string) {
  var need_release: bool = _fwrite_lock( f);

  if (!f.isOpen) {
    _fopenError(f, isRead = false);
  }
  if (f.mode != "w") {
    _fmodeError(f, isRead = false);
  }
  var returnVal = fprintf(f.fp, "%s", val);
  if (returnVal < 0) {
    _fprintfError();
  }

  if (need_release) { _fwrite_unlock( f); }
}

pragma "rename _chpl_fwrite_nil"
def fwrite(f: file, x : _nilType) : void {
  var need_release: bool = _fwrite_lock( f);

  if (f.isOpen) {
    var returnVal: int = fprintf(f.fp, "%s", "nil");
    if (returnVal < 0) {
      _fprintfError();
    } else if (returnVal == 0) {
      halt("*** Error: No value was written***");
    }
  } else {
    _fopenError(f, isRead = false);
  }
  if (need_release) { _fwrite_unlock( f); }
}

def fwrite(f: file, args ...?numArgs) {
  var need_release: bool = _fwrite_lock( f);
  for param i in 1..numArgs {
    fwrite(f, args(i));
  }
  if (need_release) { _fwrite_unlock( f); }
}

def fwriteln(f: file, args ...?numArgs) {
  var need_release: bool = _fwrite_lock( f);
  fwrite(f, (...args));
  fwriteln(f);
  if (need_release) { _fwrite_unlock( f); }
}

def fwriteln(f: file) {
  var need_release: bool = _fwrite_lock( f);
  fwrite(f, "\n");
  if (need_release) { _fwrite_unlock( f); }
}

def write(args ...?numArgs) {
  fwrite(stdout, (...args));
}

def writeln(args ...?numArgs) {
  fwriteln(stdout, (...args));
}

def writeln() {
  fwriteln(stdout);
}


Revert "Revert "Revert "temporarily break hello.chpl test to verify travis prints start_test log"""

This reverts commit e16e184a857fd03743a7d474da5b9ea2ce04f44d.

writeln("Hello, world!");    // print 'Hello, world!' to the console

writeln("Hello, world!!!");    // print 'Hello, world!' to the console


ChapelRoot is now the parent of every top-level module

/*
 * Copyright 2004-2015 Cray Inc.
 * Other additional copyright holders may be indicated within.
 *
 * The entirety of this work is licensed under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 *
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// ChapelBase.chpl
//

module ChapelBase
{
  //
  // Assignment operators
  //
  inline proc =  (ref a : bool, b : bool) : void { __primitive("=", a, b); }
  inline proc =  (ref a : int,  b : int ) : void { __primitive("=", a, b); }
  inline proc =  (ref a : real, b : real) : void { __primitive("=", a, b); }

  //
  // Basic unary arithmetic operators
  //

  inline proc + (a : int ) : int  return a;
  inline proc + (a : real) : real return a;

  inline proc - (a : int ) : int  return __primitive("u-", a);
  inline proc - (a : real) : real return __primitive("u-", a);

  //
  // Basic binary arithmetic operators
  //
  inline proc +  (    a : int,  b : int ) : int  return __primitive("+",  a, b);
  inline proc -  (    a : int,  b : int ) : int  return __primitive("-",  a, b);
  inline proc *  (    a : int,  b : int ) : int  return __primitive("*",  a, b);
  inline proc /  (    a : int,  b : int ) : int  return __primitive("/",  a, b);

  inline proc +  (    a : real, b : real) : real return __primitive("+",  a, b);
  inline proc -  (    a : real, b : real) : real return __primitive("-",  a, b);
  inline proc *  (    a : real, b : real) : real return __primitive("*",  a, b);
  inline proc /  (    a : real, b : real) : real return __primitive("/",  a, b);

  //
  // Equality comparison on primitive types
  //
  inline proc == (    a : bool, b : bool) : bool return __primitive("==", a, b);
  inline proc == (    a : int,  b : int ) : bool return __primitive("==", a, b);
  inline proc == (    a : real, b : real) : bool return __primitive("==", a, b);

  inline proc != (    a : bool, b : bool) : bool return __primitive("!=", a, b);
  inline proc != (    a : int,  b : int ) : bool return __primitive("!=", a, b);
  inline proc != (    a : real, b : real) : bool return __primitive("!=", a, b);

  //
  // Ordered comparison on primitive types
  //
  inline proc <  (    a : int,  b : int ) : bool return __primitive("<",  a, b);
  inline proc <  (    a : real, b : real) : bool return __primitive("<",  a, b);

  inline proc >  (    a : int,  b : int ) : bool return __primitive(">",  a, b);
  inline proc >  (    a : real, b : real) : bool return __primitive(">",  a, b);

  inline proc <= (    a : int,  b : int ) : bool return __primitive("<=", a, b);
  inline proc <= (    a : real, b : real) : bool return __primitive("<=", a, b);

  inline proc >= (    a : int,  b : int ) : bool return __primitive(">=", a, b);
  inline proc >= (    a : real, b : real) : bool return __primitive(">=", a, b);

  //
  // Absolute value
  //

  proc abs(a : int) : int
  {
    var retval : int  = a;

    if (a < 0) then
      retval = 0 - a;

    return retval;
  }

  proc abs(a : real) : real
  {
    var retval : real = a;

    if (a < 0.0) then
      retval = 0.0 - a;

    return retval;
  }

  //
  // Support for implicit boolean conversion for conditional expressions
  //
  inline proc _cond_test(x : bool) : bool return x;
  inline proc _cond_test(x : int ) : bool return x != 0;

  //
  // These are implemented within the interpreter
  //

  extern proc print(x : bool)                      : void;
  extern proc print(x : int)                       : void;
  extern proc print(x : real)                      : void;
  extern proc print(x : c_string)                  : void;

  extern proc writeln(format : c_string)           : void;

  extern proc writeln(format : c_string, x : bool) : void;
  extern proc writeln(format : c_string, x : int)  : void;
  extern proc writeln(format : c_string, x : real) : void;

  extern proc quit()                               : void;
}

/*
 * Copyright 2004-2015 Cray Inc.
 * Other additional copyright holders may be indicated within.
 *
 * The entirety of this work is licensed under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 *
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// ChapelBase.chpl
//

module ChapelBase
{
  use ChapelRoot;

  //
  // Assignment operators
  //
  inline proc =  (ref a : bool, b : bool) : void { __primitive("=", a, b); }
  inline proc =  (ref a : int,  b : int ) : void { __primitive("=", a, b); }
  inline proc =  (ref a : real, b : real) : void { __primitive("=", a, b); }

  //
  // Basic unary arithmetic operators
  //

  inline proc + (a : int ) : int  return a;
  inline proc + (a : real) : real return a;

  inline proc - (a : int ) : int  return __primitive("u-", a);
  inline proc - (a : real) : real return __primitive("u-", a);

  //
  // Basic binary arithmetic operators
  //
  inline proc +  (    a : int,  b : int ) : int  return __primitive("+",  a, b);
  inline proc -  (    a : int,  b : int ) : int  return __primitive("-",  a, b);
  inline proc *  (    a : int,  b : int ) : int  return __primitive("*",  a, b);
  inline proc /  (    a : int,  b : int ) : int  return __primitive("/",  a, b);

  inline proc +  (    a : real, b : real) : real return __primitive("+",  a, b);
  inline proc -  (    a : real, b : real) : real return __primitive("-",  a, b);
  inline proc *  (    a : real, b : real) : real return __primitive("*",  a, b);
  inline proc /  (    a : real, b : real) : real return __primitive("/",  a, b);

  //
  // Equality comparison on primitive types
  //
  inline proc == (    a : bool, b : bool) : bool return __primitive("==", a, b);
  inline proc == (    a : int,  b : int ) : bool return __primitive("==", a, b);
  inline proc == (    a : real, b : real) : bool return __primitive("==", a, b);

  inline proc != (    a : bool, b : bool) : bool return __primitive("!=", a, b);
  inline proc != (    a : int,  b : int ) : bool return __primitive("!=", a, b);
  inline proc != (    a : real, b : real) : bool return __primitive("!=", a, b);

  //
  // Ordered comparison on primitive types
  //
  inline proc <  (    a : int,  b : int ) : bool return __primitive("<",  a, b);
  inline proc <  (    a : real, b : real) : bool return __primitive("<",  a, b);

  inline proc >  (    a : int,  b : int ) : bool return __primitive(">",  a, b);
  inline proc >  (    a : real, b : real) : bool return __primitive(">",  a, b);

  inline proc <= (    a : int,  b : int ) : bool return __primitive("<=", a, b);
  inline proc <= (    a : real, b : real) : bool return __primitive("<=", a, b);

  inline proc >= (    a : int,  b : int ) : bool return __primitive(">=", a, b);
  inline proc >= (    a : real, b : real) : bool return __primitive(">=", a, b);

  //
  // Absolute value
  //

  proc abs(a : int) : int
  {
    var retval : int = a;

    if (a < 0) then
      retval = 0 - a;

    return retval;
  }

  proc abs(a : real) : real
  {
    var retval : real = a;

    if (a < 0.0) then
      retval = 0.0 - a;

    return retval;
  }

  //
  // Support for implicit boolean conversion for conditional expressions
  //
  inline proc _cond_test(x : bool) : bool return x;
  inline proc _cond_test(x : int ) : bool return x != 0;

  //
  // These are implemented within the interpreter
  //

  extern proc print(x : bool)                      : void;
  extern proc print(x : int)                       : void;
  extern proc print(x : real)                      : void;
  extern proc print(x : c_string)                  : void;

  extern proc writeln(format : c_string)           : void;

  extern proc writeln(format : c_string, x : bool) : void;
  extern proc writeln(format : c_string, x : int)  : void;
  extern proc writeln(format : c_string, x : real) : void;

  extern proc quit()                               : void;
}