init commit

This commit is contained in:
2026-03-09 23:09:46 -04:00
parent 5cbc493cc5
commit 5da77e3360
73 changed files with 9935 additions and 103 deletions
+39 -19
View File
@@ -83,26 +83,46 @@ defmodule CljElixir.Compiler do
@spec eval_string(String.t(), keyword()) :: {:ok, term(), keyword()} | {:error, list()}
def eval_string(source, opts \\ []) do
with {:ok, ast} <- compile_string(source, opts) do
try do
bindings = opts[:bindings] || []
env_opts = build_eval_opts(opts)
{result, new_bindings} = Code.eval_quoted(ast, bindings, env_opts)
{:ok, result, new_bindings}
rescue
e ->
file = opts[:file] || "nofile"
eval_ast(ast, opts)
end
end
{:error,
[
%{
severity: :error,
message: format_eval_error(e),
file: file,
line: extract_line(e),
col: 0
}
]}
end
@doc """
Evaluate pre-parsed CljElixir AST forms.
Runs analyze → transform → eval, skipping the read step.
Used by the REPL for incremental re-evaluation of accumulated definitions.
Returns `{:ok, result, bindings}` on success, or `{:error, diagnostics}` on failure.
"""
@spec eval_forms(list(), keyword()) :: {:ok, term(), keyword()} | {:error, list()}
def eval_forms(forms, opts \\ []) do
with {:ok, forms} <- analyze(forms, opts),
{:ok, ast} <- transform(forms, opts) do
eval_ast(ast, opts)
end
end
defp eval_ast(ast, opts) do
try do
bindings = opts[:bindings] || []
env_opts = build_eval_opts(opts)
{result, new_bindings} = Code.eval_quoted(ast, bindings, env_opts)
{:ok, result, new_bindings}
rescue
e ->
file = opts[:file] || "nofile"
{:error,
[
%{
severity: :error,
message: format_eval_error(e),
file: file,
line: extract_line(e),
col: 0
}
]}
end
end