From 9169f5970e089c11511b0b31e62c604880a24445 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Tue, 20 Oct 2020 13:10:53 -0700 Subject: [PATCH] Add IntValue type alias for backend integer values Signed-off-by: Alek Ratzloff --- src/compile/mod.rs | 6 +++--- src/obj/int.rs | 7 ++++--- src/obj/str.rs | 2 +- src/syn/ast.rs | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/compile/mod.rs b/src/compile/mod.rs index b189cc9..8268410 100644 --- a/src/compile/mod.rs +++ b/src/compile/mod.rs @@ -56,7 +56,7 @@ impl Compile { } /// Gets or inserts a static int reference. - pub fn const_int(&mut self, int: i64) -> (ConstHandle, IntRef) { + pub fn const_int(&mut self, int: IntValue) -> (ConstHandle, IntRef) { self.const_data_mut().const_int(int) } @@ -115,14 +115,14 @@ impl Compile { /// This distinguishes between the different types while building a const pool to avoid duplicates. #[derive(Debug, Default)] pub struct ConstData { - ints: HashMap, + ints: HashMap, strs: HashMap, const_pool: ConstPool, } impl ConstData { /// Gets or inserts a static int reference. - pub fn const_int(&mut self, int: i64) -> (ConstHandle, IntRef) { + pub fn const_int(&mut self, int: IntValue) -> (ConstHandle, IntRef) { if let Some(pair) = self.ints.get(&int) { pair.clone() } else { diff --git a/src/obj/int.rs b/src/obj/int.rs index e4a0d00..d221213 100644 --- a/src/obj/int.rs +++ b/src/obj/int.rs @@ -4,16 +4,17 @@ use shredder::Scan; use std::fmt::{Debug, Formatter, self}; pub type IntRef = ObjRef; +pub type IntValue = i64; #[derive(Scan)] pub struct Int { - value: i64, + value: IntValue, vtable: Vtable, attrs: Attrs, } impl Int { - pub fn new_obj(value: i64) -> ObjRef { + pub fn new_obj(value: IntValue) -> ObjRef { // TODO(cache) : cache int values self_referring_obj! { Self { @@ -33,7 +34,7 @@ impl Int { } } - pub fn value(&self) -> i64 { + pub fn value(&self) -> IntValue { self.value } } diff --git a/src/obj/str.rs b/src/obj/str.rs index 0f3aa81..27503be 100644 --- a/src/obj/str.rs +++ b/src/obj/str.rs @@ -86,7 +86,7 @@ static STR_INT_FUN: Lazy = Lazy::new(|| { error: "expected Str value".to_string(), })?; - let int: i64 = str_obj.value.parse() + let int: IntValue = str_obj.value.parse() .map_err(|_| Error::ValueError { error: "invalid Int value".to_string(), })?; vm.push(Int::new_obj(int)); diff --git a/src/syn/ast.rs b/src/syn/ast.rs index fc1e67f..b313614 100644 --- a/src/syn/ast.rs +++ b/src/syn/ast.rs @@ -1,4 +1,4 @@ -use crate::syn::visit::*; +use crate::{obj::int::IntValue, syn::visit::*}; // TODO : add locations to parsed items @@ -444,7 +444,7 @@ impl DefaultAccept for FunExpr { pub enum Atom { Ident(String), Sym(String), - Num(i64), + Num(IntValue), String(String), }