Skip to content

v2.types #

Constants #

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

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

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 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 returns and clears the deferred items

fn (Checker) add_deferred #

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

add_deferred adds deferred items from another checker (used in parallel checking)

fn (Checker) process_struct_deferred #

fn (mut c Checker) process_struct_deferred()

process_struct_deferred processes only struct_decl deferred items Used after Phase 1 to resolve struct fields before full checking

fn (Checker) process_all_deferred #

fn (mut c Checker) process_all_deferred()

process_all_deferred processes all deferred items in proper order

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)

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

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

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 - maps position to computed type for direct access
	// This simplifies the type system by storing types directly rather than through scopes
	expr_types map[int]Type
}

fn (Environment) set_expr_type #

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

set_expr_type stores the computed type for an expression at a given position

fn (Environment) get_expr_type #

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

get_expr_type retrieves the computed type for an expression at a given position

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

struct Field #

struct Field {
pub:
	name string
	typ  Type
}

struct NamedType { name string }

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 {
	name    string
	path    string
	imports []Module
	scope   &Scope = new_scope(unsafe { nil })
}

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 (mut 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 (mut s Scope) lookup(name string) ?Object

fn (Scope) lookup_parent #

fn (mut s Scope) lookup_parent(name string, pos token.Pos) ?Object

fn (Scope) lookup_var_type #

fn (mut 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 (mut s Scope) lookup_parent_with_scope(name string, pos token.Pos) ?(&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 }