go_engine/
lib.rs

1// Copyright 2022 The Goscript Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//! This crate is part of the Goscript project. Please refer to <https://goscript.dev> for more information.
6//!
7//! It's a wapper of all the parts of the Goscript project. It also implements the standard library,
8//! the standard library part is still under development, only a few parts are implemented.
9//!  
10//! # Example:
11//! ```
12//! use std::path::{Path, PathBuf};
13//! use go_engine::{Config, ErrorList, SourceReader, run};
14//!
15//!fn run_file(path: &str, trace: bool) -> Result<(), ErrorList> {
16//!    let mut cfg = Config::default();
17//!    cfg.trace_parser = trace;
18//!    cfg.trace_checker = trace;
19//!    let sr = SourceReader::local_fs(PathBuf::from("../std/"), PathBuf::from("./"));
20//!    let result = run(cfg, &sr, Path::new(path), None);
21//!    if let Err(el) = &result {
22//!        el.sort();
23//!        eprint!("{}", el);
24//!    }
25//!    result
26//!}
27//! ```
28//!
29//! # Feature
30//! The project is entended to be enbedded, so it has a lot of feature flags to turn on/off different parts.
31//! - `read_fs`: Read source code from local file system
32//! - `read_zip`: Read source code from zip file
33//! - `async`: Channel and goroutine support
34//! - `go_std`: Enable the Go standard library
35//! - `btree_map`: Make it use BTreeMap instead of HashMap
36//! - `codegen`: Enable codegen
37//! - `instruction_pos`: Add instruction position to bytecode for debugging
38//! - `serde_borsh`: Serde support for bytecode using Borsh
39//! - `wasm`: Enable wasm support
40//!
41
42mod engine;
43
44#[cfg(feature = "go_std")]
45mod std;
46
47mod vfs;
48
49mod source;
50
51#[macro_use]
52pub mod ffi;
53
54#[cfg(feature = "go_std")]
55#[macro_use]
56extern crate lazy_static;
57
58pub use engine::*;
59pub use go_parser::{ErrorList, FileSet};
60pub use source::*;
61
62pub use crate::vfs::{compound::CompoundFs, vfs_map::VfsMap, VirtualFs};
63
64#[cfg(feature = "read_fs")]
65pub use crate::vfs::vfs_fs::VfsFs;
66#[cfg(feature = "read_zip")]
67pub use crate::vfs::vfs_zip::VfsZip;