diff --git a/.github/workflows/trybot.yaml b/.github/workflows/trybot.yaml index 527f0c3..3d3f3ca 100644 --- a/.github/workflows/trybot.yaml +++ b/.github/workflows/trybot.yaml @@ -20,9 +20,11 @@ jobs: matrix: go-version: - stable - runner: - - namespace-profile-linux-amd64 - - ns-macos-arm64 + include: + - runner: namespace-profile-linux-amd64 + binary: linux-amd64 + - runner: ns-macos-arm64 + binary: darwin-arm64 runs-on: ${{ matrix.runner }} if: |- (contains(github.event.head_commit.message, ' @@ -101,17 +103,11 @@ jobs: path: libcue - name: Build libcue working-directory: libcue - run: |- - go build -o libcue.so -buildmode=c-shared - cp libcue.so libcue.dylib - cp libcue.so cue.dll + run: go build -o ../src/main/resources/${{ matrix.binary }} -buildmode=c-shared - name: Early git and code sanity checks run: go run cuelang.org/go/internal/ci/checks@v0.14.1 - name: Test - env: - LD_LIBRARY_PATH: ${{ github.workspace }}/libcue - DYLD_LIBRARY_PATH: ${{ github.workspace }}/libcue - run: mvn clean install package + run: ./mvnw clean install package - name: go generate run: go generate ./... - if: always() diff --git a/.gitignore b/.gitignore index 50de843..815b1ff 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,8 @@ buildNumber.properties *.zip *.tar.gz *.rar + +/.idea/ + +/src/main/resources/darwin-arm64 +/src/main/resources/linux-amd64 \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index a55e7a1..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index b9168da..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/dictionaries/aram.xml b/.idea/dictionaries/aram.xml deleted file mode 100644 index 1058cda..0000000 --- a/.idea/dictionaries/aram.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 590e08c..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index 2b63946..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..c0b0262 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/4.0.0-rc-5/apache-maven-4.0.0-rc-5-bin.zip diff --git a/cue.mod/usr/github.com/SchemaStore/schemastore/src/schemas/json/workflow.cue b/cue.mod/usr/github.com/SchemaStore/schemastore/src/schemas/json/workflow.cue deleted file mode 100644 index 7b0e3c8..0000000 --- a/cue.mod/usr/github.com/SchemaStore/schemastore/src/schemas/json/workflow.cue +++ /dev/null @@ -1,15 +0,0 @@ -package json - -#job: ((#Workflow & {jobs: _}).jobs & {x: _}).x -#step: ((#job & {steps: _}).steps & [_])[0] - -// CUE does not properly encode a JSON Schema oneOf; see -// https://cuelang.org/issue/3165. For now, apply a temporary workaround which -// forces the other option to bottom. -#Workflow: jobs?: [string]: steps?: [...( - { - uses?: _|_ - } | { - run?: _|_ - }), -] diff --git a/gen b/gen index 33264c2..5c95182 100755 --- a/gen +++ b/gen @@ -18,4 +18,4 @@ fi : ${LIBCUE:=$HOME/src/libcue} rm -rf src/main/java/org/cuelang/libcue -jextract -t org.cuelang.libcue --output src/main/java -lcue --use-system-load-library @includes.txt "$LIBCUE/cue.h" +jextract -t org.cuelang.libcue --output src/main/java --use-system-load-library @includes.txt "$LIBCUE/cue.h" diff --git a/includes.txt b/includes.txt index acabe77..ae34f1f 100644 --- a/includes.txt +++ b/includes.txt @@ -39,6 +39,7 @@ --include-function cue_errors_as_values --include-function cue_error_string --include-function cue_filename +--include-function cue_fields --include-function cue_final --include-function cue_free --include-function cue_free_all @@ -46,6 +47,7 @@ --include-function cue_from_bytes --include-function cue_from_double --include-function cue_from_int64 +--include-function cue_from_list --include-function cue_from_string --include-function cue_from_uint64 --include-function cue_hidden @@ -55,9 +57,11 @@ --include-function cue_inline_imports --include-function cue_instance_of --include-function cue_is_equal +--include-function cue_list --include-function cue_lookup_string --include-function cue_newctx --include-function cue_optionals +--include-function cue_path --include-function cue_raw --include-function cue_schema --include-function cue_scope diff --git a/internal/ci/github/trybot.cue b/internal/ci/github/trybot.cue index e17c0b3..da8c281 100644 --- a/internal/ci/github/trybot.cue +++ b/internal/ci/github/trybot.cue @@ -71,7 +71,10 @@ workflows: trybot: _repo.bashWorkflow & { "go-version": ["stable"] // TODO: Windows is missing because of issue #3016. - runner: [_repo.linuxMachine, _repo.macosMachine] + include: [ + {runner: _repo.linuxMachine, binary: "linux-amd64"}, + {runner: _repo.macosMachine, binary: "darwin-arm64"}, + ] } } @@ -105,18 +108,12 @@ workflows: trybot: _repo.bashWorkflow & { // The name of the shared library is target-dependent. // Build libcue with all possible names so we're covered // in all cases. - run: """ - go build -o libcue.so -buildmode=c-shared - cp libcue.so libcue.dylib - cp libcue.so cue.dll - """ + run: "go build -o ../src/main/resources/${{ matrix.binary }} -buildmode=c-shared" } _mavenTest: githubactions.#Step & { name: "Test" - env: LD_LIBRARY_PATH: "${{ github.workspace }}/libcue" - env: DYLD_LIBRARY_PATH: "${{ github.workspace }}/libcue" - run: "mvn clean install package" + run: "./mvnw clean install package" } _goGenerate: githubactions.#Step & { diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..92450f9 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/pom.xml b/pom.xml index 577c419..65cbe2b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,12 +4,12 @@ 4.0.0 org.cuelang - CUE - 0.0-devel + cue-api-java + 0.0.1-devel - 1.8 - 1.8 + 22 + 22 diff --git a/src/main/java/org/cuelang/cue/CueContext.java b/src/main/java/org/cuelang/cue/CueContext.java index 130f057..65b8887 100644 --- a/src/main/java/org/cuelang/cue/CueContext.java +++ b/src/main/java/org/cuelang/cue/CueContext.java @@ -15,6 +15,7 @@ package org.cuelang.cue; import org.cuelang.libcue.cue_bopt; +import org.cuelang.cue.loader.NativeLibraryLoader; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -26,6 +27,11 @@ import static org.cuelang.libcue.cue_h.*; public final class CueContext { + + static { + NativeLibraryLoader.loadLibcue(); + } + private static final Cleaner cleaner = Cleaner.create(); private final CueResource ctx; @@ -156,4 +162,7 @@ Cleaner cleaner() { public @NotNull Value toValue(byte[] buf) { return new Value(this, buf); } + + @Contract("_ -> new") + public @NotNull Value toValue(Value... values) { return new Value(this, values); } } diff --git a/src/main/java/org/cuelang/cue/Value.java b/src/main/java/org/cuelang/cue/Value.java index a273f62..f5b2ff3 100644 --- a/src/main/java/org/cuelang/cue/Value.java +++ b/src/main/java/org/cuelang/cue/Value.java @@ -20,6 +20,7 @@ import java.lang.foreign.*; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -87,6 +88,18 @@ public Value(@NotNull CueContext ctx, byte[] buf) { } } + public Value(@NotNull CueContext ctx, Value... values) { + try (Arena arena = Arena.ofConfined()) { + var mem = arena.allocate(ValueLayout.JAVA_LONG, values.length); + for (int i = 0; i < values.length; i++) { + mem.setAtIndex(ValueLayout.JAVA_LONG, i, values[i].res.handle()); + } + var res = cue_from_list(ctx.handle(), mem, values.length); + this.res = new CueResource(ctx.cleaner(), res); + this.ctx = ctx; + } + } + private static MemorySegment encodeEvalOptions(@NotNull Arena arena, EvalOption @NotNull ... opts) { if (opts.length == 0) { return MemorySegment.ofAddress(0); @@ -372,4 +385,42 @@ public byte[] getBytes() throws CueError { return attributes; } } + + public String path() { + var labelPtr = cue_path(this.handle()); + return labelPtr.getString(0); + } + + public @NotNull Value[] fields() { + try (Arena arena = Arena.ofConfined()) { + var lenPtr = arena.allocate(ValueLayout.JAVA_LONG); + var valuesPtr = cue_fields(this.handle(), lenPtr); + + return mapToValueAndMemFree(lenPtr, valuesPtr); + } + } + + public @NotNull Value[] list() { + try (Arena arena = Arena.ofConfined()) { + var lenPtr = arena.allocate(ValueLayout.JAVA_LONG); + var valuesPtr = cue_list(this.handle(), lenPtr); + + return mapToValueAndMemFree(lenPtr, valuesPtr); + } + } + + private @NotNull Value[] mapToValueAndMemFree(MemorySegment lenPtr, MemorySegment valuesPtr) { + var len = (int)lenPtr.get(ValueLayout.JAVA_LONG, 0); + if (len == 0) + return new Value[0]; + + var jValues = new Value[len]; + for (int i = 0; i < jValues.length; i++) { + var res = valuesPtr.getAtIndex(ValueLayout.JAVA_LONG, i); + var cueRes = new CueResource(ctx.cleaner(), res); + jValues[i] = new Value(ctx, cueRes); + } + libc_free(valuesPtr); + return jValues; + } } diff --git a/src/main/java/org/cuelang/cue/loader/NativeLibraryLoader.java b/src/main/java/org/cuelang/cue/loader/NativeLibraryLoader.java new file mode 100644 index 0000000..f98a745 --- /dev/null +++ b/src/main/java/org/cuelang/cue/loader/NativeLibraryLoader.java @@ -0,0 +1,28 @@ +package org.cuelang.cue.loader; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +public class NativeLibraryLoader { + public static void loadLibcue() { + String osName = System.getProperty("os.name").toLowerCase(); + + String binaryName = switch (osName) { + case String os when os.contains("mac") -> "darwin-arm64"; + case String os when os.contains("linux") -> "linux-amd64"; + default -> throw new IllegalStateException("Unknown Platform!"); + }; + + try (InputStream lib = NativeLibraryLoader.class.getResourceAsStream(File.separator + binaryName)) { + File tempFile = File.createTempFile("native_", "_" + binaryName); + tempFile.deleteOnExit(); + Files.copy(lib, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + System.load(tempFile.getAbsolutePath()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/org/cuelang/libcue/cue_attr_arg.java b/src/main/java/org/cuelang/libcue/cue_attr_arg.java index 4fbd377..66254b7 100644 --- a/src/main/java/org/cuelang/libcue/cue_attr_arg.java +++ b/src/main/java/org/cuelang/libcue/cue_attr_arg.java @@ -155,7 +155,7 @@ public static MemorySegment allocateArray(long elementCount, SegmentAllocator al } /** - * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). * The returned segment has size {@code layout().byteSize()} */ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { @@ -163,7 +163,7 @@ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consume } /** - * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). * The returned segment has size {@code elementCount * layout().byteSize()} */ public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { diff --git a/src/main/java/org/cuelang/libcue/cue_bopt.java b/src/main/java/org/cuelang/libcue/cue_bopt.java index a55fd1f..558fe5b 100644 --- a/src/main/java/org/cuelang/libcue/cue_bopt.java +++ b/src/main/java/org/cuelang/libcue/cue_bopt.java @@ -249,7 +249,7 @@ public static MemorySegment allocateArray(long elementCount, SegmentAllocator al } /** - * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). * The returned segment has size {@code layout().byteSize()} */ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { @@ -257,7 +257,7 @@ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consume } /** - * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). * The returned segment has size {@code elementCount * layout().byteSize()} */ public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { diff --git a/src/main/java/org/cuelang/libcue/cue_eopt.java b/src/main/java/org/cuelang/libcue/cue_eopt.java index df60a0b..1d91af2 100644 --- a/src/main/java/org/cuelang/libcue/cue_eopt.java +++ b/src/main/java/org/cuelang/libcue/cue_eopt.java @@ -156,7 +156,7 @@ public static MemorySegment allocateArray(long elementCount, SegmentAllocator al } /** - * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). * The returned segment has size {@code layout().byteSize()} */ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer cleanup) { @@ -164,7 +164,7 @@ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consume } /** - * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction) (if any). + * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any). * The returned segment has size {@code elementCount * layout().byteSize()} */ public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer cleanup) { diff --git a/src/main/java/org/cuelang/libcue/cue_h.java b/src/main/java/org/cuelang/libcue/cue_h.java index 88fcc94..a11ef8d 100644 --- a/src/main/java/org/cuelang/libcue/cue_h.java +++ b/src/main/java/org/cuelang/libcue/cue_h.java @@ -57,7 +57,6 @@ static MemoryLayout align(MemoryLayout layout, long align) { static { - System.loadLibrary("cue"); } static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() @@ -423,9 +422,9 @@ private static class cue_newctx { public static final FunctionDescriptor DESC = FunctionDescriptor.of( cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_newctx"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_newctx"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -447,6 +446,17 @@ private static class cue_newctx { public static MethodHandle cue_newctx$handle() { return cue_newctx.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_ctx cue_newctx() + * } + */ + public static MemorySegment cue_newctx$address() { + return cue_newctx.ADDR; + } + /** * {@snippet lang=c : * cue_ctx cue_newctx() @@ -470,9 +480,9 @@ private static class cue_error_string { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_error_string"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_error_string"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -494,6 +504,17 @@ private static class cue_error_string { public static MethodHandle cue_error_string$handle() { return cue_error_string.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * char *cue_error_string(cue_error) + * } + */ + public static MemorySegment cue_error_string$address() { + return cue_error_string.ADDR; + } + /** * {@snippet lang=c : * char *cue_error_string(cue_error) @@ -520,9 +541,9 @@ private static class cue_compile_string { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_compile_string"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_compile_string"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -544,6 +565,17 @@ private static class cue_compile_string { public static MethodHandle cue_compile_string$handle() { return cue_compile_string.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_compile_string(cue_ctx, char *, cue_bopt *, cue_value *) + * } + */ + public static MemorySegment cue_compile_string$address() { + return cue_compile_string.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_compile_string(cue_ctx, char *, cue_bopt *, cue_value *) @@ -571,9 +603,9 @@ private static class cue_compile_bytes { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_compile_bytes"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_compile_bytes"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -595,6 +627,17 @@ private static class cue_compile_bytes { public static MethodHandle cue_compile_bytes$handle() { return cue_compile_bytes.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_compile_bytes(cue_ctx, void *, size_t, cue_bopt *, cue_value *) + * } + */ + public static MemorySegment cue_compile_bytes$address() { + return cue_compile_bytes.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_compile_bytes(cue_ctx, void *, size_t, cue_bopt *, cue_value *) @@ -612,15 +655,133 @@ public static long cue_compile_bytes(long x0, MemorySegment x1, long x2, MemoryS } } + private static class cue_fields { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + cue_h.C_POINTER, + cue_h.C_LONG, + cue_h.C_POINTER + ); + + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_fields"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * cue_value *cue_fields(cue_value, size_t *) + * } + */ + public static FunctionDescriptor cue_fields$descriptor() { + return cue_fields.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * cue_value *cue_fields(cue_value, size_t *) + * } + */ + public static MethodHandle cue_fields$handle() { + return cue_fields.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * cue_value *cue_fields(cue_value, size_t *) + * } + */ + public static MemorySegment cue_fields$address() { + return cue_fields.ADDR; + } + + /** + * {@snippet lang=c : + * cue_value *cue_fields(cue_value, size_t *) + * } + */ + public static MemorySegment cue_fields(long x0, MemorySegment x1) { + var mh$ = cue_fields.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("cue_fields", x0, x1); + } + return (MemorySegment)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class cue_list { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + cue_h.C_POINTER, + cue_h.C_LONG, + cue_h.C_POINTER + ); + + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_list"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * cue_value *cue_list(cue_value, size_t *) + * } + */ + public static FunctionDescriptor cue_list$descriptor() { + return cue_list.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * cue_value *cue_list(cue_value, size_t *) + * } + */ + public static MethodHandle cue_list$handle() { + return cue_list.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * cue_value *cue_list(cue_value, size_t *) + * } + */ + public static MemorySegment cue_list$address() { + return cue_list.ADDR; + } + + /** + * {@snippet lang=c : + * cue_value *cue_list(cue_value, size_t *) + * } + */ + public static MemorySegment cue_list(long x0, MemorySegment x1) { + var mh$ = cue_list.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("cue_list", x0, x1); + } + return (MemorySegment)mh$.invokeExact(x0, x1); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + private static class cue_top { public static final FunctionDescriptor DESC = FunctionDescriptor.of( cue_h.C_LONG, cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_top"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_top"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -642,6 +803,17 @@ private static class cue_top { public static MethodHandle cue_top$handle() { return cue_top.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_top(cue_ctx) + * } + */ + public static MemorySegment cue_top$address() { + return cue_top.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_top(cue_ctx) @@ -665,9 +837,9 @@ private static class cue_bottom { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_bottom"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_bottom"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -689,6 +861,17 @@ private static class cue_bottom { public static MethodHandle cue_bottom$handle() { return cue_bottom.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_bottom(cue_ctx) + * } + */ + public static MemorySegment cue_bottom$address() { + return cue_bottom.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_bottom(cue_ctx) @@ -713,9 +896,9 @@ private static class cue_unify { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_unify"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_unify"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -737,6 +920,17 @@ private static class cue_unify { public static MethodHandle cue_unify$handle() { return cue_unify.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_unify(cue_value, cue_value) + * } + */ + public static MemorySegment cue_unify$address() { + return cue_unify.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_unify(cue_value, cue_value) @@ -762,9 +956,9 @@ private static class cue_instance_of { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_instance_of"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_instance_of"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -786,6 +980,17 @@ private static class cue_instance_of { public static MethodHandle cue_instance_of$handle() { return cue_instance_of.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_instance_of(cue_value, cue_value, cue_eopt *) + * } + */ + public static MemorySegment cue_instance_of$address() { + return cue_instance_of.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_instance_of(cue_value, cue_value, cue_eopt *) @@ -811,9 +1016,9 @@ private static class cue_lookup_string { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_lookup_string"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_lookup_string"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -835,6 +1040,17 @@ private static class cue_lookup_string { public static MethodHandle cue_lookup_string$handle() { return cue_lookup_string.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_lookup_string(cue_value, char *, cue_value *) + * } + */ + public static MemorySegment cue_lookup_string$address() { + return cue_lookup_string.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_lookup_string(cue_value, char *, cue_value *) @@ -859,9 +1075,9 @@ private static class cue_from_int64 { cue_h.C_LONG_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_from_int64"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_from_int64"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -883,6 +1099,17 @@ private static class cue_from_int64 { public static MethodHandle cue_from_int64$handle() { return cue_from_int64.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_from_int64(cue_ctx, int64_t) + * } + */ + public static MemorySegment cue_from_int64$address() { + return cue_from_int64.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_from_int64(cue_ctx, int64_t) @@ -907,9 +1134,9 @@ private static class cue_from_uint64 { cue_h.C_LONG_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_from_uint64"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_from_uint64"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -931,6 +1158,17 @@ private static class cue_from_uint64 { public static MethodHandle cue_from_uint64$handle() { return cue_from_uint64.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_from_uint64(cue_ctx, uint64_t) + * } + */ + public static MemorySegment cue_from_uint64$address() { + return cue_from_uint64.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_from_uint64(cue_ctx, uint64_t) @@ -955,9 +1193,9 @@ private static class cue_from_bool { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_from_bool"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_from_bool"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -979,6 +1217,17 @@ private static class cue_from_bool { public static MethodHandle cue_from_bool$handle() { return cue_from_bool.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_from_bool(cue_ctx, bool) + * } + */ + public static MemorySegment cue_from_bool$address() { + return cue_from_bool.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_from_bool(cue_ctx, bool) @@ -1003,9 +1252,9 @@ private static class cue_from_double { cue_h.C_DOUBLE ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_from_double"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_from_double"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1027,6 +1276,17 @@ private static class cue_from_double { public static MethodHandle cue_from_double$handle() { return cue_from_double.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_from_double(cue_ctx, double) + * } + */ + public static MemorySegment cue_from_double$address() { + return cue_from_double.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_from_double(cue_ctx, double) @@ -1051,9 +1311,9 @@ private static class cue_from_string { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_from_string"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_from_string"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1075,6 +1335,17 @@ private static class cue_from_string { public static MethodHandle cue_from_string$handle() { return cue_from_string.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_from_string(cue_ctx, char *) + * } + */ + public static MemorySegment cue_from_string$address() { + return cue_from_string.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_from_string(cue_ctx, char *) @@ -1100,9 +1371,9 @@ private static class cue_from_bytes { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_from_bytes"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_from_bytes"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1124,6 +1395,17 @@ private static class cue_from_bytes { public static MethodHandle cue_from_bytes$handle() { return cue_from_bytes.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_from_bytes(cue_ctx, void *, size_t) + * } + */ + public static MemorySegment cue_from_bytes$address() { + return cue_from_bytes.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_from_bytes(cue_ctx, void *, size_t) @@ -1141,6 +1423,66 @@ public static long cue_from_bytes(long x0, MemorySegment x1, long x2) { } } + private static class cue_from_list { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + cue_h.C_LONG, + cue_h.C_LONG, + cue_h.C_POINTER, + cue_h.C_LONG + ); + + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_from_list"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * cue_value cue_from_list(cue_ctx, cue_value *, size_t) + * } + */ + public static FunctionDescriptor cue_from_list$descriptor() { + return cue_from_list.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * cue_value cue_from_list(cue_ctx, cue_value *, size_t) + * } + */ + public static MethodHandle cue_from_list$handle() { + return cue_from_list.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_from_list(cue_ctx, cue_value *, size_t) + * } + */ + public static MemorySegment cue_from_list$address() { + return cue_from_list.ADDR; + } + + /** + * {@snippet lang=c : + * cue_value cue_from_list(cue_ctx, cue_value *, size_t) + * } + */ + public static long cue_from_list(long x0, MemorySegment x1, long x2) { + var mh$ = cue_from_list.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("cue_from_list", x0, x1, x2); + } + return (long)mh$.invokeExact(x0, x1, x2); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + private static class cue_dec_int64 { public static final FunctionDescriptor DESC = FunctionDescriptor.of( cue_h.C_LONG, @@ -1148,9 +1490,9 @@ private static class cue_dec_int64 { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_dec_int64"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_dec_int64"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1172,6 +1514,17 @@ private static class cue_dec_int64 { public static MethodHandle cue_dec_int64$handle() { return cue_dec_int64.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_dec_int64(cue_value, int64_t *) + * } + */ + public static MemorySegment cue_dec_int64$address() { + return cue_dec_int64.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_dec_int64(cue_value, int64_t *) @@ -1196,9 +1549,9 @@ private static class cue_dec_uint64 { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_dec_uint64"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_dec_uint64"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1220,6 +1573,17 @@ private static class cue_dec_uint64 { public static MethodHandle cue_dec_uint64$handle() { return cue_dec_uint64.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_dec_uint64(cue_value, uint64_t *) + * } + */ + public static MemorySegment cue_dec_uint64$address() { + return cue_dec_uint64.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_dec_uint64(cue_value, uint64_t *) @@ -1244,9 +1608,9 @@ private static class cue_dec_bool { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_dec_bool"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_dec_bool"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1268,6 +1632,17 @@ private static class cue_dec_bool { public static MethodHandle cue_dec_bool$handle() { return cue_dec_bool.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_dec_bool(cue_value, bool *) + * } + */ + public static MemorySegment cue_dec_bool$address() { + return cue_dec_bool.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_dec_bool(cue_value, bool *) @@ -1292,9 +1667,9 @@ private static class cue_dec_double { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_dec_double"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_dec_double"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1316,6 +1691,17 @@ private static class cue_dec_double { public static MethodHandle cue_dec_double$handle() { return cue_dec_double.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_dec_double(cue_value, double *) + * } + */ + public static MemorySegment cue_dec_double$address() { + return cue_dec_double.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_dec_double(cue_value, double *) @@ -1340,9 +1726,9 @@ private static class cue_dec_string { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_dec_string"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_dec_string"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1364,6 +1750,17 @@ private static class cue_dec_string { public static MethodHandle cue_dec_string$handle() { return cue_dec_string.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_dec_string(cue_value, char **) + * } + */ + public static MemorySegment cue_dec_string$address() { + return cue_dec_string.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_dec_string(cue_value, char **) @@ -1389,9 +1786,9 @@ private static class cue_dec_bytes { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_dec_bytes"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_dec_bytes"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1413,6 +1810,17 @@ private static class cue_dec_bytes { public static MethodHandle cue_dec_bytes$handle() { return cue_dec_bytes.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_dec_bytes(cue_value, void **, size_t *) + * } + */ + public static MemorySegment cue_dec_bytes$address() { + return cue_dec_bytes.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_dec_bytes(cue_value, void **, size_t *) @@ -1438,9 +1846,9 @@ private static class cue_dec_json { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_dec_json"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_dec_json"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1462,6 +1870,17 @@ private static class cue_dec_json { public static MethodHandle cue_dec_json$handle() { return cue_dec_json.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_dec_json(cue_value, void **, size_t *) + * } + */ + public static MemorySegment cue_dec_json$address() { + return cue_dec_json.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_dec_json(cue_value, void **, size_t *) @@ -1486,9 +1905,9 @@ private static class cue_validate { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_validate"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_validate"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1510,6 +1929,17 @@ private static class cue_validate { public static MethodHandle cue_validate$handle() { return cue_validate.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_validate(cue_value, cue_eopt *) + * } + */ + public static MemorySegment cue_validate$address() { + return cue_validate.ADDR; + } + /** * {@snippet lang=c : * cue_error cue_validate(cue_value, cue_eopt *) @@ -1534,9 +1964,9 @@ private static class cue_default { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_default"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_default"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1558,6 +1988,17 @@ private static class cue_default { public static MethodHandle cue_default$handle() { return cue_default.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_value cue_default(cue_value, bool *) + * } + */ + public static MemorySegment cue_default$address() { + return cue_default.ADDR; + } + /** * {@snippet lang=c : * cue_value cue_default(cue_value, bool *) @@ -1581,9 +2022,9 @@ private static class cue_concrete_kind { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_concrete_kind"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_concrete_kind"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1605,6 +2046,17 @@ private static class cue_concrete_kind { public static MethodHandle cue_concrete_kind$handle() { return cue_concrete_kind.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_kind cue_concrete_kind(cue_value) + * } + */ + public static MemorySegment cue_concrete_kind$address() { + return cue_concrete_kind.ADDR; + } + /** * {@snippet lang=c : * cue_kind cue_concrete_kind(cue_value) @@ -1628,9 +2080,9 @@ private static class cue_incomplete_kind { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_incomplete_kind"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_incomplete_kind"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1652,65 +2104,145 @@ private static class cue_incomplete_kind { public static MethodHandle cue_incomplete_kind$handle() { return cue_incomplete_kind.HANDLE; } + /** + * Address for: * {@snippet lang=c : * cue_kind cue_incomplete_kind(cue_value) * } */ - public static int cue_incomplete_kind(long x0) { - var mh$ = cue_incomplete_kind.HANDLE; + public static MemorySegment cue_incomplete_kind$address() { + return cue_incomplete_kind.ADDR; + } + + /** + * {@snippet lang=c : + * cue_kind cue_incomplete_kind(cue_value) + * } + */ + public static int cue_incomplete_kind(long x0) { + var mh$ = cue_incomplete_kind.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("cue_incomplete_kind", x0); + } + return (int)mh$.invokeExact(x0); + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class cue_value_error { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + cue_h.C_LONG, + cue_h.C_LONG + ); + + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_value_error"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * cue_error cue_value_error(cue_value) + * } + */ + public static FunctionDescriptor cue_value_error$descriptor() { + return cue_value_error.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * cue_error cue_value_error(cue_value) + * } + */ + public static MethodHandle cue_value_error$handle() { + return cue_value_error.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * cue_error cue_value_error(cue_value) + * } + */ + public static MemorySegment cue_value_error$address() { + return cue_value_error.ADDR; + } + + /** + * {@snippet lang=c : + * cue_error cue_value_error(cue_value) + * } + */ + public static long cue_value_error(long x0) { + var mh$ = cue_value_error.HANDLE; try { if (TRACE_DOWNCALLS) { - traceDowncall("cue_incomplete_kind", x0); + traceDowncall("cue_value_error", x0); } - return (int)mh$.invokeExact(x0); + return (long)mh$.invokeExact(x0); } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } } - private static class cue_value_error { + private static class cue_path { public static final FunctionDescriptor DESC = FunctionDescriptor.of( - cue_h.C_LONG, + cue_h.C_POINTER, cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_value_error"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_path"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** * Function descriptor for: * {@snippet lang=c : - * cue_error cue_value_error(cue_value) + * char *cue_path(cue_value) * } */ - public static FunctionDescriptor cue_value_error$descriptor() { - return cue_value_error.DESC; + public static FunctionDescriptor cue_path$descriptor() { + return cue_path.DESC; } /** * Downcall method handle for: * {@snippet lang=c : - * cue_error cue_value_error(cue_value) + * char *cue_path(cue_value) * } */ - public static MethodHandle cue_value_error$handle() { - return cue_value_error.HANDLE; + public static MethodHandle cue_path$handle() { + return cue_path.HANDLE; } + /** + * Address for: * {@snippet lang=c : - * cue_error cue_value_error(cue_value) + * char *cue_path(cue_value) * } */ - public static long cue_value_error(long x0) { - var mh$ = cue_value_error.HANDLE; + public static MemorySegment cue_path$address() { + return cue_path.ADDR; + } + + /** + * {@snippet lang=c : + * char *cue_path(cue_value) + * } + */ + public static MemorySegment cue_path(long x0) { + var mh$ = cue_path.HANDLE; try { if (TRACE_DOWNCALLS) { - traceDowncall("cue_value_error", x0); + traceDowncall("cue_path", x0); } - return (long)mh$.invokeExact(x0); + return (MemorySegment)mh$.invokeExact(x0); } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1723,9 +2255,9 @@ private static class cue_is_equal { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_is_equal"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_is_equal"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1747,6 +2279,17 @@ private static class cue_is_equal { public static MethodHandle cue_is_equal$handle() { return cue_is_equal.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * bool cue_is_equal(cue_value, cue_value) + * } + */ + public static MemorySegment cue_is_equal$address() { + return cue_is_equal.ADDR; + } + /** * {@snippet lang=c : * bool cue_is_equal(cue_value, cue_value) @@ -1770,9 +2313,9 @@ private static class cue_filename { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_filename"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_filename"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1794,6 +2337,17 @@ private static class cue_filename { public static MethodHandle cue_filename$handle() { return cue_filename.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_bopt cue_filename(char *) + * } + */ + public static MemorySegment cue_filename$address() { + return cue_filename.ADDR; + } + /** * {@snippet lang=c : * cue_bopt cue_filename(char *) @@ -1817,9 +2371,9 @@ private static class cue_import_path { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_import_path"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_import_path"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1841,6 +2395,17 @@ private static class cue_import_path { public static MethodHandle cue_import_path$handle() { return cue_import_path.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_bopt cue_import_path(char *) + * } + */ + public static MemorySegment cue_import_path$address() { + return cue_import_path.ADDR; + } + /** * {@snippet lang=c : * cue_bopt cue_import_path(char *) @@ -1864,9 +2429,9 @@ private static class cue_infer_builtins { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_infer_builtins"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_infer_builtins"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1888,6 +2453,17 @@ private static class cue_infer_builtins { public static MethodHandle cue_infer_builtins$handle() { return cue_infer_builtins.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_bopt cue_infer_builtins(bool) + * } + */ + public static MemorySegment cue_infer_builtins$address() { + return cue_infer_builtins.ADDR; + } + /** * {@snippet lang=c : * cue_bopt cue_infer_builtins(bool) @@ -1911,9 +2487,9 @@ private static class cue_scope { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_scope"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_scope"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1935,6 +2511,17 @@ private static class cue_scope { public static MethodHandle cue_scope$handle() { return cue_scope.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_bopt cue_scope(cue_value) + * } + */ + public static MemorySegment cue_scope$address() { + return cue_scope.ADDR; + } + /** * {@snippet lang=c : * cue_bopt cue_scope(cue_value) @@ -1956,9 +2543,9 @@ private static class cue_all { public static final FunctionDescriptor DESC = FunctionDescriptor.of( cue_eopt.layout() ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_all"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_all"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -1980,6 +2567,17 @@ private static class cue_all { public static MethodHandle cue_all$handle() { return cue_all.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_all() + * } + */ + public static MemorySegment cue_all$address() { + return cue_all.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_all() @@ -2003,9 +2601,9 @@ private static class cue_concrete { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_concrete"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_concrete"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2027,6 +2625,17 @@ private static class cue_concrete { public static MethodHandle cue_concrete$handle() { return cue_concrete.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_concrete(bool) + * } + */ + public static MemorySegment cue_concrete$address() { + return cue_concrete.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_concrete(bool) @@ -2050,9 +2659,9 @@ private static class cue_definitions { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_definitions"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_definitions"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2074,6 +2683,17 @@ private static class cue_definitions { public static MethodHandle cue_definitions$handle() { return cue_definitions.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_definitions(bool) + * } + */ + public static MemorySegment cue_definitions$address() { + return cue_definitions.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_definitions(bool) @@ -2097,9 +2717,9 @@ private static class cue_disallow_cycles { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_disallow_cycles"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_disallow_cycles"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2121,6 +2741,17 @@ private static class cue_disallow_cycles { public static MethodHandle cue_disallow_cycles$handle() { return cue_disallow_cycles.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_disallow_cycles(bool) + * } + */ + public static MemorySegment cue_disallow_cycles$address() { + return cue_disallow_cycles.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_disallow_cycles(bool) @@ -2144,9 +2775,9 @@ private static class cue_docs { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_docs"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_docs"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2168,6 +2799,17 @@ private static class cue_docs { public static MethodHandle cue_docs$handle() { return cue_docs.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_docs(bool) + * } + */ + public static MemorySegment cue_docs$address() { + return cue_docs.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_docs(bool) @@ -2191,9 +2833,9 @@ private static class cue_errors_as_values { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_errors_as_values"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_errors_as_values"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2215,6 +2857,17 @@ private static class cue_errors_as_values { public static MethodHandle cue_errors_as_values$handle() { return cue_errors_as_values.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_errors_as_values(bool) + * } + */ + public static MemorySegment cue_errors_as_values$address() { + return cue_errors_as_values.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_errors_as_values(bool) @@ -2236,9 +2889,9 @@ private static class cue_final { public static final FunctionDescriptor DESC = FunctionDescriptor.of( cue_eopt.layout() ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_final"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_final"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2260,6 +2913,17 @@ private static class cue_final { public static MethodHandle cue_final$handle() { return cue_final.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_final() + * } + */ + public static MemorySegment cue_final$address() { + return cue_final.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_final() @@ -2283,9 +2947,9 @@ private static class cue_hidden { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_hidden"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_hidden"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2307,6 +2971,17 @@ private static class cue_hidden { public static MethodHandle cue_hidden$handle() { return cue_hidden.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_hidden(bool) + * } + */ + public static MemorySegment cue_hidden$address() { + return cue_hidden.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_hidden(bool) @@ -2330,9 +3005,9 @@ private static class cue_inline_imports { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_inline_imports"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_inline_imports"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2354,6 +3029,17 @@ private static class cue_inline_imports { public static MethodHandle cue_inline_imports$handle() { return cue_inline_imports.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_inline_imports(bool) + * } + */ + public static MemorySegment cue_inline_imports$address() { + return cue_inline_imports.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_inline_imports(bool) @@ -2377,9 +3063,9 @@ private static class cue_optionals { cue_h.C_BOOL ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_optionals"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_optionals"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2401,6 +3087,17 @@ private static class cue_optionals { public static MethodHandle cue_optionals$handle() { return cue_optionals.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_optionals(bool) + * } + */ + public static MemorySegment cue_optionals$address() { + return cue_optionals.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_optionals(bool) @@ -2422,9 +3119,9 @@ private static class cue_raw { public static final FunctionDescriptor DESC = FunctionDescriptor.of( cue_eopt.layout() ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_raw"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_raw"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2446,6 +3143,17 @@ private static class cue_raw { public static MethodHandle cue_raw$handle() { return cue_raw.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_raw() + * } + */ + public static MemorySegment cue_raw$address() { + return cue_raw.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_raw() @@ -2467,9 +3175,9 @@ private static class cue_schema { public static final FunctionDescriptor DESC = FunctionDescriptor.of( cue_eopt.layout() ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_schema"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_schema"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2491,6 +3199,17 @@ private static class cue_schema { public static MethodHandle cue_schema$handle() { return cue_schema.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_eopt cue_schema() + * } + */ + public static MemorySegment cue_schema$address() { + return cue_schema.ADDR; + } + /** * {@snippet lang=c : * cue_eopt cue_schema() @@ -2516,9 +3235,9 @@ private static class cue_attrs { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_attrs"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_attrs"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2540,6 +3259,17 @@ private static class cue_attrs { public static MethodHandle cue_attrs$handle() { return cue_attrs.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * cue_attr *cue_attrs(cue_value, cue_attr_kind, size_t *) + * } + */ + public static MemorySegment cue_attrs$address() { + return cue_attrs.ADDR; + } + /** * {@snippet lang=c : * cue_attr *cue_attrs(cue_value, cue_attr_kind, size_t *) @@ -2563,9 +3293,9 @@ private static class cue_attr_name { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_attr_name"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_attr_name"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2587,6 +3317,17 @@ private static class cue_attr_name { public static MethodHandle cue_attr_name$handle() { return cue_attr_name.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * char *cue_attr_name(cue_attr) + * } + */ + public static MemorySegment cue_attr_name$address() { + return cue_attr_name.ADDR; + } + /** * {@snippet lang=c : * char *cue_attr_name(cue_attr) @@ -2610,9 +3351,9 @@ private static class cue_attr_value { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_attr_value"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_attr_value"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2634,6 +3375,17 @@ private static class cue_attr_value { public static MethodHandle cue_attr_value$handle() { return cue_attr_value.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * char *cue_attr_value(cue_attr) + * } + */ + public static MemorySegment cue_attr_value$address() { + return cue_attr_value.ADDR; + } + /** * {@snippet lang=c : * char *cue_attr_value(cue_attr) @@ -2657,9 +3409,9 @@ private static class cue_attr_numargs { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_attr_numargs"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_attr_numargs"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2681,6 +3433,17 @@ private static class cue_attr_numargs { public static MethodHandle cue_attr_numargs$handle() { return cue_attr_numargs.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * size_t cue_attr_numargs(cue_attr) + * } + */ + public static MemorySegment cue_attr_numargs$address() { + return cue_attr_numargs.ADDR; + } + /** * {@snippet lang=c : * size_t cue_attr_numargs(cue_attr) @@ -2705,9 +3468,9 @@ private static class cue_attr_getarg { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_attr_getarg"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_attr_getarg"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2729,6 +3492,17 @@ private static class cue_attr_getarg { public static MethodHandle cue_attr_getarg$handle() { return cue_attr_getarg.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * void cue_attr_getarg(cue_attr, size_t, cue_attr_arg *) + * } + */ + public static MemorySegment cue_attr_getarg$address() { + return cue_attr_getarg.ADDR; + } + /** * {@snippet lang=c : * void cue_attr_getarg(cue_attr, size_t, cue_attr_arg *) @@ -2751,9 +3525,9 @@ private static class cue_free { cue_h.C_LONG ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_free"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_free"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2775,6 +3549,17 @@ private static class cue_free { public static MethodHandle cue_free$handle() { return cue_free.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * void cue_free(uintptr_t) + * } + */ + public static MemorySegment cue_free$address() { + return cue_free.ADDR; + } + /** * {@snippet lang=c : * void cue_free(uintptr_t) @@ -2797,9 +3582,9 @@ private static class cue_free_all { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("cue_free_all"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("cue_free_all"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2821,6 +3606,17 @@ private static class cue_free_all { public static MethodHandle cue_free_all$handle() { return cue_free_all.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * void cue_free_all(uintptr_t *) + * } + */ + public static MemorySegment cue_free_all$address() { + return cue_free_all.ADDR; + } + /** * {@snippet lang=c : * void cue_free_all(uintptr_t *) @@ -2843,9 +3639,9 @@ private static class libc_free { cue_h.C_POINTER ); - public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle( - cue_h.findOrThrow("libc_free"), - DESC); + public static final MemorySegment ADDR = cue_h.findOrThrow("libc_free"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } /** @@ -2867,6 +3663,17 @@ private static class libc_free { public static MethodHandle libc_free$handle() { return libc_free.HANDLE; } + + /** + * Address for: + * {@snippet lang=c : + * void libc_free(void *) + * } + */ + public static MemorySegment libc_free$address() { + return libc_free.ADDR; + } + /** * {@snippet lang=c : * void libc_free(void *) diff --git a/src/test/java/org/cuelang/cue/ValueTest.java b/src/test/java/org/cuelang/cue/ValueTest.java index e8c19b9..bc932f0 100644 --- a/src/test/java/org/cuelang/cue/ValueTest.java +++ b/src/test/java/org/cuelang/cue/ValueTest.java @@ -1,6 +1,8 @@ package org.cuelang.cue; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.util.Optional; @@ -579,4 +581,66 @@ void checkAttributes() { y.attributes(AttributeKind.FIELD).length); }); } + + @Test + @DisplayName("should return path of value") + void checkPath() { + assertDoesNotThrow(() -> { + Value v; + v = ctx.compile(""" + a: int + b: c: string + """); + assertEquals("", v.path()); + assertEquals("a", v.lookup("a").path()); + assertEquals("b.c", v.lookup("b.c").path()); + }); + } + + @Test + @DisplayName("should return array of Value") + void checkFields() { + assertDoesNotThrow(() -> { + Value v; + v = ctx.compile(""" + a: int + b: string + c: [...] + """); + Value[] fields = v.fields(); + + assertEquals(3, fields.length); + + assertEquals("a", fields[0].path()); + assertEquals("b", fields[1].path()); + assertEquals("c",fields[2].path()); + + assertEquals(0, v.lookup("a").fields().length); + assertEquals(0, v.lookup("c").fields().length); + }); + } + + @Test + @DisplayName("should return array of Value") + void checkList() { + assertDoesNotThrow(() -> { + Value[] values = ctx.compile("[1,2,3]").list(); + + assertEquals(3, values.length); + }); + } + + @Test + @DisplayName("should zip values into one value") + void createValueFromListValues() { + assertDoesNotThrow(() -> { + Value a = ctx.compile("\"a\""); + Value b = ctx.compile("\"b\""); + Value c = ctx.compile("\"c\""); + + Value zip = ctx.toValue(a, b, c); + + assertEquals("[\"a\",\"b\",\"c\"]", zip.getJSON()); + }); + } } \ No newline at end of file