Module: reefmarker.evaluator

Source: ./reefmarker/evaluator.reef


Overview

reefmarker/evaluator — Expression → Value against a Context.

MethodCall builtins (? / .method()) dispatch to reefmarker.builtins.apply.

Usage: import reefmarker.evaluator as evaluator let r = evaluator.eval_expr(expr, ctx)


Functions

fn ok_val(v: value.Value): result.Result[value.Value, error.Error]

fn err_val(span: source.SourcePos, msg: string): result.Result[value.Value, error.Error]

fn int_as_float(n: int): float

fn is_empty_or_null(v: value.Value): bool

fn is_truthy(v: value.Value): bool

fn value_to_string(v: value.Value): string

fn is_str_val(v: value.Value): bool

fn is_int_val(v: value.Value): bool

fn is_float_val(v: value.Value): bool

fn is_number(v: value.Value): bool

fn as_float(v: value.Value): option.Option[float]

0.9.2 C16: None for a non-numeric Value.

These returned 0 / 0.0 for any Value that was not a number, which is the same answer as a Value that genuinely holds zero -- so "foo" + 1 evaluated to 1 rather than erroring, whenever a caller forgot the is_number() pre-check. The Option makes "is this a number" and "give me the number" ONE operation instead of two conventions that have to agree.

fn as_int(v: value.Value): option.Option[int]

None for anything that is not an integer -- INCLUDING a float. Callers use that to enforce the integers-only rule for %.

fn eval_default_pair(left: ast.Expression, right: ast.Expression, ctx: context.Context): result.Result[value.Value, error.Error]

fn concat_values(left: value.Value, right: value.Value): value.Value

fn eval_arith(span: source.SourcePos, op: string, left: value.Value, right: value.Value): result.Result[value.Value, error.Error]

fn cmp_numbers(left: value.Value, right: value.Value): int

Callers must have established is_number(left) and is_number(right) -- eval_compare is the only one and does exactly that -- so every unwrap here is guard-proven and a None would be a bug in the caller, not bad input.

fn values_equal(a: value.Value, b: value.Value): bool

fn eval_compare(span: source.SourcePos, op: string, left: value.Value, right: value.Value): result.Result[value.Value, error.Error]

fn eval_binary(expr: ast.Expression, ctx: context.Context): result.Result[value.Value, error.Error]

fn eval_unary(expr: ast.Expression, ctx: context.Context): result.Result[value.Value, error.Error]

fn eval_property(expr: ast.Expression, ctx: context.Context): result.Result[value.Value, error.Error]

fn eval_index(expr: ast.Expression, ctx: context.Context): result.Result[value.Value, error.Error]

fn eval_method(expr: ast.Expression, ctx: context.Context): result.Result[value.Value, error.Error]

fn eval_ternary(expr: ast.Expression, ctx: context.Context): result.Result[value.Value, error.Error]

fn eval_expr(expr: ast.Expression, ctx: context.Context): result.Result[value.Value, error.Error]


Generated by reefc doc