DEADSOFTWARE

d3e1ae2e013e14d4fa67dd37104805b6922b36c5
[dsw-obn.git] / rtl / java / SYSTEM.java
1 import java.lang.Math;
2
3 public class SYSTEM
4 {
5 /* Каркас для фреймов процедур */
6 public static abstract class FRAME
7 {
8 public FRAME up;
9 }
10
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 }
21
22 public static String STRING(byte[] x)
23 {
24 return new String(x, 0, LEN(x));
25 }
26
27 public static void COPY(byte[] x, byte[] v)
28 {
29 int ix = LEN(x);
30 int iv = v.length - 1;
31
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 }
41
42 public static int STRCMP(byte[] a, byte[] b)
43 {
44 int i = 0;
45 while(a[i] != 0 && a[i] == b[i])
46 {
47 i += 1;
48 }
49 return a[i] - b[i];
50 }
51
52 public static void HALT(long n)
53 {
54 System.exit((int) n);
55 }
56
57 public static void ASSERT(boolean x)
58 {
59 assert x;
60 }
61
62 public static void ASSERT(boolean x, long n)
63 {
64 assert x : n;
65 }
66
67 public static void TRAP(long n)
68 {
69 if(n == -1)
70 {
71 throw new RuntimeException("CASE TRAP");
72 }
73 else if(n == -2)
74 {
75 throw new RuntimeException("WITH TRAP");
76 }
77 else if(n == -3)
78 {
79 throw new RuntimeException("NOT IMPLEMENTED");
80 }
81 else if(n == -4)
82 {
83 throw new RuntimeException("RETURN TRAP");
84 }
85 else
86 {
87 throw new RuntimeException("TRAP CODE " + n);
88 }
89 }
90
91 public static int ASH(int x, int n)
92 {
93 return (n > 0) ? (x << n) : (x >> Math.abs(n));
94 }
95
96 public static long ASH(long x, long n)
97 {
98 return (n > 0) ? (x << n) : (x >> Math.abs(n));
99 }
100
101 public static int LSH(int x, int n)
102 {
103 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
104 }
105
106 public static long LSH(long x, long n)
107 {
108 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
109 }
110
111 public static int ROT(int x, int n)
112 {
113 if(n > 0)
114 {
115 return (x << n) | (x >>> (Integer.SIZE - n));
116 }
117 else
118 {
119 n = Math.abs(n);
120 return (x >>> n) | (x << (Integer.SIZE - n));
121 }
122 }
123
124 public static long ROT(long x, long n)
125 {
126 if(n > 0)
127 {
128 return (x << n) | (x >>> (Long.SIZE - n));
129 }
130 else
131 {
132 n = Math.abs(n);
133 return (x >>> n) | (x << (Long.SIZE - n));
134 }
135 }
136 }