Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

72
LINES

< > BotCompany Repo | #1006146 // Bit Analysis 2 [evaluate expressions, works]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (4471L/29K).

1  
!7
2  
3  
sS bla = [[
4  
The images "9176714c9a935fc91e14595dbb3adddf 35731666e72dd0c9448f616ff3a7464a da9bc5a24bd503e898f69ad43bb9b92e" are the characters "yet".
5  
  The images "412f9e0f8e177817a4fa285415c5a13f 386b289407599f31e3a7c57c3adb2587 6cd2a2284a5a6fda3a7cad3e3a048671 b0c47c014d665ec5b658f510c258dc47 b273ff598fe6afa04cfed9f9e8fb4109" are the grouped characters "[Ob]ject".
6  
  The images "175116b749670b7b65707c10c935b42c ddaf2b9c198818c49628387ecc2910ed 3777597e39eb0de16c022293c8c91cc0 fad86bda3f716ef4e7fa9d199f6c4383 35731666e72dd0c9448f616ff3a7464a 03b96c30adaaed5b60cea4ab9bc37263" are the characters "images".
7  
]];
8  
9  
p-typewriter {
10  
  Bits bits = new Bits(bla);
11  
  print(bits.n);
12  
  printStruct(bits.toByteArray());
13  
  print(quote(bits.getString()));
14  
  
15  
  S exp = [[chunks(8).splitAt("\"")]];
16  
  calcPrint(exp, bits);
17  
  exp = [[chunks(8).splitAt("\"").get(1)]];
18  
  calcPrint(exp, bits);
19  
  exp += [[.chunks(8).splitAt(" ")]];
20  
  calcPrint(exp, bits);
21  
}
22  
23  
static void calcPrint(S exp, O obj) {
24  
  print(exp);
25  
  print("  " + structureOrText(bits_prettyPrint(calcExp(exp, obj))));
26  
}
27  
28  
static O calcExp(S exp, O obj) {
29  
  L<S> tok = javaTokC(exp);
30  
  while (nempty(tok)) {
31  
    S f = first(tok);
32  
    assertIsIdentifier(f);
33  
    if (eq(get(tok, 1), "(")) {
34  
      assertEquals("(", tok.get(1));
35  
      assertEquals(")", tok.get(3));
36  
      S t = tok.get(2);
37  
      O arg; 
38  
      if (isQuoted(t)) arg = unquote(t);
39  
      else if (isInteger(t)) arg = parseInt(t);
40  
      else fail("Unknown argument: " + quote(t));
41  
      obj = call(mc(), "bits_" + f, obj, arg);
42  
      tok = subList(tok, 4);
43  
    } else {
44  
      obj = call(mc(), "bits_" + f, obj);
45  
      tok = subList(tok, 1);
46  
    }
47  
    if (l(tok) == 0) break;
48  
    assertEquals(".", tok.get(0));
49  
    tok = subList(tok, 1);
50  
  }
51  
  ret obj;
52  
}
53  
54  
static S bits_prettyPrint(O o) {
55  
  if (o instanceof Bits)
56  
    ret o/Bits.getString();
57  
  if (isListOfElementType(o, Bits))
58  
    ret struct(map(func(Bits b) { b.getString() }, (L) o));
59  
  ret struct(o);
60  
}
61  
62  
static L<Bits> bits_chunks(Bits bits, int width) {
63  
  ret bitsFullChunks(bits, width);
64  
}
65  
66  
static L<Bits> bits_splitAt(L<Bits> l, S s) {
67  
  ret splitBitsAtElement(l, new Bits(s));
68  
}
69  
70  
static O bits_get(L l, int idx) {
71  
  ret get(l, idx);
72  
}

Author comment

Began life as a copy of #1006137

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006146
Snippet name: Bit Analysis 2 [evaluate expressions, works]
Eternal ID of this version: #1006146/2
Text MD5: 0a848aedf657891775b42bccd2fb7e1b
Transpilation MD5: 8175ac289e645b14d40540598867e5e2
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-19 22:44:27
Source code size: 2272 bytes / 72 lines
Pitched / IR pitched: No / No
Views / Downloads: 625 / 1243
Version history: 1 change(s)
Referenced in: [show references]