From 98ed2cdbd1bce20d38fda1c830ef68807975ea93 Mon Sep 17 00:00:00 2001 From: s-ol Date: Sun, 12 Apr 2020 19:45:02 +0200 Subject: rename Action to Builtin --- core/base/action.moon | 96 -------------------------------------------------- core/base/builtin.moon | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ core/base/init.moon | 6 ++-- 3 files changed, 99 insertions(+), 99 deletions(-) delete mode 100644 core/base/action.moon create mode 100644 core/base/builtin.moon (limited to 'core/base') diff --git a/core/base/action.moon b/core/base/action.moon deleted file mode 100644 index d10712f..0000000 --- a/core/base/action.moon +++ /dev/null @@ -1,96 +0,0 @@ ----- --- Builtin / Special Form evaluation Strategy (`builtin`). --- --- Responsible for quoting/evaluating subexpressions, instantiating and setting --- up `Op`s, updating the current `Scope`, etc. --- See `builtin` and `invoke` for examples. --- --- @classmod Action - -class Action ---- Action interface. --- --- methods that have to be implemented by `Action` implementations. --- @section interface - - --- create a new instance. - -- - -- @tparam Cell cell the Cell to evaluate - -- @tparam Value head the (`AST:eval`d) `head` of the Cell to evaluate - new: (@cell, @head) => - @tag = @cell.tag - @tag\register @ - - --- perform the actual evaluation. - -- - -- Implementations should: - -- - -- - eval or quote `tail` values - -- - perform scope effects - -- - wrap all child-results - -- - -- @tparam Scope scope the active scope - -- @tparam {AST,...} tail the arguments to this expression - -- @treturn Result the result of this evaluation - eval: (scope, tail) => error "not implemented" - - --- free resources - destroy: => - - --- setup or copy state from previous instance of same type. - -- - -- `prev` is only passed if Action types of prev and current expression match. - -- Otherwise, or when no previous expression exists, `nil` is passed. - -- - -- @tparam ?Action prev the previous Action instance - setup: (prev) => - - --- the `Cell` this Action was created for. - -- @tfield Cell cell - - --- the evaluated head of `cell`. - -- @tfield AST head - - --- the identity of `cell`. - -- @tfield Tag tag - ---- static functions --- @section static - - --- create and setup an `Action` for a given tag, then evaluate it. - -- - -- Create a new instance using `tag` and `head` and call `setup` on it. - -- If a previous instance with the same `tag` exists and has the same `head`, - -- it pass it to `setup`. Register the `Action` with `tag`, evaluate it - -- and return the `Result`. - -- - -- @tparam Cell cell the `Cell` being evaluated - -- @tparam Scope scope the active scope - -- @tparam Value head the (`AST:eval`d) head of the `Cell` being evaluated - -- @treturn Result the result of evaluation - @eval_cell: (cell, scope, head) => - last = cell.tag\last! - compatible = last and (last.__class == @) and last.head == head - - L\trace if compatible - "reusing #{last} for #{cell.tag} <#{@__name} #{head}>" - else if last - "replacing #{last} with new #{cell.tag} <#{@__name} #{head}>" - else - "initializing #{cell.tag} <#{@__name} #{head}>" - - action = @ cell, head - if compatible - action\setup last - else - last\destroy! if last - action\setup nil - - action\eval scope, cell\tail! - - __tostring: => "<#{@@__name} #{@head}>" - __inherited: (cls) => cls.__base.__tostring = @__tostring - -{ - :Action -} diff --git a/core/base/builtin.moon b/core/base/builtin.moon new file mode 100644 index 0000000..fd36c69 --- /dev/null +++ b/core/base/builtin.moon @@ -0,0 +1,96 @@ +---- +-- Builtin / Special Form evaluation Strategy (`builtin`). +-- +-- Responsible for quoting/evaluating subexpressions, instantiating and setting +-- up `Op`s, updating the current `Scope`, etc. +-- See `builtin` and `invoke` for examples. +-- +-- @classmod Builtin + +class Builtin +--- Builtin interface. +-- +-- methods that have to be implemented by `Builtin` implementations. +-- @section interface + + --- create a new instance. + -- + -- @tparam Cell cell the Cell to evaluate + -- @tparam Value head the (`AST:eval`d) `head` of the Cell to evaluate + new: (@cell, @head) => + @tag = @cell.tag + @tag\register @ + + --- perform the actual evaluation. + -- + -- Implementations should: + -- + -- - eval or quote `tail` values + -- - perform scope effects + -- - wrap all child-results + -- + -- @tparam Scope scope the active scope + -- @tparam {AST,...} tail the arguments to this expression + -- @treturn Result the result of this evaluation + eval: (scope, tail) => error "not implemented" + + --- free resources + destroy: => + + --- setup or copy state from previous instance of same type. + -- + -- `prev` is only passed if Builtin types of prev and current expression match. + -- Otherwise, or when no previous expression exists, `nil` is passed. + -- + -- @tparam ?Builtin prev the previous Builtin instance + setup: (prev) => + + --- the `Cell` this Builtin was created for. + -- @tfield Cell cell + + --- the evaluated head of `cell`. + -- @tfield AST head + + --- the identity of `cell`. + -- @tfield Tag tag + +--- static functions +-- @section static + + --- create and setup a `Builtin` for a given tag, then evaluate it. + -- + -- Create a new instance using `tag` and `head` and call `setup` on it. + -- If a previous instance with the same `tag` exists and has the same `head`, + -- it pass it to `setup`. Register the `Builtin` with `tag`, evaluate it + -- and return the `Result`. + -- + -- @tparam Cell cell the `Cell` being evaluated + -- @tparam Scope scope the active scope + -- @tparam Value head the (`AST:eval`d) head of the `Cell` being evaluated + -- @treturn Result the result of evaluation + @eval_cell: (cell, scope, head) => + last = cell.tag\last! + compatible = last and (last.__class == @) and last.head == head + + L\trace if compatible + "reusing #{last} for #{cell.tag} <#{@__name} #{head}>" + else if last + "replacing #{last} with new #{cell.tag} <#{@__name} #{head}>" + else + "initializing #{cell.tag} <#{@__name} #{head}>" + + builtin = @ cell, head + if compatible + builtin\setup last + else + last\destroy! if last + builtin\setup nil + + builtin\eval scope, cell\tail! + + __tostring: => "<#{@@__name} #{@head}>" + __inherited: (cls) => cls.__base.__tostring = @__tostring + +{ + :Builtin +} diff --git a/core/base/init.moon b/core/base/init.moon index 1b71086..9153f79 100644 --- a/core/base/init.moon +++ b/core/base/init.moon @@ -6,7 +6,7 @@ -- -- @module base -- @see Op --- @see Action +-- @see Builtin -- @see FnDef -- @see Input -- @see base.match.val @@ -18,7 +18,7 @@ -- @see Error import Op from require 'core.base.op' -import Action from require 'core.base.action' +import Builtin from require 'core.base.builtin' import FnDef from require 'core.base.fndef' import Input from require 'core.base.input' import val, evt from require 'core.base.match' @@ -28,7 +28,7 @@ import Error from require 'core.error' { :Op - :Action + :Builtin :FnDef :Input :val, :evt -- cgit v1.2.3