Merge branch 'assoc-list-dict' into pretty-expect-output

This commit is contained in:
Folkert 2022-07-14 00:39:01 +02:00
commit 06938429a1
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
49 changed files with 1139 additions and 366 deletions

View file

@ -3,9 +3,9 @@ use crate::llvm::bitcode::{
call_str_bitcode_fn, call_void_bitcode_fn,
};
use crate::llvm::build_list::{
self, allocate_list, empty_polymorphic_list, list_append_unsafe, list_concat, list_drop_at,
list_get_unsafe, list_len, list_map, list_map2, list_map3, list_map4, list_prepend,
list_replace_unsafe, list_reserve, list_sort_with, list_sublist, list_swap,
self, allocate_list, empty_polymorphic_list, list_append_unsafe, list_capacity, list_concat,
list_drop_at, list_get_unsafe, list_len, list_map, list_map2, list_map3, list_map4,
list_prepend, list_replace_unsafe, list_reserve, list_sort_with, list_sublist, list_swap,
list_symbol_to_c_abi, list_to_c_abi, list_with_capacity, pass_update_mode,
};
use crate::llvm::build_str::{str_from_float, str_from_int};
@ -5661,12 +5661,19 @@ fn run_low_level<'a, 'ctx, 'env>(
call_bitcode_fn(env, &[string, index], bitcode::STR_GET_SCALAR_UNSAFE)
}
StrCountUtf8Bytes => {
// Str.countGraphemes : Str -> Nat
// Str.countUtf8Bytes : Str -> Nat
debug_assert_eq!(args.len(), 1);
let string = load_symbol(scope, &args[0]);
call_bitcode_fn(env, &[string], bitcode::STR_COUNT_UTF8_BYTES)
}
StrGetCapacity => {
// Str.capacity : Str -> Nat
debug_assert_eq!(args.len(), 1);
let string = load_symbol(scope, &args[0]);
call_bitcode_fn(env, &[string], bitcode::STR_CAPACITY)
}
StrSubstringUnsafe => {
// Str.substringUnsafe : Str, Nat, Nat -> Str
debug_assert_eq!(args.len(), 3);
@ -5714,13 +5721,21 @@ fn run_low_level<'a, 'ctx, 'env>(
call_str_bitcode_fn(env, &[string], bitcode::STR_TRIM_RIGHT)
}
ListLen => {
// List.len : List * -> Int
// List.len : List * -> Nat
debug_assert_eq!(args.len(), 1);
let arg = load_symbol(scope, &args[0]);
list_len(env.builder, arg.into_struct_value()).into()
}
ListGetCapacity => {
// List.capacity : List * -> Nat
debug_assert_eq!(args.len(), 1);
let arg = load_symbol(scope, &args[0]);
list_capacity(env.builder, arg.into_struct_value()).into()
}
ListWithCapacity => {
// List.withCapacity : Nat -> List a
debug_assert_eq!(args.len(), 1);

View file

@ -10,6 +10,7 @@ use crate::llvm::build_list::{layout_width, pass_as_opaque};
use crate::llvm::convert::{basic_type_from_layout, zig_dict_type};
use crate::llvm::refcounting::Mode;
use inkwell::attributes::{Attribute, AttributeLoc};
use inkwell::builder::Builder;
use inkwell::context::Context;
use inkwell::types::BasicType;
use inkwell::values::{BasicValue, BasicValueEnum, FunctionValue, IntValue, StructValue};
@ -679,6 +680,28 @@ pub fn dict_values<'a, 'ctx, 'env>(
)
}
/// Dict.capacity : Dict * * -> Nat
pub fn dict_capacity<'ctx>(
builder: &Builder<'ctx>,
wrapper_struct: StructValue<'ctx>,
) -> IntValue<'ctx> {
builder
.build_extract_value(wrapper_struct, Builtin::WRAPPER_CAPACITY, "dict_capacity")
.unwrap()
.into_int_value()
}
/// Set.capacity : Set * -> Nat
pub fn set_capacity<'ctx>(
builder: &Builder<'ctx>,
wrapper_struct: StructValue<'ctx>,
) -> IntValue<'ctx> {
builder
.build_extract_value(wrapper_struct, Builtin::WRAPPER_CAPACITY, "set_capacity")
.unwrap()
.into_int_value()
}
#[allow(clippy::too_many_arguments)]
pub fn set_from_list<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,

View file

@ -351,7 +351,7 @@ fn bounds_check_comparison<'ctx>(
builder.build_int_compare(IntPredicate::ULT, elem_index, len, "bounds_check")
}
/// List.len : List elem -> Int
/// List.len : List * -> Nat
pub fn list_len<'ctx>(
builder: &Builder<'ctx>,
wrapper_struct: StructValue<'ctx>,
@ -362,6 +362,17 @@ pub fn list_len<'ctx>(
.into_int_value()
}
/// List.capacity : List * -> Nat
pub fn list_capacity<'ctx>(
builder: &Builder<'ctx>,
wrapper_struct: StructValue<'ctx>,
) -> IntValue<'ctx> {
builder
.build_extract_value(wrapper_struct, Builtin::WRAPPER_CAPACITY, "list_capacity")
.unwrap()
.into_int_value()
}
/// List.sortWith : List a, (a, a -> Ordering) -> List a
pub fn list_sort_with<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,