Skip to content

v2.types #

Constants #

const bool_ = Primitive{
	props: .boolean
}

primitives

const int_ = Primitive{
	props: .integer
	// size: 32
}

Todo: represent platform specific sizewill this be calculated at compile time?

const string_ = String(0)

complex / non primitives String struct is defined in cmd/v2/builtin/string.v: pub struct string { str &u8, len int, is_lit int }

const void_ = Void(0)
const voidptr_ = Alias{
	name:      'voidptr'
	base_type: Pointer{
		base_type: Type(void_)
	}
}

fn init_universe #

fn init_universe() &Scope

fn new_module #

fn new_module(name string, path string) &Module

fn new_scope #

fn new_scope(parent &Scope) &Scope

fn sum_type_name #

fn sum_type_name(t SumType) string

fn Checker.new #

fn Checker.new(prefs &pref.Preferences, file_set &token.FileSet, env &Environment) &Checker

fn Environment.new #

fn Environment.new() &Environment

fn (Checker) get_module_scope #

fn (mut c Checker) get_module_scope(module_name string, parent &Scope) &Scope

fn (Checker) check_files #

fn (mut c Checker) check_files(files []ast.File)

fn (Checker) check_file #

fn (mut c Checker) check_file(file ast.File)

fn (Checker) preregister_scopes #

fn (mut c Checker) preregister_scopes(file ast.File)

fn (Checker) preregister_types #

fn (mut c Checker) preregister_types(file ast.File)

fn (Checker) preregister_fn_signatures #

fn (mut c Checker) preregister_fn_signatures(file ast.File)

fn (Checker) take_deferred #

fn (mut c Checker) take_deferred() []Deferred

take_deferred is kept for compatibility with parallel type-checking plumbing.

fn (Checker) add_deferred #

fn (mut c Checker) add_deferred(items []Deferred)

add_deferred is kept for compatibility with parallel type-checking plumbing.

fn (Checker) process_struct_deferred #

fn (mut c Checker) process_struct_deferred()

process_struct_deferred is kept for compatibility with parallel type-checking plumbing.

fn (Checker) process_all_deferred #

fn (mut c Checker) process_all_deferred()

process_all_deferred is kept for compatibility with parallel type-checking plumbing.

fn (Fn) get_name #

fn (f &Fn) get_name() string

get_name returns the function's name

fn (Fn) get_typ #

fn (f &Fn) get_typ() Type

get_typ returns the function's type (FnType)

type Object #

type Object = Const | Fn | Global | Module | SmartCastSelector | Type

fn (Object) typ #

fn (obj &Object) typ() Type

fn (SumType) get_name #

fn (t SumType) get_name() string

get_sum_type_name returns the name of a SumType (public accessor)

fn (SumType) get_variants #

fn (t SumType) get_variants() []Type

get_variants returns the variant types of a SumType

fn (Tuple) get_types #

fn (t &Tuple) get_types() []Type

type Type #

type Type = Alias
	| Array
	| ArrayFixed
	| Channel
	| Char
	| Enum
	| FnType
	| ISize
	| Interface
	| Map
	| NamedType
	| Nil
	| None
	| OptionType
	| Pointer
	| Primitive
	| ResultType
	| Rune
	| String
	| Struct
	| SumType
	| Thread
	| Tuple
	| USize
	| Void

Todo: fix nested sum type in tinyv (like TS)

fn (Type) base_type #

fn (t Type) base_type() Type

fn (Type) key_type #

fn (t Type) key_type() Type

return the key type used with for in loops

fn (Type) value_type #

fn (t Type) value_type() Type

return the value type used with for in loops

fn (Type) name #

fn (t Type) name() string

enum DeferredKind #

enum DeferredKind {
	fn_decl
	fn_decl_generic
	struct_decl
	const_decl
}

enum Properties #

@[flag]
enum Properties {
	boolean
	float
	integer
	unsigned
	untyped
}

struct Alias #

struct Alias {
pub:
	name string
pub mut:
	base_type Type
}

struct Array #

struct Array {
pub:
	elem_type Type
}

struct ArrayFixed #

struct ArrayFixed {
pub:
	len       int
	elem_type Type
}

struct Deferred #

struct Deferred {
pub:
	kind  DeferredKind
	func  fn () = unsafe { nil }
	scope &Scope
}

struct Enum #

struct Enum {
pub:
	// TODO: store attributes enum or bool?
	is_flag bool
	name    string
	fields  []Field
	// fields	map[string]Type
}

struct Environment #

struct Environment {
pub mut:
	// errors with no default value
	scopes shared map[string]&Scope = map[string]&Scope{}
	// Function scopes - stores the scope for each function by qualified name (module__fn_name)
	// This allows later passes (transformer, codegen) to look up local variable types
	fn_scopes shared map[string]&Scope = map[string]&Scope{}
	// types map[int]Type
	// methods - shared for parallel type checking
	methods           shared map[string][]&Fn = map[string][]&Fn{}
	generic_types     map[string][]map[string]Type
	cur_generic_types []map[string]Type
	// Expression types - indexed directly by pos.id.
	// Positive IDs (1-based) come from the parser via token.Pos.id.
	// Negative IDs come from transformer's synthesized nodes.
	expr_type_values     []Type // indexed by pos.id for positive IDs
	expr_type_neg_values []Type // indexed by -pos.id for negative IDs (synth nodes)
}

fn (Environment) set_expr_type #

fn (mut e Environment) set_expr_type(id int, typ Type)

