[][src]Struct gluon::Compiler

pub struct Compiler { /* fields omitted */ }

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

Methods

impl Compiler[src]

pub fn new() -> Compiler[src]

Creates a new compiler with default settings

pub fn implicit_prelude(self, implicit_prelude: bool) -> Self[src]

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

pub fn set_implicit_prelude(&mut self, implicit_prelude: bool)[src]

pub fn emit_debug_info(self, emit_debug_info: bool) -> Self[src]

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

pub fn set_emit_debug_info(&mut self, emit_debug_info: bool)[src]

pub fn run_io(self, run_io: bool) -> Self[src]

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

pub fn set_run_io(&mut self, run_io: bool)[src]

pub fn full_metadata(self, full_metadata: bool) -> Self[src]

Sets whether full metadata is required (default: false)

pub fn set_full_metadata(&mut self, full_metadata: bool)[src]

pub fn code_map(&self) -> CodeMap[src]

pub fn update_filemap<S>(
    &mut self,
    file: &str,
    source: S
) -> Option<Arc<FileMap>> where
    S: Into<String>, 
[src]

pub fn get_filemap(&self, file: &str) -> Option<Arc<FileMap>>[src]

pub fn mut_symbols(&mut self) -> &mut Symbols[src]

pub fn split(&self) -> Self[src]

pub fn parse_expr(
    &mut self,
    type_cache: &TypeCache<Symbol, ArcType>,
    file: &str,
    expr_str: &str
) -> StdResult<SpannedExpr<Symbol>, InFile<Error>>
[src]

Parse expr_str, returning an expression if successful

pub fn parse_partial_expr(
    &mut self,
    type_cache: &TypeCache<Symbol, ArcType>,
    file: &str,
    expr_str: &str
) -> StdResult<SpannedExpr<Symbol>, (Option<SpannedExpr<Symbol>>, InFile<Error>)>
[src]

Parse input, returning an expression if successful

pub fn typecheck_expr(
    &mut self,
    vm: &Thread,
    file: &str,
    expr_str: &str,
    expr: &mut SpannedExpr<Symbol>
) -> Result<ArcType>
[src]

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

pub fn typecheck_str(
    &mut self,
    vm: &Thread,
    file: &str,
    expr_str: &str,
    expected_type: Option<&ArcType>
) -> Result<(SpannedExpr<Symbol>, ArcType)>
[src]

pub fn compile_script(
    &mut self,
    vm: &Thread,
    filename: &str,
    expr_str: &str,
    expr: &SpannedExpr<Symbol>
) -> Result<CompiledModule>
[src]

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

pub fn compile_to_bytecode<S>(
    &mut self,
    thread: &Thread,
    name: &str,
    expr_str: &str,
    serializer: S
) -> StdResult<S::Ok, Either<Error, S::Error>> where
    S: Serializer,
    S::Error: 'static, 
[src]

Compiles the source code expr_str into bytecode serialized using serializer

pub fn load_bytecode<'vm, D>(
    &mut self,
    thread: &'vm Thread,
    name: &str,
    deserializer: D
) -> impl Future<Item = (), Error = Error> + 'vm where
    D: Deserializer<'vm> + 'vm,
    D::Error: Send + Sync
[src]

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

load_script is equivalent to compile_to_bytecode followed by load_bytecode

pub fn extract_metadata(
    &mut self,
    vm: &Thread,
    file: &str,
    expr_str: &str
) -> Result<(SpannedExpr<Symbol>, ArcType, Arc<Metadata>)>
[src]

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

pub fn load_script(
    &mut self,
    vm: &Thread,
    filename: &str,
    input: &str
) -> Result<()>
[src]

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.

pub fn load_script_async<'vm>(
    &mut self,
    vm: &'vm Thread,
    filename: &str,
    input: &str
) -> impl Future<Item = (), Error = Error> + 'vm
[src]

pub fn load_file<'vm>(&mut self, vm: &'vm Thread, filename: &str) -> Result<()>[src]

Loads filename and compiles and runs its input by calling load_script

pub fn load_file_async<'vm>(
    &mut self,
    vm: &'vm Thread,
    filename: &str
) -> impl Future<Item = (), Error = Error>
[src]

pub fn run_expr<'vm, T>(
    &mut self,
    vm: &'vm Thread,
    name: &str,
    expr_str: &str
) -> Result<(T, ArcType)> where
    T: for<'value> Getable<'vm, 'value> + VmType + Send + 'vm, 
[src]

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");

pub fn run_expr_async<T>(
    &mut self,
    vm: &Thread,
    name: &str,
    expr_str: &str
) -> impl Future<Item = (T, ArcType), Error = Error> where
    T: for<'vm, 'value> Getable<'vm, 'value> + VmType + Send + 'static, 
[src]

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);
}

pub fn format_expr(
    &mut self,
    formatter: &mut Formatter,
    thread: &Thread,
    file: &str,
    input: &str
) -> Result<String>
[src]

Trait Implementations

impl Default for Compiler[src]

Auto Trait Implementations

impl Send for Compiler

impl Sync for Compiler

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: Any

impl<D, T> FromPtr for T[src]

impl<T> Any for T where
    T: Any

impl<Choices> CoproductSubsetter for Choices

type Remainder = Choices

impl<Source> Sculptor for Source

type Remainder = Source

impl<T, U, I> LiftInto for T where
    U: LiftFrom<T, I>,