DEADSOFTWARE

Исправлены переводы строк в модуле Reals
[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 int ix = x.length();
45 int iv = v.length - 1;
47 int i = 0;
48 int len = (ix < iv) ? (ix) : (iv);
49 while(i < len)
50 {
51 v[i] = (byte) x.charAt(i);
52 i += 1;
53 }
54 v[i] = 0;
55 }
57 public static int STRCMP(byte[] a, byte[] b)
58 {
59 int i = 0;
60 while(a[i] != 0 && a[i] == b[i])
61 {
62 i += 1;
63 }
64 return a[i] - b[i];
65 }
67 public static void HALT(long n)
68 {
69 System.exit((int) n);
70 }
72 public static void ASSERT(boolean x)
73 {
74 assert x;
75 }
77 public static void ASSERT(boolean x, long n)
78 {
79 assert x : n;
80 }
82 public static void TRAP(long n)
83 {
84 if(n == -1)
85 {
86 throw new RuntimeException("CASE TRAP");
87 }
88 else if(n == -2)
89 {
90 throw new RuntimeException("WITH TRAP");
91 }
92 else if(n == -3)
93 {
94 throw new RuntimeException("NOT IMPLEMENTED");
95 }
96 else if(n == -4)
97 {
98 throw new RuntimeException("RETURN TRAP");
99 }
100 else
102 throw new RuntimeException("TRAP CODE " + n);
106 public static int ASH(int x, int n)
108 return (n > 0) ? (x << n) : (x >> Math.abs(n));
111 public static long ASH(long x, long n)
113 return (n > 0) ? (x << n) : (x >> Math.abs(n));
116 public static int LSH(int x, int n)
118 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
121 public static long LSH(long x, long n)
123 return (n > 0) ? (x << n) : (x >>> Math.abs(n));
126 public static int ROT(int x, int n)
128 if(n > 0)
130 return (x << n) | (x >>> (Integer.SIZE - n));
132 else
134 n = Math.abs(n);
135 return (x >>> n) | (x << (Integer.SIZE - n));
139 public static long ROT(long x, long n)
141 if(n > 0)
143 return (x << n) | (x >>> (Long.SIZE - n));
145 else
147 n = Math.abs(n);
148 return (x >>> n) | (x << (Long.SIZE - n));