@eagleoutice/flowr 2.14.4 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -63
- package/abstract-interpretation/absint-inference.d.ts +347 -0
- package/abstract-interpretation/{absint-visitor.js → absint-inference.js} +327 -97
- package/abstract-interpretation/abstract-semantics.d.ts +246 -0
- package/abstract-interpretation/abstract-semantics.js +3 -0
- package/abstract-interpretation/data-frame/{mappers/arguments.d.ts → arguments.d.ts} +18 -16
- package/abstract-interpretation/data-frame/{mappers/arguments.js → arguments.js} +20 -21
- package/abstract-interpretation/data-frame/dataframe-semantics.d.ts +52 -0
- package/abstract-interpretation/data-frame/dataframe-semantics.js +1656 -0
- package/abstract-interpretation/data-frame/resolve-args.js +4 -4
- package/abstract-interpretation/data-frame/semantics.d.ts +15 -21
- package/abstract-interpretation/data-frame/semantics.js +27 -29
- package/abstract-interpretation/data-frame/shape-inference.d.ts +28 -24
- package/abstract-interpretation/data-frame/shape-inference.js +14 -79
- package/abstract-interpretation/domains/interval-domain.d.ts +5 -1
- package/abstract-interpretation/domains/interval-domain.js +25 -33
- package/abstract-interpretation/domains/multi-value-state-domain.d.ts +6 -3
- package/abstract-interpretation/domains/multi-value-state-domain.js +24 -4
- package/abstract-interpretation/domains/partial-product-domain.d.ts +12 -6
- package/abstract-interpretation/domains/partial-product-domain.js +26 -43
- package/abstract-interpretation/domains/positive-interval-domain.d.ts +1 -6
- package/abstract-interpretation/domains/positive-interval-domain.js +3 -29
- package/abstract-interpretation/domains/product-domain.d.ts +1 -1
- package/abstract-interpretation/domains/set-range-domain.d.ts +6 -0
- package/abstract-interpretation/domains/set-range-domain.js +29 -62
- package/abstract-interpretation/domains/state-abstract-domain.d.ts +9 -2
- package/abstract-interpretation/domains/state-abstract-domain.js +26 -37
- package/abstract-interpretation/domains/{state-domain-like.d.ts → state-domain.d.ts} +10 -6
- package/abstract-interpretation/domains/{state-domain-like.js → state-domain.js} +1 -1
- package/abstract-interpretation/value-semantics.d.ts +113 -0
- package/abstract-interpretation/value-semantics.js +115 -0
- package/benchmark/slicer.js +12 -6
- package/benchmark/stats/feature-counts.d.ts +2 -1
- package/benchmark/stats/feature-counts.js +25 -1
- package/benchmark/stats/stats.d.ts +4 -0
- package/benchmark/summarizer/second-phase/graph.js +7 -0
- package/cli/repl/commands/repl-parse.js +11 -22
- package/cli/repl/parser/slice-query-parser.d.ts +2 -0
- package/cli/repl/parser/slice-query-parser.js +1 -0
- package/config.d.ts +30 -205
- package/config.js +37 -3
- package/control-flow/cfg-properties.d.ts +5 -0
- package/control-flow/cfg-properties.js +25 -7
- package/control-flow/control-flow-graph.d.ts +11 -37
- package/control-flow/control-flow-graph.js +33 -77
- package/control-flow/semantic-cfg-guided-visitor.d.ts +63 -320
- package/control-flow/semantic-cfg-guided-visitor.js +65 -320
- package/dataflow/environments/built-in-config.d.ts +2 -0
- package/dataflow/environments/built-in-proc-name.d.ts +4 -0
- package/dataflow/environments/built-in-proc-name.js +4 -0
- package/dataflow/environments/built-in-props.d.ts +192 -82
- package/dataflow/environments/built-in-props.js +336 -106
- package/dataflow/environments/built-in.d.ts +21 -9
- package/dataflow/environments/built-in.js +43 -12
- package/dataflow/environments/default-builtin-config.d.ts +3219 -313
- package/dataflow/environments/default-builtin-config.js +803 -1012
- package/dataflow/environments/environment.d.ts +26 -49
- package/dataflow/environments/environment.js +34 -47
- package/dataflow/environments/group-generics.d.ts +11 -2
- package/dataflow/environments/group-generics.js +22 -3
- package/dataflow/environments/identifier.d.ts +106 -6
- package/dataflow/environments/identifier.js +19 -1
- package/dataflow/environments/query-fn-props.d.ts +16 -8
- package/dataflow/environments/query-fn-props.js +45 -21
- package/dataflow/environments/resolve-by-name.js +9 -2
- package/dataflow/environments/scoping.d.ts +5 -0
- package/dataflow/environments/scoping.js +11 -0
- package/dataflow/eval/resolve/alias-tracking.d.ts +1 -1
- package/dataflow/eval/resolve/alias-tracking.js +20 -2
- package/dataflow/eval/resolve/resolve-numbers.d.ts +182 -7
- package/dataflow/eval/resolve/resolve-numbers.js +44 -9
- package/dataflow/eval/resolve/resolve-strings.d.ts +79 -2
- package/dataflow/eval/resolve/resolve-strings.js +16 -7
- package/dataflow/eval/resolve/resolve.d.ts +5 -22
- package/dataflow/eval/resolve/resolve.js +24 -34
- package/dataflow/eval/values/general.d.ts +7 -1
- package/dataflow/eval/values/general.js +17 -3
- package/dataflow/eval/values/string/string-constants.d.ts +16 -15
- package/dataflow/eval/values/string/string-constants.js +59 -27
- package/dataflow/extractor.d.ts +2 -1
- package/dataflow/extractor.js +16 -4
- package/dataflow/fn/argument-roles.d.ts +35 -0
- package/dataflow/fn/argument-roles.js +252 -0
- package/dataflow/fn/class-declaration.d.ts +148 -0
- package/dataflow/fn/class-declaration.js +317 -0
- package/dataflow/fn/condition-handlers.d.ts +5 -0
- package/dataflow/fn/condition-handlers.js +13 -0
- package/dataflow/fn/exceptions-of-function.d.ts +21 -7
- package/dataflow/fn/exceptions-of-function.js +74 -43
- package/dataflow/fn/frame-reflection.d.ts +46 -0
- package/dataflow/fn/frame-reflection.js +169 -0
- package/dataflow/fn/function-props.d.ts +32 -0
- package/dataflow/fn/function-props.js +160 -0
- package/dataflow/fn/higher-order-function.d.ts +23 -5
- package/dataflow/fn/higher-order-function.js +64 -18
- package/dataflow/fn/strict-function.d.ts +24 -2
- package/dataflow/fn/strict-function.js +49 -19
- package/dataflow/graph/call-graph.js +10 -2
- package/dataflow/graph/df-helper.d.ts +1 -12
- package/dataflow/graph/df-helper.js +2 -19
- package/dataflow/graph/diff-dataflow-graph.d.ts +1 -1
- package/dataflow/graph/diff-dataflow-graph.js +2 -2
- package/dataflow/graph/graph.d.ts +39 -188
- package/dataflow/graph/graph.js +46 -163
- package/dataflow/graph/match-args.d.ts +34 -2
- package/dataflow/graph/match-args.js +45 -12
- package/dataflow/graph/vertex.d.ts +8 -0
- package/dataflow/info.d.ts +7 -5
- package/dataflow/info.js +1 -5
- package/dataflow/internal/control-flow.js +20 -17
- package/dataflow/internal/linker.d.ts +8 -37
- package/dataflow/internal/linker.js +22 -55
- package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +3 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +8 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +43 -50
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +4 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +5 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-class-relation.d.ts +23 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-class-relation.js +24 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +0 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +73 -27
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -11
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +131 -92
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +17 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +187 -99
- package/dataflow/internal/process/functions/call/built-in/built-in-load.d.ts +4 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +2 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +4 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +1 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +0 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +31 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +101 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-dispatch.js +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +7 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +23 -21
- package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.d.ts +1 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +22 -1
- package/dataflow/internal/process/functions/call/common.d.ts +4 -6
- package/dataflow/internal/process/functions/call/common.js +2 -2
- package/dataflow/internal/process/functions/call/deferred.d.ts +1 -1
- package/dataflow/internal/process/functions/call/deferred.js +2 -2
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +5 -3
- package/dataflow/internal/process/functions/call/known-call-handling.js +6 -4
- package/dataflow/internal/process/functions/call/named-call-handling.js +19 -13
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -2
- package/dataflow/internal/process/functions/call/quoted.js +144 -28
- package/dataflow/origin/dfg-get-origin.js +23 -10
- package/dataflow/processor.d.ts +2 -1
- package/dataflow/processor.js +6 -0
- package/documentation/data/interface/doc-writing-code.js +2 -0
- package/documentation/doc-util/doc-search.js +1 -1
- package/documentation/wiki-absint.d.ts +11 -14
- package/documentation/wiki-absint.js +73 -59
- package/documentation/wiki-core.js +64 -24
- package/documentation/wiki-linter.js +1 -0
- package/documentation/wiki-query.js +82 -264
- package/documentation/wiki-signature-database.js +17 -5
- package/gas.d.ts +91 -47
- package/gas.js +97 -13
- package/index.d.ts +31 -0
- package/index.js +52 -0
- package/linter/linter-rules.d.ts +87 -23
- package/linter/linter-rules.js +3 -1
- package/linter/rules/absolute-path.d.ts +1 -1
- package/linter/rules/dataframe-access-validation.d.ts +1 -1
- package/linter/rules/dataframe-access-validation.js +10 -8
- package/linter/rules/dead-code.d.ts +1 -1
- package/linter/rules/deprecated-functions.js +14 -5
- package/linter/rules/file-path-validity.d.ts +1 -1
- package/linter/rules/naming-convention.d.ts +1 -1
- package/linter/rules/naming-convention.js +13 -2
- package/linter/rules/network-functions.d.ts +10 -5
- package/linter/rules/network-functions.js +48 -36
- package/linter/rules/no-leaked-credentials.d.ts +1 -1
- package/linter/rules/problematic-inputs.d.ts +1 -1
- package/linter/rules/problematic-inputs.js +1 -1
- package/linter/rules/seeded-randomness.d.ts +3 -2
- package/linter/rules/seeded-randomness.js +7 -3
- package/linter/rules/software-has-license.d.ts +1 -1
- package/linter/rules/software-has-tests.d.ts +1 -1
- package/linter/rules/stop-with-call-arg.d.ts +1 -1
- package/linter/rules/syntactically-valid.d.ts +1 -1
- package/linter/rules/unclosed-connection.d.ts +3 -3
- package/linter/rules/unclosed-connection.js +3 -4
- package/linter/rules/undefined-symbol.d.ts +1 -1
- package/linter/rules/unescaped-arguments.d.ts +161 -0
- package/linter/rules/unescaped-arguments.js +293 -0
- package/linter/rules/unused-definition.d.ts +1 -1
- package/linter/rules/unused-definition.js +49 -4
- package/linter/rules/unused-import.d.ts +1 -1
- package/linter/rules/useless-loop.d.ts +1 -1
- package/package.json +3 -198
- package/project/context/flowr-analyzer-environment-context.d.ts +12 -1
- package/project/context/flowr-analyzer-environment-context.js +33 -1
- package/project/context/flowr-analyzer-files-context.d.ts +24 -1
- package/project/context/flowr-analyzer-files-context.js +42 -21
- package/project/context/flowr-analyzer-functions-context.d.ts +8 -0
- package/project/context/flowr-analyzer-functions-context.js +2 -0
- package/project/context/flowr-analyzer-gas-context.d.ts +9 -1
- package/project/context/flowr-analyzer-gas-context.js +21 -0
- package/project/context/flowr-file.d.ts +16 -1
- package/project/context/flowr-file.js +26 -2
- package/project/plugins/file-plugins/files/flowr-description-file.d.ts +19 -20
- package/project/plugins/file-plugins/files/flowr-description-file.js +55 -41
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +9 -4
- package/project/plugins/file-plugins/files/flowr-jupyter-file.js +11 -3
- package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +6 -9
- package/project/plugins/file-plugins/files/flowr-manifest-files.js +5 -21
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +11 -12
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +48 -61
- package/project/plugins/file-plugins/files/flowr-news-file.d.ts +3 -12
- package/project/plugins/file-plugins/files/flowr-news-file.js +2 -19
- package/project/plugins/file-plugins/files/flowr-rd-file.d.ts +145 -0
- package/project/plugins/file-plugins/files/flowr-rd-file.js +676 -0
- package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +122 -422
- package/project/plugins/file-plugins/files/flowr-rda-file.js +517 -1005
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +8 -2
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +10 -1
- package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +7 -2
- package/project/plugins/file-plugins/files/flowr-sweave-file.js +9 -1
- package/project/plugins/file-plugins/files/flowr-sysdata-file.d.ts +17 -0
- package/project/plugins/file-plugins/files/flowr-sysdata-file.js +40 -0
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +2 -0
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +3 -1
- package/project/plugins/file-plugins/flowr-analyzer-rd-file-plugin.d.ts +58 -0
- package/project/plugins/file-plugins/flowr-analyzer-rd-file-plugin.js +95 -0
- package/project/plugins/file-plugins/flowr-analyzer-sysdata-file-plugin.d.ts +23 -0
- package/project/plugins/file-plugins/flowr-analyzer-sysdata-file-plugin.js +33 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +33 -72
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +17 -15
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +20 -37
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +29 -53
- package/project/plugins/package-version-plugins/package.js +2 -1
- package/project/plugins/plugin-registry.d.ts +3 -1
- package/project/plugins/plugin-registry.js +11 -0
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +20 -4
- package/project/sigdb/build.d.ts +9 -15
- package/project/sigdb/build.js +63 -42
- package/project/sigdb/decode.d.ts +10 -4
- package/project/sigdb/decode.js +60 -21
- package/project/sigdb/memory-source.d.ts +4 -0
- package/project/sigdb/memory-source.js +8 -0
- package/project/sigdb/reader.d.ts +50 -100
- package/project/sigdb/reader.js +84 -105
- package/project/sigdb/schema.d.ts +90 -26
- package/project/sigdb/schema.js +12 -6
- package/queries/base-query-format.d.ts +7 -0
- package/queries/base-query-format.js +29 -0
- package/queries/catalog/absint-query/absint-query-executor.js +8 -6
- package/queries/catalog/absint-query/absint-query-format.d.ts +20 -9
- package/queries/catalog/absint-query/absint-query-format.js +32 -19
- package/queries/catalog/call-context-query/call-context-query-executor.js +3 -3
- package/queries/catalog/call-graph-query/call-graph-query-format.d.ts +1 -1
- package/queries/catalog/cluster-query/cluster-query-format.d.ts +1 -1
- package/queries/catalog/control-flow-query/control-flow-query-format.d.ts +1 -1
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +1 -1
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +1 -1
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +1 -1
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +33 -7
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +1 -1
- package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +2 -2
- package/queries/catalog/dependencies-query/function-info/derived-functions.js +14 -4
- package/queries/catalog/dependencies-query/function-info/read-functions.js +7 -121
- package/queries/catalog/dependencies-query/function-info/statistics-functions.d.ts +1 -1
- package/queries/catalog/dependencies-query/function-info/statistics-functions.js +2 -2
- package/queries/catalog/dependencies-query/function-info/visualize-functions.js +4 -46
- package/queries/catalog/dependencies-query/function-info/write-functions.js +3 -76
- package/queries/catalog/dependencies-query/implicit-echo.js +2 -2
- package/queries/catalog/dependencies-query/link-devices.d.ts +2 -2
- package/queries/catalog/dependencies-query/link-devices.js +6 -7
- package/queries/catalog/dice-query/dice-query-executor.js +1 -1
- package/queries/catalog/dice-query/dice-query-format.d.ts +1 -1
- package/queries/catalog/does-call-query/does-call-query-executor.js +4 -0
- package/queries/catalog/does-call-query/does-call-query-format.d.ts +7 -1
- package/queries/catalog/files-query/files-query-format.d.ts +1 -1
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +1 -1
- package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -1
- package/queries/catalog/id-map-query/id-map-query-format.d.ts +1 -1
- package/queries/catalog/input-sources-query/input-source-functions.d.ts +1 -1
- package/queries/catalog/input-sources-query/input-source-functions.js +2 -2
- package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +7 -17
- package/queries/catalog/input-sources-query/input-sources-query-format.js +11 -27
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +1 -1
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.d.ts +3 -8
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +2 -11
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.d.ts +4 -0
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.js +60 -0
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.d.ts +35 -0
- package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +63 -0
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +3 -6
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.d.ts +3 -8
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +2 -11
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.d.ts +3 -8
- package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +2 -12
- package/queries/catalog/linter-query/linter-query-format.d.ts +1 -1
- package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +1 -1
- package/queries/catalog/origin-query/origin-query-format.d.ts +1 -1
- package/queries/catalog/project-query/project-query-format.d.ts +1 -1
- package/queries/catalog/provenance-query/provenance-query-format.d.ts +3 -8
- package/queries/catalog/provenance-query/provenance-query-format.js +2 -14
- package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -1
- package/queries/catalog/search-query/search-query-format.d.ts +1 -1
- package/queries/catalog/signature-query/signature-query-executor.d.ts +5 -10
- package/queries/catalog/signature-query/signature-query-executor.js +87 -93
- package/queries/catalog/signature-query/signature-query-format.d.ts +20 -5
- package/queries/catalog/signature-query/signature-query-format.js +16 -4
- package/queries/catalog/signature-query/signature-query-render.js +18 -4
- package/queries/catalog/slice-query-options.d.ts +14 -0
- package/queries/catalog/slice-query-options.js +15 -0
- package/queries/catalog/static-slice-query/static-slice-query-executor.d.ts +2 -1
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +3 -2
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +4 -3
- package/queries/catalog/static-slice-query/static-slice-query-format.js +7 -5
- package/queries/query-function-filter.d.ts +8 -3
- package/queries/query-function-filter.js +16 -6
- package/queries/query.d.ts +38 -38
- package/queries/query.js +30 -4
- package/r-bridge/lang-4.x/ast/model/model.d.ts +5 -0
- package/r-bridge/lang-4.x/ast/model/model.js +14 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +17 -9
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +35 -27
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +33 -22
- package/reconstruct/reconstruct.d.ts +9 -20
- package/reconstruct/reconstruct.js +66 -28
- package/search/flowr-search-filters.d.ts +7 -6
- package/search/flowr-search-filters.js +6 -4
- package/search/search-executor/search-enrichers.d.ts +10 -10
- package/search/search-executor/search-enrichers.js +32 -3
- package/search/search-executor/search-transformer.js +15 -23
- package/slicing/criterion/parse.js +2 -12
- package/slicing/static/slice-call.js +1 -8
- package/slicing/static/static-slicer.js +1 -1
- package/util/collections/bimap.js +14 -6
- package/util/objects.js +16 -17
- package/util/r-value.d.ts +5 -4
- package/util/record.d.ts +38 -3
- package/util/record.js +48 -1
- package/util/simple-df/dfg-ascii.js +1 -1
- package/util/text/strings.d.ts +5 -0
- package/util/text/strings.js +10 -0
- package/util/version.js +2 -2
- package/abstract-interpretation/absint-visitor.d.ts +0 -223
- package/abstract-interpretation/data-frame/mappers/access-mapper.d.ts +0 -19
- package/abstract-interpretation/data-frame/mappers/access-mapper.js +0 -151
- package/abstract-interpretation/data-frame/mappers/function-mapper.d.ts +0 -287
- package/abstract-interpretation/data-frame/mappers/function-mapper.js +0 -1096
- package/abstract-interpretation/data-frame/mappers/replacement-mapper.d.ts +0 -15
- package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +0 -207
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.d.ts +0 -6
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.js +0 -25
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.d.ts +0 -31
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.js +0 -56
|
@@ -4,6 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RDAParser = exports.SerializationFormat = exports.SexpType = exports.SerializationTypeTag = exports.CompressionType = exports.FlowrRDAFile = void 0;
|
|
7
|
+
exports.attributeOf = attributeOf;
|
|
8
|
+
exports.stringsOf = stringsOf;
|
|
9
|
+
exports.namesOf = namesOf;
|
|
10
|
+
exports.elementOf = elementOf;
|
|
7
11
|
const flowr_file_1 = require("../../../context/flowr-file");
|
|
8
12
|
const fs_1 = __importDefault(require("fs"));
|
|
9
13
|
const assert_1 = require("../../../../util/assert");
|
|
@@ -15,32 +19,20 @@ const shell_executor_1 = require("../../../../r-bridge/shell-executor");
|
|
|
15
19
|
class FlowrRDAFile extends flowr_file_1.FlowrFile {
|
|
16
20
|
wrapped;
|
|
17
21
|
shortcut;
|
|
18
|
-
/**
|
|
19
|
-
* Prefer the static {@link FlowrRDAFile.from} method to create instances of this class as it will not re-create if already a description file
|
|
20
|
-
* and handle role assignments.
|
|
21
|
-
* @param file - The underlying file provider whose path points to an RDA file.
|
|
22
|
-
* @param shortcut - When `true`, only top-level object names and types are
|
|
23
|
-
* collected during parsing. Payload data is skipped.
|
|
24
|
-
*/
|
|
22
|
+
/** Prefer {@link FlowrRDAFile.from}, which avoids re-wrapping and handles roles. `shortcut` collects only top-level names/types and skips payloads when `true`. */
|
|
25
23
|
constructor(file, shortcut = true) {
|
|
26
24
|
super(file.path(), file.roles);
|
|
27
25
|
this.wrapped = file;
|
|
28
26
|
this.shortcut = shortcut;
|
|
29
27
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Loads and parses the content of the wrapped file as an RDA structure.
|
|
32
|
-
* @see {@link parse} for details on the parsing logic.
|
|
33
|
-
* @returns An array of top-level {@link RObjectData}s or `[{}]` when the
|
|
34
|
-
* file contains no R objects.
|
|
35
|
-
*/
|
|
28
|
+
/** See {@link RDAParser.parse}. Answers top-level {@link RObjectData}s, or `[{}]` when the file holds no R objects. */
|
|
36
29
|
loadContent() {
|
|
37
30
|
return new RDAParser(this.wrapped, this.shortcut).parse() ?? [{}];
|
|
38
31
|
}
|
|
39
32
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param file -
|
|
42
|
-
* @param role -
|
|
43
|
-
* @returns The (possibly newly created) {@link FlowrRDAFile}.
|
|
33
|
+
* Lifts a file to a {@link FlowrRDAFile}, reusing it if already one and assigning roles.
|
|
34
|
+
* @param file - The file to lift or return if already an RDA file
|
|
35
|
+
* @param role - An optional role to assign to the file
|
|
44
36
|
*/
|
|
45
37
|
static from(file, role) {
|
|
46
38
|
if (role) {
|
|
@@ -118,6 +110,15 @@ const SerializationMagic = {
|
|
|
118
110
|
'RDB3\n': SerializationTypeTag.MagicBinaryV3,
|
|
119
111
|
'RDX3\n': SerializationTypeTag.MagicXdrV3,
|
|
120
112
|
};
|
|
113
|
+
/** the format byte a bare serialization stream opens with, before its newline */
|
|
114
|
+
const BareStreamFormats = new Set(['A', 'B', 'X']);
|
|
115
|
+
/**
|
|
116
|
+
* Whether `buf` is a bare serialization stream rather than a saved workspace: an `.rds` written by `saveRDS`
|
|
117
|
+
* carries no `RDX3\n` magic and no pairlist of names, it starts straight at the format byte.
|
|
118
|
+
*/
|
|
119
|
+
function isBareSerializationStream(buf) {
|
|
120
|
+
return buf.length >= 2 && buf[1] === 0x0a && BareStreamFormats.has(String.fromCodePoint(buf[0]));
|
|
121
|
+
}
|
|
121
122
|
/** The variants {@link RDAParser.deserialize} handles. */
|
|
122
123
|
const SupportedSerializationTypes = new Set([
|
|
123
124
|
SerializationTypeTag.MagicAsciiV2, SerializationTypeTag.MagicBinaryV2, SerializationTypeTag.MagicXdrV2,
|
|
@@ -208,6 +209,20 @@ var SerializationFormat;
|
|
|
208
209
|
SerializationFormat["Ascii"] = "ASCII";
|
|
209
210
|
SerializationFormat["Binary"] = "BINARY";
|
|
210
211
|
})(SerializationFormat || (exports.SerializationFormat = SerializationFormat = {}));
|
|
212
|
+
/** pairlist-based SEXP types {@link RDAParser.readItemIterative} unrolls iteratively rather than recursing per element. */
|
|
213
|
+
const IterativeSexpTypes = new Set([
|
|
214
|
+
SexpType.ListSxp, SexpType.LangSxp, SexpType.CloSxp, SexpType.PromSxp, SexpType.DotSxp
|
|
215
|
+
]);
|
|
216
|
+
/** the `{ value, type }` every parameterless special SEXP marker in {@link RDAParser.readItemRecursive} decodes to directly. */
|
|
217
|
+
const SpecialValueSxps = new Map([
|
|
218
|
+
[SexpType.NilValueSxp, { value: RValues.NilValue, type: SexpType.NilSxp }],
|
|
219
|
+
[SexpType.EmptyEnvSxp, { value: RValues.EmptyEnv, type: SexpType.EnvSxp }],
|
|
220
|
+
[SexpType.BaseEnvSxp, { value: RValues.BaseEnv, type: SexpType.EnvSxp }],
|
|
221
|
+
[SexpType.GlobalEnvSxp, { value: RValues.GlobalEnv, type: SexpType.EnvSxp }],
|
|
222
|
+
[SexpType.UnboundValueSxp, { value: RValues.UnboundValue, type: SexpType.EnvSxp }],
|
|
223
|
+
[SexpType.MissingArgSxp, { value: RValues.MissingArg, type: SexpType.EnvSxp }],
|
|
224
|
+
[SexpType.BaseNamespaceSxp, { value: RValues.BaseNamespace, type: SexpType.EnvSxp }],
|
|
225
|
+
]);
|
|
211
226
|
/**
|
|
212
227
|
* Parser for RDA files.
|
|
213
228
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c | R source: serialize.c}
|
|
@@ -229,26 +244,13 @@ class RDAParser {
|
|
|
229
244
|
format;
|
|
230
245
|
refTable = [];
|
|
231
246
|
Registry = null;
|
|
232
|
-
/**
|
|
233
|
-
* @param file - The RDA file to read.
|
|
234
|
-
* @param shortcut - When `true`, only top-level object names and types are collected, payloads are skipped.
|
|
235
|
-
*/
|
|
236
247
|
constructor(file, shortcut = true) {
|
|
237
248
|
this.file = file;
|
|
238
249
|
this.shortcut = shortcut;
|
|
239
250
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Parses an RDA file.
|
|
242
|
-
*
|
|
243
|
-
* The file is decompressed, deserialized, and converted into a flattened object representation,
|
|
244
|
-
* as far as the `shortcut` the parser was constructed with asks for.
|
|
245
|
-
* @returns List of found {@link RObjectData} or `null` if the file is empty.
|
|
246
|
-
*/
|
|
251
|
+
/** Decompresses, deserializes, and flattens (per the constructor's `shortcut`) the file. Answers found {@link RObjectData}s, `null` if the file is empty. */
|
|
247
252
|
parse() {
|
|
248
|
-
const
|
|
249
|
-
const compressionType = this.detectCompression(fileContent);
|
|
250
|
-
this.buffer = this.decompress(fileContent, compressionType);
|
|
251
|
-
const result = this.deserialize2();
|
|
253
|
+
const result = this.parseObject();
|
|
252
254
|
if (result === RValues.NilValue) {
|
|
253
255
|
return null;
|
|
254
256
|
}
|
|
@@ -257,12 +259,17 @@ class RDAParser {
|
|
|
257
259
|
}
|
|
258
260
|
}
|
|
259
261
|
/**
|
|
260
|
-
*
|
|
261
|
-
* @
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
262
|
+
* Parses the file into the single R object it serializes (what an `.rds` holds), without the flattening
|
|
263
|
+
* {@link parse} applies. Answers the deserialized object, {@link RValues.NilValue} for an empty file.
|
|
264
|
+
*/
|
|
265
|
+
parseObject() {
|
|
266
|
+
const fileContent = fs_1.default.readFileSync(this.file.path());
|
|
267
|
+
this.buffer = this.decompress(fileContent, this.detectCompression(fileContent));
|
|
268
|
+
return this.deserialize2();
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* First {@link CompressionSignatures} entry `buf` matches, {@link CompressionType.CompUnknownOrNo} if none does.
|
|
272
|
+
* Throws Error if the file is of a recognized but unreadable kind. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/connections.c#L2675-L2710 | R source: comp_type_from_memory}
|
|
266
273
|
*/
|
|
267
274
|
detectCompression(buf, withZlib = false) {
|
|
268
275
|
for (const signature of CompressionSignatures) {
|
|
@@ -276,13 +283,7 @@ class RDAParser {
|
|
|
276
283
|
}
|
|
277
284
|
return CompressionType.CompUnknownOrNo;
|
|
278
285
|
}
|
|
279
|
-
/**
|
|
280
|
-
* Decompresses the given RDA file buffer.
|
|
281
|
-
* @param fileContent - Raw compressed file buffer.
|
|
282
|
-
* @param compressionType - {@link CompressionType} as returned by {@link detectCompression}.
|
|
283
|
-
* @returns Decompressed buffer.
|
|
284
|
-
* @throws Error for unsupported compression types.
|
|
285
|
-
*/
|
|
286
|
+
/** Decompresses `fileContent` per the {@link detectCompression} result `compressionType`. Throws error for unsupported compression types. */
|
|
286
287
|
decompress(fileContent, compressionType) {
|
|
287
288
|
let buffer;
|
|
288
289
|
switch (compressionType) {
|
|
@@ -321,9 +322,7 @@ class RDAParser {
|
|
|
321
322
|
return buffer;
|
|
322
323
|
}
|
|
323
324
|
/**
|
|
324
|
-
*
|
|
325
|
-
* @param buf - Buffer with decompressed RDA-file content
|
|
326
|
-
* @returns The identified {@link SerializationTypes} of decompressed RDA-file
|
|
325
|
+
* Identifies the {@link SerializationTypes} of a decompressed RDA-file buffer.
|
|
327
326
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/saveload.c#L1808-L1858 | R source: R_ReadMagic}
|
|
328
327
|
*/
|
|
329
328
|
determineSerializationType(buf) {
|
|
@@ -346,12 +345,15 @@ class RDAParser {
|
|
|
346
345
|
return Number(buf.toString('ascii', 0, 4));
|
|
347
346
|
}
|
|
348
347
|
/**
|
|
349
|
-
* Deserializes a decompressed RDA-file.
|
|
350
|
-
* @returns Deserialized RDA-file as {@link RObject} or {@link RValues.NilValue}, if the deserialization fails
|
|
348
|
+
* Deserializes a decompressed RDA-file. Answers {@link RObject}, or {@link RValues.NilValue} if deserialization fails.
|
|
351
349
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/saveload.c#L1923-L1972 | R source: R_LoadFromFile}
|
|
352
350
|
*/
|
|
353
351
|
deserialize2() {
|
|
354
352
|
this.offset = 0;
|
|
353
|
+
/* an `.rds` holds a single object as a bare stream: no workspace magic, no pairlist of names */
|
|
354
|
+
if (isBareSerializationStream(this.buffer)) {
|
|
355
|
+
return this.deserialize();
|
|
356
|
+
}
|
|
355
357
|
const serializationType = this.determineSerializationType(this.buffer);
|
|
356
358
|
this.offset += 5;
|
|
357
359
|
if (serializationType === SerializationTypeTag.MagicCorrupt ||
|
|
@@ -367,11 +369,7 @@ class RDAParser {
|
|
|
367
369
|
}
|
|
368
370
|
return RValues.NilValue;
|
|
369
371
|
}
|
|
370
|
-
/**
|
|
371
|
-
* Deserializes a decompressed RDA-file.
|
|
372
|
-
* @returns Deserialized RDA-file as {@link RObject}
|
|
373
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2237-L2292 | R source: R_Unserialize}
|
|
374
|
-
*/
|
|
372
|
+
/** Deserializes a decompressed RDA-file. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2237-L2292 | R source: R_Unserialize} */
|
|
375
373
|
deserialize() {
|
|
376
374
|
switch (String.fromCodePoint(this.buffer[this.offset])) {
|
|
377
375
|
case 'A':
|
|
@@ -423,11 +421,7 @@ class RDAParser {
|
|
|
423
421
|
}
|
|
424
422
|
return this.readItem();
|
|
425
423
|
}
|
|
426
|
-
/**
|
|
427
|
-
* Reads a serialized integer value from the current buffer position.
|
|
428
|
-
* @returns Parsed integer value or {@link RValues.NaInteger}.
|
|
429
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L396-L420 | R source: inInteger}
|
|
430
|
-
*/
|
|
424
|
+
/** Reads a serialized integer. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L396-L420 | R source: inInteger} */
|
|
431
425
|
inInteger() {
|
|
432
426
|
switch (this.format) {
|
|
433
427
|
case SerializationFormat.Ascii: {
|
|
@@ -455,11 +449,7 @@ class RDAParser {
|
|
|
455
449
|
return RValues.NaInteger;
|
|
456
450
|
}
|
|
457
451
|
}
|
|
458
|
-
/**
|
|
459
|
-
* Advances the buffer offset past a serialized integer value.
|
|
460
|
-
*
|
|
461
|
-
* Mirrors {@link inInteger}.
|
|
462
|
-
*/
|
|
452
|
+
/** Advances past a serialized integer. Mirrors {@link inInteger}. */
|
|
463
453
|
skipInteger() {
|
|
464
454
|
if (this.format === SerializationFormat.Ascii) {
|
|
465
455
|
this.skipWord();
|
|
@@ -468,24 +458,14 @@ class RDAParser {
|
|
|
468
458
|
this.offset += 4;
|
|
469
459
|
}
|
|
470
460
|
}
|
|
471
|
-
|
|
472
|
-
* Ensures that the given value is not {@link RValues.NaInteger}.
|
|
473
|
-
* @param value - Integer value to be tested.
|
|
474
|
-
* @returns The validated integer value.
|
|
475
|
-
* @throws Error if the value equals `RValues.NaInteger`.
|
|
476
|
-
*/
|
|
461
|
+
/**. Throws error if `value` is {@link RValues.NaInteger}. */
|
|
477
462
|
assertInteger(value) {
|
|
478
463
|
if (value === RValues.NaInteger) {
|
|
479
464
|
throw new Error('Unexpected NA integer');
|
|
480
465
|
}
|
|
481
466
|
return value;
|
|
482
467
|
}
|
|
483
|
-
|
|
484
|
-
* Ensures that the given object is not {@link RValues.NilValue}.
|
|
485
|
-
* @param obj - R object to validate.
|
|
486
|
-
* @returns The validated {@link RObjectData}.
|
|
487
|
-
* @throws Error if the object equals {@link RValues.NilValue}.
|
|
488
|
-
*/
|
|
468
|
+
/**. Throws error if `obj` is {@link RValues.NilValue}. */
|
|
489
469
|
assertRObjectData(obj) {
|
|
490
470
|
if (obj === RValues.NilValue) {
|
|
491
471
|
throw new Error('Unexpected NilValue');
|
|
@@ -493,10 +473,7 @@ class RDAParser {
|
|
|
493
473
|
return obj;
|
|
494
474
|
}
|
|
495
475
|
/**
|
|
496
|
-
* Reads an ASCII word
|
|
497
|
-
* @param size - Maximum allowed word size.
|
|
498
|
-
* @returns The parsed word.
|
|
499
|
-
* @throws Error if EOF is reached or the word exceeds the allowed size.
|
|
476
|
+
* Reads an ASCII word of at most `size` bytes. Throws error on EOF or overflow.
|
|
500
477
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L378-L394 | R source: inWord}
|
|
501
478
|
*/
|
|
502
479
|
inWord(size) {
|
|
@@ -518,21 +495,12 @@ class RDAParser {
|
|
|
518
495
|
}
|
|
519
496
|
return word.join('');
|
|
520
497
|
}
|
|
521
|
-
/**
|
|
522
|
-
* Skips an ASCII word in the input buffer.
|
|
523
|
-
*
|
|
524
|
-
* Mirrors {@link inWord}
|
|
525
|
-
* @returns An empty string.
|
|
526
|
-
* @throws Error if EOF is reached or the word exceeds {@link RDAParser.WORD_SIZE}.
|
|
527
|
-
*/
|
|
498
|
+
/** Skips an ASCII word. Mirrors {@link inWord}. Throws error on EOF or overflow past {@link RDAParser.WORD_SIZE}. */
|
|
528
499
|
skipWord() {
|
|
529
500
|
this.inWord(RDAParser.WORD_SIZE);
|
|
530
501
|
return '';
|
|
531
502
|
}
|
|
532
|
-
|
|
533
|
-
* Reads the next character from the input buffer.
|
|
534
|
-
* @returns The next character or `-1` on EOF.
|
|
535
|
-
*/
|
|
503
|
+
/**. Answers the next character, or `-1` on EOF. */
|
|
536
504
|
inChar() {
|
|
537
505
|
if (this.offset >= this.buffer.length) {
|
|
538
506
|
return -1;
|
|
@@ -541,18 +509,12 @@ class RDAParser {
|
|
|
541
509
|
this.offset++;
|
|
542
510
|
return char;
|
|
543
511
|
}
|
|
544
|
-
/**
|
|
545
|
-
* Checks whether the given byte represents a whitespace character.
|
|
546
|
-
* @param c - Character code to check.
|
|
547
|
-
* @returns `true` if the character is whitespace.
|
|
548
|
-
*/
|
|
512
|
+
/** Whether `c` is a whitespace byte. */
|
|
549
513
|
isSpace(c) {
|
|
550
514
|
return c >= 9 && c <= 13 || c === 32;
|
|
551
515
|
}
|
|
552
516
|
/**
|
|
553
|
-
* Reads a serialized string
|
|
554
|
-
* @param len - Length of the serialized string.
|
|
555
|
-
* @returns Decoded string.
|
|
517
|
+
* Reads a serialized string of `len` bytes.
|
|
556
518
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L505-L550 | R source: inString}
|
|
557
519
|
*/
|
|
558
520
|
inString(len) {
|
|
@@ -641,12 +603,7 @@ class RDAParser {
|
|
|
641
603
|
return bytes.toString('latin1');
|
|
642
604
|
}
|
|
643
605
|
}
|
|
644
|
-
/**
|
|
645
|
-
* Skips a serialized string depending on the current serialization format.
|
|
646
|
-
*
|
|
647
|
-
* Mirrors {@link inString}
|
|
648
|
-
* @param len - Length of the serialized string.
|
|
649
|
-
*/
|
|
606
|
+
/** Skips a serialized string of `len` bytes. Mirrors {@link inString}. */
|
|
650
607
|
skipString(len) {
|
|
651
608
|
if (this.format === SerializationFormat.Ascii) {
|
|
652
609
|
// the escape handling makes the consumed length depend on the content, so we have to decode it
|
|
@@ -657,9 +614,7 @@ class RDAParser {
|
|
|
657
614
|
}
|
|
658
615
|
}
|
|
659
616
|
/**
|
|
660
|
-
* Decodes an R writer version
|
|
661
|
-
* @param writerVersion - Encoded writer version.
|
|
662
|
-
* @returns Tuple containing version components `[v,p,s]`.
|
|
617
|
+
* Decodes an encoded R writer version into `[v, p, s]`.
|
|
663
618
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2230-L2235 | R source: decodeVersion}
|
|
664
619
|
*/
|
|
665
620
|
decodeVersion(writerVersion) {
|
|
@@ -671,101 +626,54 @@ class RDAParser {
|
|
|
671
626
|
return [v, p, s];
|
|
672
627
|
}
|
|
673
628
|
/**
|
|
674
|
-
* Reads the next flags and dispatches to {@link readItemRecursive}
|
|
675
|
-
*
|
|
676
|
-
* during deserialization.
|
|
629
|
+
* Reads the next flags and dispatches to {@link readItemRecursive}; the main recursive entry point for every R
|
|
630
|
+
* object encountered during deserialization.
|
|
677
631
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2117-L2121 | R source: ReadItem}
|
|
678
632
|
*/
|
|
679
633
|
readItem() {
|
|
680
634
|
const flags = this.assertInteger(this.inInteger());
|
|
681
635
|
return this.readItemRecursive(flags);
|
|
682
636
|
}
|
|
683
|
-
/**
|
|
684
|
-
|
|
685
|
-
* Simpler variant of {@link R_FindNamespace1}.
|
|
686
|
-
* @param info - The {@link RObjectData} holding the namespace/package info.
|
|
687
|
-
* @returns An {@link RObjectData} of type {@link SexpType.EnvSxp} whose
|
|
688
|
-
* `value` is set to the resolved environment. Currently only
|
|
689
|
-
* `R_GlobalEnv` is handled; other results are logged as warnings.
|
|
690
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/envir.c#L3795-L3804 | R source: R_FindNamespace}
|
|
691
|
-
*/
|
|
692
|
-
R_FindNamespace(info) {
|
|
693
|
-
const namespaceName = info.value.name;
|
|
694
|
-
const code = `getNamespace("${namespaceName}")`;
|
|
637
|
+
/** Runs `code` in R and answers an `EnvSxp`, `value` set to {@link RValues.GlobalEnv} when the result names it. Shared by {@link R_FindNamespace} and {@link R_FindNamespace1}. */
|
|
638
|
+
runNamespaceLookup(code) {
|
|
695
639
|
const shell = new shell_executor_1.RShellExecutor();
|
|
696
640
|
const result = shell.run(code);
|
|
697
641
|
shell.close();
|
|
698
|
-
const val = {};
|
|
699
|
-
val.type = SexpType.EnvSxp;
|
|
642
|
+
const val = { type: SexpType.EnvSxp };
|
|
700
643
|
if (result === '<environment: R_GlobalEnv>') {
|
|
701
644
|
val.value = RValues.GlobalEnv;
|
|
702
645
|
}
|
|
703
646
|
return val;
|
|
704
647
|
}
|
|
705
648
|
/**
|
|
706
|
-
* Resolves a
|
|
707
|
-
* @
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
649
|
+
* Resolves a namespace reference by name via `getNamespace()` in R. Simpler variant of {@link R_FindNamespace1}.
|
|
650
|
+
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/envir.c#L3795-L3804 | R source: R_FindNamespace}
|
|
651
|
+
*/
|
|
652
|
+
R_FindNamespace(info) {
|
|
653
|
+
const namespaceName = info.value.name;
|
|
654
|
+
return this.runNamespaceLookup(`getNamespace("${namespaceName}")`);
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Resolves a serialized namespace reference by executing R at runtime. See {@link R_FindNamespace} for the result shape.
|
|
711
658
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1785-L1796 | R source: R_FindNamespace1}
|
|
712
659
|
*/
|
|
713
660
|
R_FindNamespace1(info) {
|
|
714
|
-
const where =
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
const code = `..getNamespace("${info.value[0].name}", "${where.value}")`;
|
|
718
|
-
const shell = new shell_executor_1.RShellExecutor();
|
|
719
|
-
const result = shell.run(code);
|
|
720
|
-
shell.close();
|
|
721
|
-
const val = {};
|
|
722
|
-
val.type = SexpType.EnvSxp;
|
|
723
|
-
if (result == '<environment: R_GlobalEnv>') {
|
|
724
|
-
val.value = RValues.GlobalEnv;
|
|
725
|
-
}
|
|
726
|
-
return val;
|
|
661
|
+
const where = this.lastName;
|
|
662
|
+
const code = `..getNamespace("${info.value[0].name}", "${where}")`;
|
|
663
|
+
return this.runNamespaceLookup(code);
|
|
727
664
|
}
|
|
728
665
|
/**
|
|
729
|
-
* Deserializes a single SEXP node
|
|
730
|
-
*
|
|
731
|
-
* The method dispatches to the corresponding deserialization logic
|
|
732
|
-
* depending on the encoded {@link SexpType}.
|
|
733
|
-
* @param flags - Serialized SEXP flags word.
|
|
734
|
-
* @returns Deserialized {@link RObjectData}.
|
|
666
|
+
* Deserializes a single SEXP node, dispatching on its encoded {@link SexpType}.
|
|
735
667
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1871-L2115 | R source: ReadItem_Recursive}
|
|
736
668
|
*/
|
|
737
669
|
readItemRecursive(flags) {
|
|
738
670
|
const [type, levels, object, hasAttribute, _hasTag] = this.unpackFlags(flags);
|
|
739
|
-
|
|
671
|
+
const special = SpecialValueSxps.get(type);
|
|
672
|
+
if (special) {
|
|
673
|
+
return { ...special };
|
|
674
|
+
}
|
|
675
|
+
let s;
|
|
740
676
|
switch (type) {
|
|
741
|
-
case SexpType.NilValueSxp:
|
|
742
|
-
s.value = RValues.NilValue;
|
|
743
|
-
s.type = SexpType.NilSxp;
|
|
744
|
-
return s;
|
|
745
|
-
case SexpType.EmptyEnvSxp:
|
|
746
|
-
s.value = RValues.EmptyEnv;
|
|
747
|
-
s.type = SexpType.EnvSxp;
|
|
748
|
-
return s;
|
|
749
|
-
case SexpType.BaseEnvSxp:
|
|
750
|
-
s.value = RValues.BaseEnv;
|
|
751
|
-
s.type = SexpType.EnvSxp;
|
|
752
|
-
return s;
|
|
753
|
-
case SexpType.GlobalEnvSxp:
|
|
754
|
-
s.value = RValues.GlobalEnv;
|
|
755
|
-
s.type = SexpType.EnvSxp;
|
|
756
|
-
return s;
|
|
757
|
-
case SexpType.UnboundValueSxp:
|
|
758
|
-
s.value = RValues.UnboundValue;
|
|
759
|
-
s.type = SexpType.EnvSxp;
|
|
760
|
-
return s;
|
|
761
|
-
case SexpType.MissingArgSxp:
|
|
762
|
-
s.value = RValues.MissingArg;
|
|
763
|
-
s.type = SexpType.EnvSxp;
|
|
764
|
-
return s;
|
|
765
|
-
case SexpType.BaseNamespaceSxp:
|
|
766
|
-
s.value = RValues.BaseNamespace;
|
|
767
|
-
s.type = SexpType.EnvSxp;
|
|
768
|
-
return s;
|
|
769
677
|
case SexpType.RefSxp: return this.getReadRef(this.inRefIndex(flags));
|
|
770
678
|
case SexpType.PersistSxp: {
|
|
771
679
|
s = this.inStringVec();
|
|
@@ -773,25 +681,10 @@ class RDAParser {
|
|
|
773
681
|
return s;
|
|
774
682
|
}
|
|
775
683
|
case SexpType.AltRepSxp:
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
const state = this.readItem();
|
|
781
|
-
const attr = this.readItem();
|
|
782
|
-
s.type = info.cdr.cdr.car.type;
|
|
783
|
-
s = this.AltRepUnserializeEx(info, state, attr, object, levels);
|
|
784
|
-
this.currentDepth--;
|
|
785
|
-
return s;
|
|
786
|
-
}
|
|
787
|
-
case SexpType.SymSxp: {
|
|
788
|
-
this.currentDepth++;
|
|
789
|
-
s = this.assertRObjectData(this.readItem());
|
|
790
|
-
this.currentDepth--;
|
|
791
|
-
s.type = SexpType.SymSxp;
|
|
792
|
-
this.addReadRef(s);
|
|
793
|
-
return s;
|
|
794
|
-
}
|
|
684
|
+
console.warn('AltReps are not supported yet!');
|
|
685
|
+
return this.readOrSkipAltRep(object, levels, false);
|
|
686
|
+
case SexpType.SymSxp:
|
|
687
|
+
return this.readOrSkipSym(false);
|
|
795
688
|
case SexpType.PackageSxp:
|
|
796
689
|
{
|
|
797
690
|
s = this.inStringVec();
|
|
@@ -805,32 +698,7 @@ class RDAParser {
|
|
|
805
698
|
this.addReadRef(s);
|
|
806
699
|
return s;
|
|
807
700
|
case SexpType.EnvSxp:
|
|
808
|
-
|
|
809
|
-
const locked = this.inInteger();
|
|
810
|
-
s.type = SexpType.EnvSxp;
|
|
811
|
-
this.addReadRef(s);
|
|
812
|
-
this.currentDepth++;
|
|
813
|
-
this.SetEnClos(s, this.assertRObjectData(this.readItem()));
|
|
814
|
-
s.frame = this.readItem();
|
|
815
|
-
s.hashTab = this.readItem();
|
|
816
|
-
s.attributes = this.assertRObjectData(this.readItem()).attributes;
|
|
817
|
-
this.currentDepth--;
|
|
818
|
-
if (s.attributes?.some(e => e.name === RValues.ClassSymbol)) {
|
|
819
|
-
s._isObject = true;
|
|
820
|
-
}
|
|
821
|
-
// R_RestoreHashCount(s);
|
|
822
|
-
if (locked) {
|
|
823
|
-
s._isLocked = false;
|
|
824
|
-
}
|
|
825
|
-
if (!s.enClos || s.enClos === RValues.NilValue) {
|
|
826
|
-
this.SetEnClos(s, {
|
|
827
|
-
value: RValues.BaseEnv,
|
|
828
|
-
type: SexpType.EnvSxp,
|
|
829
|
-
enClos: RValues.NilValue
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
return s;
|
|
833
|
-
}
|
|
701
|
+
return this.readOrSkipEnv(false);
|
|
834
702
|
case SexpType.ListSxp:
|
|
835
703
|
case SexpType.LangSxp:
|
|
836
704
|
case SexpType.CloSxp:
|
|
@@ -838,145 +706,241 @@ class RDAParser {
|
|
|
838
706
|
case SexpType.DotSxp:
|
|
839
707
|
return this.readItemIterative(flags);
|
|
840
708
|
default:
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
709
|
+
return this.readOrSkipLeaf(type, levels, object, hasAttribute, false);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
/** Reads (or with `skip`, discards) a `SymSxp` symbol. Shared by {@link readItemRecursive} and {@link skipItem}. */
|
|
713
|
+
readOrSkipSym(skip) {
|
|
714
|
+
this.currentDepth++;
|
|
715
|
+
const s = skip ? this.skipItem() : this.assertRObjectData(this.readItem());
|
|
716
|
+
this.currentDepth--;
|
|
717
|
+
s.type = SexpType.SymSxp;
|
|
718
|
+
this.addReadRef(s);
|
|
719
|
+
return s;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Reads (or with `skip`, discards) an `AltRepSxp`. Only `skip === false` attempts {@link AltRepUnserializeEx};
|
|
723
|
+
* discarding it just derives the base type its payload triple encodes. Shared by {@link readItemRecursive} and {@link skipItem}.
|
|
724
|
+
*/
|
|
725
|
+
readOrSkipAltRep(object, levels, skip) {
|
|
726
|
+
this.currentDepth++;
|
|
727
|
+
const info = skip ? this.skipItem() : this.readItem();
|
|
728
|
+
const state = skip ? this.skipItem() : this.readItem();
|
|
729
|
+
const attr = skip ? this.skipItem() : this.readItem();
|
|
730
|
+
const s = skip ?
|
|
731
|
+
{ type: info.cdr.cdr.car.type } :
|
|
732
|
+
this.AltRepUnserializeEx(info, state, attr, object, levels);
|
|
733
|
+
this.currentDepth--;
|
|
734
|
+
return s;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Reads (or with `skip`, discards) an `EnvSxp` environment frame; the locked/class-object bookkeeping only matters when kept.
|
|
738
|
+
* Shared by {@link readItemRecursive} and {@link skipItem}.
|
|
739
|
+
*/
|
|
740
|
+
readOrSkipEnv(skip) {
|
|
741
|
+
let locked = 0;
|
|
742
|
+
if (skip) {
|
|
743
|
+
this.skipInteger();
|
|
744
|
+
}
|
|
745
|
+
else {
|
|
746
|
+
locked = this.inInteger();
|
|
747
|
+
}
|
|
748
|
+
const s = { type: SexpType.EnvSxp };
|
|
749
|
+
this.addReadRef(s);
|
|
750
|
+
this.currentDepth++;
|
|
751
|
+
this.SetEnClos(s, this.assertRObjectData(skip ? this.skipItem() : this.readItem()));
|
|
752
|
+
s.frame = skip ? this.skipItem() : this.readItem();
|
|
753
|
+
s.hashTab = skip ? this.skipItem() : this.readItem();
|
|
754
|
+
s.attributes = this.assertRObjectData(skip ? this.skipItem() : this.readItem()).attributes;
|
|
755
|
+
this.currentDepth--;
|
|
756
|
+
if (!skip) {
|
|
757
|
+
if (s.attributes?.some(e => e.name === RValues.ClassSymbol)) {
|
|
758
|
+
s._isObject = true;
|
|
759
|
+
}
|
|
760
|
+
// R_RestoreHashCount(s);
|
|
761
|
+
if (locked) {
|
|
762
|
+
s._isLocked = false;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
if (!s.enClos || s.enClos === RValues.NilValue) {
|
|
766
|
+
this.SetEnClos(s, {
|
|
767
|
+
value: RValues.BaseEnv,
|
|
768
|
+
type: SexpType.EnvSxp,
|
|
769
|
+
enClos: RValues.NilValue
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
return s;
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Reads (or with `skip`, discards) the payload of a leaf SEXP node, shared by {@link readItemRecursive} and {@link skipItem}.
|
|
776
|
+
* `skip` mirrors their field-by-field differences exactly; see the branches below.
|
|
777
|
+
*/
|
|
778
|
+
readOrSkipLeaf(type, levels, object, hasAttribute, skip) {
|
|
779
|
+
let s = {};
|
|
780
|
+
switch (type) {
|
|
781
|
+
case SexpType.ExtPtrSxp: {
|
|
782
|
+
s.type = type;
|
|
783
|
+
this.addReadRef(s);
|
|
784
|
+
if (!skip) {
|
|
785
|
+
s.address = null;
|
|
786
|
+
}
|
|
787
|
+
this.currentDepth++;
|
|
788
|
+
s.protected = skip ? this.skipItem() : this.readItem();
|
|
789
|
+
s.tag = skip ? this.skipItem() : this.readItem();
|
|
790
|
+
this.currentDepth--;
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
case SexpType.WeakRefSxp: {
|
|
794
|
+
const nilSxp = { type: SexpType.NilSxp, value: RValues.NilValue };
|
|
795
|
+
s.value = this.R_MakeWeakRef(nilSxp, RValues.NilValue, nilSxp, false);
|
|
796
|
+
this.addReadRef(s);
|
|
797
|
+
break;
|
|
798
|
+
}
|
|
799
|
+
case SexpType.SpecialSxp:
|
|
800
|
+
case SexpType.BuiltInSxp: {
|
|
801
|
+
const len = this.assertInteger(this.inInteger());
|
|
802
|
+
if (len < 0) {
|
|
803
|
+
throw new Error('invalid length');
|
|
804
|
+
}
|
|
805
|
+
if (skip) {
|
|
806
|
+
s.type = type;
|
|
807
|
+
this.skipString(len);
|
|
808
|
+
}
|
|
809
|
+
else {
|
|
810
|
+
const name = this.inString(len);
|
|
811
|
+
if (!(name in r_fun_tab_1.RFunTabOffsets)) {
|
|
812
|
+
throw new Error(`unrecognized internal function name "${name}"`);
|
|
883
813
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
814
|
+
const index = r_fun_tab_1.RFunTabOffsets[name];
|
|
815
|
+
s = this.mkPrimSxp(index, type === SexpType.BuiltInSxp ? 1 : 0);
|
|
816
|
+
}
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
case SexpType.CharSxp: {
|
|
820
|
+
const len = this.assertInteger(this.inInteger());
|
|
821
|
+
if (len < -1) {
|
|
822
|
+
throw new Error(`Invalid length ${len} of string.`);
|
|
823
|
+
}
|
|
824
|
+
else if (len == -1) {
|
|
825
|
+
s.name = RValues.NaString;
|
|
826
|
+
}
|
|
827
|
+
else {
|
|
828
|
+
s.name = this.readChar(len, levels);
|
|
829
|
+
}
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
case SexpType.LglSxp:
|
|
833
|
+
case SexpType.IntSxp: {
|
|
834
|
+
const len = this.readLength();
|
|
835
|
+
s.type = type;
|
|
836
|
+
s.value = this.inIntegerVec(len, skip);
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
case SexpType.RealSxp: {
|
|
840
|
+
const len = this.readLength();
|
|
841
|
+
s.type = type;
|
|
842
|
+
s.value = this.inRealVec(len, skip);
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
case SexpType.CplxSxp: {
|
|
846
|
+
const len = this.readLength();
|
|
847
|
+
s.type = type;
|
|
848
|
+
if (skip) {
|
|
849
|
+
this.inComplexVec(len, true);
|
|
850
|
+
}
|
|
851
|
+
else {
|
|
852
|
+
s.value = this.inComplexVec(len);
|
|
853
|
+
}
|
|
854
|
+
break;
|
|
855
|
+
}
|
|
856
|
+
case SexpType.StrSxp:
|
|
857
|
+
case SexpType.VecSxp:
|
|
858
|
+
case SexpType.ExprSxp: {
|
|
859
|
+
const len = this.readLength();
|
|
860
|
+
s.type = type;
|
|
861
|
+
this.currentDepth++;
|
|
862
|
+
if (skip) {
|
|
863
|
+
for (let count = 0; count < len; ++count) {
|
|
864
|
+
this.skipItem();
|
|
904
865
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
for (let count = 0; count < len; ++count) {
|
|
866
|
+
}
|
|
867
|
+
else {
|
|
868
|
+
s.value = new Array(len);
|
|
869
|
+
for (let count = 0; count < len; ++count) {
|
|
870
|
+
if (type === SexpType.StrSxp) {
|
|
911
871
|
this.SET_STRING_ELT(s, count, this.assertRObjectData(this.readItem()));
|
|
912
872
|
}
|
|
913
|
-
|
|
914
|
-
break;
|
|
915
|
-
}
|
|
916
|
-
case SexpType.VecSxp:
|
|
917
|
-
case SexpType.ExprSxp: {
|
|
918
|
-
const len = this.readLength();
|
|
919
|
-
s.type = type;
|
|
920
|
-
s.value = new Array(len);
|
|
921
|
-
this.currentDepth++;
|
|
922
|
-
for (let count = 0; count < len; ++count) {
|
|
873
|
+
else {
|
|
923
874
|
this.SET_VECTOR_ELT(s, count, this.readItem());
|
|
924
875
|
}
|
|
925
|
-
this.currentDepth--;
|
|
926
|
-
break;
|
|
927
|
-
}
|
|
928
|
-
case SexpType.BcodesSxp:
|
|
929
|
-
s = this.readBC();
|
|
930
|
-
break;
|
|
931
|
-
case SexpType.ClassRefSxp:
|
|
932
|
-
throw new Error('this version of R cannot read class references');
|
|
933
|
-
case SexpType.GenericRefSxp:
|
|
934
|
-
throw new Error('this version of R cannot read generic function references');
|
|
935
|
-
case SexpType.RawSxp: {
|
|
936
|
-
const len = this.readLength();
|
|
937
|
-
s.type = type;
|
|
938
|
-
s.value = this.inRaw(len);
|
|
939
|
-
break;
|
|
940
876
|
}
|
|
941
|
-
case SexpType.ObjSxp:
|
|
942
|
-
s.type = SexpType.ObjSxp;
|
|
943
|
-
break;
|
|
944
|
-
default:
|
|
945
|
-
throw new Error(`ReadItem: unknown type ${type}, perhaps written by later version of R`);
|
|
946
877
|
}
|
|
947
|
-
|
|
948
|
-
|
|
878
|
+
this.currentDepth--;
|
|
879
|
+
break;
|
|
880
|
+
}
|
|
881
|
+
case SexpType.BcodesSxp:
|
|
882
|
+
if (skip) {
|
|
883
|
+
this.skipBC();
|
|
884
|
+
s.type = SexpType.VecSxp;
|
|
949
885
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
886
|
+
else {
|
|
887
|
+
s = this.readBC();
|
|
888
|
+
}
|
|
889
|
+
break;
|
|
890
|
+
case SexpType.ClassRefSxp:
|
|
891
|
+
throw new Error('this version of R cannot read class references');
|
|
892
|
+
case SexpType.GenericRefSxp:
|
|
893
|
+
throw new Error('this version of R cannot read generic function references');
|
|
894
|
+
case SexpType.RawSxp: {
|
|
895
|
+
const len = this.readLength();
|
|
896
|
+
s.type = type;
|
|
897
|
+
if (skip) {
|
|
898
|
+
this.inRaw(len, true);
|
|
957
899
|
}
|
|
958
900
|
else {
|
|
959
|
-
this.
|
|
960
|
-
s.attributes = hasAttribute ? [this.readItem()] : undefined;
|
|
961
|
-
this.currentDepth--;
|
|
901
|
+
s.value = this.inRaw(len);
|
|
962
902
|
}
|
|
963
|
-
|
|
964
|
-
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
case SexpType.ObjSxp:
|
|
906
|
+
s.type = SexpType.ObjSxp;
|
|
907
|
+
break;
|
|
908
|
+
default:
|
|
909
|
+
throw new Error(`ReadItem: unknown type ${type}, perhaps written by later version of R`);
|
|
910
|
+
}
|
|
911
|
+
if (!skip) {
|
|
912
|
+
if (type !== SexpType.CharSxp) {
|
|
913
|
+
s.levels = levels;
|
|
914
|
+
}
|
|
915
|
+
s.object = object;
|
|
916
|
+
}
|
|
917
|
+
if (s.type === SexpType.CharSxp) {
|
|
918
|
+
this.currentDepth++;
|
|
919
|
+
if (hasAttribute) {
|
|
920
|
+
if (skip) {
|
|
921
|
+
this.skipItem();
|
|
965
922
|
}
|
|
966
|
-
|
|
923
|
+
else {
|
|
924
|
+
this.readItem();
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
this.currentDepth--;
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
this.currentDepth++;
|
|
931
|
+
s.attributes = hasAttribute ? [skip ? this.skipItem() : this.assertRObjectData(this.readItem())] : undefined;
|
|
932
|
+
this.currentDepth--;
|
|
967
933
|
}
|
|
934
|
+
if (!skip && s.type === SexpType.BcodesSxp && !this.R_BCVersionOK(s)) {
|
|
935
|
+
return this.R_BytecodeExpr(s);
|
|
936
|
+
}
|
|
937
|
+
return s;
|
|
968
938
|
}
|
|
969
|
-
/**
|
|
970
|
-
* Skips a serialized SEXP node, only filling in its type and calling other skip methods to
|
|
971
|
-
* advance the buffer position.
|
|
972
|
-
*
|
|
973
|
-
* Mirrors the structure of {@link readItemRecursive} but skips payload data.
|
|
974
|
-
* @returns A minimal {@link RObjectData} with little to no payload.
|
|
975
|
-
*/
|
|
939
|
+
/** Advances past a serialized SEXP node, filling in only its type. Mirrors {@link readItemRecursive}'s structure, but skips payload data. */
|
|
976
940
|
skipItem() {
|
|
977
941
|
const flags = this.assertInteger(this.inInteger());
|
|
978
|
-
const [type, levels,
|
|
979
|
-
|
|
942
|
+
const [type, levels, object, hasAttribute, _hasTag] = this.unpackFlags(flags);
|
|
943
|
+
const s = {};
|
|
980
944
|
switch (type) {
|
|
981
945
|
case SexpType.NilValueSxp:
|
|
982
946
|
case SexpType.EmptyEnvSxp:
|
|
@@ -990,54 +954,22 @@ class RDAParser {
|
|
|
990
954
|
case SexpType.RefSxp:
|
|
991
955
|
return this.getReadRef(this.inRefIndex(flags));
|
|
992
956
|
case SexpType.NamespaceSxp:
|
|
993
|
-
this.
|
|
957
|
+
this.inStringVec(true);
|
|
994
958
|
s.type = SexpType.EnvSxp;
|
|
995
959
|
this.addReadRef(s);
|
|
996
960
|
return s;
|
|
997
961
|
case SexpType.PackageSxp:
|
|
998
962
|
case SexpType.PersistSxp: {
|
|
999
|
-
this.
|
|
963
|
+
this.inStringVec(true);
|
|
1000
964
|
s.type = SexpType.CharSxp;
|
|
1001
965
|
return s;
|
|
1002
966
|
}
|
|
1003
967
|
case SexpType.AltRepSxp:
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
const _state = this.skipItem();
|
|
1008
|
-
const _attr = this.skipItem();
|
|
1009
|
-
s.type = info.cdr.cdr.car.type;
|
|
1010
|
-
this.currentDepth--;
|
|
1011
|
-
return s;
|
|
1012
|
-
}
|
|
1013
|
-
case SexpType.SymSxp: {
|
|
1014
|
-
this.currentDepth++;
|
|
1015
|
-
s = this.skipItem();
|
|
1016
|
-
this.currentDepth--;
|
|
1017
|
-
s.type = SexpType.SymSxp;
|
|
1018
|
-
this.addReadRef(s);
|
|
1019
|
-
return s;
|
|
1020
|
-
}
|
|
968
|
+
return this.readOrSkipAltRep(object, levels, true);
|
|
969
|
+
case SexpType.SymSxp:
|
|
970
|
+
return this.readOrSkipSym(true);
|
|
1021
971
|
case SexpType.EnvSxp:
|
|
1022
|
-
|
|
1023
|
-
this.skipInteger();
|
|
1024
|
-
s.type = SexpType.EnvSxp;
|
|
1025
|
-
this.addReadRef(s);
|
|
1026
|
-
this.currentDepth++;
|
|
1027
|
-
this.SetEnClos(s, this.assertRObjectData(this.skipItem()));
|
|
1028
|
-
s.frame = this.skipItem();
|
|
1029
|
-
s.hashTab = this.skipItem();
|
|
1030
|
-
s.attributes = this.assertRObjectData(this.skipItem()).attributes;
|
|
1031
|
-
this.currentDepth--;
|
|
1032
|
-
if (!s.enClos || s.enClos === RValues.NilValue) {
|
|
1033
|
-
this.SetEnClos(s, {
|
|
1034
|
-
value: RValues.BaseEnv,
|
|
1035
|
-
type: SexpType.EnvSxp,
|
|
1036
|
-
enClos: RValues.NilValue
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
return s;
|
|
1040
|
-
}
|
|
972
|
+
return this.readOrSkipEnv(true);
|
|
1041
973
|
case SexpType.ListSxp:
|
|
1042
974
|
case SexpType.LangSxp:
|
|
1043
975
|
case SexpType.CloSxp:
|
|
@@ -1045,168 +977,41 @@ class RDAParser {
|
|
|
1045
977
|
case SexpType.DotSxp:
|
|
1046
978
|
return this.readItemIterative(flags);
|
|
1047
979
|
default:
|
|
1048
|
-
|
|
1049
|
-
case SexpType.ExtPtrSxp: {
|
|
1050
|
-
s.type = type;
|
|
1051
|
-
this.addReadRef(s);
|
|
1052
|
-
this.currentDepth++;
|
|
1053
|
-
s.protected = this.skipItem();
|
|
1054
|
-
s.tag = this.skipItem();
|
|
1055
|
-
this.currentDepth--;
|
|
1056
|
-
break;
|
|
1057
|
-
}
|
|
1058
|
-
case SexpType.WeakRefSxp:
|
|
1059
|
-
s.value = this.R_MakeWeakRef({ type: SexpType.NilSxp, value: RValues.NilValue }, RValues.NilValue, { type: SexpType.NilSxp, value: RValues.NilValue }, false);
|
|
1060
|
-
this.addReadRef(s);
|
|
1061
|
-
break;
|
|
1062
|
-
case SexpType.SpecialSxp:
|
|
1063
|
-
case SexpType.BuiltInSxp:
|
|
1064
|
-
{
|
|
1065
|
-
s.type = type;
|
|
1066
|
-
const len = this.assertInteger(this.inInteger());
|
|
1067
|
-
if (len < 0) {
|
|
1068
|
-
throw new Error('invalid length');
|
|
1069
|
-
}
|
|
1070
|
-
this.skipString(len);
|
|
1071
|
-
}
|
|
1072
|
-
break;
|
|
1073
|
-
case SexpType.CharSxp: {
|
|
1074
|
-
const len = this.assertInteger(this.inInteger());
|
|
1075
|
-
if (len < -1) {
|
|
1076
|
-
throw new Error(`Invalid length ${len} of string.`);
|
|
1077
|
-
}
|
|
1078
|
-
else if (len == -1) {
|
|
1079
|
-
s.name = RValues.NaString;
|
|
1080
|
-
}
|
|
1081
|
-
else {
|
|
1082
|
-
s.name = this.readChar(len, levels);
|
|
1083
|
-
}
|
|
1084
|
-
break;
|
|
1085
|
-
}
|
|
1086
|
-
case SexpType.LglSxp:
|
|
1087
|
-
case SexpType.IntSxp:
|
|
1088
|
-
{
|
|
1089
|
-
const len = this.readLength();
|
|
1090
|
-
s.type = type;
|
|
1091
|
-
s.value = this.skipIntegerVec(len);
|
|
1092
|
-
break;
|
|
1093
|
-
}
|
|
1094
|
-
case SexpType.RealSxp:
|
|
1095
|
-
{
|
|
1096
|
-
const len = this.readLength();
|
|
1097
|
-
s.type = type;
|
|
1098
|
-
s.value = this.skipRealVec(len);
|
|
1099
|
-
break;
|
|
1100
|
-
}
|
|
1101
|
-
case SexpType.CplxSxp: {
|
|
1102
|
-
const len = this.readLength();
|
|
1103
|
-
s.type = type;
|
|
1104
|
-
this.skipComplexVec(len);
|
|
1105
|
-
break;
|
|
1106
|
-
}
|
|
1107
|
-
case SexpType.StrSxp:
|
|
1108
|
-
case SexpType.VecSxp:
|
|
1109
|
-
case SexpType.ExprSxp: {
|
|
1110
|
-
const len = this.readLength();
|
|
1111
|
-
s.type = type;
|
|
1112
|
-
this.currentDepth++;
|
|
1113
|
-
for (let count = 0; count < len; ++count) {
|
|
1114
|
-
this.skipItem();
|
|
1115
|
-
}
|
|
1116
|
-
this.currentDepth--;
|
|
1117
|
-
break;
|
|
1118
|
-
}
|
|
1119
|
-
case SexpType.BcodesSxp:
|
|
1120
|
-
this.skipBC();
|
|
1121
|
-
s.type = SexpType.VecSxp;
|
|
1122
|
-
break;
|
|
1123
|
-
case SexpType.ClassRefSxp:
|
|
1124
|
-
throw new Error('this version of R cannot read class references');
|
|
1125
|
-
case SexpType.GenericRefSxp:
|
|
1126
|
-
throw new Error('this version of R cannot read generic function references');
|
|
1127
|
-
case SexpType.RawSxp: {
|
|
1128
|
-
const len = this.readLength();
|
|
1129
|
-
s.type = type;
|
|
1130
|
-
this.skipRaw(len);
|
|
1131
|
-
break;
|
|
1132
|
-
}
|
|
1133
|
-
case SexpType.ObjSxp:
|
|
1134
|
-
s.type = SexpType.ObjSxp;
|
|
1135
|
-
break;
|
|
1136
|
-
default:
|
|
1137
|
-
throw new Error(`ReadItem: unknown type ${type}, perhaps written by later version of R`);
|
|
1138
|
-
}
|
|
1139
|
-
if (s.type === SexpType.CharSxp) {
|
|
1140
|
-
this.currentDepth++;
|
|
1141
|
-
if (hasAttribute) {
|
|
1142
|
-
this.skipItem();
|
|
1143
|
-
}
|
|
1144
|
-
this.currentDepth--;
|
|
1145
|
-
}
|
|
1146
|
-
else {
|
|
1147
|
-
this.currentDepth++;
|
|
1148
|
-
s.attributes = hasAttribute ? [this.skipItem()] : undefined;
|
|
1149
|
-
this.currentDepth--;
|
|
1150
|
-
}
|
|
1151
|
-
return s;
|
|
980
|
+
return this.readOrSkipLeaf(type, levels, object, hasAttribute, true);
|
|
1152
981
|
}
|
|
1153
982
|
}
|
|
1154
983
|
/**
|
|
1155
|
-
* Reads `len` raw bytes
|
|
1156
|
-
* @param len - Number of raw bytes to read.
|
|
1157
|
-
* @returns Array of unsigned byte values.
|
|
984
|
+
* Reads (or with `skip`, discards) `len` raw bytes into a number array.
|
|
1158
985
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2062-L2084 | R source: ReadItem_Recursive}
|
|
1159
986
|
*/
|
|
1160
|
-
inRaw(len) {
|
|
987
|
+
inRaw(len, skip = false) {
|
|
1161
988
|
const result = [];
|
|
1162
|
-
switch (this.format) {
|
|
1163
|
-
case SerializationFormat.Ascii:
|
|
1164
|
-
for (let ix = 0; ix < len; ix++) {
|
|
1165
|
-
const word = this.inWord(128);
|
|
1166
|
-
result[ix] = Number.parseInt(word, 16);
|
|
1167
|
-
}
|
|
1168
|
-
break;
|
|
1169
|
-
default: {
|
|
1170
|
-
for (let i = 0; i < len; i++) {
|
|
1171
|
-
result[i] = this.buffer[this.offset++];
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
return result;
|
|
1176
|
-
}
|
|
1177
|
-
/**
|
|
1178
|
-
* Advances the buffer offset past `len` raw bytes without reading values.
|
|
1179
|
-
*
|
|
1180
|
-
* Mirrors {@link inRaw}.
|
|
1181
|
-
* @param len - Number of raw bytes to skip.
|
|
1182
|
-
*/
|
|
1183
|
-
skipRaw(len) {
|
|
1184
989
|
if (this.format === SerializationFormat.Ascii) {
|
|
1185
990
|
for (let ix = 0; ix < len; ix++) {
|
|
1186
|
-
|
|
991
|
+
if (skip) {
|
|
992
|
+
this.skipWord();
|
|
993
|
+
}
|
|
994
|
+
else {
|
|
995
|
+
result[ix] = Number.parseInt(this.inWord(128), 16);
|
|
996
|
+
}
|
|
1187
997
|
}
|
|
998
|
+
return result;
|
|
1188
999
|
}
|
|
1189
|
-
|
|
1000
|
+
if (skip) {
|
|
1190
1001
|
this.offset += len;
|
|
1002
|
+
return result;
|
|
1003
|
+
}
|
|
1004
|
+
for (let i = 0; i < len; i++) {
|
|
1005
|
+
result[i] = this.buffer[this.offset++];
|
|
1191
1006
|
}
|
|
1007
|
+
return result;
|
|
1192
1008
|
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Resolves package environments.
|
|
1195
|
-
* @param s - String-vec {@link RObject} identifying the package.
|
|
1196
|
-
*
|
|
1197
|
-
* Not implemented yet!
|
|
1198
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/envir.c#L3732-L3741 | R source: R_FindPackageEnv}
|
|
1199
|
-
*/
|
|
1009
|
+
/** Resolves package environments. Not implemented yet!. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/envir.c#L3732-L3741 | R source: R_FindPackageEnv} */
|
|
1200
1010
|
rFindPackageEnv(s) {
|
|
1201
1011
|
console.warn('Resolving package environments was triggered, but is not implemented yet!');
|
|
1202
1012
|
return s;
|
|
1203
1013
|
}
|
|
1204
|
-
/**
|
|
1205
|
-
* Decodes the SEXP flags.
|
|
1206
|
-
* @param flags - Raw 32-bit flags word.
|
|
1207
|
-
* @returns `[type, levels, isObject, hasAttribute, hasTag]`.
|
|
1208
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L748-L756 | R source: UnpackFlags}
|
|
1209
|
-
*/
|
|
1014
|
+
/** Decodes a raw SEXP flags word into `[type, levels, isObject, hasAttribute, hasTag]`. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L748-L756 | R source: UnpackFlags} */
|
|
1210
1015
|
unpackFlags(flags) {
|
|
1211
1016
|
const pType = flags & 255;
|
|
1212
1017
|
const pLevels = flags >> 12;
|
|
@@ -1215,13 +1020,7 @@ class RDAParser {
|
|
|
1215
1020
|
const pHasTag = (flags & (1 << 10)) !== 0;
|
|
1216
1021
|
return [pType, pLevels, pIsObj, pHasAttr, pHasTag];
|
|
1217
1022
|
}
|
|
1218
|
-
/**
|
|
1219
|
-
* Retrieves an object from the reference table.
|
|
1220
|
-
* @param index - 1-based reference index.
|
|
1221
|
-
* @returns A registered {@link RObjectData}.
|
|
1222
|
-
* @throws Error if the index is out of range.
|
|
1223
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1461-L1469 | R source: GetReadRef}
|
|
1224
|
-
*/
|
|
1023
|
+
/** Retrieves the registered object at 1-based reference `index`. Throws error if out of range. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1461-L1469 | R source: GetReadRef} */
|
|
1225
1024
|
getReadRef(index) {
|
|
1226
1025
|
const i = index - 1;
|
|
1227
1026
|
if (i < 0 || i >= this.refTable.length) {
|
|
@@ -1230,12 +1029,7 @@ class RDAParser {
|
|
|
1230
1029
|
return this.refTable[i];
|
|
1231
1030
|
}
|
|
1232
1031
|
/**
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
* When bits 8–31 are non-zero they encode the index directly;
|
|
1236
|
-
* otherwise the index is read as the next integer from the stream.
|
|
1237
|
-
* @param flags - Raw 32-bit flags word.
|
|
1238
|
-
* @returns A 1-based reference index.
|
|
1032
|
+
* The 1-based reference index encoded in `flags`: bits 8-31 encode it directly when non-zero, otherwise it is read as the next stream integer.
|
|
1239
1033
|
* @see {@link http://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L782-L789 | R source: InRefIndex}
|
|
1240
1034
|
*/
|
|
1241
1035
|
inRefIndex(flags) {
|
|
@@ -1247,59 +1041,35 @@ class RDAParser {
|
|
|
1247
1041
|
return i;
|
|
1248
1042
|
}
|
|
1249
1043
|
}
|
|
1250
|
-
/**
|
|
1251
|
-
* Appends an object to the reference table so it can be resolved later by {@link getReadRef}.
|
|
1252
|
-
* @param value - The {@link RObject} to register.
|
|
1253
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1471-L1490 | R source: AddReadRef}
|
|
1254
|
-
*/
|
|
1044
|
+
/** Appends `value` to the reference table so it can be resolved later by {@link getReadRef}. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1471-L1490 | R source: AddReadRef} */
|
|
1255
1045
|
addReadRef(value) {
|
|
1256
1046
|
this.refTable.push(value);
|
|
1257
1047
|
}
|
|
1258
1048
|
/**
|
|
1259
|
-
* Reads a persistent string vector
|
|
1260
|
-
*
|
|
1261
|
-
* @
|
|
1262
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1492-L1504 | R source: InStringVec}
|
|
1049
|
+
* Reads (or with `skip`, discards) a persistent string vector. Answers a `CharSxp` {@link RObjectData} whose
|
|
1050
|
+
* `value` array holds the deserialized items, empty when skipped. Throws Error if the names flag is non-zero.
|
|
1051
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1492-L1504 | R source: InStringVec}
|
|
1263
1052
|
*/
|
|
1264
|
-
inStringVec() {
|
|
1053
|
+
inStringVec(skip = false) {
|
|
1265
1054
|
if (this.inInteger() !== 0) {
|
|
1266
1055
|
throw new Error('names in persistent strings are not supported yet');
|
|
1267
1056
|
}
|
|
1268
1057
|
const len = this.assertInteger(this.inInteger());
|
|
1269
|
-
const s = {};
|
|
1270
|
-
s.
|
|
1271
|
-
s.value = new Array(len);
|
|
1058
|
+
const s = { type: SexpType.CharSxp };
|
|
1059
|
+
s.value = new Array(skip ? 0 : len);
|
|
1272
1060
|
this.currentDepth++;
|
|
1273
1061
|
for (let i = 0; i < len; i++) {
|
|
1274
|
-
(
|
|
1062
|
+
if (skip) {
|
|
1063
|
+
this.skipItem();
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
(s.value)[i] = this.readItem();
|
|
1067
|
+
}
|
|
1275
1068
|
}
|
|
1276
1069
|
this.currentDepth--;
|
|
1277
1070
|
return s;
|
|
1278
1071
|
}
|
|
1279
|
-
/**
|
|
1280
|
-
* Advances the buffer past a persistent string vector without reading values.
|
|
1281
|
-
*
|
|
1282
|
-
* Mirrors {@link inStringVec}.
|
|
1283
|
-
* @throws Error if the names flag is non-zero.
|
|
1284
|
-
*/
|
|
1285
|
-
skipStringVec() {
|
|
1286
|
-
if (this.inInteger() !== 0) {
|
|
1287
|
-
throw new Error('names in persistent strings are not supported yet');
|
|
1288
|
-
}
|
|
1289
|
-
const len = this.assertInteger(this.inInteger());
|
|
1290
|
-
this.currentDepth++;
|
|
1291
|
-
for (let i = 0; i < len; i++) {
|
|
1292
|
-
this.skipItem();
|
|
1293
|
-
}
|
|
1294
|
-
this.currentDepth--;
|
|
1295
|
-
}
|
|
1296
|
-
/**
|
|
1297
|
-
* Sets the enclosing environment of an environment object.
|
|
1298
|
-
* @param x - Environment whose enclosure should be set.
|
|
1299
|
-
* @param v - Parent environment.
|
|
1300
|
-
* @throws Error if the parent is invalid or would introduce a cycle.
|
|
1301
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L4677-L4690 | R source: SET_ENCLOS}
|
|
1302
|
-
*/
|
|
1072
|
+
/** Sets `x`'s enclosing environment to `v`. Throws error if `v` is invalid or would introduce a cycle. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L4677-L4690 | R source: SET_ENCLOS} */
|
|
1303
1073
|
SetEnClos(x, v) {
|
|
1304
1074
|
if (v.value === undefined || v.value === RValues.NilValue) {
|
|
1305
1075
|
v.value = RValues.EmptyEnv;
|
|
@@ -1315,37 +1085,21 @@ class RDAParser {
|
|
|
1315
1085
|
x.enClos = v;
|
|
1316
1086
|
}
|
|
1317
1087
|
/**
|
|
1318
|
-
* Iteratively deserializes linked-list based SEXP structures.
|
|
1319
|
-
*
|
|
1320
|
-
* @
|
|
1321
|
-
* @throws Error if the initial type is not a valid pairlist type.
|
|
1322
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1800-L1868 | R source: ReadItem_Iterative}
|
|
1088
|
+
* Iteratively deserializes linked-list based SEXP structures. Answers head node of the reconstructed pairlist
|
|
1089
|
+
* chain. Throws Error if the initial type is not a valid pairlist type.
|
|
1090
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1800-L1868 | R source: ReadItem_Iterative}
|
|
1323
1091
|
*/
|
|
1324
1092
|
readItemIterative(flags) {
|
|
1325
1093
|
let sFirst = null;
|
|
1326
1094
|
let sLast = {};
|
|
1327
1095
|
let type = flags & 255;
|
|
1328
|
-
|
|
1329
|
-
SexpType.ListSxp, // 2
|
|
1330
|
-
SexpType.LangSxp, // 6
|
|
1331
|
-
SexpType.CloSxp, // 3
|
|
1332
|
-
SexpType.PromSxp, // 5
|
|
1333
|
-
SexpType.DotSxp // 17
|
|
1334
|
-
]);
|
|
1335
|
-
if (!validIterativeTypes.has(type)) {
|
|
1096
|
+
if (!IterativeSexpTypes.has(type)) {
|
|
1336
1097
|
throw new Error('Wrong type.');
|
|
1337
1098
|
}
|
|
1338
|
-
while (
|
|
1339
|
-
|
|
1340
|
-
type =
|
|
1341
|
-
const
|
|
1342
|
-
const isObject = unpackedFlags[2];
|
|
1343
|
-
const hasAttr = unpackedFlags[3];
|
|
1344
|
-
const hasTag = unpackedFlags[4];
|
|
1345
|
-
const s = {};
|
|
1346
|
-
s.type = type;
|
|
1347
|
-
s.levels = levels;
|
|
1348
|
-
s.object = isObject;
|
|
1099
|
+
while (IterativeSexpTypes.has(type)) {
|
|
1100
|
+
let levels, isObject, hasAttr, hasTag;
|
|
1101
|
+
[type, levels, isObject, hasAttr, hasTag] = this.unpackFlags(flags);
|
|
1102
|
+
const s = { type, levels, object: isObject };
|
|
1349
1103
|
this.currentDepth++;
|
|
1350
1104
|
s.attributes = hasAttr ? [this.shortcut ? this.skipItem() : this.assertRObjectData(this.readItem())] : undefined;
|
|
1351
1105
|
s.tag = hasTag ? this.readItem() : RValues.NilValue;
|
|
@@ -1376,16 +1130,7 @@ class RDAParser {
|
|
|
1376
1130
|
sLast.cdr = s;
|
|
1377
1131
|
return sFirst;
|
|
1378
1132
|
}
|
|
1379
|
-
/**
|
|
1380
|
-
* Creates a weak reference object.
|
|
1381
|
-
* @param key - Weak reference key object.
|
|
1382
|
-
* @param val - Referenced value.
|
|
1383
|
-
* @param fin - Finalizer function or NULL.
|
|
1384
|
-
* @param onexit - Whether the finalizer should run on exit.
|
|
1385
|
-
* @returns The created weak reference object as {@link RObject}.
|
|
1386
|
-
* @throws Error if the finalizer type is invalid.
|
|
1387
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L1424-L1435 | R source: R_MakeWeakRef}
|
|
1388
|
-
*/
|
|
1133
|
+
/** Creates a weak reference object. Throws error if `fin` is not a function or NULL. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L1424-L1435 | R source: R_MakeWeakRef} */
|
|
1389
1134
|
R_MakeWeakRef(key, val, fin, onexit) {
|
|
1390
1135
|
switch (fin.type) {
|
|
1391
1136
|
case SexpType.NilSxp:
|
|
@@ -1398,17 +1143,8 @@ class RDAParser {
|
|
|
1398
1143
|
}
|
|
1399
1144
|
return this.newWeakRef(key, val, fin, onexit);
|
|
1400
1145
|
}
|
|
1401
|
-
/**
|
|
1402
|
-
|
|
1403
|
-
* @param key - Weak reference key object.
|
|
1404
|
-
* @param val - Referenced value.
|
|
1405
|
-
* @param fin - Finalizer function.
|
|
1406
|
-
* @param onexit - Whether the finalizer should run on exit.
|
|
1407
|
-
* @returns The initialized weak reference object as {@link RObject}.
|
|
1408
|
-
* @throws Error if the key type is invalid.
|
|
1409
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L1388-L1422 | R source: NewWeakRef}
|
|
1410
|
-
*/
|
|
1411
|
-
newWeakRef(key, val, fin, onexit) {
|
|
1146
|
+
/** Allocates and initializes a weak reference object. Throws error if `key`'s type is invalid. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L1388-L1422 | R source: NewWeakRef} */
|
|
1147
|
+
newWeakRef(key, val, fin, _onexit) {
|
|
1412
1148
|
switch (key.type) {
|
|
1413
1149
|
case SexpType.NilSxp:
|
|
1414
1150
|
case SexpType.EnvSxp:
|
|
@@ -1418,41 +1154,21 @@ class RDAParser {
|
|
|
1418
1154
|
default:
|
|
1419
1155
|
throw new Error('can only weakly reference/finalize reference objects');
|
|
1420
1156
|
}
|
|
1421
|
-
|
|
1422
|
-
// w = allocVector(VECSXP, WEAKREF_SIZE);
|
|
1423
|
-
// SET_TYPEOF(w, WEAKREFSXP);
|
|
1424
|
-
const w = {};
|
|
1425
|
-
w.type = SexpType.WeakRefSxp;
|
|
1157
|
+
const w = { type: SexpType.WeakRefSxp };
|
|
1426
1158
|
if (key.value !== RValues.NilValue) {
|
|
1427
1159
|
w.key = key;
|
|
1428
1160
|
w.value = val;
|
|
1429
1161
|
w.finalizer = fin;
|
|
1430
1162
|
w.next = this.RWeakRefs;
|
|
1431
|
-
//
|
|
1432
|
-
if (w.gp) {
|
|
1433
|
-
w.gp &= ~1;
|
|
1434
|
-
}
|
|
1435
|
-
if (onexit) {
|
|
1436
|
-
if (w.gp) {
|
|
1437
|
-
w.gp |= 2;
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
else {
|
|
1441
|
-
if (w.gp) {
|
|
1442
|
-
w.gp &= ~2;
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1163
|
+
// gp bitflag bookkeeping omitted: gp is never populated on a freshly built RObjectData, so it was always a no-op
|
|
1445
1164
|
this.RWeakRefs = w;
|
|
1446
1165
|
}
|
|
1447
1166
|
return w;
|
|
1448
1167
|
}
|
|
1449
1168
|
/**
|
|
1450
|
-
* Creates or retrieves a cached primitive function object.
|
|
1451
|
-
* @
|
|
1452
|
-
*
|
|
1453
|
-
* @returns of type {@link SexpType.BuiltInSxp} or {@link SexpType.SpecialSxp}.
|
|
1454
|
-
* @throws Error if the index is out of range or the cached type mismatches.
|
|
1455
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/dstruct.c#L37-L68 | R source: mkPRIMSXP}
|
|
1169
|
+
* Creates or retrieves a cached primitive function object of type {@link SexpType.BuiltInSxp} (`evaluation` non-zero)
|
|
1170
|
+
* or {@link SexpType.SpecialSxp}, from `index` into the primitive function table. Throws Error if out of range.
|
|
1171
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/dstruct.c#L37-L68 | R source: mkPRIMSXP}
|
|
1456
1172
|
*/
|
|
1457
1173
|
mkPrimSxp(index, evaluation) {
|
|
1458
1174
|
if (index < 0 || index >= Object.keys(r_fun_tab_1.RFunTabOffsets).length) {
|
|
@@ -1464,13 +1180,9 @@ class RDAParser {
|
|
|
1464
1180
|
};
|
|
1465
1181
|
}
|
|
1466
1182
|
/**
|
|
1467
|
-
* Reads `len` bytes as a character string
|
|
1468
|
-
*
|
|
1469
|
-
*
|
|
1470
|
-
* @param len - Number of bytes to read.
|
|
1471
|
-
* @param levels - GP levels bits from the `CharSxp` flags word.
|
|
1472
|
-
* @returns The decoded string, or `''` when the encoding is not yet handled.
|
|
1473
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1689-L1759 | R source: ReadChar}
|
|
1183
|
+
* Reads `len` bytes as a character string, decoded per the encoding flags in `levels` (bit 3 UTF-8, bit 2 Latin-1,
|
|
1184
|
+
* bit 1 raw bytes, bit 6 ASCII); answers `''` for a native encoding, which is not yet handled.
|
|
1185
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1689-L1759 | R source: ReadChar}
|
|
1474
1186
|
*/
|
|
1475
1187
|
readChar(len, levels) {
|
|
1476
1188
|
const cBuf = this.inString(len);
|
|
@@ -1488,10 +1200,8 @@ class RDAParser {
|
|
|
1488
1200
|
return '';
|
|
1489
1201
|
}
|
|
1490
1202
|
/**
|
|
1491
|
-
* Reads a vector length from the stream.
|
|
1492
|
-
* @
|
|
1493
|
-
* @throws Error for negative lengths or an invalid high-word value.
|
|
1494
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1761-L1782 | R source: ReadLENGTH}
|
|
1203
|
+
* Reads a vector length from the stream. Throws Error for negative lengths or an invalid high-word value.
|
|
1204
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1761-L1782 | R source: ReadLENGTH}
|
|
1495
1205
|
*/
|
|
1496
1206
|
readLength() {
|
|
1497
1207
|
const len = this.assertInteger(this.inInteger());
|
|
@@ -1513,79 +1223,53 @@ class RDAParser {
|
|
|
1513
1223
|
}
|
|
1514
1224
|
}
|
|
1515
1225
|
/**
|
|
1516
|
-
* Reads `len` integers
|
|
1517
|
-
* @
|
|
1518
|
-
* @returns Array of integer values or {@link RValues.NaInteger}.
|
|
1519
|
-
* @throws Error for BINARY format or XDR buffer overrun.
|
|
1520
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1507-L1541 | R source: InIntegerVec}
|
|
1226
|
+
* Reads (or with `skip`, discards) `len` integers. Throws Error for BINARY format or XDR buffer overrun.
|
|
1227
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1507-L1541 | R source: InIntegerVec}
|
|
1521
1228
|
*/
|
|
1522
|
-
inIntegerVec(len) {
|
|
1229
|
+
inIntegerVec(len, skip = false) {
|
|
1523
1230
|
switch (this.format) {
|
|
1524
|
-
case SerializationFormat.Xdr:
|
|
1525
|
-
{
|
|
1526
|
-
|
|
1527
|
-
for (let cnt = 0; cnt < len; cnt++) {
|
|
1528
|
-
if (this.offset + 4 > this.buffer.length) {
|
|
1529
|
-
throw new Error('XDR read failed');
|
|
1530
|
-
}
|
|
1531
|
-
result[cnt] = this.buffer.readInt32BE(this.offset);
|
|
1532
|
-
this.offset += 4;
|
|
1533
|
-
}
|
|
1534
|
-
return result;
|
|
1231
|
+
case SerializationFormat.Xdr: {
|
|
1232
|
+
if (this.offset + 4 * len > this.buffer.length) {
|
|
1233
|
+
throw new Error('XDR read failed');
|
|
1535
1234
|
}
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1235
|
+
if (skip) {
|
|
1236
|
+
this.offset += 4 * len;
|
|
1237
|
+
return [];
|
|
1539
1238
|
}
|
|
1540
|
-
default: {
|
|
1541
1239
|
const result = [];
|
|
1542
1240
|
for (let cnt = 0; cnt < len; cnt++) {
|
|
1543
|
-
result[cnt] = this.
|
|
1241
|
+
result[cnt] = this.buffer.readInt32BE(this.offset);
|
|
1242
|
+
this.offset += 4;
|
|
1544
1243
|
}
|
|
1545
1244
|
return result;
|
|
1546
1245
|
}
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
/**
|
|
1550
|
-
* Advances the buffer past `len` serialized integers without reading values.
|
|
1551
|
-
*
|
|
1552
|
-
* Mirrors {@link inIntegerVec}.
|
|
1553
|
-
* @param len - Number of integers to skip.
|
|
1554
|
-
* @returns An empty array.
|
|
1555
|
-
* @throws Error for BINARY format or XDR buffer overrun.
|
|
1556
|
-
*/
|
|
1557
|
-
skipIntegerVec(len) {
|
|
1558
|
-
switch (this.format) {
|
|
1559
|
-
case SerializationFormat.Xdr:
|
|
1560
|
-
{
|
|
1561
|
-
if (this.offset + 4 * len > this.buffer.length) {
|
|
1562
|
-
throw new Error('XDR read failed');
|
|
1563
|
-
}
|
|
1564
|
-
this.offset += 4 * len;
|
|
1565
|
-
break;
|
|
1566
|
-
}
|
|
1567
1246
|
case SerializationFormat.Binary:
|
|
1568
|
-
|
|
1569
|
-
throw new Error('No binary support yet.');
|
|
1570
|
-
}
|
|
1247
|
+
throw new Error('No binary support yet.');
|
|
1571
1248
|
default: {
|
|
1249
|
+
const result = [];
|
|
1572
1250
|
for (let cnt = 0; cnt < len; cnt++) {
|
|
1573
|
-
|
|
1251
|
+
if (skip) {
|
|
1252
|
+
this.skipInteger();
|
|
1253
|
+
}
|
|
1254
|
+
else {
|
|
1255
|
+
result[cnt] = this.inInteger();
|
|
1256
|
+
}
|
|
1574
1257
|
}
|
|
1258
|
+
return skip ? [] : result;
|
|
1575
1259
|
}
|
|
1576
1260
|
}
|
|
1577
|
-
return [];
|
|
1578
1261
|
}
|
|
1579
1262
|
/**
|
|
1580
|
-
* Reads `len` doubles
|
|
1581
|
-
* @
|
|
1582
|
-
* @returns Array of numbers or {@link RValues}.
|
|
1583
|
-
* @throws Error for BINARY format.
|
|
1584
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1543-L1577 | R source: InRealVec}
|
|
1263
|
+
* Reads (or with `skip`, discards) `len` doubles. Throws Error for BINARY format.
|
|
1264
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1543-L1577 | R source: InRealVec}
|
|
1585
1265
|
*/
|
|
1586
|
-
inRealVec(len) {
|
|
1266
|
+
inRealVec(len, skip = false) {
|
|
1587
1267
|
switch (this.format) {
|
|
1588
1268
|
case SerializationFormat.Xdr: {
|
|
1269
|
+
if (skip) {
|
|
1270
|
+
this.offset += len * RDAParser.SIZE_OF_DOUBLE;
|
|
1271
|
+
return [];
|
|
1272
|
+
}
|
|
1589
1273
|
const result = [];
|
|
1590
1274
|
for (let i = 0; i < len; i++) {
|
|
1591
1275
|
result.push(this.buffer.readDoubleBE(this.offset));
|
|
@@ -1594,53 +1278,32 @@ class RDAParser {
|
|
|
1594
1278
|
return result;
|
|
1595
1279
|
}
|
|
1596
1280
|
case SerializationFormat.Binary:
|
|
1597
|
-
|
|
1598
|
-
throw new Error('No binary support yet.');
|
|
1599
|
-
}
|
|
1281
|
+
throw new Error('No binary support yet.');
|
|
1600
1282
|
default: {
|
|
1601
1283
|
const result = [];
|
|
1602
1284
|
for (let cnt = 0; cnt < len; cnt++) {
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
/**
|
|
1610
|
-
* Advances the buffer past `len` serialized doubles without reading values.
|
|
1611
|
-
*
|
|
1612
|
-
* Mirrors {@link inRealVec}.
|
|
1613
|
-
* @param len - Number of doubles to skip.
|
|
1614
|
-
* @returns An empty array.
|
|
1615
|
-
* @throws Error for BINARY format.
|
|
1616
|
-
*/
|
|
1617
|
-
skipRealVec(len) {
|
|
1618
|
-
switch (this.format) {
|
|
1619
|
-
case SerializationFormat.Xdr: {
|
|
1620
|
-
this.offset += len * RDAParser.SIZE_OF_DOUBLE;
|
|
1621
|
-
break;
|
|
1622
|
-
}
|
|
1623
|
-
case SerializationFormat.Binary:
|
|
1624
|
-
{
|
|
1625
|
-
throw new Error('No binary support yet.');
|
|
1626
|
-
}
|
|
1627
|
-
default: {
|
|
1628
|
-
for (let cnt = 0; cnt < len; cnt++) {
|
|
1629
|
-
this.skipReal();
|
|
1285
|
+
if (skip) {
|
|
1286
|
+
this.inReal(true);
|
|
1287
|
+
}
|
|
1288
|
+
else {
|
|
1289
|
+
result[cnt] = this.inReal();
|
|
1290
|
+
}
|
|
1630
1291
|
}
|
|
1292
|
+
return skip ? [] : result;
|
|
1631
1293
|
}
|
|
1632
1294
|
}
|
|
1633
|
-
return [];
|
|
1634
1295
|
}
|
|
1635
1296
|
/**
|
|
1636
|
-
* Reads the next double
|
|
1637
|
-
* @
|
|
1638
|
-
* @throws TypeError if the ASCII token is not a valid float.
|
|
1639
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L427-L463 | R source: InReal}
|
|
1297
|
+
* Reads (or with `skip`, discards) the next double. Throws TypeError if the ASCII token is not a valid float.
|
|
1298
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L427-L463 | R source: InReal}
|
|
1640
1299
|
*/
|
|
1641
|
-
inReal() {
|
|
1300
|
+
inReal(skip = false) {
|
|
1642
1301
|
switch (this.format) {
|
|
1643
1302
|
case SerializationFormat.Ascii: {
|
|
1303
|
+
if (skip) {
|
|
1304
|
+
this.skipWord();
|
|
1305
|
+
return RValues.NilValue;
|
|
1306
|
+
}
|
|
1644
1307
|
const word = this.inWord(128);
|
|
1645
1308
|
if (word === 'NA') {
|
|
1646
1309
|
return RValues.NaReal;
|
|
@@ -1662,13 +1325,10 @@ class RDAParser {
|
|
|
1662
1325
|
return d;
|
|
1663
1326
|
}
|
|
1664
1327
|
}
|
|
1665
|
-
case SerializationFormat.Binary:
|
|
1666
|
-
const d = this.buffer.readDoubleLE(this.offset);
|
|
1667
|
-
this.offset += 8;
|
|
1668
|
-
return d;
|
|
1669
|
-
}
|
|
1328
|
+
case SerializationFormat.Binary:
|
|
1670
1329
|
case SerializationFormat.Xdr: {
|
|
1671
|
-
const d =
|
|
1330
|
+
const d = skip ? RValues.NilValue :
|
|
1331
|
+
this.format === SerializationFormat.Binary ? this.buffer.readDoubleLE(this.offset) : this.buffer.readDoubleBE(this.offset);
|
|
1672
1332
|
this.offset += 8;
|
|
1673
1333
|
return d;
|
|
1674
1334
|
}
|
|
@@ -1677,76 +1337,29 @@ class RDAParser {
|
|
|
1677
1337
|
}
|
|
1678
1338
|
}
|
|
1679
1339
|
/**
|
|
1680
|
-
*
|
|
1681
|
-
*
|
|
1682
|
-
* Mirrors {@link inReal}.
|
|
1683
|
-
*/
|
|
1684
|
-
skipReal() {
|
|
1685
|
-
if (this.format === SerializationFormat.Ascii) {
|
|
1686
|
-
this.skipWord();
|
|
1687
|
-
}
|
|
1688
|
-
else if (this.format === SerializationFormat.Binary || this.format === SerializationFormat.Xdr) {
|
|
1689
|
-
this.offset += 8;
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
/**
|
|
1693
|
-
* Reads `len` complex numbers from the buffer.
|
|
1694
|
-
*
|
|
1695
|
-
* Each value is read as two consecutive doubles via {@link inComplex}.
|
|
1696
|
-
* @param len - Number of complex values to read.
|
|
1697
|
-
* @returns Array of {@link Complex} objects.
|
|
1698
|
-
* @throws Error for BINARY format.
|
|
1699
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1579-L1616 | R source: InComplexVec}
|
|
1340
|
+
* Reads (or with `skip`, discards) `len` complex numbers, each as two consecutive doubles via {@link inComplex}. Throws Error for BINARY format.
|
|
1341
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1579-L1616 | R source: InComplexVec}
|
|
1700
1342
|
*/
|
|
1701
|
-
inComplexVec(len) {
|
|
1343
|
+
inComplexVec(len, skip = false) {
|
|
1702
1344
|
if (this.format === SerializationFormat.Binary) {
|
|
1703
1345
|
throw new Error('No binary support yet.');
|
|
1704
1346
|
}
|
|
1705
1347
|
const result = [];
|
|
1706
1348
|
for (let cnt = 0; cnt < len; cnt++) {
|
|
1707
|
-
result[cnt] = this.inComplex();
|
|
1349
|
+
result[cnt] = this.inComplex(skip);
|
|
1708
1350
|
}
|
|
1709
|
-
return result;
|
|
1351
|
+
return skip ? [] : result;
|
|
1710
1352
|
}
|
|
1711
1353
|
/**
|
|
1712
|
-
*
|
|
1713
|
-
*
|
|
1714
|
-
* Mirrors {@link inComplexVec}.
|
|
1715
|
-
* @param len - Number of complex values to skip.
|
|
1716
|
-
* @throws Error for BINARY format.
|
|
1717
|
-
*/
|
|
1718
|
-
skipComplexVec(len) {
|
|
1719
|
-
if (this.format === SerializationFormat.Binary) {
|
|
1720
|
-
throw new Error('No binary support yet.');
|
|
1721
|
-
}
|
|
1722
|
-
for (let cnt = 0; cnt < len; cnt++) {
|
|
1723
|
-
this.skipComplex();
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
/**
|
|
1727
|
-
* Reads a single complex number as two consecutive real values.
|
|
1728
|
-
* @returns A {@link Complex} object with `r` (real) and `i` (imaginary) parts.
|
|
1354
|
+
* Reads (or with `skip`, discards) a single complex number as two consecutive real values.
|
|
1729
1355
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L465-L471 | R source: InComplex}
|
|
1730
1356
|
*/
|
|
1731
|
-
inComplex() {
|
|
1732
|
-
return { r: this.inReal(), i: this.inReal() };
|
|
1733
|
-
}
|
|
1734
|
-
/**
|
|
1735
|
-
* Advances the buffer past a single serialized complex number (two doubles).
|
|
1736
|
-
*
|
|
1737
|
-
* Mirrors {@link inComplex}.
|
|
1738
|
-
*/
|
|
1739
|
-
skipComplex() {
|
|
1740
|
-
this.skipReal();
|
|
1741
|
-
this.skipReal();
|
|
1357
|
+
inComplex(skip = false) {
|
|
1358
|
+
return { r: this.inReal(skip), i: this.inReal(skip) };
|
|
1742
1359
|
}
|
|
1743
1360
|
/**
|
|
1744
|
-
* Sets the `i`-th element of a character vector.
|
|
1745
|
-
* @
|
|
1746
|
-
* @param i - index to set.
|
|
1747
|
-
* @param v - The {@link SexpType.CharSxp} {@link RObjectData} whose `name` is stored.
|
|
1748
|
-
* @throws Error if `x` is not a {@link SexpType.StrSxp} or `i` is out of bounds.
|
|
1749
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L4283-L4301 | R source: SET_STRING_ELT}
|
|
1361
|
+
* Sets the `i`-th element of a {@link SexpType.StrSxp} character vector to `v.name`. Throws Error if `x` is not
|
|
1362
|
+
* a {@link SexpType.StrSxp} or `i` is out of bounds. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L4283-L4301 | R source: SET_STRING_ELT}
|
|
1750
1363
|
*/
|
|
1751
1364
|
SET_STRING_ELT(x, i, v) {
|
|
1752
1365
|
if (x.type !== SexpType.StrSxp) {
|
|
@@ -1759,14 +1372,8 @@ class RDAParser {
|
|
|
1759
1372
|
arr[i] = v.name ?? RValues.NaString;
|
|
1760
1373
|
}
|
|
1761
1374
|
/**
|
|
1762
|
-
* Sets the `i`-th element of a generic list or vector.
|
|
1763
|
-
*
|
|
1764
|
-
* Mirrors R's `SET_VECTOR_ELT` macro.
|
|
1765
|
-
* @param x - The list or vector to modify.
|
|
1766
|
-
* @param i - index to set.
|
|
1767
|
-
* @param v - The {@link RObject} to store at position `i`.
|
|
1768
|
-
* @throws Error if `x` is not a list type or `i` is out of bounds.
|
|
1769
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L4303-L4322 | R source: SET_VECTOR_ELT}
|
|
1375
|
+
* Sets the `i`-th element of a generic list or vector. Mirrors R's `SET_VECTOR_ELT` macro. Throws Error if `x`
|
|
1376
|
+
* is not a list type or `i` is out of bounds. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L4303-L4322 | R source: SET_VECTOR_ELT}
|
|
1770
1377
|
*/
|
|
1771
1378
|
SET_VECTOR_ELT(x, i, v) {
|
|
1772
1379
|
if (x.type !== SexpType.VecSxp &&
|
|
@@ -1779,66 +1386,22 @@ class RDAParser {
|
|
|
1779
1386
|
}
|
|
1780
1387
|
x.value[i] = v;
|
|
1781
1388
|
}
|
|
1782
|
-
/**
|
|
1783
|
-
* Deserializes an R bytecode object.
|
|
1784
|
-
* @returns A {@link SexpType.BcodesSxp} {@link RObject}.
|
|
1785
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2221-L2228 | R source: ReadBC}
|
|
1786
|
-
*/
|
|
1389
|
+
/** Deserializes an R bytecode object. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2221-L2228 | R source: ReadBC} */
|
|
1787
1390
|
readBC() {
|
|
1788
|
-
const reps = {};
|
|
1789
|
-
reps.type = SexpType.VecSxp;
|
|
1790
|
-
reps.value = new Array(this.assertInteger(this.inInteger()));
|
|
1391
|
+
const reps = { type: SexpType.VecSxp, value: new Array(this.assertInteger(this.inInteger())) };
|
|
1791
1392
|
return this.readBC1(reps);
|
|
1792
1393
|
}
|
|
1793
|
-
/**
|
|
1794
|
-
* Advances the buffer past a bytecode object without reading it.
|
|
1795
|
-
*
|
|
1796
|
-
* Mirrors {@link readBC}.
|
|
1797
|
-
*/
|
|
1394
|
+
/** Advances past a bytecode object. Mirrors {@link readBC}. */
|
|
1798
1395
|
skipBC() {
|
|
1799
1396
|
this.skipInteger();
|
|
1800
1397
|
this.skipBC1();
|
|
1801
1398
|
}
|
|
1802
|
-
/**
|
|
1803
|
-
* Advances past a single bytecode.
|
|
1804
|
-
*
|
|
1805
|
-
* Mirrors {@link readBC1}.
|
|
1806
|
-
*/
|
|
1399
|
+
/** Advances past a single bytecode. Mirrors {@link readBC1}. */
|
|
1807
1400
|
skipBC1() {
|
|
1808
1401
|
this.currentDepth++;
|
|
1809
1402
|
this.skipItem();
|
|
1810
1403
|
this.currentDepth--;
|
|
1811
|
-
this.
|
|
1812
|
-
}
|
|
1813
|
-
/**
|
|
1814
|
-
* Advances past all bytecode constants.
|
|
1815
|
-
*
|
|
1816
|
-
* Mirrors {@link ReadBCConsts}.
|
|
1817
|
-
*/
|
|
1818
|
-
skipBCConsts() {
|
|
1819
|
-
const n = this.assertInteger(this.inInteger());
|
|
1820
|
-
for (let i = 0; i < n; i++) {
|
|
1821
|
-
const type = this.inInteger();
|
|
1822
|
-
switch (type) {
|
|
1823
|
-
case SexpType.BcodesSxp: {
|
|
1824
|
-
this.skipBC1();
|
|
1825
|
-
break;
|
|
1826
|
-
}
|
|
1827
|
-
case SexpType.LangSxp:
|
|
1828
|
-
case SexpType.ListSxp:
|
|
1829
|
-
case SexpType.BcRepDef:
|
|
1830
|
-
case SexpType.BcRepRef:
|
|
1831
|
-
case SexpType.AltLangSxp:
|
|
1832
|
-
case SexpType.AttrListSxp: {
|
|
1833
|
-
this.skipBCLang(type);
|
|
1834
|
-
break;
|
|
1835
|
-
}
|
|
1836
|
-
default:
|
|
1837
|
-
this.currentDepth++;
|
|
1838
|
-
this.skipItem();
|
|
1839
|
-
this.currentDepth--;
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1404
|
+
this.readOrSkipBCConsts(undefined, true);
|
|
1842
1405
|
}
|
|
1843
1406
|
/**
|
|
1844
1407
|
* Registers a bytecode object after encoding.
|
|
@@ -1847,77 +1410,67 @@ class RDAParser {
|
|
|
1847
1410
|
R_registerBC(_bytes, _s) {
|
|
1848
1411
|
throw new Error('BC not implemented yet');
|
|
1849
1412
|
}
|
|
1850
|
-
/**
|
|
1851
|
-
* Deserializes a single bytecode object.
|
|
1852
|
-
* @param reps - Pre-allocated repetition table shared across all constants.
|
|
1853
|
-
* @returns A {@link SexpType.BcodesSxp} {@link RObjectData}.
|
|
1854
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2205-L2219 | R source: ReadBC1}
|
|
1855
|
-
*/
|
|
1413
|
+
/** Deserializes a single bytecode object, `reps` is the repetition table shared across all constants. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2205-L2219 | R source: ReadBC1} */
|
|
1856
1414
|
readBC1(reps) {
|
|
1857
|
-
const s = {};
|
|
1858
|
-
s.type = SexpType.BcodesSxp;
|
|
1415
|
+
const s = { type: SexpType.BcodesSxp };
|
|
1859
1416
|
this.currentDepth++;
|
|
1860
1417
|
s.car = this.readItem();
|
|
1861
1418
|
this.currentDepth--;
|
|
1862
|
-
const _bytes = s.car;
|
|
1863
1419
|
// s.car = R_bcEncode(bytes);
|
|
1864
|
-
s.cdr = this.
|
|
1420
|
+
s.cdr = this.readOrSkipBCConsts(reps, false);
|
|
1865
1421
|
s.tag = RValues.NilValue;
|
|
1866
1422
|
// R_registerBC(bytes, s);
|
|
1867
1423
|
return s;
|
|
1868
1424
|
}
|
|
1869
|
-
/**
|
|
1870
|
-
* Encodes bytecode instructions.
|
|
1871
|
-
* @param _bytes - integer array
|
|
1872
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/eval.c#L8723-L8771 | R source: R_bcEncode}
|
|
1873
|
-
*/
|
|
1425
|
+
/** Encodes bytecode instructions. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/eval.c#L8723-L8771 | R source: R_bcEncode} */
|
|
1874
1426
|
_R_bcEncode(_bytes) {
|
|
1875
1427
|
throw new Error('Not implemented');
|
|
1876
1428
|
}
|
|
1877
1429
|
/**
|
|
1878
|
-
* Reads the constants of a bytecode object
|
|
1879
|
-
* @
|
|
1880
|
-
* @returns A `VecSxp` {@link RObjectData} holding all `n` constants.
|
|
1881
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2173-L2203 | R source: ReadBCConsts}
|
|
1430
|
+
* Reads (or with `skip`, discards) the `n` constants of a bytecode object into a `VecSxp`, `reps` resolves `BcRepDef`/`BcRepRef`.
|
|
1431
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2173-L2203 | R source: ReadBCConsts}
|
|
1882
1432
|
*/
|
|
1883
|
-
|
|
1433
|
+
readOrSkipBCConsts(reps, skip) {
|
|
1884
1434
|
const n = this.assertInteger(this.inInteger());
|
|
1885
|
-
const ans = {};
|
|
1886
|
-
ans.type = SexpType.VecSxp;
|
|
1887
|
-
ans.value = new Array(n);
|
|
1435
|
+
const ans = { type: SexpType.VecSxp, value: new Array(n) };
|
|
1888
1436
|
for (let i = 0; i < n; i++) {
|
|
1889
1437
|
const type = this.inInteger();
|
|
1890
1438
|
switch (type) {
|
|
1891
|
-
case SexpType.BcodesSxp:
|
|
1892
|
-
|
|
1893
|
-
|
|
1439
|
+
case SexpType.BcodesSxp:
|
|
1440
|
+
if (skip) {
|
|
1441
|
+
this.skipBC1();
|
|
1442
|
+
}
|
|
1443
|
+
else {
|
|
1444
|
+
this.SET_VECTOR_ELT(ans, i, this.readBC1(reps));
|
|
1445
|
+
}
|
|
1894
1446
|
break;
|
|
1895
|
-
}
|
|
1896
1447
|
case SexpType.LangSxp:
|
|
1897
1448
|
case SexpType.ListSxp:
|
|
1898
1449
|
case SexpType.BcRepDef:
|
|
1899
1450
|
case SexpType.BcRepRef:
|
|
1900
1451
|
case SexpType.AltLangSxp:
|
|
1901
|
-
case SexpType.AttrListSxp:
|
|
1902
|
-
|
|
1903
|
-
|
|
1452
|
+
case SexpType.AttrListSxp:
|
|
1453
|
+
if (skip) {
|
|
1454
|
+
this.skipBCLang(type);
|
|
1455
|
+
}
|
|
1456
|
+
else {
|
|
1457
|
+
this.SET_VECTOR_ELT(ans, i, this.ReadBCLang(type, reps));
|
|
1458
|
+
}
|
|
1904
1459
|
break;
|
|
1905
|
-
}
|
|
1906
1460
|
default:
|
|
1907
1461
|
this.currentDepth++;
|
|
1908
|
-
|
|
1462
|
+
if (skip) {
|
|
1463
|
+
this.skipItem();
|
|
1464
|
+
}
|
|
1465
|
+
else {
|
|
1466
|
+
this.SET_VECTOR_ELT(ans, i, this.readItem());
|
|
1467
|
+
}
|
|
1909
1468
|
this.currentDepth--;
|
|
1910
1469
|
}
|
|
1911
1470
|
}
|
|
1912
1471
|
return ans;
|
|
1913
1472
|
}
|
|
1914
|
-
/**
|
|
1915
|
-
* Reads a single language object from bytecode constants.
|
|
1916
|
-
* @param type - {@link SexpType} read from the constants.
|
|
1917
|
-
* @param reps - Shared repetition table.
|
|
1918
|
-
* @returns The deserialized language {@link RObjectData}.
|
|
1919
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2125-L2171 | R source: ReadBCLang}
|
|
1920
|
-
*/
|
|
1473
|
+
/** Reads a single language object from bytecode constants, `reps` is the shared repetition table. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2125-L2171 | R source: ReadBCLang} */
|
|
1921
1474
|
ReadBCLang(type, reps) {
|
|
1922
1475
|
switch (type) {
|
|
1923
1476
|
case SexpType.BcRepRef:
|
|
@@ -1969,12 +1522,7 @@ class RDAParser {
|
|
|
1969
1522
|
}
|
|
1970
1523
|
}
|
|
1971
1524
|
}
|
|
1972
|
-
/**
|
|
1973
|
-
* Advances the buffer past a single language object.
|
|
1974
|
-
*
|
|
1975
|
-
* Mirrors {@link ReadBCLang}.
|
|
1976
|
-
* @param type - read {@link SexpType}.
|
|
1977
|
-
*/
|
|
1525
|
+
/** Advances past a single language object. Mirrors {@link ReadBCLang}. */
|
|
1978
1526
|
skipBCLang(type) {
|
|
1979
1527
|
switch (type) {
|
|
1980
1528
|
case SexpType.BcRepRef:
|
|
@@ -2023,12 +1571,8 @@ class RDAParser {
|
|
|
2023
1571
|
}
|
|
2024
1572
|
}
|
|
2025
1573
|
/**
|
|
2026
|
-
* Retrieves the `i`-th element of a generic list or vector.
|
|
2027
|
-
* @
|
|
2028
|
-
* @param i - The index to retrieve.
|
|
2029
|
-
* @returns The {@link RObject} at position `i`.
|
|
2030
|
-
* @throws Error if `x` is not a list type or `i` is out of bounds.
|
|
2031
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L4122-L4142 | R source: VECTOR_ELT}
|
|
1574
|
+
* Retrieves the `i`-th element of a generic list or vector. Throws Error if `x` is not a list type or `i` is out of bounds.
|
|
1575
|
+
* See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L4122-L4142 | R source: VECTOR_ELT}
|
|
2032
1576
|
*/
|
|
2033
1577
|
VECTOR_ELT(x, i) {
|
|
2034
1578
|
if (x.type !== SexpType.VecSxp &&
|
|
@@ -2036,11 +1580,9 @@ class RDAParser {
|
|
|
2036
1580
|
x.type !== SexpType.WeakRefSxp) {
|
|
2037
1581
|
throw new Error(`VECTOR_ELT() can only be applied to a 'list', not a '${x.type}'`);
|
|
2038
1582
|
}
|
|
2039
|
-
// "VECTOR_ELT", "list", R_typeToChar(x));
|
|
2040
1583
|
if (i < 0 || i >= x.value?.length) {
|
|
2041
1584
|
throw new Error('attempt access index %lld/%lld in VECTOR_ELT');
|
|
2042
1585
|
}
|
|
2043
|
-
// (long long)i, (long long)XLENGTH(x));
|
|
2044
1586
|
if (x.altRep) {
|
|
2045
1587
|
const ans = x.value[i];
|
|
2046
1588
|
/* the element is marked as not mutable since complex
|
|
@@ -2053,27 +1595,16 @@ class RDAParser {
|
|
|
2053
1595
|
return x.value[i];
|
|
2054
1596
|
}
|
|
2055
1597
|
}
|
|
2056
|
-
/**
|
|
2057
|
-
* Checks whether a bytecode object's version is within the supported range.
|
|
2058
|
-
* @param s - The {@link SexpType.BcodesSxp} {@link RObjectData} to check.
|
|
2059
|
-
* @returns `true` if the version is supported.
|
|
2060
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/eval.c#L7166-L7175 | R source: R_BCVersionOK}
|
|
2061
|
-
*/
|
|
1598
|
+
/** Whether a {@link SexpType.BcodesSxp}'s version is within the supported range. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/eval.c#L7166-L7175 | R source: R_BCVersionOK} */
|
|
2062
1599
|
R_BCVersionOK(s) {
|
|
2063
1600
|
if (s.type !== SexpType.BcodesSxp) {
|
|
2064
1601
|
return false;
|
|
2065
1602
|
}
|
|
2066
|
-
// const
|
|
2067
|
-
const
|
|
2068
|
-
|
|
2069
|
-
return (version >= 9 && version <= 12);
|
|
1603
|
+
// const version = s.code;
|
|
1604
|
+
const version = 0;
|
|
1605
|
+
return version >= 9 && version <= 12;
|
|
2070
1606
|
}
|
|
2071
|
-
/**
|
|
2072
|
-
* Returns the source-language expression for an unsupported bytecode object.
|
|
2073
|
-
* @param s - The {@link SexpType.BcodesSxp} {@link RObjectData}.
|
|
2074
|
-
* @returns First constant pool entry if available, otherwise {@link RValues.NilValue}.
|
|
2075
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/eval.c#L5566-L5574 | R source: bytecodeExpr}
|
|
2076
|
-
*/
|
|
1607
|
+
/** Source-language expression for an unsupported bytecode object: its first constant pool entry, or {@link RValues.NilValue}. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/eval.c#L5566-L5574 | R source: bytecodeExpr} */
|
|
2077
1608
|
R_BytecodeExpr(s) {
|
|
2078
1609
|
if (s.type === SexpType.BcodesSxp) {
|
|
2079
1610
|
if (s.cdr.value?.length > 0) {
|
|
@@ -2088,14 +1619,7 @@ class RDAParser {
|
|
|
2088
1619
|
}
|
|
2089
1620
|
}
|
|
2090
1621
|
/**
|
|
2091
|
-
* Attempts to unserialize an ALTREP object.
|
|
2092
|
-
* @param info - The info to be unserialized.
|
|
2093
|
-
* @param _state - Serialized state.
|
|
2094
|
-
* @param _attr - Serialized attributes.
|
|
2095
|
-
* @param _objf - IS_OBJECT flag.
|
|
2096
|
-
* @param _levs - GP levels bits.
|
|
2097
|
-
* @returns The {@link RObjectData} or .
|
|
2098
|
-
* @throws Error if the base type is not a supported vector type.
|
|
1622
|
+
* Attempts to unserialize an ALTREP object. Throws error if the base type is not a supported vector type.
|
|
2099
1623
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/altrep.c#L298-L338 | R source: ALTREP_UNSERIALIZE_EX}
|
|
2100
1624
|
*/
|
|
2101
1625
|
AltRepUnserializeEx(info, _state, _attr, _objf, _levs) {
|
|
@@ -2125,9 +1649,7 @@ class RDAParser {
|
|
|
2125
1649
|
return {};
|
|
2126
1650
|
}
|
|
2127
1651
|
/**
|
|
2128
|
-
*
|
|
2129
|
-
* @param info - The info to be looked up.
|
|
2130
|
-
* @returns The class {@link RObjectData} when found, `undefined` if unregistered, or `null` if `info` is not a `ListSxp`.
|
|
1652
|
+
* The ALTREP class registered for `info`'s class/package symbol pair, `undefined` if unregistered, `null` if `info` is not a `ListSxp`.
|
|
2131
1653
|
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/altrep.c#L279-L296 | R source: ALTREP_UNSERIALIZE_CLASS}
|
|
2132
1654
|
*/
|
|
2133
1655
|
ALTREP_UNSERIALIZE_CLASS(info) {
|
|
@@ -2149,24 +1671,12 @@ class RDAParser {
|
|
|
2149
1671
|
}
|
|
2150
1672
|
return null;
|
|
2151
1673
|
}
|
|
2152
|
-
/**
|
|
2153
|
-
* Looks up an ALTREP class entry by class and package symbol.
|
|
2154
|
-
* @param cSym - Class symbol.
|
|
2155
|
-
* @param pSym - Package symbol.
|
|
2156
|
-
* @returns The {@link RObjectData} or `undefined` if not registered.
|
|
2157
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/altrep.c#L90-L94 | R source: LookupClass}
|
|
2158
|
-
*/
|
|
1674
|
+
/** ALTREP class entry for `cSym`/`pSym`, `undefined` if not registered. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/altrep.c#L90-L94 | R source: LookupClass} */
|
|
2159
1675
|
LookupClass(cSym, pSym) {
|
|
2160
1676
|
const entry = this.LookupClassEntry(cSym, pSym);
|
|
2161
1677
|
return entry === undefined || entry === null ? undefined : entry.car;
|
|
2162
1678
|
}
|
|
2163
|
-
/**
|
|
2164
|
-
* Searches the ALTREP class registry for an entry matching the given symbols.
|
|
2165
|
-
* @param cSym - Class symbol to match.
|
|
2166
|
-
* @param pSym - Package symbol to match.
|
|
2167
|
-
* @returns The matching registry node or `null` if not found.
|
|
2168
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/altrep.c#L53-L59 | R source: LookupClassEntry}
|
|
2169
|
-
*/
|
|
1679
|
+
/** Searches the ALTREP class registry for an entry matching `cSym`/`pSym`. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/altrep.c#L53-L59 | R source: LookupClassEntry} */
|
|
2170
1680
|
LookupClassEntry(cSym, pSym) {
|
|
2171
1681
|
if (!this.Registry) {
|
|
2172
1682
|
return null;
|
|
@@ -2178,24 +1688,13 @@ class RDAParser {
|
|
|
2178
1688
|
}
|
|
2179
1689
|
return null;
|
|
2180
1690
|
}
|
|
2181
|
-
/**
|
|
2182
|
-
* Creates a length-1 character vector wrapping the given string.
|
|
2183
|
-
* @param x - The string value to wrap.
|
|
2184
|
-
* @returns A {@link SexpType.StrSxp} {@link RObjectData} with one element.
|
|
2185
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/include/Rinlinedfuns.h#L1044-L1052 | R source: ScalarString}
|
|
2186
|
-
*/
|
|
1691
|
+
/** A length-1 {@link SexpType.StrSxp} character vector wrapping `x`. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/include/Rinlinedfuns.h#L1044-L1052 | R source: ScalarString} */
|
|
2187
1692
|
ScalarString(x) {
|
|
2188
|
-
const ans = {};
|
|
2189
|
-
ans.type = SexpType.StrSxp;
|
|
2190
|
-
ans.value = new Array(1);
|
|
1693
|
+
const ans = { type: SexpType.StrSxp, value: new Array(1) };
|
|
2191
1694
|
this.SET_STRING_ELT(ans, 0, { name: x });
|
|
2192
1695
|
return ans;
|
|
2193
1696
|
}
|
|
2194
|
-
/**
|
|
2195
|
-
* Recomputes and restores the cached hash-table priority count for an environment.
|
|
2196
|
-
* @param s - The {@link RObjectData} whose hash table is to be repaired.
|
|
2197
|
-
* @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/envir.c#L3685-L3698 | R source: R_RestoreHashCount}
|
|
2198
|
-
*/
|
|
1697
|
+
/** Recomputes and restores the cached hash-table priority count for environment `s`. See {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/envir.c#L3685-L3698 | R source: R_RestoreHashCount} */
|
|
2199
1698
|
restoreHashCount(s) {
|
|
2200
1699
|
if (s.hashTab !== RValues.NilValue) {
|
|
2201
1700
|
const table = s.hashTab;
|
|
@@ -2209,46 +1708,59 @@ class RDAParser {
|
|
|
2209
1708
|
// SET_HASHPRI(table, count);
|
|
2210
1709
|
}
|
|
2211
1710
|
}
|
|
2212
|
-
/**
|
|
2213
|
-
* Converts a linked-list based R object tree into a flat array representation.
|
|
2214
|
-
* @param node - Root node of the deserialized object tree.
|
|
2215
|
-
* @param shortcut - Whether payload values should be omitted.
|
|
2216
|
-
* @returns Flattened array of top-level objects.
|
|
2217
|
-
*/
|
|
1711
|
+
/** Converts a linked-list based R object tree into a flat array of top-level objects, omitting payloads when `shortcut`. */
|
|
2218
1712
|
flattenRObject(node, shortcut) {
|
|
2219
1713
|
const result = [];
|
|
2220
|
-
function walk(n
|
|
1714
|
+
function walk(n) {
|
|
2221
1715
|
if (!n || n === RValues.NilValue) {
|
|
2222
1716
|
return;
|
|
2223
1717
|
}
|
|
2224
1718
|
const name = n.tag?.name;
|
|
2225
1719
|
if (name !== undefined) {
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
hasAttribute: !!n.hasAttribute,
|
|
2238
|
-
attributes: n.attributes,
|
|
2239
|
-
type: n.car.type,
|
|
2240
|
-
tag: RValues.NilValue
|
|
2241
|
-
};
|
|
2242
|
-
}
|
|
2243
|
-
result.push(copy);
|
|
1720
|
+
result.push(shortcut ? {
|
|
1721
|
+
name: n.tag.name,
|
|
1722
|
+
type: n.car.type,
|
|
1723
|
+
} : {
|
|
1724
|
+
name: n.tag.name,
|
|
1725
|
+
value: n.car.value,
|
|
1726
|
+
hasAttribute: !!n.hasAttribute,
|
|
1727
|
+
attributes: n.attributes,
|
|
1728
|
+
type: n.car.type,
|
|
1729
|
+
tag: RValues.NilValue
|
|
1730
|
+
});
|
|
2244
1731
|
}
|
|
2245
1732
|
if (n.cdr && n.cdr !== RValues.NilValue) {
|
|
2246
|
-
walk(n.cdr
|
|
1733
|
+
walk(n.cdr);
|
|
2247
1734
|
}
|
|
2248
1735
|
}
|
|
2249
|
-
walk(node
|
|
1736
|
+
walk(node);
|
|
2250
1737
|
return result;
|
|
2251
1738
|
}
|
|
2252
1739
|
}
|
|
2253
1740
|
exports.RDAParser = RDAParser;
|
|
1741
|
+
/** the value of the R attribute `name`, which hangs off an object as a chain of pairlist cells */
|
|
1742
|
+
function attributeOf(obj, name) {
|
|
1743
|
+
for (const attribute of (typeof obj === 'object' && obj !== null ? obj.attributes : undefined) ?? []) {
|
|
1744
|
+
for (let cell = attribute; cell !== undefined; cell = cell.cdr) {
|
|
1745
|
+
if (cell.tag?.name === name) {
|
|
1746
|
+
return cell.car;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
return undefined;
|
|
1751
|
+
}
|
|
1752
|
+
/** the strings of a character vector, empty for anything that is not one */
|
|
1753
|
+
function stringsOf(obj) {
|
|
1754
|
+
return obj?.type === SexpType.StrSxp && Array.isArray(obj.value) ? obj.value.filter(v => typeof v === 'string') : [];
|
|
1755
|
+
}
|
|
1756
|
+
/** the `names` attribute of a serialized object, empty when it states none */
|
|
1757
|
+
function namesOf(obj) {
|
|
1758
|
+
return stringsOf(attributeOf(obj, 'names'));
|
|
1759
|
+
}
|
|
1760
|
+
/** the element called `name` of a serialized named list */
|
|
1761
|
+
function elementOf(obj, name) {
|
|
1762
|
+
const at = namesOf(obj).indexOf(name);
|
|
1763
|
+
const elements = typeof obj === 'object' && obj !== null ? obj.value : undefined;
|
|
1764
|
+
return at < 0 || !Array.isArray(elements) ? undefined : elements[at];
|
|
1765
|
+
}
|
|
2254
1766
|
//# sourceMappingURL=flowr-rda-file.js.map
|