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

46
LINES

< > BotCompany Repo | #1001120 // Speaking VM (developing)

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

Libraryless. Click here for Pure Java version (1043L/8K/26K).

1  
!747
2  
3  
m {
4  
  static S[] args;
5  
  
6  
  p {
7  
    main.args = args;
8  
    makeAndroid("This is a JavaX VM talking to you.", stringfunc {
9  
      answer(s)
10  
    });
11  
  }
12  
  
13  
  static synchronized S answer(S s) {
14  
    new Matches m;
15  
    
16  
    if (match3("kill!", s)) {
17  
      killMyself();
18  
      return "ok";
19  
    }
20  
    if (match3("What is your process ID?", s) || match3("what is your pid?", s))
21  
      return getPID();
22  
    if (match3("what is your program id?", s))
23  
      return getProgramID();
24  
    if (match3("what are your program arguments?", s))
25  
      return structure(args);
26  
    if (match3("get fields of main class", s))
27  
      return structure(listFields(main.class));
28  
    if (match3("get field * of main class", s, m))
29  
      return structure(get(main.class, m.m[0]));
30  
    if (match3("invoke function * of main class", s, m))
31  
      return structure(call(main.class, m.m[0]));
32  
    if (match3("set field * of main class to *", s, m)) {
33  
      set(main.class, m.m[0], unstructure(m.m[1]));
34  
      return "ok";
35  
    }
36  
    if (match3("how much memory are you consuming", s))
37  
      return "Java heap size: " + (Runtime.getRuntime().totalMemory()+1024*1024-1)/1024/1024 + " MB";
38  
    if (match3("how much memory is used after GC?", s)) {
39  
      System.gc();
40  
      return "Java heap used: " + (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()+1024*1024-1)/1024/1024 + " MB";
41  
    }
42  
    if (match3("how much memory is used?", s))
43  
      return "Java heap used: " + (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()+1024*1024-1)/1024/1024 + " MB";
44  
    return null;
45  
  }
46  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001120
Snippet name: Speaking VM (developing)
Eternal ID of this version: #1001120/1
Text MD5: 9cb5fccd7eb249f6c9325939bdb7548b
Transpilation MD5: 00b44a3fa87d97a2132b580f472d0569
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-22 20:52:34
Source code size: 1624 bytes / 46 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 623 / 638
Referenced in: [show references]