set_expr_type stores the computed type for an expression by its unique ID.

fn (Environment) get_expr_type #

fn (e &Environment) get_expr_type(id int) ?Type

get_expr_type retrieves the computed type for an expression by its unique ID.

fn (Environment) lookup_method #

fn (e &Environment) lookup_method(type_name string, method_name string) ?FnType

lookup_method looks up a method by receiver type name and method name Returns the method's FnType if found

fn (Environment) lookup_fn #

fn (e &Environment) lookup_fn(module_name string, fn_name string) ?FnType

lookup_fn looks up a function by module and name in the environment's scopes Returns the function's FnType if found

fn (Environment) lookup_local_var #

fn (e &Environment) lookup_local_var(scope &Scope, name string) ?Type

lookup_local_var looks up a local variable by name in the given scope. Walks up the scope chain to find the variable and returns its type.

fn (Environment) set_fn_scope #

fn (mut e Environment) set_fn_scope(module_name string, fn_name string, scope &Scope)

set_fn_scope stores the scope for a function by its qualified name

fn (Environment) get_fn_scope #

fn (e &Environment) get_fn_scope(module_name string, fn_name string) ?&Scope

get_fn_scope retrieves the scope for a function by its qualified name

fn (Environment) get_scope #

fn (e &Environment) get_scope(module_name string) ?&Scope

get_scope retrieves a module scope by exact module name.

fn (Environment) get_fn_scope_by_key #

fn (e &Environment) get_fn_scope_by_key(key string) ?&Scope

get_fn_scope_by_key retrieves a function scope by its fully-qualified key.

struct Field #

struct Field {
pub:
	name         string
	typ          Type
	default_expr ast.Expr = ast.empty_expr
}

struct NamedType { name string }

struct FnType #

struct FnType {
	// generic_params []NamedType // T  ,Y
	generic_params []string // T  ,Y
	// TODO: save in checker.env? or gere?
	// I think I prefer checker env
	// generic_types  []Types  // int,int
	params      []Parameter
	return_type ?Type
	is_variadic bool
	attributes  FnTypeAttribute
mut:
	generic_types []map[string]Type
	// scope was originally used for deferred type checking
	// but its better if we dont need it here, although it may
	// be meeded for soething later im not thinking of??
	// 	scope          &Scope
}

fn (FnType) get_return_type #

fn (f &FnType) get_return_type() ?Type

get_return_type returns the function's return type, or none if void

fn (FnType) get_param_types #

fn (f &FnType) get_param_types() []Type

get_param_types returns function parameter types in declaration order.

fn (FnType) get_param_names #

fn (f &FnType) get_param_names() []string

get_param_names returns function parameter names in declaration order.

fn (FnType) is_variadic_fn #

fn (f &FnType) is_variadic_fn() bool

is_variadic_fn reports whether this function type was declared variadic.

struct Interface #

struct Interface {
pub:
	name string
pub mut:
	fields []Field
	// fields map[string]Type
	// TODO:
}

struct Map #

struct Map {
pub:
	key_type   Type
	value_type Type
}

struct Module #

struct Module {
pub:
	name    string
	path    string
	imports []Module
	scope   &Scope = new_scope(unsafe { nil })
}

fn (Module) lookup #

fn (m &Module) lookup(name string) ?Object

lookup resolves a symbol from this module scope.

struct OptionType #

struct OptionType {
pub:
	base_type Type
}

struct Pointer #

struct Pointer {
pub:
	base_type Type
}

struct Primitive #

struct Primitive {
pub:
	// kind  PrimitiveKind
	props Properties
	size  u8
}

Todo: decide if kind will be used or just propertiesenum PrimitiveKind { bool_ i8_ i16_ // i32_ int_ i64_ // u8_ byte_ u16_ u32_ u64_ untyped_int untyped_float }

struct ResultType #

struct ResultType {
pub:
	base_type Type
}

struct Scope #

@[heap]
struct Scope {
pub:
	parent &Scope = unsafe { nil }
pub mut:
	objects map[string]Object
	// TODO: try implement using original concept
	field_smartcasts map[string]Type
	// smartcasts map[string]Type
	// TODO: it may be more efficient looking up local vars using an ID
	// even if we had to store them in two different places. investigate.
	// variables []Object
	start int
	end   int
}

fn (Scope) lookup_field_smartcast #

fn (s &Scope) lookup_field_smartcast(name string) ?Type

Todo: try implement the alternate method I was experimenting with (SmartCastSelector)i'm not sure if it is actually possible though. need to explore it.

fn (Scope) lookup #

fn (s &Scope) lookup(name string) ?Object

fn (Scope) lookup_parent #

fn (s &Scope) lookup_parent(name string, pos int) ?Object

fn (Scope) lookup_var_type #

fn (s &Scope) lookup_var_type(name string) ?Type

lookup_var_type looks up a variable by name and returns its type. Walks up the scope chain to find the variable.

fn (Scope) lookup_parent_with_scope #

fn (s &Scope) lookup_parent_with_scope(name string, pos int) ?(&Scope, Object)

fn (Scope) insert #

fn (mut s Scope) insert(name string, obj Object)

fn (Scope) print #

fn (s &Scope) print(recurse_parents bool)

struct Struct #

struct Struct {
pub:
	name           string
	generic_params []string
pub mut:
	embedded []Struct
	// embedded       []Type
	fields []Field
	// fields	 map[string]Type
	// methods 	   []Method
}

struct Method { name string typ FnType }