time-to-botec

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

index.js (6780B)


      1 import { vLambda, vNumber, vString } from "../../value/index.js";
      2 import { SqArray } from "./SqArray.js";
      3 import { SqCalculator } from "./SqCalculator.js";
      4 import { SqDict } from "./SqDict.js";
      5 import { wrapDistribution } from "./SqDistribution/index.js";
      6 import { wrapDomain } from "./SqDomain.js";
      7 import { wrapInput } from "./SqInput.js";
      8 import { SqLambda } from "./SqLambda.js";
      9 import { wrapPlot } from "./SqPlot.js";
     10 import { wrapScale } from "./SqScale.js";
     11 import { SqTableChart } from "./SqTableChart.js";
     12 export function wrapValue(value, context) {
     13     switch (value.type) {
     14         case "Array":
     15             return new SqArrayValue(value, context);
     16         case "Bool":
     17             return new SqBoolValue(value, context);
     18         case "Date":
     19             return new SqDateValue(value, context);
     20         case "Dist":
     21             return new SqDistributionValue(value, context);
     22         case "Lambda":
     23             return new SqLambdaValue(value, context);
     24         case "Number":
     25             return new SqNumberValue(value, context);
     26         case "Dict":
     27             return new SqDictValue(value, context);
     28         case "String":
     29             return new SqStringValue(value, context);
     30         case "Plot":
     31             return new SqPlotValue(value, context);
     32         case "TableChart":
     33             return new SqTableChartValue(value, context);
     34         case "Calculator":
     35             return new SqCalculatorValue(value, context);
     36         case "Scale":
     37             return new SqScaleValue(value, context);
     38         case "TimeDuration":
     39             return new SqTimeDurationValue(value, context);
     40         case "Void":
     41             return new SqVoidValue(value, context);
     42         case "Domain":
     43             return new SqDomainValue(value, context);
     44         case "Input":
     45             return new SqInputValue(value, context);
     46         default:
     47             throw new Error(`Unknown value ${JSON.stringify(value)}`);
     48     }
     49 }
     50 export class SqAbstractValue {
     51     constructor(_value, context) {
     52         this._value = _value;
     53         this.context = context;
     54     }
     55     toString() {
     56         return this._value.toString();
     57     }
     58     publicName() {
     59         return this._value.publicName;
     60     }
     61 }
     62 export class SqArrayValue extends SqAbstractValue {
     63     constructor() {
     64         super(...arguments);
     65         this.tag = "Array";
     66     }
     67     get value() {
     68         return new SqArray(this._value.value, this.context);
     69     }
     70     asJS() {
     71         return this.value.getValues().map((value) => value.asJS());
     72     }
     73 }
     74 export class SqBoolValue extends SqAbstractValue {
     75     constructor() {
     76         super(...arguments);
     77         this.tag = "Bool";
     78     }
     79     get value() {
     80         return this._value.value;
     81     }
     82     asJS() {
     83         return this.value;
     84     }
     85 }
     86 export class SqDateValue extends SqAbstractValue {
     87     constructor() {
     88         super(...arguments);
     89         this.tag = "Date";
     90     }
     91     get value() {
     92         return this._value.value;
     93     }
     94     asJS() {
     95         return this.value;
     96     }
     97 }
     98 export class SqDistributionValue extends SqAbstractValue {
     99     constructor() {
    100         super(...arguments);
    101         this.tag = "Dist";
    102     }
    103     get value() {
    104         return wrapDistribution(this._value.value);
    105     }
    106     asJS() {
    107         return this.value;
    108     }
    109 }
    110 export class SqLambdaValue extends SqAbstractValue {
    111     constructor() {
    112         super(...arguments);
    113         this.tag = "Lambda";
    114     }
    115     static create(value) {
    116         return new SqLambdaValue(vLambda(value._value));
    117     }
    118     get value() {
    119         return new SqLambda(this._value.value, this.context);
    120     }
    121     asJS() {
    122         return this.value;
    123     }
    124 }
    125 export class SqNumberValue extends SqAbstractValue {
    126     constructor() {
    127         super(...arguments);
    128         this.tag = "Number";
    129     }
    130     static create(value) {
    131         return new SqNumberValue(vNumber(value));
    132     }
    133     get value() {
    134         return this._value.value;
    135     }
    136     asJS() {
    137         return this.value;
    138     }
    139 }
    140 export class SqDictValue extends SqAbstractValue {
    141     constructor() {
    142         super(...arguments);
    143         this.tag = "Dict";
    144     }
    145     get value() {
    146         return new SqDict(this._value.value, this.context);
    147     }
    148     asJS() {
    149         return new Map(this.value.entries().map(([k, v]) => [k, v.asJS()]));
    150     }
    151 }
    152 export class SqStringValue extends SqAbstractValue {
    153     constructor() {
    154         super(...arguments);
    155         this.tag = "String";
    156     }
    157     static create(value) {
    158         return new SqStringValue(vString(value));
    159     }
    160     get value() {
    161         return this._value.value;
    162     }
    163     asJS() {
    164         return this.value;
    165     }
    166 }
    167 export class SqTimeDurationValue extends SqAbstractValue {
    168     constructor() {
    169         super(...arguments);
    170         this.tag = "TimeDuration";
    171     }
    172     get value() {
    173         return this._value.value;
    174     }
    175     asJS() {
    176         return this._value.value;
    177     }
    178 }
    179 export class SqPlotValue extends SqAbstractValue {
    180     constructor() {
    181         super(...arguments);
    182         this.tag = "Plot";
    183     }
    184     get value() {
    185         return wrapPlot(this._value.value, this.context);
    186     }
    187     asJS() {
    188         return this.value;
    189     }
    190 }
    191 export class SqTableChartValue extends SqAbstractValue {
    192     constructor() {
    193         super(...arguments);
    194         this.tag = "TableChart";
    195     }
    196     get value() {
    197         return new SqTableChart(this._value.value, this.context);
    198     }
    199     asJS() {
    200         return this.value;
    201     }
    202 }
    203 export class SqCalculatorValue extends SqAbstractValue {
    204     constructor() {
    205         super(...arguments);
    206         this.tag = "Calculator";
    207     }
    208     get value() {
    209         return new SqCalculator(this._value.value, this.context);
    210     }
    211     asJS() {
    212         return this.value;
    213     }
    214 }
    215 export class SqScaleValue extends SqAbstractValue {
    216     constructor() {
    217         super(...arguments);
    218         this.tag = "Scale";
    219     }
    220     get value() {
    221         return wrapScale(this._value.value);
    222     }
    223     asJS() {
    224         return this.value;
    225     }
    226 }
    227 export class SqInputValue extends SqAbstractValue {
    228     constructor() {
    229         super(...arguments);
    230         this.tag = "Input";
    231     }
    232     get value() {
    233         return wrapInput(this._value.value);
    234     }
    235     asJS() {
    236         return this.value;
    237     }
    238 }
    239 export class SqVoidValue extends SqAbstractValue {
    240     constructor() {
    241         super(...arguments);
    242         this.tag = "Void";
    243     }
    244     get value() {
    245         return null;
    246     }
    247     asJS() {
    248         return null;
    249     }
    250 }
    251 export class SqDomainValue extends SqAbstractValue {
    252     constructor() {
    253         super(...arguments);
    254         this.tag = "Domain";
    255     }
    256     get value() {
    257         return wrapDomain(this._value.value);
    258     }
    259     asJS() {
    260         return this.value;
    261     }
    262 }
    263 export function toStringResult(result) {
    264     return `${result.ok ? "Ok" : "Error"}(${result.value.toString()})`;
    265 }
    266 //# sourceMappingURL=index.js.map