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).

!747

m {
  static S[] args;
  
  p {
    main.args = args;
    makeAndroid("This is a JavaX VM talking to you.", stringfunc {
      answer(s)
    });
  }
  
  static synchronized S answer(S s) {
    new Matches m;
    
    if (match3("kill!", s)) {
      killMyself();
      return "ok";
    }
    if (match3("What is your process ID?", s) || match3("what is your pid?", s))
      return getPID();
    if (match3("what is your program id?", s))
      return getProgramID();
    if (match3("what are your program arguments?", s))
      return structure(args);
    if (match3("get fields of main class", s))
      return structure(listFields(main.class));
    if (match3("get field * of main class", s, m))
      return structure(get(main.class, m.m[0]));
    if (match3("invoke function * of main class", s, m))
      return structure(call(main.class, m.m[0]));
    if (match3("set field * of main class to *", s, m)) {
      set(main.class, m.m[0], unstructure(m.m[1]));
      return "ok";
    }
    if (match3("how much memory are you consuming", s))
      return "Java heap size: " + (Runtime.getRuntime().totalMemory()+1024*1024-1)/1024/1024 + " MB";
    if (match3("how much memory is used after GC?", s)) {
      System.gc();
      return "Java heap used: " + (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()+1024*1024-1)/1024/1024 + " MB";
    }
    if (match3("how much memory is used?", s))
      return "Java heap used: " + (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()+1024*1024-1)/1024/1024 + " MB";
    return null;
  }
}

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: 622 / 637
Referenced in: #3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)