Struct gluon::Compiler

source ·
pub struct Compiler { /* private fields */ }
Expand description

Type which makes parsing, typechecking and compiling an AST into bytecode

Implementations

Creates a new compiler with default settings

Sets whether the implicit prelude should be include when compiling a file using this compiler (default: true)

Sets whether the compiler should emit debug information such as source maps and variable names. (default: true)

Sets whether IO expressions are evaluated. (default: false)

Sets whether full metadata is required (default: false)

Parse expr_str, returning an expression if successful

Parse input, returning an expression if successful

Parse and typecheck expr_str returning the typechecked expression and type of the expression

Compiles expr into a function which can be added and run by the vm

Compiles the source code expr_str into bytecode serialized using serializer

Loads bytecode from a Deserializer and stores it into the module name.

load_script is equivalent to compile_to_bytecode followed by load_bytecode

Parses and typechecks expr_str followed by extracting metadata from the created expression

Compiles input and if it is successful runs the resulting code and stores the resulting value in the vm.

If at any point the function fails the resulting error is returned and nothing is added to the VM.

Loads filename and compiles and runs its input by calling load_script

Compiles and runs the expression in expr_str. If successful the value from running the expression is returned

Examples

Import from gluon’s standard library and evaluate a string

let vm = new_vm();
let (result, _) = Compiler::new()
    .run_expr::<String>(
        &vm,
        "example",
        " let string  = import! \"std/string.glu\" in string.trim \"  Hello world  \t\" "
    )
    .unwrap();
assert_eq!(result, "Hello world");

Compiles and runs the expression in expr_str. If successful the value from running the expression is returned

Examples

Import from gluon’s standard library and evaluate a string

let vm = new_vm();
let result = Compiler::new()
    .run_expr::<String>(&vm, "example",
        " let string  = import! \"std/string.glu\" in string.trim \"    Hello world  \t\" ")
    .unwrap();
let expected = ("Hello world".to_string(), Type::string());

assert_eq!(result, expected);
}

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Extract a subset of the possible types in a coproduct (or get the remaining possibilities) Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Performs the indexed conversion.
Consumes the current HList and returns an HList with the requested shape. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.