File: SType.cs

package info (click to toggle)
bearssl 0.6%2Bdfsg.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,484 kB
  • sloc: ansic: 49,044; cs: 3,473; sh: 524; makefile: 40
file content (129 lines) | stat: -rw-r--r-- 2,422 bytes parent folder | download | duplicates (3)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;

/*
 * This structure contains the stack effect of a word: number of stack
 * element consumed on input, and number of stack element produced on
 * output.
 */

struct SType {

	/*
	 * Get number of stack elements consumed on input; this is -1 if
	 * the stack effect is not known.
	 */
	internal int DataIn {
		get {
			return din;
		}
	}

	/*
	 * Get number of stack elements produced on output; this is -1 if
	 * either the stack effect is not known, or if the word never
	 * exits.
	 */
	internal int DataOut {
		get {
			return dout;
		}
	}

	/*
	 * Tell whether the stack effect is known.
	 */
	internal bool IsKnown {
		get {
			return din >= 0;
		}
	}

	/*
	 * Tell whether the stack effect is known and the word never exits.
	 */
	internal bool NoExit {
		get {
			return din >= 0 && dout < 0;
		}
	}

	int din, dout;

	internal SType(int din, int dout)
	{
		if (din < 0) {
			din = -1;
		}
		if (dout < 0) {
			dout = -1;
		}
		this.din = din;
		this.dout = dout;
	}

	/*
	 * Special value for the unknown stack effect.
	 */
	internal static SType UNKNOWN = new SType(-1, -1);

	/*
	 * Constant for the "blank stack effect".
	 */
	internal static SType BLANK = new SType(0, 0);

	public static bool operator ==(SType s1, SType s2)
	{
		return s1.din == s2.din && s1.dout == s2.dout;
	}

	public static bool operator !=(SType s1, SType s2)
	{
		return s1.din != s2.din || s1.dout != s2.dout;
	}

	public override bool Equals(Object obj)
	{
		return (obj is SType) && ((SType)obj == this);
	}

	public override int GetHashCode()
	{
		return din * 31 + dout * 17;
	}

	public override string ToString()
	{
		if (!IsKnown) {
			return "UNKNOWN";
		} else if (NoExit) {
			return string.Format("in:{0},noexit", din);
		} else {
			return string.Format("in:{0},out:{1}", din, dout);
		}
	}

	/*
	 * Test whether this stack effect is a sub-effect of the provided
	 * stack effect s. Stack effect s1 is a sub-effect of stack-effect
	 * s2 if any of the following holds:
	 * -- s1 and s2 are known, s1.din <= s2.din and s1 does not exit.
	 * -- s1 and s2 are known, s1.din <= s2.din, s1 and s2 exit,
	 *    and s1.din - s1.dout == s2.din - s2.dout.
	 */
	internal bool IsSubOf(SType s)
	{
		if (!IsKnown || !s.IsKnown) {
			return false;
		}
		if (din > s.din) {
			return false;
		}
		if (NoExit) {
			return true;
		}
		if (s.NoExit) {
			return false;
		}
		return (din - dout) == (s.din - s.dout);
	}
}