time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

index.js (1447B)


      1 import { REOther } from "../errors/messages.js";
      2 import { INDEX_LOOKUP_FUNCTION } from "../expression/constants.js";
      3 import { BuiltinLambda } from "../reducer/lambda.js";
      4 import { vLambda } from "../value/index.js";
      5 import { ImmutableMap } from "../utility/immutableMap.js";
      6 import { makeMathConstants } from "./math.js";
      7 import { makeSquiggleBindings, registry } from "./registry/index.js";
      8 import { makeVersionConstant } from "./version.js";
      9 import { frAny } from "./registry/frTypes.js";
     10 import { makeDefinition } from "./registry/fnDefinition.js";
     11 const definitions = [
     12     makeDefinition([frAny, frAny], ([obj, key]) => {
     13         if ("get" in obj) {
     14             return obj.get(key).clone();
     15         }
     16         else {
     17             throw new REOther("Trying to access key on wrong value");
     18         }
     19     }),
     20 ];
     21 function makeLookupLambda() {
     22     return new BuiltinLambda(INDEX_LOOKUP_FUNCTION, definitions);
     23 }
     24 function makeStdLib() {
     25     let res = ImmutableMap();
     26     res = res.merge(makeMathConstants());
     27     res = res.merge(makeVersionConstant());
     28     res = res.set(INDEX_LOOKUP_FUNCTION, vLambda(makeLookupLambda()));
     29     for (const name of registry.allNames()) {
     30         res = res.set(name, vLambda(registry.makeLambda(name)));
     31     }
     32     res = res.merge(makeSquiggleBindings(res));
     33     return res;
     34 }
     35 let cachedStdLib;
     36 export function getStdLib() {
     37     cachedStdLib ??= makeStdLib();
     38     return cachedStdLib;
     39 }
     40 //# sourceMappingURL=index.js.map