type

XetoEnv

@Js
abstract const class XetoEnv : Obj

Environment for the Xeto data and spec handling. There is one instance for the VM accessed via XetoEnv.cur.

methods

compileData

Compile a Xeto data file into an in-memory value.

compileLib

Compile Xeto source code into a temp library.

cur

Current default environment for the VM

derive

Derive a new spec from the given base type, additional meta, and slots.

dict

Coerce one of the following values to a dict

fits

Return if the given instance fits the spec via structural typing.

instance

Get or load instance by the given qualified name

instantiate

Create default instance for the given spec.

isRemote

Is this a remote environment loaded over a network transport.

lib

Get or load library by the given library name.

libAsync

Get or load library asynchronously by the given library name.

marker

Marker singleton value

na

NA singleton value

none

None singleton value

ref

Construct instance of Ref

reload

Reload the entire data env.

spec

Get or load spec by the given qualified name

specOf

Spec for Fantom Type or the typeof given object

type

Get or load type by the given qualified name

writeData

Write instance data in Xeto text format to an output stream.

Slot Details

compileData

abstract Obj? compileData(Str src, Dict? opts := null)

Compile a Xeto data file into an in-memory value. Raise exception if there are any syntax or semantic errors. If the file contains a scalar value or one dict, then it is returned as the value. If the file contains two or more dicts then return a Dict[] of the instances. Also see writeData to encode data back to Xeto text format.

Options

  • externRefs: marker to allow unresolved refs to compile

compileLib

abstract Lib compileLib(Str src, Dict? opts := null)

Compile Xeto source code into a temp library. Raise exception if there are any syntax or semantic errors.

cur

static XetoEnv cur()

Current default environment for the VM

derive

abstract Spec derive(Str name, Spec base, Dict meta, [Str:Spec]? slots := null)

Derive a new spec from the given base type, additional meta, and slots. The spec is not associated with any library and a synthetic qname is generated.

dict

abstract Dict dict(Obj? x)

Coerce one of the following values to a dict:

  • null return empty dict
  • if Dict return it
  • if Str:Obj wrap it as dict
  • raise exception for anything else

fits

abstract Bool fits(XetoContext cx, Obj? val, Spec spec, Dict? opts := null)

Return if the given instance fits the spec via structural typing.

instance

abstract Dict? instance(Str qname, Bool checked := true)

Get or load instance by the given qualified name

instantiate

abstract Obj? instantiate(Spec spec, Dict? opts := null)

Create default instance for the given spec. Raise exception if spec is abstract.

Options:

  • graph: marker tag to instantiate graph of recs (will auto-generate ids)
  • abstract: marker to supress error if spec is abstract
  • id: Ref tag to include in new instance

isRemote

abstract Bool isRemote()

Is this a remote environment loaded over a network transport. Remote environments must load libraries asynchronously and do not support the full feature set.

lib

abstract Lib? lib(Str name, Bool checked := true)

Get or load library by the given library name. If the library is found but cannot be compiled, then raise an exception.

libAsync

abstract Void libAsync(Str name, |Err?,Lib?| f)

Get or load library asynchronously by the given library name. Once loaded then invoke callback with library or err.

marker

abstract Obj marker()

Marker singleton value

na

abstract Obj na()

NA singleton value

none

abstract Obj none()

None singleton value

ref

abstract Ref ref(Str id, Str? dis := null)

Construct instance of Ref

reload

static Void reload()

Reload the entire data env. This creates a new environment, rescans the local file system for installed libs, and all previously loaded libraries with be reloaded on first access. Any references to Lib or Specs must no longer be used.

spec

abstract Spec? spec(Str qname, Bool checked := true)

Get or load spec by the given qualified name:

  • type: "foo.bar::Baz"
  • slot: "foo.bar::Baz.qux"

specOf

abstract Spec? specOf(Obj? val, Bool checked := true)

Spec for Fantom Type or the typeof given object

type

abstract Spec? type(Str qname, Bool checked := true)

Get or load type by the given qualified name

writeData

abstract Void writeData(OutStream out, Obj val, Dict? opts := null)

Write instance data in Xeto text format to an output stream. If the value is a Dict[], then it is flattened in the output. Use compileData to read data from Xeto text format.