wip: (broken) working on Call reference challenges
This commit is contained in:
parent
f02ab3e231
commit
13e64e5f73
|
@ -1,7 +1,7 @@
|
|||
pub use crate::CallExt;
|
||||
pub use nu_protocol::{
|
||||
ast::{Call, CellPath},
|
||||
engine::{Command, EngineState, Stack, StateWorkingSet},
|
||||
ast::CellPath,
|
||||
engine::{Call, Command, EngineState, Stack, StateWorkingSet},
|
||||
record, ByteStream, ByteStreamType, Category, ErrSpan, Example, IntoInterruptiblePipelineData,
|
||||
IntoPipelineData, IntoSpanned, PipelineData, Record, ShellError, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Value,
|
||||
|
|
|
@ -45,10 +45,12 @@ fn nu_highlight_string(code_string: &str, engine_state: &EngineState, stack: &mu
|
|||
if let Some(highlighter) = engine_state.find_decl(b"nu-highlight", &[]) {
|
||||
let decl = engine_state.get_decl(highlighter);
|
||||
|
||||
let call = Call::new(Span::unknown());
|
||||
|
||||
if let Ok(output) = decl.run(
|
||||
engine_state,
|
||||
stack,
|
||||
&Call::new(Span::unknown()),
|
||||
&(&call).into(),
|
||||
Value::string(code_string, Span::unknown()).into_pipeline_data(),
|
||||
) {
|
||||
let result = output.into_value(Span::unknown());
|
||||
|
@ -269,11 +271,12 @@ fn get_documentation(
|
|||
let _ = write!(long_desc, "\n > {}\n", example.example);
|
||||
} else if let Some(highlighter) = engine_state.find_decl(b"nu-highlight", &[]) {
|
||||
let decl = engine_state.get_decl(highlighter);
|
||||
let call = Call::new(Span::unknown());
|
||||
|
||||
match decl.run(
|
||||
engine_state,
|
||||
stack,
|
||||
&Call::new(Span::unknown()),
|
||||
&(&call).into(),
|
||||
Value::string(example.example, Span::unknown()).into_pipeline_data(),
|
||||
) {
|
||||
Ok(output) => {
|
||||
|
@ -299,12 +302,13 @@ fn get_documentation(
|
|||
let table = engine_state
|
||||
.find_decl("table".as_bytes(), &[])
|
||||
.and_then(|decl_id| {
|
||||
let call = Call::new(Span::unknown());
|
||||
engine_state
|
||||
.get_decl(decl_id)
|
||||
.run(
|
||||
engine_state,
|
||||
stack,
|
||||
&Call::new(Span::new(0, 0)),
|
||||
&(&call).into(),
|
||||
PipelineData::Value(result.clone(), None),
|
||||
)
|
||||
.ok()
|
||||
|
|
|
@ -176,7 +176,7 @@ pub fn eval_call<D: DebugContext>(
|
|||
// We pass caller_stack here with the knowledge that internal commands
|
||||
// are going to be specifically looking for global state in the stack
|
||||
// rather than any local state.
|
||||
decl.run(engine_state, caller_stack, call, input)
|
||||
decl.run(engine_state, caller_stack, &call.into(), input)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ fn eval_external(
|
|||
}
|
||||
}
|
||||
|
||||
command.run(engine_state, stack, &call, input)
|
||||
command.run(engine_state, stack, &(&call).into(), input)
|
||||
}
|
||||
|
||||
pub fn eval_expression<D: DebugContext>(
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use crate::util::MutableCow;
|
||||
use nu_engine::{get_eval_block_with_early_return, get_full_help, ClosureEvalOnce};
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Closure, EngineState, Redirection, Stack},
|
||||
engine::{Call, Closure, EngineState, Redirection, Stack},
|
||||
Config, IntoSpanned, OutDest, PipelineData, PluginIdentity, ShellError, Span, Spanned, Value,
|
||||
};
|
||||
use std::{
|
||||
|
@ -56,7 +55,7 @@ pub struct PluginExecutionCommandContext<'a> {
|
|||
identity: Arc<PluginIdentity>,
|
||||
engine_state: Cow<'a, EngineState>,
|
||||
stack: MutableCow<'a, Stack>,
|
||||
call: Cow<'a, Call>,
|
||||
call: Cow<'a, Call<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> PluginExecutionCommandContext<'a> {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
ast::{Call, Expression},
|
||||
engine::{Command, CommandType, EngineState, Stack},
|
||||
ast::Expression,
|
||||
engine::{Call, Command, CommandType, EngineState, Stack},
|
||||
PipelineData, ShellError, Signature,
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
use crate::{ast, ir, Span};
|
||||
use crate::{
|
||||
ast,
|
||||
ir::{self, Instruction},
|
||||
DeclId, Span,
|
||||
};
|
||||
|
||||
/// This is a HACK to help [`Command`](super::Command) support both the old AST evaluator and the
|
||||
/// new IR evaluator at the same time. It should be removed once we are satisfied with the new
|
||||
|
@ -6,6 +10,7 @@ use crate::{ast, ir, Span};
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct Call<'a> {
|
||||
pub head: Span,
|
||||
pub decl_id: DeclId,
|
||||
pub inner: CallImpl<'a>,
|
||||
}
|
||||
|
||||
|
@ -14,3 +19,26 @@ pub enum CallImpl<'a> {
|
|||
Ast(&'a ast::Call),
|
||||
Ir(ir::Call<'a>),
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::Call> for Call<'a> {
|
||||
fn from(call: &'a ast::Call) -> Self {
|
||||
Call {
|
||||
head: call.head,
|
||||
decl_id: call.decl_id,
|
||||
inner: CallImpl::Ast(call),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<ir::Call<'a>> for Call<'a> {
|
||||
fn from(call: ir::Call<'a>) -> Self {
|
||||
let Instruction::Call { decl_id, .. } = *call.instruction else {
|
||||
panic!("ir::Call instruction was not Call: {:?}", call.instruction);
|
||||
};
|
||||
Call {
|
||||
head: *call.head,
|
||||
decl_id,
|
||||
inner: CallImpl::Ir(call),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use super::{EngineState, Stack, StateWorkingSet};
|
||||
use crate::{ast::Call, Alias, BlockId, Example, OutDest, PipelineData, ShellError, Signature};
|
||||
use crate::{
|
||||
ast, engine::Call, Alias, BlockId, Example, OutDest, PipelineData, ShellError, Signature,
|
||||
};
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
@ -52,7 +54,7 @@ pub trait Command: Send + Sync + CommandClone {
|
|||
fn run_const(
|
||||
&self,
|
||||
working_set: &StateWorkingSet,
|
||||
call: &Call,
|
||||
call: &ast::Call,
|
||||
input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
Err(ShellError::MissingConstEvalImpl { span: call.head })
|
||||
|
|
|
@ -568,7 +568,7 @@ impl PipelineData {
|
|||
self.write_all_and_flush(engine_state, no_newline, to_stderr)
|
||||
} else {
|
||||
let call = Call::new(Span::new(0, 0));
|
||||
let table = command.run(engine_state, stack, &call, self)?;
|
||||
let table = command.run(engine_state, stack, &(&call).into(), self)?;
|
||||
table.write_all_and_flush(engine_state, no_newline, to_stderr)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::{
|
||||
ast::Call,
|
||||
engine::{Command, CommandType, EngineState, Stack},
|
||||
engine::{Call, Command, CommandType, EngineState, Stack},
|
||||
BlockId, PipelineData, ShellError, SyntaxShape, Type, Value, VarId,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
Loading…
Reference in New Issue
Block a user