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 u32
	values         []Value
}

fn (ArrayValue) elem_type_name_text #

@[inline]
fn (value &ArrayValue) elem_type_name_text() string

elem_type_name_text resolves the indexed source type spelling.

struct EnumValue #

struct EnumValue {
pub:
	type_name u32
	value     i64
}

fn (EnumValue) type_name_text #

@[inline]
fn (value &EnumValue) type_name_text() string

type_name_text resolves the indexed source type spelling.

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]u32
	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            flat.TypeTextListBindings
	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 flat.TypeTextBindings
}

struct MapEntry #

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

struct MapValue #

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

fn (MapValue) key_type_name_text #

@[inline]
fn (value &MapValue) key_type_name_text() string

key_type_name_text resolves the indexed source type spelling.

fn (MapValue) value_type_name_text #

@[inline]
fn (value &MapValue) value_type_name_text() string

value_type_name_text resolves the indexed source type spelling.

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 u32
pub mut:
	fields map[string]Value
}

fn (StructValue) type_name_text #

@[inline]
fn (value &StructValue) type_name_text() string

type_name_text resolves the indexed source type spelling.

struct SumValue #

struct SumValue {
pub:
	type_name    u32
	variant_name u32
pub mut:
	payload &Value
}

fn (SumValue) type_name_text #

@[inline]
fn (value &SumValue) type_name_text() string

type_name_text resolves the indexed source type spelling.

fn (SumValue) variant_name_text #

@[inline]
fn (value &SumValue) variant_name_text() string

variant_name_text resolves the indexed source type spelling.

struct TupleValue #

struct TupleValue {
pub:
	values []Value
}

struct TypeValue #

struct TypeValue {
pub:
	name u32
}

fn (TypeValue) name_text #

fn (value &TypeValue) name_text() string

name_text resolves the stored source spelling for a text consumer.

struct VoidValue #

struct VoidValue {}