mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-25 18:49:50 -04:00
DEV: Cleanup unused functions.
This commit is contained in:
parent
33a5694aad
commit
8c58dd5c7e
@ -12,7 +12,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::ast::Position;
|
use crate::ast::Position;
|
||||||
@ -438,10 +437,13 @@ where
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(dbg!(Error::new(
|
return Err(dbg!(Error::new(
|
||||||
format!("Expected Numeric values of the same type but got {:?} and {:?}", left, right),
|
format!(
|
||||||
|
"Expected Numeric values of the same type but got {:?} and {:?}",
|
||||||
|
left, right
|
||||||
|
),
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
)));
|
)));
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -458,10 +460,13 @@ where
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(dbg!(Error::new(
|
return Err(dbg!(Error::new(
|
||||||
format!("Expected Numeric values of the same type but got {:?} and {:?}", left, right),
|
format!(
|
||||||
|
"Expected Numeric values of the same type but got {:?} and {:?}",
|
||||||
|
left, right
|
||||||
|
),
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
)));
|
)));
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -478,10 +483,13 @@ where
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(dbg!(Error::new(
|
return Err(dbg!(Error::new(
|
||||||
format!("Expected Numeric values of the same type but got {:?} and {:?}", left, right),
|
format!(
|
||||||
|
"Expected Numeric values of the same type but got {:?} and {:?}",
|
||||||
|
left, right
|
||||||
|
),
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
)));
|
)));
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -498,10 +506,13 @@ where
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(dbg!(Error::new(
|
return Err(dbg!(Error::new(
|
||||||
format!("Expected Numeric values of the same type but got {:?} and {:?}", left, right),
|
format!(
|
||||||
|
"Expected Numeric values of the same type but got {:?} and {:?}",
|
||||||
|
left, right
|
||||||
|
),
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
)));
|
)));
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -606,59 +617,6 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_in_list(&self, index: &Value, elems: &Vec<Rc<Value>>, pos: &Position) -> Result<Rc<Value>, Error> {
|
|
||||||
let idx = match index {
|
|
||||||
P(Int(i)) => i.clone(),
|
|
||||||
_ => return Err(dbg!(Error::new(
|
|
||||||
format!("Expected int for index but got {:?}", index),
|
|
||||||
pos.clone(),
|
|
||||||
))),
|
|
||||||
};
|
|
||||||
match elems.get(idx as usize) {
|
|
||||||
Some(v) => Ok(v.clone()),
|
|
||||||
None => return Err(dbg!(Error::new(
|
|
||||||
format!("No such index {}", idx),
|
|
||||||
pos.clone(),
|
|
||||||
))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_in_flds(
|
|
||||||
&self,
|
|
||||||
index: &Value,
|
|
||||||
flds: &Vec<(String, Rc<Value>)>,
|
|
||||||
pos: &Position,
|
|
||||||
) -> Result<Rc<Value>, Error> {
|
|
||||||
let idx = match index {
|
|
||||||
S(p) => p,
|
|
||||||
P(Str(p)) => p,
|
|
||||||
_ => return Err(dbg!(Error::new(
|
|
||||||
format!("Expected String or Symbol for index but got {:?}", index),
|
|
||||||
pos.clone(),
|
|
||||||
))),
|
|
||||||
};
|
|
||||||
for f in flds.iter() {
|
|
||||||
if idx == &f.0 {
|
|
||||||
return Ok(f.1.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(dbg!(Error::new(
|
|
||||||
format!("No such field {}", idx),
|
|
||||||
pos.clone()
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_in_value(&self, index: &Value, target: &Value, pos: &Position) -> Result<Rc<Value>, Error> {
|
|
||||||
match target {
|
|
||||||
C(Tuple(flds)) => self.find_in_flds(index, flds, pos),
|
|
||||||
C(List(elements)) => self.find_in_list(index, elements, pos),
|
|
||||||
_ => return Err(dbg!(Error::new(
|
|
||||||
format!("Expected tuple for list but got {:?}", target),
|
|
||||||
pos.clone(),
|
|
||||||
))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn op_bang(&mut self) -> Result<(), Error> {
|
fn op_bang(&mut self) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -826,10 +784,15 @@ where
|
|||||||
Ok(match (left, right) {
|
Ok(match (left, right) {
|
||||||
(P(Int(i)), P(Int(ii))) => Int(i * ii),
|
(P(Int(i)), P(Int(ii))) => Int(i * ii),
|
||||||
(P(Float(f)), P(Float(ff))) => Float(f * ff),
|
(P(Float(f)), P(Float(ff))) => Float(f * ff),
|
||||||
_ => return Err(dbg!(Error::new(
|
_ => {
|
||||||
format!("Expected numeric values of the same type but got {:?} and {:?}", left, right),
|
return Err(dbg!(Error::new(
|
||||||
|
format!(
|
||||||
|
"Expected numeric values of the same type but got {:?} and {:?}",
|
||||||
|
left, right
|
||||||
|
),
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
))),
|
)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -837,10 +800,15 @@ where
|
|||||||
Ok(match (left, right) {
|
Ok(match (left, right) {
|
||||||
(P(Int(i)), P(Int(ii))) => Int(i / ii),
|
(P(Int(i)), P(Int(ii))) => Int(i / ii),
|
||||||
(P(Float(f)), P(Float(ff))) => Float(f / ff),
|
(P(Float(f)), P(Float(ff))) => Float(f / ff),
|
||||||
_ => return Err(dbg!(Error::new(
|
_ => {
|
||||||
format!("Expected numeric values of the same type but got {:?} and {:?}", left, right),
|
return Err(dbg!(Error::new(
|
||||||
|
format!(
|
||||||
|
"Expected numeric values of the same type but got {:?} and {:?}",
|
||||||
|
left, right
|
||||||
|
),
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
))),
|
)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -848,10 +816,15 @@ where
|
|||||||
Ok(match (left, right) {
|
Ok(match (left, right) {
|
||||||
(P(Int(i)), Value::P(Int(ii))) => Int(i - ii),
|
(P(Int(i)), Value::P(Int(ii))) => Int(i - ii),
|
||||||
(P(Float(f)), Value::P(Float(ff))) => Float(f - ff),
|
(P(Float(f)), Value::P(Float(ff))) => Float(f - ff),
|
||||||
_ => return Err(dbg!(Error::new(
|
_ => {
|
||||||
format!("Expected numeric values of the same type but got {:?} and {:?}", left, right),
|
return Err(dbg!(Error::new(
|
||||||
|
format!(
|
||||||
|
"Expected numeric values of the same type but got {:?} and {:?}",
|
||||||
|
left, right
|
||||||
|
),
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
))),
|
)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -859,10 +832,15 @@ where
|
|||||||
Ok(match (left, right) {
|
Ok(match (left, right) {
|
||||||
(P(Int(i)), Value::P(Int(ii))) => Int(i % ii),
|
(P(Int(i)), Value::P(Int(ii))) => Int(i % ii),
|
||||||
(P(Float(f)), Value::P(Float(ff))) => Float(f % ff),
|
(P(Float(f)), Value::P(Float(ff))) => Float(f % ff),
|
||||||
_ => return Err(dbg!(Error::new(
|
_ => {
|
||||||
format!("Expected numeric values of the same type but got {:?} and {:?}", left, right),
|
return Err(dbg!(Error::new(
|
||||||
|
format!(
|
||||||
|
"Expected numeric values of the same type but got {:?} and {:?}",
|
||||||
|
left, right
|
||||||
|
),
|
||||||
pos.clone(),
|
pos.clone(),
|
||||||
))),
|
)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,16 +864,23 @@ where
|
|||||||
}
|
}
|
||||||
C(List(new_list))
|
C(List(new_list))
|
||||||
}
|
}
|
||||||
_ => return Err(dbg!(Error::new(
|
_ => {
|
||||||
|
return Err(dbg!(Error::new(
|
||||||
format!("You can not add {:?} and {:?}", left, right),
|
format!("You can not add {:?} and {:?}", left, right),
|
||||||
pos.clone()
|
pos.clone()
|
||||||
))),
|
)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_runtime(&mut self, h: Hook, pos: &Position) -> Result<(), Error> {
|
fn op_runtime(&mut self, h: Hook, pos: &Position) -> Result<(), Error> {
|
||||||
self.runtime
|
self.runtime.handle(
|
||||||
.handle(self.ops.path.as_ref(), h, &mut self.stack, self.env.clone(), pos)
|
self.ops.path.as_ref(),
|
||||||
|
h,
|
||||||
|
&mut self.stack,
|
||||||
|
self.env.clone(),
|
||||||
|
pos,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_render(&mut self) -> Result<(), Error> {
|
fn op_render(&mut self) -> Result<(), Error> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user