DEADSOFTWARE

e1105c0aa3abd3c9fb3c5efe2253550300cf7bb5
[dsw-obn.git] / rtl / java / SYSTEM.java
1 import java.lang.Math;
3 public class SYSTEM
4 {
5 /* Каркас для фреймов процедур */
6 public static abstract class FRAME
7 {
8 public FRAME up;
9 }
11 /* Длинна строки LEN(s$) */
12 public static int LEN(byte[] x)
13 {
14 int i = 0;
15 while(x[i] != 0)
16 {
17 i += 1;
18 }
19 return i;
20 }
22 public static String STRING(byte[] x)
23 {
24 return new String(x, 0, LEN(x));
25 }
27 public static void COPY(byte[] x, byte[] v)
28 {
29 int ix = LEN(x);
30 int iv = v.length - 1;
32 int i = 0;
33 int len = (ix < iv) ? (ix) : (iv);
34 while(i < len)
35 {
36 v[i] = x[i];
37 i += 1;
38 }
39 v[i] = 0;
40 }
42 public static void COPY(String x, byte[] v)
43 {
44 COPY(x.getBytes(), v);
45 }
47 public static int STRCMP(byte[] a, byte[] b)
48 {
49 int i = 0;
50 while(a[i] != 0 && a[i] == b[i])
51 {
52 i += 1;
53 }
54 return a[i] - b[i];
55 }
57 public static void HALT(long n)
58 {
59 System.exit((int) n);
60 }
62 public static void ASSERT(boolean x)
63 {
64 assert x;
65 }
67 public static void ASSERT(boolean x, long n)
68 {
69 assert x : n;
70 }
72 public static void TRAP(long n)
73 {
74 if(n == -1)
75 {
76 throw new RuntimeException("CASE TRAP");
77 }
78 else if(n == -2)
79 {
80 throw new RuntimeException("WITH TRAP");
81 }
82 else if(n == -3)
83 {
84 throw new RuntimeException("NOT IMPLEMENTED");
85 }
86 else if(n == -4)
87 {
88 throw new RuntimeException("RETURN TRAP");
89 }
90 else
91 {
92 throw new RuntimeException("TRAP CODE " + n);
93 }
94 }
96 public static int ASH(int x, int n)
97 {
98 return (n > 0) ? (x << n) : (x >> Math.abs(n));
99 }
101 public static long ASH(long x, long n)
103 return (n > 0) ? (x << n) : (x >> Math.abs(n));
106 public static int LSH(int x, int n)
108 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
111 public static long LSH(long x, long n)
113 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
116 public static int ROT(int x, int n)
118 if(n > 0)
120 return (x << n) | (x >>> (Integer.SIZE - n));
122 else
124 n = Math.abs(n);
125 return (x >>> n) | (x << (Integer.SIZE - n));
129 public static long ROT(long x, long n)
131 if(n > 0)
133 return (x << n) | (x >>> (Long.SIZE - n));
135 else
137 n = Math.abs(n);
138 return (x >>> n) | (x << (Long.SIZE - n));