about summary refs log tree commit diff stats
path: root/src/io/promise.nim
Commit message (Collapse)AuthorAgeFilesLines
* move around more modulesbptato2023-09-141-1/+1
| | | | | | | | | | * ips -> io/ * loader related stuff -> loader/ * tempfile -> extern/ * buffer, forkserver -> server/ * lineedit, window -> display/ * cell -> types/ * opt -> types/
* Fixes & workarounds to compile on Nim 2.0.0bptato2023-08-011-0/+3
| | | | | | | | | | | | | | * Import punycode, as it has been removed from stdlib. * Fix some syntax errors * Apparently you can no longer compare distinct pointers with nil. Add explicit comparisons with typeof(nil) instead. * htmlparser: rename _ to other, as semantics of _ have changed. (Quite a shame, it looked better with _. Oh well.) * Explicitly specify mm:refc, as the browser OOMs with orc for some reason. Confirmed to compile & run on 2.0.0, 1.6.14, 1.6.12, 1.6.10 and 1.6.8. (<1.6.8 it's broken & wontfix.)
* Buffer search fixes & improvementsbptato2023-07-111-9/+17
| | | | | * Fix race condition in updateReadLineISearch * Disable reshape during isearch
* Rework JS exception systembptato2023-06-191-0/+16
| | | | | Now we use Result for passing exceptions to JS. As a result, we can finally get rid of the .jserr pragma.
* Cleanups & bug fixes involving promisesbptato2023-06-151-10/+18
| | | | | Now a promise returning nil doesn't just leave the rest of the then chain hanging. Hooray.
* Make Result.text, json return promisebptato2023-06-131-2/+10
|
* Async resource loading, exception handling fixesbptato2023-05-141-0/+19
|
* promise: set get, cb, next to nil after then is calledbptato2023-01-041-7/+5
| | | | | | Actually we don't even need a state variable, just set cb to nil when resolving. (I'm sure this is a great idea that will absolutely not backfire in the future.)
* Add promise support to JSbptato2022-12-311-0/+107
olor: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
// A simple test harness. To create new tests define functions starting with
// 'test_'. To run all tests so defined, run:
//   $ wart test
//
// So far it seems tasteful for layers to never ever reach back to modify
// previously-defined tests. Every test is a contract once written, and should
// pass as-is if it is included, regardless of how much later layers change
// the program. Avoid writing 'temporary' tests that only work with some
// subsets of the program.

:(before "End Types")
typedef void (*test_fn)(void);

:(before "End Globals")
const test_fn Tests[] = {
  #include "test_list"  // auto-generated; see makefile
};

bool Passed = true;

long Num_failures = 0;

#define CHECK(X) \
  if (!(X)) { \
    ++Num_failures; \
    cerr << "\nF " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): " << #X << '\n'; \
    Passed = false; \
    return; \
  }

#define CHECK_EQ(X, Y) \
  if ((X) != (Y)) { \
    ++Num_failures; \
    cerr << "\nF " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): " << #X << " == " << #Y << '\n'; \
    cerr << "  got " << (X) << '\n';  /* BEWARE: multiple eval */ \
    Passed = false; \
    return; \
  }

:(before "End Main")
if (argc == 2 && is_equal(argv[1], "test")) {
  run_tests();
  cerr << '\n';
  if (Num_failures > 0)
    cerr << Num_failures << " failure"
         << (Num_failures > 1 ? "s" : "")
         << '\n';
  return 0;
}
// pass in a set of line numbers in test_file to run just those tests
if (argc > 2 && is_equal(argv[1], "test")) {
  for (int i = 2; i < argc; ++i) {
    run_test(to_int(argv[i])-1);
  }
  cerr << '\n';
  if (Num_failures > 0)
    cerr << Num_failures << " failure"
         << (Num_failures > 1 ? "s" : "")
         << '\n';
  return 0;
}

:(code)
void run_tests() {
  time_t t; time(&t);
  cerr << "C tests: " << ctime(&t);
  for (size_t i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) {
    run_test(i);
  }
  // End Tests
}

void run_test(size_t i) {
  if (i >= sizeof(Tests)/sizeof(Tests[0])) {
    cerr << "no test " << i << '\n';
    return;
  }
  setup();
  // End Test Setup
  (*Tests[i])();
  if (Passed) cerr << ".";
  // Test Teardown
  // End Test Teardown
}

bool is_equal(char* s, const char* lit) {
  return strncmp(s, lit, strlen(lit)) == 0;
}

int to_int(string n) {
  char* end = NULL;
  int result = strtol(n.c_str(), &end, /*any base*/0);
  assert(*end == '\0');
  return result;
}

:(before "End Includes")
#include<assert.h>
#include<cstdlib>

#include<iostream>
using std::istream;
using std::ostream;
using std::iostream;
using std::cin;
using std::cout;
using std::cerr;

#include<cstring>
#include<string>
using std::string;
#define NOT_FOUND string::npos  // macro doesn't complain about redef