Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Prelude

module ByRefParam =
type C() =
static member M(x: byref<int>) = x <- 5
let mutable res = 9
let v = C.M(&res)
check "cwvereweoiwekl4" res 5

let minfo = typeof<C>.GetMethod("M")
check "cwnoreeker1" (minfo.GetParameters().[0].IsIn) false
check "cwnoreeker2" (minfo.GetParameters().[0].IsOut) false
check "cwnoreeker3" (minfo.ReturnParameter.IsIn) false
check "cwnoreeker4" (minfo.ReturnParameter.IsOut) false
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
open Prelude

module ByRefParam_ExplicitInAttribute =
type C() =
static member M([<System.Runtime.InteropServices.In>] x: byref<int>) = x <- 5
let mutable res = 9
let v = C.M(&res)
check "cwvereweoiwekl4" res 5

let minfo = typeof<C>.GetMethod("M")
check "cwnoreeker9" (minfo.GetParameters().[0].IsIn) true
check "cwnoreekerq" (minfo.GetParameters().[0].IsOut) false
check "cwnoreeker6c" (minfo.GetParameters().[0].GetRequiredCustomModifiers().Length) 0
check "cwnoreekers2" (minfo.ReturnParameter.GetRequiredCustomModifiers().Length) 0
check "cwnoreekerw" (minfo.ReturnParameter.IsIn) false
check "cwnoreekere" (minfo.ReturnParameter.IsOut) false
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
open Prelude

module ByRefParam_ExplicitOutAttribute =
type C() =
static member M([<System.Runtime.InteropServices.Out>] x: byref<int>) = x <- 5
let mutable res = 9
let v = C.M(&res)
check "cwvereweoiwekl4" res 5

let minfo = typeof<C>.GetMethod("M")
check "cwnoreeker5" (minfo.GetParameters().[0].IsIn) false
check "cwnoreeker6a" (minfo.GetParameters().[0].IsOut) true
check "cwnoreeker6b" (minfo.GetParameters().[0].GetRequiredCustomModifiers().Length) 0
check "cwnoreekers1" (minfo.ReturnParameter.GetRequiredCustomModifiers().Length) 0
check "cwnoreeker7" (minfo.ReturnParameter.IsIn) false
check "cwnoreeker8" (minfo.ReturnParameter.IsOut) false
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
open Prelude

module ByRefParam_OverloadedTest_ExplicitOutAttribute =
type C() =
static member M(a: int, [<System.Runtime.InteropServices.Out>] x: byref<int>) = x <- 7
static member M(a: string, [<System.Runtime.InteropServices.Out>] x: byref<int>) = x <- 8
let mutable res = 9
C.M("a", &res)
check "cweweoiwek2cbe9" res 8
C.M(3, &res)
check "cweweoiwek28498" res 7
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
open Prelude

module ByRefReturn =
type C() =
static member M(x: byref<int>) = x <- x + 1; &x
let mutable res = 9
let v = C.M(&res)
check "cwvereweoiwvw4" v 10

let minfo = typeof<C>.GetMethod("M")
check "cwnoreeker6d" (minfo.GetParameters().[0].GetRequiredCustomModifiers().Length) 0
check "cwnoreekerr" (minfo.ReturnParameter.IsIn) false
check "cwnoreekert" (minfo.ReturnParameter.IsOut) false
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
open Prelude

module TestArrayParam =

let f (x:int[]) = &x.[0]

let test() =
let r = [| 1 |]
let addr = &f r
addr <- addr + 1
check2 "cepojcwem14" 2 r.[0]

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Prelude

module TestBaseCall =
type Incrementor(z) =
abstract member Increment : int byref * int byref -> unit
default this.Increment(i : int byref,j : int byref) =
i <- i + z

type Decrementor(z) =
inherit Incrementor(z)
override this.Increment(i, j) =
base.Increment(&i, &j)

i <- i - z
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
open Prelude

module TestClassParamMutableField =

type C() = [<DefaultValue>] val mutable z : int

let f (x:C) = &x.z

let test() =
let c = C()
let addr = &f c
addr <- addr + 1
check2 "cepojcwem13b" 1 c.z

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open Prelude

module TestConditionalReturn =
let mutable x = 1
let mutable y = 1

let f inp = if inp = 3 then &x else &y

let test() =
let addr = &f 3
addr <- addr + 1
check2 "cepojcwem6" 2 x
check2 "cepojcwem7" 1 y
let addr = &f 4
addr <- addr + 1
check2 "cepojcwem8" 2 x
check2 "cepojcwem9" 2 y

