APWTCL Arnulf's Preferred Web Tcl

Check-in [ccfcb18356]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:initial version
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ccfcb18356d8e192e31297950716e89638960152
User & Date: arnulf 2012-04-15 10:32:08
Context
2012-04-15
14:12
fixes. t1.test - t77.test now running successfully check-in: 3d37e8df8c user: arnulf tags: trunk
10:32
initial version check-in: ccfcb18356 user: arnulf tags: trunk
10:31
fixes. First simple itcl class body parsed successfully. check-in: 0ed9289030 user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added src/org/apwtcl/lang/cmd/UnknownCommand.java.











































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*=======================================================
 * UnknownCommand.java 
 *
 * "A Tcl like language implementation in Java named APWTCL
 * ((Java) Arnulf's Preferred Web Tcl)"
 *
 * APWTCL UnknownCommand 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 UnknownCommand extends Token {

  /* ==================== UnknownCommand ================================== */
  public UnknownCommand() {
  }

  /* ==================== unknownCmd ================================== */
  public int unknownCmd(Interp interp, ArrayList<ApwtclObj> args) {
print("unknown called!"+args+"!");
    interp.setResultString("no such command: \""+args.get(1)+"\"");
    return ERROR;
  }

}

Added src/org/apwtcl/lang/cmd/UplevelCommand.java.























































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*=======================================================
 * UplevelCommand.java 
 *
 * "A Tcl like language implementation in Java named APWTCL
 * ((Java) Arnulf's Preferred Web Tcl)"
 *
 * APWTCL UplevelCommand 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.CallFrame;
import org.apwtcl.lang.Command;
import org.apwtcl.lang.Interp;
import org.apwtcl.lang.ApwtclObj;
import org.apwtcl.lang.Token;

public class UplevelCommand extends Token {

  /* ==================== UplevelCommand ================================== */
  public UplevelCommand() {
  }

  /* ==================== uplevelCmd ================================== */
  public int uplevelCmd(Interp interp, ArrayList<ApwtclObj> args) {
//print("uplevel called!"+args+"!");
    if (args.size() >= 2) {
      int retcode;
      CallFrame saved_call_frame;
      CallFrame saved_var_call_frame;
      CallFrame target_call_frame;
      String str;
      int argc = args.size();
      int i = 1;

      /* Save the old call_frame pointer */
      saved_call_frame = interp.frame_ptr;
      saved_var_call_frame = interp.var_frame_ptr;
      /* Lookup the target frame pointer */
      str = args.get(1).getString();
      if ((str.charAt(0) >= '0' && str.charAt(0) <= '9') || str.charAt(0) == '#') {
        target_call_frame = interp.getCallFrameByLevel(args.get(i));
        argc--;
        i++;
      } else {
        target_call_frame = interp.getCallFrameByLevel(null);
      }
      if (target_call_frame == null) {
        return ERROR;
      }
      if (argc < 2) {
        i--;
        interp.wrongNumArgs(1, args, "?level? command ?arg ...?");
        return ERROR;
      }
      /* Eval the code in the target call_frame. */
      interp.frame_ptr = target_call_frame;
      interp.var_frame_ptr = target_call_frame;
      if (argc == 2) {
//print("cc!"+args.get(i)+"!"+target_call_frame.toDebugString()+"!");
        retcode = interp.eval_statement.evalObj(args.get(i));
      } else {
        /* cannot use evalObjVector() as that makes problems with ensemble commands!! */
        int k = i;
        ArrayList<ApwtclObj> my_args2 = new ArrayList<ApwtclObj>();
        for (; k < args.size(); k++) {
          my_args2.add(args.get(k));
        }
        ApwtclObj my_obj_ptr = interp.default_obj.concatObj(my_args2.size(), my_args2);
        my_obj_ptr.incrRefCount("I_PKG_CORECMD_5");
        retcode = interp.eval_statement.evalObj(my_obj_ptr);
        my_obj_ptr.decrRefCount("D_PKG_CORE_CMD_6");
      }
      interp.var_frame_ptr = saved_var_call_frame;
      interp.frame_ptr = saved_call_frame;
      return retcode;
    } else {
      interp.wrongNumArgs(1, args, "?level? command ?arg ...?");
      return ERROR;
    }
  }

}

Added src/org/apwtcl/lang/cmd/UpvarCommand.java.































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*=======================================================
 * UpvarCommand.java 
 *
 * "A Tcl like language implementation in Java named APWTCL
 * ((Java) Arnulf's Preferred Web Tcl)"
 *
 * APWTCL UpvarCommand 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.CallFrame;
import org.apwtcl.lang.Interp;
import org.apwtcl.lang.ApwtclObj;
import org.apwtcl.lang.Token;
import org.apwtcl.lang.Variable;

public class UpvarCommand extends Token {

  /* ==================== UpvarCommand ================================== */
  public UpvarCommand() {
  }

  /* ==================== upvarCmd ================================== */
  public int upvarCmd(Interp interp, ArrayList<ApwtclObj> args) {
print("upvar called!"+args+"!");
    int i;
    CallFrame target_call_frame;
    int idx = 1;

    /* Lookup the target frame pointer */
    if (args.size() > 3 && (args.size() % 2 == 0)) {
      target_call_frame = interp.getCallFrameByLevel(args.get(idx));
      idx++;
    } else {
      target_call_frame = interp.getCallFrameByLevel(null);
    }
    if (target_call_frame == null) {
      return ERROR;
    }
    /* Check for arity */
    if (idx < args.size() - 2) {
      interp.wrongNumArgs(1, args, "?level? otherVar localVar ?otherVar localVar ...?");
      return ERROR;
    }
    /* Now... for every other/local couple: */
    for (i = idx; i < args.size(); i += 2) {
      if (interp.variable_obj_type.setVariableLink(args.get(i + 1), args.get(i), target_call_frame) != OK) {
        return ERROR;
      }
    }
    return OK;
  }

}