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

156
LINES

< > BotCompany Repo | #1034255 // G22LeftArrowScript (script as a concept)

JavaX fragment (include) [tags: use-pretranspiled]

Uses 2164K of libraries. Click here for Pure Java version (68562L/364K).

concept G22LeftArrowScript > G22Text {
  // the latest code that has been cleared to auto-run (if any)
  settableWithVar ClearForAutoRun<S> clearedForAutoRun;

  // auto-run when project is opened
  settableWithVar bool runOnProjectOpen;
  
  // only when runOnProjectOpen is seT:
  // when to run in sequence (sorted with alphanumIC)
  settableWithVar S runOrder;
  
  // run stats
  long runCount;
  
  // info about last result (or error) of script run by mode
  Map<G22ScriptMode, WithTimestamp<PersistableOKOrError<G22TypeDesc>>> lastResultByMode;
  
  // is there a newer version of this script?
  new Ref<G22LeftArrowScript> supercededBy;
  
  // Put meta-functions here (e.g. for improving an IDE showing
  // this script)
  settableWithVar S metaCode;
  
  void _doneLoading2 :: after {
    //print("_doneLoading " + this);
    cMigrateField(this, "code", "text");
  }
  
  toString {
    if (empty(description)) 
      ret myType() + " " + id;
    else
      ret "Script " + id + ": " + description;
  }
  
  bool isSavedDistinctFromAutoRunVersion() { ret isSaved() && !eq(text, codeForAutoRun()); }
  bool isClearForAutoRun() { ret clearedForAutoRun != null; }
  
  S codeForAutoRun() { ret getVar(clearedForAutoRun()); }
  
  // return code clear for auto run if available
  // otherwise returns saved code if available
  // in all other cases returns null
  // (never returns text being edited)
  S safestCode() { ret or(codeForAutoRun(), stableText()); }
  
  void clearForAutoRun {
    if (!isSaved()) ret;
    S text = text();
    saveFieldToHistory("Auto-runnable code", text);
    clearedForAutoRun(new ClearForAutoRun(text));
  }
  
  void forgetAutoRunCode {
    if (!isClearForAutoRun()) ret;
    saveFieldToHistory("Auto-runnable code", null);
    clearedForAutoRun(null);
    compileResultForAutoRun = null;
  }
  
  void forgetCompileResults {
    compileResultForAutoRun = compileResultForSaved = null;
  }

  GazelleV_LeftArrowScriptParser makeParser() {
    ret g22utils().leftArrowParser()
      .sourceInfo(this);
  }
  
  LASCompileResult newCompileResult() { ret new LASCompileResult; }
  
  LASCompileResult returnOrCompile(LASCompileResult lastCompileResult, S code) {
    if (g22utils().compileResultValid(lastCompileResult, code))
      ret lastCompileResult;
    var cr = newCompileResult();
    cr.script(code);
    var parser = makeParser();
    cr.parser(parser);
    cr.compile();
    ret cr;
  }
  
  transient LASCompileResult compileResultForAutoRun;
  LASCompileResult compileForAutoRun() {
    S code = codeForAutoRun();
    if (code == null) null;
    var cr = returnOrCompile(compileResultForAutoRun, code);
    ret compileResultForAutoRun = cr;
  }
  
  transient LASCompileResult compileResultForSaved;
  LASCompileResult compileSaved() {
    S code = stableText();
    if (code == null) null;
    var cr = returnOrCompile(compileResultForSaved, code);
    ret compileResultForSaved = cr;
  }
  
  transient LASCompileResult compileResultForEditing;
  LASCompileResult compileEditing() {
    S code = editingText();
    if (code == null) null;
    var cr = returnOrCompile(compileResultForEditing, code);
    ret compileResultForEditing = cr;
  }
  
  LASCompileResult safestCompileResult() {
    try object compileForAutoRun();
    ret compileSaved();
  }
  
  LASCompileResult latestCompileResult() {
    try object compileEditing();
    try object compileSaved();
    ret compileForAutoRun();
  }
  
  LASCompileResult latestRunnableCompileResult() {
    var cr = compileEditing();
    if (cr != null && cr.runnable()) ret cr;
    cr = compileSaved();
    if (cr != null && cr.runnable()) ret cr;
    cr = compileForAutoRun();
    if (cr != null && cr.runnable()) ret cr;
    null;
  }
  
  O evaluateWithoutTimeout() {
    var cr = safestCompileResult();
    if (cr == null)
      fail("Not saved: " + this);
      
    temp g22utils().enter(); // enter module
    ret cr.parsedScriptMandatory()!;
  }
  
  O evaluateAutoRunWithoutTimeout() {
    var cr = compileForAutoRun();
    if (cr == null)
      fail("Not cleared for auto-run: " + this);
      
    temp g22utils().enter(); // enter module
    ret cr.parsedScriptMandatory()!;
  }
  
  S renderRunOnProjectOpenStatus() {
    ret runOnProjectOpen
      ? "Yes" + appendBracketed(appendPrefixIfNempty("prio ", runOrder))
      : null;
  }
  
  Set<S> allTexts() {
    ret addAndReturnCollection(super.allTexts(), codeForAutoRun());
  }
}

Author comment

Began life as a copy of #1034204

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034255
Snippet name: G22LeftArrowScript (script as a concept)
Eternal ID of this version: #1034255/89
Text MD5: bb639f3077124d5d7cc47878831b732b
Transpilation MD5: 5e3091ea6095d63095648ca5cc6a7537
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-04-27 18:30:59
Source code size: 4601 bytes / 156 lines
Pitched / IR pitched: No / No
Views / Downloads: 345 / 1008
Version history: 88 change(s)
Referenced in: [show references]