X-Git-Url: http://deadsoftware.ru/gitweb?p=dsw-obn.git;a=blobdiff_plain;f=rtl%2FSYSTEM.java;h=ce1b50621e447042154ad9d70dc11136278673ff;hp=f98236bd90926eeb0ca4d8dd58c46e190e43cd8e;hb=7b989fe6cfb3cf6e529b888bb6827714c45c62c6;hpb=9f8036eb00032fa7f756113365cb42e05ab262df diff --git a/rtl/SYSTEM.java b/rtl/SYSTEM.java index f98236b..ce1b506 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,24 @@ 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); + } + } }