Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript modules #38

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5888b89
Convert JS runtime to “use modules”
robin-aws Sep 23, 2023
3be8abb
Hacking around to get it working for TS for now
robin-aws Sep 23, 2023
91edbe4
Add export as needed
robin-aws Sep 24, 2023
a49c15f
First pass of replacing BigNumber with BitInt
robin-aws Sep 25, 2023
b9aeb2a
Export all classes in runtime
robin-aws Sep 25, 2023
c214796
More fixes + EXPORT ALL THE THINGS
robin-aws Sep 26, 2023
747d702
More BigInt fixes
robin-aws Sep 26, 2023
be1d01b
Extra @ts-nocheck
robin-aws Sep 26, 2023
f84a4af
More Number() conversions
robin-aws Sep 26, 2023
94a6f53
More bigint fixes
robin-aws Sep 27, 2023
e83c722
Merge branch 'master' of https://github.com/dafny-lang/dafny into jav…
robin-aws Oct 3, 2023
c7dbf2b
Merge branch 'master' of https://github.com/dafny-lang/dafny into jav…
robin-aws Nov 17, 2023
df1ea0a
Fix NRE in stdlibs
robin-aws Nov 17, 2023
53d1cb4
Fix runtime embedding
robin-aws Nov 17, 2023
2b29ee2
Disable FileIO for now
robin-aws Nov 21, 2023
07b2263
Disable FileIO for now, fix DafnyRuntimeSystemModule.ts
robin-aws Nov 21, 2023
04a719b
Include JavascriptInterop.ts, fix bigint in for loops
robin-aws Nov 21, 2023
5f00202
Another isLessThan case
robin-aws Nov 21, 2023
63c5b1e
Another bigint fix
robin-aws Nov 21, 2023
ad3f82f
Interop fix
robin-aws Nov 21, 2023
ff4e7a4
Many fixes
robin-aws Nov 23, 2023
b72bc70
Switch stdlibs to —unicode-char:false for now
robin-aws Nov 23, 2023
e44cd34
Merge branch 'master' of https://github.com/dafny-lang/dafny into jav…
robin-aws Nov 23, 2023
4ef772e
Restore bug fix
robin-aws Nov 25, 2023
d45ce36
Hack to avoid IDE NRE for now
robin-aws Nov 27, 2023
08b8550
areEqual improvement
robin-aws Nov 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 87 additions & 98 deletions Source/DafnyCore/Compilers/JavaScript/Compiler-js.cs

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions Source/DafnyCore/Compilers/JavaScript/JavaScriptBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ public class JavaScriptBackend : ExecutableBackend {

public override string TargetName => "JavaScript";
public override bool IsStable => true;
public override string TargetExtension => "js";
public override string TargetExtension => "ts";

public override bool SupportsInMemoryCompilation => true;
public override bool TextualTargetIsExecutable => true;

// public override string TargetBaseDir(string dafnyProgramName) =>
// $"{Path.GetFileNameWithoutExtension(dafnyProgramName)}-ts";

public override IReadOnlySet<string> SupportedNativeTypes =>
new HashSet<string>(new List<string> { "number" });
Expand Down Expand Up @@ -53,7 +56,7 @@ bool SendToNewNodeProcess(string dafnyProgramName, string targetProgramText, str
TextWriter outputWriter) {
Contract.Requires(targetFilename != null || otherFileNames.Count == 0);

var psi = new ProcessStartInfo("node", "") {
var psi = new ProcessStartInfo("ts-node", "") {
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
Expand Down Expand Up @@ -84,7 +87,7 @@ bool SendToNewNodeProcess(string dafnyProgramName, string targetProgramText, str
#pragma warning restore VSTHRD002
return nodeProcess.ExitCode == 0;
} catch (System.ComponentModel.Win32Exception e) {
outputWriter.WriteLine("Error: Unable to start node.js ({0}): {1}", psi.FileName, e.Message);
outputWriter.WriteLine("Error: Unable to start ts-node ({0}): {1}", psi.FileName, e.Message);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyCore/Compilers/SinglePassCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5719,7 +5719,7 @@ private ConcreteSyntaxTree MaybeInjectSubtypeConstraint(string tmpVarName,
Type collectionElementType, Type boundVarType, bool inLetExprBody,
IToken tok, ConcreteSyntaxTree wr, bool isReturning = false, bool elseReturnValue = false
) {
var iterationValuesNeedToBeChecked = IsTargetSupertype(collectionElementType, boundVarType);
var iterationValuesNeedToBeChecked = !IsTargetSupertype(collectionElementType, boundVarType);
if (iterationValuesNeedToBeChecked) {
var preconditions = wr.Fork();
var conditions = GetSubtypeCondition(tmpVarName, boundVarType, tok, preconditions);
Expand Down
7 changes: 4 additions & 3 deletions Source/DafnyCore/DafnyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ public static DafnyFile CreateAndValidate(ErrorReporter reporter, IFileSystem fi
dooFile = DooFile.Read(filePath);
}

if (!dooFile.Validate(reporter, filePathForErrors, options, options.CurrentCommand, origin)) {
return null;
}
// TODO: HACK
// if (!dooFile.Validate(reporter, filePathForErrors, options, options.CurrentCommand, origin)) {
// return null;
// }

// For now it's simpler to let the rest of the pipeline parse the
// program text back into the AST representation.
Expand Down
3 changes: 2 additions & 1 deletion Source/DafnyLanguageServer/Workspace/Compilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ private IReadOnlyList<DafnyFile> DetermineRootFiles() {
if (Options.CompilerName is null or "cs" or "java" or "go" or "py" or "js") {
var targetName = Options.CompilerName ?? "notarget";
var stdlibDooUri = new Uri($"{DafnyMain.StandardLibrariesDooUriBase}-{targetName}.doo");
Options.CliRootSourceUris.Add(stdlibDooUri);
// TODO: bug fix, not hack
// Options.CliRootSourceUris.Add(stdlibDooUri);
result.Add(DafnyFile.CreateAndValidate(errorReporter, OnDiskFileSystem.Instance, Options, stdlibDooUri, Project.StartingToken));
}

Expand Down
4 changes: 2 additions & 2 deletions Source/DafnyPipeline/DafnyPipeline.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<LinkBase>DafnyStandardLibraries_java</LinkBase>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="..\DafnyStandardLibraries\src\**\*.js">
<EmbeddedResource Include="..\DafnyStandardLibraries\src\**\*.ts">
<LinkBase>DafnyStandardLibraries_js</LinkBase>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
Expand Down Expand Up @@ -118,7 +118,7 @@
<LinkBase>DafnyRuntimeCpp</LinkBase>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="..\DafnyRuntime\DafnyRuntimeJs\**\*.js">
<EmbeddedResource Include="..\DafnyRuntime\DafnyRuntimeJs\**\*.ts">
<LinkBase>DafnyRuntimeJs</LinkBase>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
Expand Down
Loading
Loading