Search in sources :

Example 36 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class ImperativeCompilerTest method testDeclare.

@Test
public void testDeclare() {
    Bytes bytes = imperativeCompiler.compile(0, "declare v = 1; {v} = 2;");
    assertNotNull(bytes);
    System.out.println(bytes);
}
Also used : Bytes(suite.primitive.Bytes) Test(org.junit.Test)

Example 37 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class ImperativeCompilerTest method testJump.

@Test
public void testJump() {
    Bytes bytes = imperativeCompiler.compile(0, "if (1 < 2) then 1 else 0;");
    assertNotNull(bytes);
    System.out.println(bytes);
}
Also used : Bytes(suite.primitive.Bytes) Test(org.junit.Test)

Example 38 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class ImperativeCompilerTest method testDataStructure.

@Test
public void testDataStructure() {
    String s = // 
    "" + // 
    "constant p = fix :p struct ( | pointer::p next);" + // 
    "declare pnext = function [pointer:p e,] e/*/next;" + // 
    "declare object = new p (next = null,);" + // 
    "{object/next} = pnext [& object,];" + "0";
    Bytes bytes = imperativeCompiler.compile(0, s);
    assertNotNull(bytes);
    System.out.println(bytes);
}
Also used : Bytes(suite.primitive.Bytes) Test(org.junit.Test)

Example 39 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class CompareZipMain method run.

@Override
protected boolean run(String[] args) throws IOException {
    String filename0 = "/tmp/a";
    String filename1 = "/tmp/b";
    ZipFile zf0 = new ZipFile(filename0);
    ZipFile zf1 = new ZipFile(filename1);
    Set<String> names = Set_.union(FileUtil.listZip(zf0), FileUtil.listZip(zf1));
    boolean isChanged = false;
    for (String name : names) {
        ZipEntry e0 = zf0.getEntry(name);
        ZipEntry e1 = zf1.getEntry(name);
        boolean b = e0 != null && e1 != null;
        if (b) {
            Bytes bytes0 = To.bytes(zf0.getInputStream(e0));
            Bytes bytes1 = To.bytes(zf1.getInputStream(e1));
            b = !textUtil.isDiff(textUtil.diff(bytes0, bytes1));
            if (!b)
                System.out.println(name + " differs");
        } else if (e0 == null)
            System.out.println(name + " not exist in " + filename0);
        else if (e1 == null)
            System.out.println(name + " not exist in " + filename1);
        isChanged |= !b;
    }
    return !isChanged;
}
Also used : Bytes(suite.primitive.Bytes) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry)

Example 40 with Bytes

use of suite.primitive.Bytes in project suite by stupidsing.

the class As method utf8encode.

public static Outlet<Bytes> utf8encode(Outlet<Chars> charsOutlet) {
    Source<Chars> source = charsOutlet.source();
    return Outlet.of(new Source<>() {

        public Bytes source() {
            Chars chars = source.source();
            if (chars != null) {
                BytesBuilder bb = new BytesBuilder();
                for (int i = 0; i < chars.size(); i++) {
                    char ch = chars.get(i);
                    if (ch < 0x80)
                        bb.append((byte) ch);
                    else if (ch < 0x800) {
                        bb.append((byte) (0xC0 + ((ch >> 6) & 0x1F)));
                        bb.append((byte) (0x80 + ((ch >> 0) & 0x3F)));
                    } else if (ch < 0x10000) {
                        bb.append((byte) (0xE0 + ((ch >> 12) & 0x0F)));
                        bb.append((byte) (0x80 + ((ch >> 6) & 0x3F)));
                        bb.append((byte) (0x80 + ((ch >> 0) & 0x3F)));
                    } else {
                        bb.append((byte) (0xF0 + ((ch >> 18) & 0x07)));
                        bb.append((byte) (0x80 + ((ch >> 12) & 0x3F)));
                        bb.append((byte) (0x80 + ((ch >> 6) & 0x3F)));
                        bb.append((byte) (0x80 + ((ch >> 0) & 0x3F)));
                    }
                }
                return bb.toBytes();
            } else
                return null;
        }
    });
}
Also used : Bytes(suite.primitive.Bytes) Chars(suite.primitive.Chars) BytesBuilder(suite.primitive.Bytes.BytesBuilder)

Aggregations

Bytes (suite.primitive.Bytes)56 Test (org.junit.Test)18 BytesBuilder (suite.primitive.Bytes.BytesBuilder)8 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Pair (suite.adt.pair.Pair)4 OutputStream (java.io.OutputStream)3 Path (java.nio.file.Path)3 To (suite.util.To)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Constants (suite.Constants)2 Amd64Interpret (suite.assembler.Amd64Interpret)2 Condition (suite.concurrent.Condition)2 Extent (suite.file.ExtentAllocator.Extent)2 JournalledPageFile (suite.file.JournalledPageFile)2 ImperativeCompiler (suite.ip.ImperativeCompiler)2 DataInput_ (suite.util.DataInput_)2