Skip to content

Commit

Permalink
Update preview image
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Aug 25, 2024
1 parent d1cfd07 commit bc7c591
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
Binary file modified docs/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion editors/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let client: LanguageClient;
export async function activate(context: ExtensionContext) {
const serverOptions: ServerOptions = {
run: {
command: "elk --lsp",
command: "elk-lsp",
transport: TransportKind.stdio,
},
debug: {
Expand Down
Binary file modified preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 12 additions & 11 deletions src/ElkProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ out var error
{
SemanticTokens = semanticTokens,
Diagnostics = diagnostics,
Ast = ast,
};
}
}
Expand All @@ -125,9 +126,13 @@ internal static EvaluationResult Evaluate(
Debug.Assert(scope.ModuleScope is not { Ast: null });

var generated = GeneratePages(ast, scope, analysisScope, virtualMachine).ToList();
var result = generated
.Select(pair => virtualMachine?.Execute(pair.page))
.LastOrDefault();
RuntimeObject? result = null;
if (virtualMachine != null)
{
result = generated
.Select(pair => virtualMachine.Execute(pair.page!))
.LastOrDefault();
}

return new EvaluationResult
{
Expand All @@ -136,7 +141,7 @@ internal static EvaluationResult Evaluate(
};
}

private static IEnumerable<(Ast analysedAst, Page page)> GeneratePages(
private static IEnumerable<(Ast analysedAst, Page? page)> GeneratePages(
Ast ast,
Scope scope,
AnalysisScope analysisScope,
Expand All @@ -154,16 +159,12 @@ internal static EvaluationResult Evaluate(
.Concat(EvaluateModules(scope.ModuleScope.Modules, virtualMachine));

var analysedAst = Analyser.Analyse(ast, scope.ModuleScope, analysisScope);
if (virtualMachine != null)
{
var result = virtualMachine.Generate(analysedAst);
pages = pages.Append((analysedAst, result));
}
var result = virtualMachine?.Generate(analysedAst);

return pages;
return pages.Append((analysedAst, result));
}

private static IEnumerable<(Ast, Page)> EvaluateModules(
private static IEnumerable<(Ast, Page?)> EvaluateModules(
IEnumerable<ModuleScope> modules,
VirtualMachine? virtualMachine)
{
Expand Down
16 changes: 14 additions & 2 deletions src/Parsing/AstNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public class CallExpr(
Scope scope,
TextPos endPos)
: Expr(
modulePath.FirstOrDefault()?.Position ?? identifier.Position,
GetStartPosition(modulePath, identifier, arguments),
endPos,
scope
)
Expand Down Expand Up @@ -491,7 +491,19 @@ public class CallExpr(
public FunctionExpr? EnclosingClosureProvidingFunction { get; init; }

public override IEnumerable<Expr> ChildExpressions
=> Arguments;
=> PipedToProgram == null
? Arguments
: Arguments.Prepend(PipedToProgram);

private static TextPos GetStartPosition(IList<Token> modulePath, Token identifier, IList<Expr> arguments)
{
var callPos = modulePath.FirstOrDefault()?.Position ?? identifier.Position;
var firstArgumentPosition = arguments.FirstOrDefault()?.StartPosition;

return firstArgumentPosition?.Index < callPos.Index
? firstArgumentPosition
: callPos;
}
}

public class LiteralExpr(Token value, Scope scope)
Expand Down

0 comments on commit bc7c591

Please sign in to comment.