Sha256: dec0abecadd2fde9298acb729259deba1ef3c4733ae5afcb4fe8cd4a633f5349

Contents?: true

Size: 1.74 KB

Versions: 38

Compression:

Stored size: 1.74 KB

Contents

use crate::core::*;
use crate::kw;
use crate::parser::{Parse, Parser, Result};
use crate::token::{Id, NameAnnotation, Span};

/// A WebAssembly global in a module
#[derive(Debug)]
pub struct Global<'a> {
    /// Where this `global` was defined.
    pub span: Span,
    /// An optional name to reference this global by
    pub id: Option<Id<'a>>,
    /// An optional name for this function stored in the custom `name` section.
    pub name: Option<NameAnnotation<'a>>,
    /// If present, inline export annotations which indicate names this
    /// definition should be exported under.
    pub exports: InlineExport<'a>,
    /// The type of this global, both its value type and whether it's mutable.
    pub ty: GlobalType<'a>,
    /// What kind of global this defined as.
    pub kind: GlobalKind<'a>,
}

/// Different kinds of globals that can be defined in a module.
#[derive(Debug)]
pub enum GlobalKind<'a> {
    /// A global which is actually defined as an import, such as:
    ///
    /// ```text
    /// (global i32 (import "foo" "bar"))
    /// ```
    Import(InlineImport<'a>),

    /// A global defined inline in the module itself
    Inline(Expression<'a>),
}

impl<'a> Parse<'a> for Global<'a> {
    fn parse(parser: Parser<'a>) -> Result<Self> {
        let span = parser.parse::<kw::global>()?.0;
        let id = parser.parse()?;
        let name = parser.parse()?;
        let exports = parser.parse()?;

        let (ty, kind) = if let Some(import) = parser.parse()? {
            (parser.parse()?, GlobalKind::Import(import))
        } else {
            (parser.parse()?, GlobalKind::Inline(parser.parse()?))
        };
        Ok(Global {
            span,
            id,
            name,
            exports,
            ty,
            kind,
        })
    }
}

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/wast-224.0.0/src/core/global.rs
wasmtime-28.0.0 ./ext/cargo-vendor/wast-223.0.0/src/core/global.rs
wasmtime-27.0.0 ./ext/cargo-vendor/wast-220.0.0/src/core/global.rs
wasmtime-26.0.0 ./ext/cargo-vendor/wast-219.0.1/src/core/global.rs
wasmtime-25.0.2 ./ext/cargo-vendor/wast-218.0.0/src/core/global.rs
wasmtime-25.0.1 ./ext/cargo-vendor/wast-217.0.0/src/core/global.rs
wasmtime-25.0.0 ./ext/cargo-vendor/wast-217.0.0/src/core/global.rs
wasmtime-24.0.0 ./ext/cargo-vendor/wast-216.0.0/src/core/global.rs
wasmtime-23.0.2 ./ext/cargo-vendor/wast-215.0.0/src/core/global.rs
wasmtime-22.0.0 ./ext/cargo-vendor/wast-209.0.1/src/core/global.rs
wasmtime-21.0.1 ./ext/cargo-vendor/wast-209.0.1/src/core/global.rs
wasmtime-20.0.2 ./ext/cargo-vendor/wast-209.0.1/src/core/global.rs
wasmtime-20.0.0 ./ext/cargo-vendor/wast-208.0.1/src/core/global.rs
wasmtime-18.0.3 ./ext/cargo-vendor/wast-201.0.0/src/core/global.rs
wasmtime-17.0.1 ./ext/cargo-vendor/wast-69.0.1/src/core/global.rs
wasmtime-17.0.0 ./ext/cargo-vendor/wast-69.0.1/src/core/global.rs
wasmtime-16.0.0 ./ext/cargo-vendor/wast-69.0.1/src/core/global.rs
wasmtime-15.0.1 ./ext/cargo-vendor/wast-69.0.1/src/core/global.rs
wasmtime-15.0.0 ./ext/cargo-vendor/wast-69.0.1/src/core/global.rs
wasmtime-14.0.4 ./ext/cargo-vendor/wast-67.0.1/src/core/global.rs