From 214cc6dc251773265c98d6d38974b08201c3415c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sun, 15 Jan 2023 18:13:51 +0100 Subject: [PATCH] Classes - May now carry a reference to their superclass --- src/interpreter/classes.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/interpreter/classes.rs b/src/interpreter/classes.rs index 0f50b2e..47fa444 100644 --- a/src/interpreter/classes.rs +++ b/src/interpreter/classes.rs @@ -24,6 +24,7 @@ pub type ClassMemberKey = (ClassMemberKind, bool, String); #[derive(Debug, Clone)] pub struct Class { name: String, + superclass: Option, members: HashMap, fields: RefCell>, } @@ -34,7 +35,7 @@ pub type ClassRef = Rc>; /// An instance of a Lox class #[derive(Debug, Clone)] pub struct Instance { - class: Rc>, + class: ClassRef, fields: RefCell>, } @@ -58,9 +59,14 @@ fn bind_method(method: &Function, this_value: Value) -> Function { impl Class { /// Create a new class, specifying its name. - pub fn new(name: String, members: HashMap) -> Self { + pub fn new( + name: String, + superclass: Option, + members: HashMap, + ) -> Self { Self { name, + superclass, members, fields: RefCell::new(HashMap::default()), }