DEADSOFTWARE

20cbe60f2115f1167d1076d32f81b2f7a3040386
[dsw-obn.git] / rtl / java / SYSTEM.java
1 public class SYSTEM
2 {
3 /* Каркас для фреймов процедур */
4 public static abstract class FRAME
5 {
6 public FRAME up;
7 }
9 /* Длинна строки LEN(s$) */
10 public static int LEN(byte[] x)
11 {
12 int i = 0;
13 while(x[i] != 0)
14 {
15 i += 1;
16 }
17 return i;
18 }
20 public static String STRING(byte[] x)
21 {
22 return new String(x, 0, LEN(x));
23 }
25 public static void COPY(byte[] x, byte[] v)
26 {
27 int ix = LEN(x);
28 int iv = v.length - 1;
30 int i = 0;
31 int len = (ix < iv) ? (ix) : (iv);
32 while(i < len)
33 {
34 v[i] = x[i];
35 i += 1;
36 }
37 v[i] = 0;
38 }
40 public static int STRCMP(byte[] a, byte[] b)
41 {
42 int i = 0;
43 while(a[i] != 0 && a[i] == b[i])
44 {
45 i += 1;
46 }
47 return a[i] - b[i];
48 }
50 public static void HALT(long n)
51 {
52 System.exit((int) n);
53 }
55 public static void ASSERT(boolean x)
56 {
57 assert x;
58 }
60 public static void ASSERT(boolean x, long n)
61 {
62 assert x : n;
63 }
65 public static void TRAP(long n)
66 {
67 if(n == -1)
68 {
69 throw new RuntimeException("CASE TRAP");
70 }
71 else if(n == -2)
72 {
73 throw new RuntimeException("WITH TRAP");
74 }
75 else if(n == -3)
76 {
77 throw new RuntimeException("NOT IMPLEMENTED");
78 }
79 else
80 {
81 throw new RuntimeException("TRAP CODE " + n);
82 }
83 }
85 public static int ASH(int x, int n)
86 {
87 return (n > 0) ? (x << n) : (x >> Math.abs(n));
88 }
90 public static long ASH(long x, long n)
91 {
92 return (n > 0) ? (x << n) : (x >> Math.abs(n));
93 }
95 public static int LSH(int x, int n)
96 {
97 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
98 }
100 public static long LSH(long x, long n)
102 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
105 public static int ROT(int x, int n)
107 if(n > 0)
109 return (x << n) | (x >>> (Integer.SIZE - n));
111 else
113 n = Math.abs(n);
114 return (x >>> n) | (x << (Integer.SIZE - n));
118 public static long ROT(long x, long n)
120 if(n > 0)
122 return (x << n) | (x >>> (Long.SIZE - n));
124 else
126 n = Math.abs(n);
127 return (x >>> n) | (x << (Long.SIZE - n));