X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=rtl%2FSYSTEM.java;h=20cbe60f2115f1167d1076d32f81b2f7a3040386;hb=f226da0f861c2dbf26d3851fbe47794b21a92a25;hp=f98236bd90926eeb0ca4d8dd58c46e190e43cd8e;hpb=9f8036eb00032fa7f756113365cb42e05ab262df;p=dsw-obn.git diff --git a/rtl/SYSTEM.java b/rtl/SYSTEM.java index f98236b..20cbe60 100644 --- a/rtl/SYSTEM.java +++ b/rtl/SYSTEM.java @@ -17,17 +17,34 @@ public class SYSTEM return i; } - /* Встроенная процедура COPY(x, v) */ + public static String STRING(byte[] x) + { + return new String(x, 0, LEN(x)); + } + public static void COPY(byte[] x, byte[] v) { - int len_x = LEN(x); - int len_v = v.length - 1; - int len = (len_x < len_v) ? (len_x) : (len_v); - for(int i = 0; i < len; i++) + int ix = LEN(x); + int iv = v.length - 1; + + int i = 0; + int len = (ix < iv) ? (ix) : (iv); + while(i < len) { v[i] = x[i]; + i += 1; + } + v[i] = 0; + } + + public static int STRCMP(byte[] a, byte[] b) + { + int i = 0; + while(a[i] != 0 && a[i] == b[i]) + { + i += 1; } - v[len] = 0; + return a[i] - b[i]; } public static void HALT(long n) @@ -44,4 +61,70 @@ public class SYSTEM { assert x : n; } + + public static void TRAP(long n) + { + if(n == -1) + { + throw new RuntimeException("CASE TRAP"); + } + else if(n == -2) + { + throw new RuntimeException("WITH TRAP"); + } + else if(n == -3) + { + throw new RuntimeException("NOT IMPLEMENTED"); + } + else + { + throw new RuntimeException("TRAP CODE " + n); + } + } + + public static int ASH(int x, int n) + { + return (n > 0) ? (x << n) : (x >> Math.abs(n)); + } + + public static long ASH(long x, long n) + { + return (n > 0) ? (x << n) : (x >> Math.abs(n)); + } + + public static int LSH(int x, int n) + { + return (n > 0) ? (x << n) : (x >>> Math.abs(n)); + } + + public static long LSH(long x, long n) + { + return (n > 0) ? (x << n) : (x >>> Math.abs(n)); + } + + public static int ROT(int x, int n) + { + if(n > 0) + { + return (x << n) | (x >>> (Integer.SIZE - n)); + } + else + { + n = Math.abs(n); + return (x >>> n) | (x << (Integer.SIZE - n)); + } + } + + public static long ROT(long x, long n) + { + if(n > 0) + { + return (x << n) | (x >>> (Long.SIZE - n)); + } + else + { + n = Math.abs(n); + return (x >>> n) | (x << (Long.SIZE - n)); + } + } }