about summary refs log tree commit diff
path: root/tvix/eval/src
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src')
-rw-r--r--tvix/eval/src/compiler.rs18
-rw-r--r--tvix/eval/src/eval.rs14
-rw-r--r--tvix/eval/src/lib.rs1
-rw-r--r--tvix/eval/src/warnings.rs11
4 files changed, 39 insertions, 5 deletions
diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs
index 1a4e8df1da4d..9b0530f0fa82 100644
--- a/tvix/eval/src/compiler.rs
+++ b/tvix/eval/src/compiler.rs
@@ -17,12 +17,22 @@ use crate::chunk::Chunk;
 use crate::errors::EvalResult;
 use crate::opcode::{CodeIdx, OpCode};
 use crate::value::Value;
+use crate::warnings::EvalWarning;
 
 use rnix;
 use rnix::types::{BinOpKind, EntryHolder, TokenWrapper, TypedNode, Wrapper};
 
+/// Represents the result of compiling a piece of Nix code. If
+/// compilation was successful, the resulting bytecode can be passed
+/// to the VM.
+pub struct CompilationResult {
+    pub chunk: Chunk,
+    pub warnings: Vec<EvalWarning>,
+}
+
 struct Compiler {
     chunk: Chunk,
+    warnings: Vec<EvalWarning>,
 }
 
 impl Compiler {
@@ -573,12 +583,16 @@ impl Compiler {
     }
 }
 
-pub fn compile(ast: rnix::AST) -> EvalResult<Chunk> {
+pub fn compile(ast: rnix::AST) -> EvalResult<CompilationResult> {
     let mut c = Compiler {
         chunk: Chunk::default(),
+        warnings: vec![],
     };
 
     c.compile(ast.node())?;
 
-    Ok(c.chunk)
+    Ok(CompilationResult {
+        chunk: c.chunk,
+        warnings: c.warnings,
+    })
 }
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index a12add48b552..31280e4cd197 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -14,8 +14,16 @@ pub fn interpret(code: &str) -> EvalResult<Value> {
         println!("{}", ast.root().dump());
     }
 
-    let code = crate::compiler::compile(ast)?;
-    println!("code: {:?}", code);
+    let result = crate::compiler::compile(ast)?;
+    println!("code: {:?}", result.chunk);
 
-    crate::vm::run_chunk(code)
+    for warning in result.warnings {
+        eprintln!(
+            "warning: {:?} at {:?}",
+            warning.kind,
+            warning.node.text_range().start()
+        )
+    }
+
+    crate::vm::run_chunk(result.chunk)
 }
diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs
index 75cd246424bb..ba037d6c8a0a 100644
--- a/tvix/eval/src/lib.rs
+++ b/tvix/eval/src/lib.rs
@@ -5,6 +5,7 @@ mod eval;
 mod opcode;
 mod value;
 mod vm;
+mod warnings;
 
 #[cfg(test)]
 mod tests;
diff --git a/tvix/eval/src/warnings.rs b/tvix/eval/src/warnings.rs
new file mode 100644
index 000000000000..4406d0510651
--- /dev/null
+++ b/tvix/eval/src/warnings.rs
@@ -0,0 +1,11 @@
+/// Warnings are emitted in cases where code passed to Tvix exhibits
+/// problems that the user could address.
+
+#[derive(Debug)]
+pub enum WarningKind {}
+
+#[derive(Debug)]
+pub struct EvalWarning {
+    pub node: rnix::SyntaxNode,
+    pub kind: WarningKind,
+}