Explorer

core.eval-ast

description
Evaluates a Definy AST expression to a number (self-hosting evaluator)
type
Fn(e: @core.expression) -> Number
expression
fn(e$1) =>
  match $1 {
    #number(n$10) =>
      $10,
    #call(c$90) =>
      match $90.function {
        #builtin(name$91) =>
          let left$92 = @core.eval-ast(e: @core.call-argument(arguments: $90.arguments, name: "left"));
          let right$93 = @core.eval-ast(e: @core.call-argument(arguments: $90.arguments, name: "right"));
          match $91 {
            "plus" =>
              @core.plus(left: $92, right: $93),
            "minus" =>
              @core.minus(left: $92, right: $93),
            "multiply" =>
              @core.multiply(left: $92, right: $93),
            "divide" =>
              @core.divide(left: $92, right: $93),
            "remainder" =>
              @core.remainder(left: $92, right: $93),
            "equal" =>
              match @core.equal(left: $92, right: $93) {
                true =>
                  1,
                false =>
                  0
              },
            "less_than" =>
              match @core.less-than(left: $92, right: $93) {
                true =>
                  1,
                false =>
                  0
              },
            _ =>
              0
          },
        _ =>
          0
      },
    _ =>
      0
  }
visibility
public
core.eval-ast (project definy, branch branch-status, snapshot OcqIMzA04f2qxxDaHf48JCDbWdgRX16sW4_jDQ3YQic)
id: 0ZMDbfOofMdW7ce7qkkHnGfmUpwd5Q-jFGFrxX2jHac
content hash: 6lBFabGeBd2WLJdIgz4lVA-7pzr5hdSrH9T2OnQiF2A