mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
rename str.len to str.number_of_bytes
This commit is contained in:
parent
22d798b7c7
commit
82e87d04e3
5 changed files with 15 additions and 48 deletions
|
@ -4,7 +4,7 @@ use crate::llvm::build::{
|
|||
use crate::llvm::build_list::{allocate_list, store_list};
|
||||
use crate::llvm::convert::collection;
|
||||
use inkwell::types::BasicTypeEnum;
|
||||
use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, StructValue};
|
||||
use inkwell::values::{BasicValueEnum, IntValue, StructValue};
|
||||
use inkwell::AddressSpace;
|
||||
use roc_builtins::bitcode;
|
||||
use roc_module::symbol::Symbol;
|
||||
|
@ -16,7 +16,6 @@ pub static CHAR_LAYOUT: Layout = Layout::Builtin(Builtin::Int8);
|
|||
pub fn str_split<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
_parent: FunctionValue<'ctx>,
|
||||
inplace: InPlace,
|
||||
str_symbol: Symbol,
|
||||
delimiter_symbol: Symbol,
|
||||
|
@ -60,29 +59,6 @@ pub fn str_split<'a, 'ctx, 'env>(
|
|||
store_list(env, ret_list_ptr, segment_count)
|
||||
}
|
||||
|
||||
/*
|
||||
fn cast_to_zig_str(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
str_as_struct: StructValue<'ctx>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
// get the RocStr type defined by zig
|
||||
let roc_str_type = env.module.get_struct_type("str.RocStr").unwrap();
|
||||
|
||||
// convert `{ *mut u8, i64 }` to `RocStr`
|
||||
builder.build_bitcast(str_as_struct, roc_str_type, "convert_to_zig_rocstr");
|
||||
}
|
||||
|
||||
fn cast_from_zig_str(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
str_as_struct: StructValue<'ctx>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let ret_type = BasicTypeEnum::StructType(collection(ctx, env.ptr_bytes));
|
||||
|
||||
// convert `RocStr` to `{ *mut u8, i64 }`
|
||||
builder.build_bitcast(str_as_struct, ret_type, "convert_from_zig_rocstr");
|
||||
}
|
||||
*/
|
||||
|
||||
fn str_symbol_to_i128<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
|
@ -144,7 +120,6 @@ pub fn str_concat<'a, 'ctx, 'env>(
|
|||
env: &Env<'a, 'ctx, 'env>,
|
||||
inplace: InPlace,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
_parent: FunctionValue<'ctx>,
|
||||
str1_symbol: Symbol,
|
||||
str2_symbol: Symbol,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
|
@ -173,7 +148,7 @@ pub fn str_concat<'a, 'ctx, 'env>(
|
|||
zig_str_to_struct(env, zig_result).into()
|
||||
}
|
||||
|
||||
pub fn str_len<'a, 'ctx, 'env>(
|
||||
pub fn str_number_of_bytes<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
str_symbol: Symbol,
|
||||
|
@ -181,7 +156,8 @@ pub fn str_len<'a, 'ctx, 'env>(
|
|||
let str_i128 = str_symbol_to_i128(env, scope, str_symbol);
|
||||
|
||||
// the builtin will always return an u64
|
||||
let length = call_bitcode_fn(env, &[str_i128.into()], &bitcode::STR_LEN).into_int_value();
|
||||
let length =
|
||||
call_bitcode_fn(env, &[str_i128.into()], &bitcode::STR_NUMBER_OF_BYTES).into_int_value();
|
||||
|
||||
// cast to the appropriate usize of the current build
|
||||
env.builder
|
||||
|
@ -191,9 +167,7 @@ pub fn str_len<'a, 'ctx, 'env>(
|
|||
/// Str.startsWith : Str, Str -> Bool
|
||||
pub fn str_starts_with<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
_inplace: InPlace,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
_parent: FunctionValue<'ctx>,
|
||||
str_symbol: Symbol,
|
||||
prefix_symbol: Symbol,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
|
@ -210,9 +184,7 @@ pub fn str_starts_with<'a, 'ctx, 'env>(
|
|||
/// Str.endsWith : Str, Str -> Bool
|
||||
pub fn str_ends_with<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
_inplace: InPlace,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
_parent: FunctionValue<'ctx>,
|
||||
str_symbol: Symbol,
|
||||
prefix_symbol: Symbol,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
|
@ -230,7 +202,6 @@ pub fn str_ends_with<'a, 'ctx, 'env>(
|
|||
pub fn str_count_graphemes<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
scope: &Scope<'a, 'ctx>,
|
||||
_parent: FunctionValue<'ctx>,
|
||||
str_symbol: Symbol,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let str_i128 = str_symbol_to_i128(env, scope, str_symbol);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue