// (c) MIT 2003.  All rights reserved.

// -*-Mode: JDE-*- 
// $Id: LispObj.java,v 1.4 2003/03/06 00:40:49 moltmans Exp $
// LispObj.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Fri Jan 26 12:45:04 2001> 
// Time-stamp: <2001-02-28 14:48:24 moltmans> 
package rec.annotate.lisp;

import com.franz.jlinker.JavaLinkDist;
import com.franz.jlinker.TranStruct;

/**
 * LispObj.java
 *
 *
 * Created: Fri Jan 26 12:45:11 2001
 *
 * @author <a href="mailto:moltmans@ai.mit.edu">Michael Oltmans</a>
 * @version
 */

public class LispObj {
  public static LispObj VOID = new LispObj("VOID");
  private TranStruct m_obj;

  public static LispObj makeResult(TranStruct[] r) {
    if (JavaLinkDist.errorP(r[0])) {
      System.out.println("Cannot make LispObj from an error");
      return null;
    } // end of if ()

    int nParams = JavaLinkDist.intValue(r[0]);
    if (nParams == 0) {
      return VOID;
    } // end of if ()
    
    if (nParams != 1) {
      System.out.println("Cannot make a LispObj with multivalue returns");
    } // end of if ()
    
    return new LispObj(r[1]);
  }

  public TranStruct getTranStruct() 
  {
    return m_obj;
  }
  
  public LispObj(int x) 
  {
    this(JavaLinkDist.newDistOb(x));
  }
  public LispObj(String x) 
  {
    this(JavaLinkDist.newDistOb(x));
  }
  public LispObj(double x) 
  {
    this(JavaLinkDist.newDistOb(x));
  }
  public LispObj(TranStruct obj) 
  {
    m_obj = obj;
  }

  public boolean isNonNil() 
  {
    return !JavaLinkDist.nullP(m_obj);
  }

  public String getStringValue()
  {
    if (!JavaLinkDist.stringP(m_obj)) {
      return null;
    }
    return JavaLinkDist.stringValue(m_obj);
  }

  public String toString() {
    return toString(m_obj);
  }

  public static String toString(TranStruct obj) {
    if (JavaLinkDist.stringP(obj) || JavaLinkDist.errorP(obj)) {
      return JavaLinkDist.stringValue(obj);
    }
    else if (JavaLinkDist.integerP(obj)) {
      return String.valueOf(JavaLinkDist.intValue(obj));
    }
    else if (JavaLinkDist.realP(obj)) {
      return String.valueOf(JavaLinkDist.doubleValue(obj));
    }
    else if (JavaLinkDist.realP(obj)) {
      return String.valueOf(JavaLinkDist.doubleValue(obj));
    }
    else if (JavaLinkDist.pointerP(obj)) {
      return JavaLinkDist.stringValue(obj);
    }
    else {
      return "unhandled type: " + obj;
    } // end of else
  }

  //  public static List parseList(String list) 
  //  {
    
  


    
}// LispObj
