DEADSOFTWARE

Добавлены модули Math MathL CPMath CPStrings
[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 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 }
52 public static void HALT(long n)
53 {
54 System.exit((int) n);
55 }
57 public static void ASSERT(boolean x)
58 {
59 assert x;
60 }
62 public static void ASSERT(boolean x, long n)
63 {
64 assert x : n;
65 }
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 }
91 public static int ASH(int x, int n)
92 {
93 return (n > 0) ? (x << n) : (x >> Math.abs(n));
94 }
96 public static long ASH(long x, long n)
97 {
98 return (n > 0) ? (x << n) : (x >> Math.abs(n));
99 }
101 public static int LSH(int x, int n)
103 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
106 public static long LSH(long x, long n)
108 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
111 public static int ROT(int x, int n)
113 if(n > 0)
115 return (x << n) | (x >>> (Integer.SIZE - n));
117 else
119 n = Math.abs(n);
120 return (x >>> n) | (x << (Integer.SIZE - n));
124 public static long ROT(long x, long n)
126 if(n > 0)
128 return (x << n) | (x >>> (Long.SIZE - n));
130 else
132 n = Math.abs(n);
133 return (x >>> n) | (x << (Long.SIZE - n));