-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out tests for extern constructors
Extern constructors are currently broken on Go and JavaScript, so I'm moving that functionality from the tests in Extern.dfy and moving it to the new ExternCtors.dfy, which only has RUN lines for C# and Java. I've included the extern code that *should* make the tests work (but currently doesn't).
- Loading branch information
Luke Maurer
committed
Dec 12, 2019
1 parent
86c744b
commit b505d02
Showing
11 changed files
with
144 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package Library; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class Class extends _ExternBase_Class { | ||
private final BigInteger n; | ||
|
||
public Class(BigInteger n) { | ||
this.n = n; | ||
} | ||
|
||
public static void SayHi() { | ||
System.out.println("Hello!"); | ||
} | ||
|
||
public BigInteger Get() { | ||
return n; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Numerics; | ||
|
||
namespace Library { | ||
public partial class Class { | ||
private readonly BigInteger n; | ||
|
||
public Class(BigInteger n) { | ||
this.n = n; | ||
} | ||
|
||
public static void SayHi() { | ||
System.Console.WriteLine("Hello!"); | ||
} | ||
|
||
public BigInteger Get() { | ||
return n; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// FIXME: Test currently fails on Go | ||
|
||
package Library | ||
|
||
import ( | ||
"dafny" | ||
"fmt" | ||
) | ||
|
||
type Class struct{ n dafny.Int } | ||
|
||
func New_Class_(n dafny.Int) *Class { | ||
return &Class{n} | ||
} | ||
|
||
func (obj *Class) Get() dafny.Int { | ||
return obj.n | ||
} | ||
|
||
// have to implement this because the Go backend can't mix Dafny and Go code :-\ | ||
|
||
func (obj *Class) Print() { | ||
fmt.Printf("My value is %d\n", obj.n) | ||
} | ||
|
||
type CompanionStruct_Class_ struct{} | ||
var Companion_Class_ = CompanionStruct_Class_{} | ||
|
||
func (CompanionStruct_Class_) SayHi() { | ||
fmt.Println("Hello!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// FIXME Test currently fails on JavaScript | ||
|
||
let Library = (function() { | ||
let $module = {}; | ||
|
||
$module.Class = class Class { | ||
constructor(n) { | ||
this.n = n; | ||
} | ||
|
||
static SayHi() { | ||
process.stdout.write("Hello!\n"); | ||
} | ||
|
||
Get() { | ||
return this.n; | ||
} | ||
} | ||
|
||
return $module; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// RUN: %dafny /compile:3 /compileTarget:cs "%s" ExternCtors-externs/Library.cs > "%t" | ||
// RUN: %dafny /compile:3 /compileTarget:java "%s" ExternCtors-externs/Class.java >> "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
// FIXME: Extern constructors are currently broken in Go and JavaScript, | ||
// so they are omitted | ||
|
||
method Main() { | ||
Library.Class.SayHi(); | ||
var obj := new Library.Class(42); | ||
obj.Print(); | ||
} | ||
|
||
module {:extern "Library"} Library { | ||
class {:extern} Class { | ||
constructor {:extern} (n: int) | ||
static method {:extern} SayHi() | ||
function method {:extern} Get() : int | ||
method Print() { | ||
print "My value is ", Get(), "\n"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
Dafny program verifier finished with 1 verified, 0 errors | ||
Hello! | ||
My value is 42 | ||
|
||
Dafny program verifier finished with 1 verified, 0 errors | ||
Hello! | ||
My value is 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters