From fa2fe8ed5d98f7ac3bd6794030a3af6b5da4e7fa Mon Sep 17 00:00:00 2001 From: ychenfo Date: Wed, 1 Dec 2021 03:23:58 +0800 Subject: [PATCH] nac3core: add ceil and floor --- nac3core/src/toplevel/builtins.rs | 176 +++++++++++++++++++++++++++++- nac3core/src/toplevel/composer.rs | 6 +- 2 files changed, 173 insertions(+), 9 deletions(-) diff --git a/nac3core/src/toplevel/builtins.rs b/nac3core/src/toplevel/builtins.rs index 97d9f8ff4..3d2f4b717 100644 --- a/nac3core/src/toplevel/builtins.rs +++ b/nac3core/src/toplevel/builtins.rs @@ -1,12 +1,14 @@ use std::cell::RefCell; - use inkwell::{IntPredicate, FloatPredicate}; - use crate::symbol_resolver::SymbolValue; - use super::*; -pub fn get_built_ins(primitives: &mut (PrimitiveStore, Unifier)) -> Vec<(Arc>, Option)> { +type BuiltinInfo = ( + Vec<(Arc>, Option)>, + &'static [&'static str] +); + +pub fn get_built_ins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo { let int32 = primitives.0.int32; let int64 = primitives.0.int64; let float = primitives.0.float; @@ -400,8 +402,172 @@ pub fn get_built_ins(primitives: &mut (PrimitiveStore, Unifier)) -> Vec<(Arc>> = (0..top_level_def_list.len()).map(|_| None).collect(); - izip!(top_level_def_list, ast_list).collect_vec() + ( + izip!(top_level_def_list, ast_list).collect_vec(), + &[ + "int32", + "int64", + "float", + "round", + "round64", + "range", + "str", + "bool", + "floor", + "floor64", + "ceil", + "ceil64" + ] + ) } \ No newline at end of file diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 4eabb983e..051af13f8 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -42,7 +42,7 @@ impl TopLevelComposer { builtins: Vec<(StrRef, FunSignature, Arc)>, ) -> (Self, HashMap, HashMap) { let mut primitives = Self::make_primitives(); - let mut definition_ast_list = builtins::get_built_ins(&mut primitives); + let (mut definition_ast_list, builtin_name_list) = builtins::get_built_ins(&mut primitives); let primitives_ty = primitives.0; let mut unifier = primitives.1; let mut keyword_list: HashSet = HashSet::from_iter(vec![ @@ -68,9 +68,7 @@ impl TopLevelComposer { let mut built_in_id: HashMap = Default::default(); let mut built_in_ty: HashMap = Default::default(); - for (id, name) in - ["int32", "int64", "float", "round", "round64", "range", "str", "bool"].iter().rev().enumerate() - { + for (id, name) in builtin_name_list.iter().rev().enumerate() { let name = (**name).into(); let id = definition_ast_list.len() - id - 1; let def = definition_ast_list[id].0.read();