Skip to content

v.eval

fn create #

fn create() Eval

create returns a capturing evaluator convenient for tests.

fn new #

fn new(prefs_ &pref.Preferences) Eval

new returns a new evaluator configured for direct execution.

type Value #

type Value = ArrayValue
	| EnumValue
	| FnValue
	| MapValue
	| ModuleValue
	| RangeValue
	| StructValue
	| SumValue
	| TupleValue
	| TypeValue
	| VoidValue
	| bool
	| f64
	| i64
	| string

struct ArrayValue #

struct ArrayValue {
pub mut:
	elem_type_name string
	values         []Value
}

struct EnumValue #

struct EnumValue {
pub:
	type_name string
	value     i64
}

struct Eval #

struct Eval {
pub mut:
	capture_output bool
	prefs          pref.Preferences
mut:
	a                    &flat.FlatAst = unsafe { nil }
	stdout_data          string
	stderr_data          string
	functions            map[string]map[string]FunctionDef
	consts               map[string]map[string]ConstEntry
	globals              map[string]map[string]Value
	global_types         map[string]map[string]string
	global_inits         []GlobalEntry
	enum_inits           []EnumInitEntry
	implicit_main        []TopLevelStmt
	structs              map[string]StructInfo
	enum_fields          map[string][]string
	enum_types           map[string]TypeAliasInfo
	sizeof_type_bindings map[string]TypeLayout
	sum_types            map[string][]string
	type_aliases         map[string]TypeAliasInfo
	type_names           map[string]map[string]bool
	module_imports       map[string][]string
	module_order         []string
	file_import_alias    map[string]map[string]string
	modules              map[string]bool
	scopes               []ScopeFrame
	call_stack           []CallFrame
}

Eval interprets v3 flat AST nodes directly for a practical subset of V.

fn (Eval) stdout #

fn (e &Eval) stdout() string

stdout returns the captured stdout stream.

fn (Eval) stderr #

fn (e &Eval) stderr() string

stderr returns the captured stderr stream.

fn (Eval) run_text #

fn (mut e Eval) run_text(code string) ![]Value

run_text parses and executes a single V source string.

fn (Eval) run_files #

fn (mut e Eval) run_files(a &flat.FlatAst) ![]Value

run_files executes parsed flat AST files and invokes main.main.

struct FnValue #

struct FnValue {
	node          flat.NodeId
	module_name   string
	file_name     string
	captures      map[string]Value
	capture_types map[string]string
}

struct MapEntry #

struct MapEntry {
pub:
	key Value
pub mut:
	value Value
}

struct MapValue #

struct MapValue {
pub mut:
	key_type_name   string
	value_type_name string
	default_value   Value
	entries         []MapEntry
}

struct ModuleValue #

struct ModuleValue {
pub:
	name string
}

struct RangeValue #

struct RangeValue {
pub:
	start     i64
	end       i64
	inclusive bool
}

struct StructValue #

struct StructValue {
pub:
	type_name string
pub mut:
	fields map[string]Value
}

struct SumValue #

struct SumValue {
pub:
	type_name    string
	variant_name string
pub mut:
	payload Value
}

struct TupleValue #

struct TupleValue {
pub:
	values []Value
}

struct TypeValue #

struct TypeValue {
pub:
	name string
}

struct VoidValue #

struct VoidValue {}