Add IntValue type alias for backend integer values
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -56,7 +56,7 @@ impl Compile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets or inserts a static int reference.
|
/// 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)
|
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.
|
/// This distinguishes between the different types while building a const pool to avoid duplicates.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct ConstData {
|
pub struct ConstData {
|
||||||
ints: HashMap<i64, (ConstHandle, IntRef)>,
|
ints: HashMap<IntValue, (ConstHandle, IntRef)>,
|
||||||
strs: HashMap<String, (ConstHandle, StrRef)>,
|
strs: HashMap<String, (ConstHandle, StrRef)>,
|
||||||
const_pool: ConstPool,
|
const_pool: ConstPool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConstData {
|
impl ConstData {
|
||||||
/// Gets or inserts a static int reference.
|
/// 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) {
|
if let Some(pair) = self.ints.get(&int) {
|
||||||
pair.clone()
|
pair.clone()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,16 +4,17 @@ use shredder::Scan;
|
|||||||
use std::fmt::{Debug, Formatter, self};
|
use std::fmt::{Debug, Formatter, self};
|
||||||
|
|
||||||
pub type IntRef = ObjRef<Int>;
|
pub type IntRef = ObjRef<Int>;
|
||||||
|
pub type IntValue = i64;
|
||||||
|
|
||||||
#[derive(Scan)]
|
#[derive(Scan)]
|
||||||
pub struct Int {
|
pub struct Int {
|
||||||
value: i64,
|
value: IntValue,
|
||||||
vtable: Vtable,
|
vtable: Vtable,
|
||||||
attrs: Attrs,
|
attrs: Attrs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Int {
|
impl Int {
|
||||||
pub fn new_obj(value: i64) -> ObjRef<Self> {
|
pub fn new_obj(value: IntValue) -> ObjRef<Self> {
|
||||||
// TODO(cache) : cache int values
|
// TODO(cache) : cache int values
|
||||||
self_referring_obj! {
|
self_referring_obj! {
|
||||||
Self {
|
Self {
|
||||||
@@ -33,7 +34,7 @@ impl Int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value(&self) -> i64 {
|
pub fn value(&self) -> IntValue {
|
||||||
self.value
|
self.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ static STR_INT_FUN: Lazy<NativeFunRef> = Lazy::new(|| {
|
|||||||
error: "expected Str value".to_string(),
|
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(), })?;
|
.map_err(|_| Error::ValueError { error: "invalid Int value".to_string(), })?;
|
||||||
vm.push(Int::new_obj(int));
|
vm.push(Int::new_obj(int));
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::syn::visit::*;
|
use crate::{obj::int::IntValue, syn::visit::*};
|
||||||
|
|
||||||
// TODO : add locations to parsed items
|
// TODO : add locations to parsed items
|
||||||
|
|
||||||
@@ -444,7 +444,7 @@ impl<V: Visit> DefaultAccept<V> for FunExpr {
|
|||||||
pub enum Atom {
|
pub enum Atom {
|
||||||
Ident(String),
|
Ident(String),
|
||||||
Sym(String),
|
Sym(String),
|
||||||
Num(i64),
|
Num(IntValue),
|
||||||
String(String),
|
String(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user