removed waring (have remaind dead code for future feature)
This commit is contained in:
+16
-16
@@ -2,8 +2,9 @@ use core::fmt;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
use std::ops::{Add, Div, Mul, Not, Rem, Sub};
|
||||
use std::ptr::fn_addr_eq;
|
||||
|
||||
use crate::common::lox_result::{runtime_error, LoxResult};
|
||||
use crate::common::lox_result::{LoxResult, runtime_error};
|
||||
use crate::common::types::Type;
|
||||
use crate::{
|
||||
backend::environment::EnvironmentStack, common::ast::AstNode,
|
||||
@@ -270,9 +271,9 @@ pub enum BaseValue {
|
||||
Number(Number),
|
||||
Boolean(bool),
|
||||
Nil,
|
||||
Function(LoxFunction),
|
||||
NativeFunction(NativeFunction),
|
||||
Struct(Struct),
|
||||
Function(Box<LoxFunction>),
|
||||
NativeFunction(Box<NativeFunction>),
|
||||
Struct(Box<Struct>),
|
||||
}
|
||||
|
||||
struct Dict {
|
||||
@@ -284,18 +285,12 @@ struct ReturnValue {
|
||||
value: Type,
|
||||
}
|
||||
|
||||
impl ReturnValue {
|
||||
pub fn new(label: Vec<String>, value: Type) -> Self {
|
||||
Self { label, value }
|
||||
}
|
||||
}
|
||||
|
||||
impl BaseValue {
|
||||
pub fn is_callable(&self) -> bool {
|
||||
match self {
|
||||
BaseValue::Function(..) | BaseValue::NativeFunction(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
self,
|
||||
BaseValue::Function(..) | BaseValue::NativeFunction(..)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,11 +345,16 @@ impl LoxFunction {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct NativeFunction {
|
||||
pub parameters: Vec<(String, Type)>,
|
||||
pub function: fn(&[BaseValue]) -> BaseValue,
|
||||
}
|
||||
impl PartialEq for NativeFunction {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.parameters == other.parameters && fn_addr_eq(self.function, other.function)
|
||||
}
|
||||
}
|
||||
|
||||
impl NativeFunction {
|
||||
pub fn new(parameters: Vec<(String, Type)>, function: fn(&[BaseValue]) -> BaseValue) -> Self {
|
||||
@@ -367,7 +367,7 @@ impl NativeFunction {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Struct {
|
||||
pub fields: Vec<(String, BaseValue)>,
|
||||
pub fields: Vec<(String, Type)>,
|
||||
}
|
||||
|
||||
// Trait implementations for BaseValue
|
||||
|
||||
Reference in New Issue
Block a user