Skip to content

Commit

Permalink
std: refactor documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jan 19, 2025
1 parent 857972a commit 32d51ce
Showing 1 changed file with 45 additions and 70 deletions.
115 changes: 45 additions & 70 deletions std/builtin.jule
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,56 @@
// license that can be found in the LICENSE file.

// Signed 8-bit integer.
type i8: [compiler_implemented]
type i8: i8

// Signed 16-bit integer.
type i16: [compiler_implemented]
type i16: i16

// Signed 32-bit integer.
type i32: [compiler_implemented]
type i32: i32

// Signed 64-bit integer.
type i64: [compiler_implemented]
type i64: i64

// Unsigned 8-bit integer.
type u8: [compiler_implemented]
type u8: u8

// Unsigned 16-bit integer.
type u16: [compiler_implemented]
type u16: u16

// Unsigned 32-bit integer.
type u32: [compiler_implemented]
type u32: u32

// Unsigned 16-bit integer.
type u64: [compiler_implemented]
type u64: u64

// 32-bit floating-point.
type f32: [compiler_implemented]
type f32: f32

// 64-bit floating-point.
type f64: [compiler_implemented]
type f64: f64

// It is a platform dependent integer type.
type int: [compiler_implemented]
type int: int

// It is a platform dependent unsigned integer type.
type uint: [compiler_implemented]
type uint: uint

// It is a platform dependent unsigned integer type
// that is big enough to hold a pointer.
// Can used for casting pointers to integers.
type uintptr: [compiler_implemented]
type uintptr: uintptr

// UTF-8 byte encoded character string.
// See for more information: http://manual.jule.dev/introduction/data-types#string
type str: [compiler_implemented]
type str: str

// Boolean type for logical expressions.
type bool: [compiler_implemented]
type bool: bool

// It can be hold any data type and nil.
// Only supports equals (==) and not equals (!=) operators.
// Panics if type is uncomparable.
//
// x == nil: true if any is nil, not checks whether data is nil
// x == y: true if x and y is nil
// x == y: true if x and y has same data type and returns true of equals operator of data type for two value
//
// Supports casting to any type.
// You can get type-safe value of any with casting.
// For example:
// let myAny: any = 10
// let x = (int)(myAny)
//
// any type protects itself against mutability if necessary.
// For example, you have slice value holds by any-typed variable.
// And your variable is immutable.
// So, if you cast your value to slice for assign to mutable variable, you will get error.
// Because of slice is mutable type, so it's breaking immutability.
type any: [compiler_implemented]
// See for more information: https://manual.jule.dev/dynamic-types/any
type any: any

// Is an alias for u8.
// It is used, by convention, to distinguish byte values from 8-bit unsigned
Expand All @@ -87,9 +70,9 @@ const true = 1 == 1
const false = !true

// Nil memory.
const nil = unsafe { (*unsafe)(uintptr(0)) }
const nil = nil

// Prints value to command line.
// Prints t to stout.
//
// Before printing the value will be converted to string. For string conversion,
// Jule's runtime package will be used, always. For types that contain special string
Expand All @@ -98,11 +81,11 @@ const nil = unsafe { (*unsafe)(uintptr(0)) }
// String conversion implementation of runtime package may not be exact for some types
// compared to other conversion implementations which is provided by
// other standard library packages such as "std/conv".
fn print(v)
fn print(t: T)

// This function same with the out function.
// One difference, prints new line after print.
fn println(v)
fn println(t: T)

// Panics program with given error message.
// This panics are not recoverable.
Expand All @@ -111,36 +94,28 @@ fn panic(message: str)
// Returns new instance of data type for supported types.
//
// Slices:
// Allocates slices dynamically. In addition
// to the slice type, it can take two more arguments.
// The first argument is mandatory. The first argument
// specifies the length of the slice. The second argument
// specifies the capacity of the slice and is optional.
// The slice is returned with its length, and the field within its
// length is initialized with the default value.
// For []byte types, variadic strings are allowed,
// such as: append(bytes, "foo"...)
//
// Strings:
// Allocates buffered strings. In addition to the str type, it can two more
// argument. This first additional argument is the length of the string's buffer.
// The second argument is the capacity of the strings's buffer capacity.
// The string is returned with its length, and the fiedld within its length is
// initialized with the nil byte (aka '\0').
// Allocates slices dynamically. In addition
// to the slice type, it can take two more arguments.
// The first argument is mandatory. The first argument
// specifies the length of the slice. The second argument
// specifies the capacity of the slice and is optional.
// The slice is returned with its length, and the field within its
// length is initialized with the default value.
// For []byte types, variadic strings are allowed,
// such as: append(bytes, "foo"...)
//
// Channels:
// Channels can only take a type parameter or a buffer capacity length.
// When a channel is initialized without capacity, it creates an unbuffered channel.
// If a capacity is provided, a buffered channel is created.
// Capacities smaller than zero result in a panic.
// If capacity is equals to zero, then an unbuffered channel will be created.
// Channels can only take a type parameter or a buffer capacity length.
// When a channel is initialized without capacity, it creates an unbuffered channel.
// If a capacity is provided, a buffered channel is created.
// Capacities smaller than zero result in a panic.
// If capacity is equals to zero, then an unbuffered channel will be created.
fn make(T, ...V): T

// The copy built-in function copies elements from a source slice into a
// destination slice. (As a special case, it also will copy bytes from a
// string to a slice of bytes.) The source and destination may overlap, it is safe.
// Copy returns the number of elements copied, which will be the minimum of
// len(src) and len(dst).
// Returns the number of elements copied, which will be the minimum of len(src) and len(dst).
fn copy(mut dest: Dest, mut src: Src): int

// If there is enough capacity, it adds to the destination slice.
Expand All @@ -152,33 +127,33 @@ fn append(mut dest: []T, mut items: ...T): []T
// Returns length of T.
//
// For slices:
// Returns length of slice, aka count of slice elements.
// If slice is nil, returns zero.
// Returns length of slice, aka count of slice elements.
// If slice is nil, returns zero.
//
// For strings:
// Returns length of string, aka count of string's bytes.
// Returns length of string, aka count of string's bytes.
//
// For arrays:
// Returns length of array, also means total capacity of array.
// Returns length of array, also means total capacity of array.
//
// For maps:
// Returns count of key-value pairs of map.
// If map is nil, returns zero.
// Returns count of key-value pairs of map.
// If map is nil, returns zero.
fn len(T): int

// Returns capacity of T.
//
// For slices:
// Returns capacity of slice, aka possible maximum count of slice elements without
// expanding buffer.
// Returns capacity of slice, aka possible maximum count of slice elements without
// expanding buffer.
fn cap(T): int

// Deletes key from map.
// It takes two argument. The first one is map, second one is the key.
// If just given one argument, this one is a map, and clears all keys of map.
fn delete(mut map[K]V, ...)

// Returns new reference-type for T initialized with default for type.
// Returns new smart pointer for T initialized with default for type.
// It may take two arguments.
// The second argument used as initialization expression for memory allocation.
fn new(T, ...T): &T
Expand Down

0 comments on commit 32d51ce

Please sign in to comment.