/*=======================================================
* ReturnCommand.java
*
* "A Tcl like language implementation in Java named APWTCL
* ((Java) Arnulf's Preferred Web Tcl)"
*
* APWTCL ReturnCommand class
*
* Released under same BSD license as Tcl.
* (Tcl BSD license found at <http://www.tcl.tk/software/tcltk/license.html>)
*
* Copyright 2012 Arnulf P. Wiedemann
*
*/
package org.apwtcl.lang.cmd;
import java.util.ArrayList;
import org.apwtcl.lang.Interp;
import org.apwtcl.lang.ApwtclObj;
import org.apwtcl.lang.Token;
import org.apwtcl.lang.Variable;
public class ReturnCommand extends Token {
/* ==================== ReturnCommand ================================== */
public ReturnCommand() {
}
/* ==================== returnCmd ================================== */
public int returnCmd(Interp interp, ArrayList<ApwtclObj> args) {
//print("return called!"+args+"!");
String errorcode = null;
String errorinfo = null;
int level = 1;
int return_code = OK;
// var options = null;
// var stack_trace_obj = null;
// var error_code_obj = null;
// var result = new Array();
// var r = "";
// var option_flags = new Array();
// var options = new Array();
// var error_msg = new Array();
// var processed_args = new Array();
// interp.eval_statement.code = RETURN;
// if (args.size == 1) {
// /* seems to be a return value only */
// r = args.get(1);
// }
// if (interp.getCallOptions(core_cmd.return_options, args.slice(1), "return", option_flags, options, error_msg, processed_args) != interp.OK) {
// interp.setResultString(error_msg[0]);
// return interp.ERROR;
// }
// processed_args = processed_args[0];
// option_flags = option_flags[0];
// options = options[0];
// if (args.length - processed_args > 2) {
// interp.setResultString("usage: return ?option value ...? ?result?");
// return interp.ERROR;
// }
/* take care of command as args[0] */
// processed_args++;
// if (option_flags & core_cmd.return_options.RETURN_OPT_ERRORCODE) {
// error_code_obj = options["-errorcode"] ;
// throw "return -errorcode not yet implemented"
// }
// if (option_flags & core_cmd.return_options.RETURN_OPT_CODE) {
// code = options["-code"];
// if (interp.return_code_obj_type.getReturnCode(code, result) == interp.ERROR) {
// return interp.ERROR;
// }
// return_code = result[0];
// }
// if (option_flags & core_cmd.return_options.RETURN_OPT_ERRORINFO) {
// error_info_obj = options["-errorinfo"] ;
// }
// if (option_flags & core_cmd.return_options.RETURN_OPT_LEVEL) {
// var level_obj = options["-level"];
//
// level = new Array();
// if (interp.int_obj_type.getLong(level_obj, level) != interp.OK || level[0] < 0) {
// interp.setResultFormatted("bad level \"%#s\"", level_obj);
// return interp.ERROR;
// }
// }
// if (option_flags & core_cmd.return_options.RETURN_OPT_OPTIONS) {
// options = options["-options"];
// interp.setResultString("return -options not yet implemented");
// return interp.ERROR;
// }
// if (processed_args != args.length - 1 && processed_args != args.length) {
// interp.wrongNumArgs(1, args, "?-code code? ?-errorinfo stacktrace? ?-level level? ?result?");
// return interp.ERROR;
// }
/* If a stack trace is supplied and code is error, set the stack trace */
// if (stack_trace_obj && return_code == interp.ERROR) {
// interp.setStackTrace(stack_trace_obj);
// }
// /* If an error code list is supplied, set the global $errorCode */
// if (error_code_obj && return_code == interp.ERROR) {
// interp.variable_obj_type.setGlobalVariableStr("errorCode", error_code_obj);
// }
// interp.return_code = return_code;
// interp.return_level = level;
// if (processed_args == args.length - 1) {
// interp.setResult(args[processed_args]);
// }
// FIXME!!!
interp.setResult(args.get(1));
return RETURN;
}
}