let test2() =
let res = f 3
let res2 = res + 1
check2 "cepojcwem8b" 3 res2
check2 "cepojcwem9b" 2 res

test()
test2()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
open Prelude

module TestDelegateMethod =
let mutable x = 1

type D = delegate of unit -> byref<int>

let d() = D(fun () -> &x)

let f (d:D) = &d.Invoke()

let test() =
let addr = &f (d())
check2 "cepojcwem18a" 1 x
addr <- addr + 1
check2 "cepojcwem18b" 2 x

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
open Prelude

module TestDelegateMethod2 =
let mutable x = 1

type D = delegate of byref<int> -> byref<int>

let d() = D(fun xb -> &xb)

let f (d:D) = &d.Invoke(&x)

let test() =
let addr = &f (d())
check2 "cepojcwem18a2" 1 x
addr <- addr + 1
check2 "cepojcwem18b3" 2 x

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
open Prelude

module TestImmediateReturn =
let mutable x = 1

let f () = &x

let test() =
let addr : byref<int> = &f()
addr <- addr + 1
check2 "cepojcwem1" 2 x


let test2() =
let v = f()
let res = v + 1
check2 "cepojcwem1b" 3 res

test()
test2()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open Prelude

module TestInterfaceMethod =
let mutable x = 1

type I =
abstract M : unit -> byref<int>

type C() =
interface I with
member this.M() = &x

let ObjExpr() =
{ new I with
member this.M() = &x }

let f (i:I) = &i.M()

let test() =
let addr = &f (C())
addr <- addr + 1
let addr = &f (ObjExpr())
addr <- addr + 1
check2 "cepojcwem16" 3 x

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open Prelude

module TestInterfaceProperty =
let mutable x = 1

type I =
abstract P : byref<int>

type C() =
interface I with
member this.P = &x

let ObjExpr() =
{ new I with
member this.P = &x }

let f (i:I) = &i.P

let test() =
let addr = &f (C())
addr <- addr + 1
let addr = &f (ObjExpr())
addr <- addr + 1
check2 "cepojcwem17" 3 x

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open Prelude

module TestMatchReturn =
let mutable x = 1
let mutable y = 1

let f inp = match inp with 3 -> &x | _ -> &y

let test() =
let addr = &f 3
addr <- addr + 1
check2 "cepojcwem2" 2 x
check2 "cepojcwem3" 1 y
let addr = &f 4
addr <- addr + 1
check2 "cepojcwem4" 2 x
check2 "cepojcwem5" 2 y

let test2() =
let res = f 3
let res2 = res + 1
check2 "cepojcwem2b" 3 res2
check2 "cepojcwem3b" 2 res

test()
test2()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
open Prelude

module TestOneArgument =

let f (x:byref<int>) = &x

let test() =
let mutable r1 = 1
let addr = &f &r1
addr <- addr + 1
check2 "cepojcwem10" 2 r1

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Prelude

module TestRecordParam =

type R = { mutable z : int }
let f (x:R) = &x.z

let test() =
let r = { z = 1 }
let addr = &f r
addr <- addr + 1
check2 "cepojcwem12" 2 r.z

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
open Prelude

module TestRecordParam2 =

type R = { mutable z : int }
let f (x:byref<R>) = &x.z

let test() =
let mutable r = { z = 1 }
let addr = &f &r
addr <- addr + 1
check2 "cepojcwem13a" 2 r.z

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
open Prelude

module TestStructParam =

[<Struct>]
type R = { mutable z : int }

let f (x:byref<R>) = &x.z

let test() =
let mutable r = { z = 1 }
let addr = &f &r
addr <- addr + 1
check2 "cepojcwem15" 2 r.z

test()
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open Prelude

module TestTryFinallyReturn =
let mutable x = 1
let mutable y = 1

let f inp = try &x with _ -> &y

let test() =
let addr = &f 3
addr <- addr + 1
check2 "cepojcwem6b" 2 x
check2 "cepojcwem7b" 1 y
let addr = &f 4
addr <- addr + 1
check2 "cepojcwem8b" 3 x
check2 "cepojcwem9b" 1 y

let test2() =
let res = f 3
let res2 = res + 1
check2 "cepojcwem2tf" 4 res2
check2 "cepojcwem3qw" 3 res

test()
test2()
Loading