mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-21 18:10:42 -04:00
FIX: v0.7.0 completely broke stdlib loading.
This commit is contained in:
parent
9a3bfbad02
commit
13f0749ac8
@ -639,6 +639,7 @@ impl ModuleDef {
|
||||
);
|
||||
// std/ paths are special and do not get made into absolute paths.
|
||||
if path.starts_with(format!("std{}", main_separator)) {
|
||||
dbg!(&path);
|
||||
return;
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
|
@ -45,7 +45,7 @@ pub mod ir;
|
||||
pub mod opcode;
|
||||
pub mod scope;
|
||||
|
||||
mod stdlib;
|
||||
pub mod stdlib;
|
||||
|
||||
pub use self::ir::Val;
|
||||
|
||||
@ -115,7 +115,8 @@ where
|
||||
stdout: Stdout,
|
||||
stderr: Stderr,
|
||||
) -> Self {
|
||||
let environment = Environment::new_with_vars(stdout, stderr, env::vars().collect());
|
||||
let mut environment = Environment::new_with_vars(stdout, stderr, env::vars().collect());
|
||||
environment.populate_stdlib();
|
||||
FileBuilder {
|
||||
environment: Rc::new(RefCell::new(environment)),
|
||||
strict: false,
|
||||
|
@ -21,6 +21,7 @@ use super::cache;
|
||||
use super::pointer::OpPointer;
|
||||
use super::Error;
|
||||
use super::Value;
|
||||
use crate::build::stdlib;
|
||||
use crate::build::AssertCollector;
|
||||
use crate::build::Val;
|
||||
use crate::convert::{ConverterRegistry, ImporterRegistry};
|
||||
@ -97,6 +98,35 @@ impl<Stdout: Write + Clone, Stderr: Write + Clone> Environment<Stdout, Stderr> {
|
||||
)
|
||||
}
|
||||
|
||||
fn add_ops_for_path_and_content<P>(&mut self, path: P, contents: &str) -> Result<(), Error>
|
||||
where
|
||||
P: Into<PathBuf> + Clone,
|
||||
{
|
||||
let path_copy = path.clone();
|
||||
self.op_cache.entry(path.clone()).get_pointer_or_else(
|
||||
|| {
|
||||
let p = path.into();
|
||||
let root = p.parent().unwrap();
|
||||
let iter = OffsetStrIter::new(contents).with_src_file(&p);
|
||||
// FIXME(jwall): Unify BuildError and our other Error
|
||||
let stmts = parse(iter, None).unwrap();
|
||||
// then we create an ops from it
|
||||
let ops = super::translate::AST::translate(stmts, &root);
|
||||
Ok(ops)
|
||||
},
|
||||
path_copy,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn populate_stdlib(&mut self) {
|
||||
for (p, s) in stdlib::get_libs().drain() {
|
||||
// We unwrap the error here since we expect stdlibs to
|
||||
// always compile.
|
||||
self.add_ops_for_path_and_content(p, s).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn record_assert_result(&mut self, desc: &str, ok: bool) {
|
||||
self.assert_results.record_assert_result(desc, ok);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
use std::cell::RefCell;
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
@ -101,7 +101,7 @@ impl Builtins {
|
||||
// Try a relative path first.
|
||||
let path = path.into();
|
||||
// stdlib paths are special
|
||||
if path.starts_with("std/") {
|
||||
if path.starts_with(format!("std{}", std::path::MAIN_SEPARATOR)) {
|
||||
return Ok(path);
|
||||
}
|
||||
let mut normalized = base_path.into();
|
||||
@ -144,18 +144,19 @@ impl Builtins {
|
||||
pos: Position,
|
||||
) -> Result<PathBuf, Error>
|
||||
where
|
||||
P: Into<PathBuf>,
|
||||
P: Into<PathBuf> + Display + Clone,
|
||||
BP: Into<PathBuf>,
|
||||
{
|
||||
// Try a relative path first.
|
||||
// FIXME(jwall): Use import paths if desired.
|
||||
let normalized = self.normalize_path(base_path, use_import_path, path)?;
|
||||
match normalized.canonicalize() {
|
||||
match self.normalize_path(base_path, use_import_path, path.clone()) {
|
||||
Ok(p) => Ok(p),
|
||||
Err(_e) => Err(Error::new(
|
||||
format!("Invalid path: {}", normalized.to_string_lossy()),
|
||||
pos.clone(),
|
||||
)),
|
||||
Err(e) => {
|
||||
//panic!(format!("Error finding path {}: {}", path, e));
|
||||
Err(Error::new(
|
||||
format!("Error finding path {}: {}", path, e),
|
||||
pos,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,7 +510,7 @@ where
|
||||
}
|
||||
|
||||
fn op_fcall(&mut self, pos: Position) -> Result<(), Error> {
|
||||
let (f, f_pos) = dbg!(self.pop())?;
|
||||
let (f, f_pos) = self.pop()?;
|
||||
let (arg_length, _) = self.pop()?;
|
||||
if let &F(ref f) = f.as_ref() {
|
||||
if let &P(Int(arg_length)) = arg_length.as_ref() {
|
||||
@ -809,7 +809,7 @@ where
|
||||
|
||||
fn op_index(&mut self, safe: bool, pos: Position) -> Result<(), Error> {
|
||||
// left and then right
|
||||
let (right, right_pos) = dbg!(self.pop())?;
|
||||
let (right, right_pos) = self.pop()?;
|
||||
let (left, _) = self.pop()?;
|
||||
match right.as_ref() {
|
||||
&P(Int(i)) => {
|
||||
@ -824,7 +824,7 @@ where
|
||||
if let &C(Tuple(ref flds, _)) = left.as_ref() {
|
||||
for &(ref key, ref val) in flds.iter() {
|
||||
if key == s {
|
||||
self.push(dbg!(val).clone(), right_pos)?;
|
||||
self.push(val.clone(), right_pos)?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user