-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- v0.24.1
- 1.15.1
- 1.15.0
- 1.14.1
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
- 0.36.1
- 0.36.0
- 0.35.1
- 0.35.0
- 0.34.0
- 0.33.0
- 0.32.1
- 0.32.0
- 0.31.1
- 0.31.0
- 0.30.1
- 0.30.0
- 0.29.0
- 0.28.0
- 0.27.2
- 0.27.1
- 0.27.0
- 0.26.1
- 0.26.0
- 0.25.1
- 0.25.0
- 0.24.2
- 0.24.1
- 0.24.0
- 0.23.1
- 0.23.0
- 0.22.0
- 0.21.1
- 0.21.0
- 0.20.5
- 0.20.4
- 0.20.3
- 0.20.2
- 0.20.1
- 0.20.0
- 0.19.4
- 0.19.3
- 0.19.2
Ary Borenszweig
committed
Sep 14, 2016
1 parent
11c7050
commit dcfd903
Showing
6 changed files
with
386 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
require "../../spec_helper" | ||
|
||
describe "Codegen: extern struct" do | ||
it "declares extern struct with no constructor" do | ||
run(%( | ||
@[Extern] | ||
struct Foo | ||
@x = uninitialized Int32 | ||
def x | ||
@x | ||
end | ||
end | ||
Foo.new.x | ||
)).to_i.should eq(0) | ||
end | ||
|
||
it "declares extern struct with no constructor, assigns var" do | ||
run(%( | ||
@[Extern] | ||
struct Foo | ||
@x = uninitialized Int32 | ||
def x=(@x) | ||
end | ||
def x | ||
@x | ||
end | ||
end | ||
foo = Foo.new | ||
foo.x = 10 | ||
foo.x | ||
)).to_i.should eq(10) | ||
end | ||
|
||
it "declares extern union with no constructor" do | ||
run(%( | ||
@[Extern(union: true)] | ||
struct Foo | ||
@x = uninitialized Int32 | ||
@y = uninitialized Float32 | ||
def x=(@x) | ||
end | ||
def x | ||
@x | ||
end | ||
def y=(@y) | ||
end | ||
end | ||
foo = Foo.new | ||
foo.x = 1 | ||
foo.y = 1.5_f32 | ||
foo.x | ||
)).to_i.should eq(1069547520) | ||
end | ||
|
||
it "declares extern struct, sets and gets insance var" do | ||
This comment has been minimized.
Sorry, something went wrong. |
||
run(%( | ||
@[Extern] | ||
struct Foo | ||
@y = uninitialized Float64 | ||
@x = uninitialized Int32 | ||
def foo | ||
@x = 42 | ||
@x | ||
end | ||
end | ||
Foo.new.foo | ||
)).to_i.should eq(42) | ||
end | ||
|
||
it "declares extern union, sets and gets insance var" do | ||
This comment has been minimized.
Sorry, something went wrong. |
||
run(%( | ||
@[Extern(union: true)] | ||
struct Foo | ||
@x = uninitialized Int32 | ||
@y = uninitialized Float32 | ||
def foo | ||
@x = 1 | ||
@y = 1.5_f32 | ||
@x | ||
end | ||
end | ||
Foo.new.foo | ||
)).to_i.should eq(1069547520) | ||
end | ||
|
||
it "sets callback on extern struct" do | ||
run(%( | ||
require "prelude" | ||
@[Extern] | ||
struct Foo | ||
@x = uninitialized -> Int32 | ||
def set | ||
@x = ->{ 42 } | ||
end | ||
def get | ||
@x.call | ||
end | ||
end | ||
foo = Foo.new | ||
foo.set | ||
foo.get | ||
)).to_i.should eq(42) | ||
end | ||
|
||
it "sets callback on extern union" do | ||
run(%( | ||
require "prelude" | ||
@[Extern(union: true)] | ||
struct Foo | ||
@y = uninitialized Float64 | ||
@x = uninitialized -> Int32 | ||
def set | ||
@x = ->{ 42 } | ||
end | ||
def get | ||
@x.call | ||
end | ||
end | ||
foo = Foo.new | ||
foo.set | ||
foo.get | ||
)).to_i.should eq(42) | ||
end | ||
end |
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,172 @@ | ||
require "../../spec_helper" | ||
|
||
describe "Semantic: extern struct" do | ||
it "declares extern struct with no constructor" do | ||
assert_type(%( | ||
@[Extern] | ||
struct Foo | ||
@x = uninitialized Int32 | ||
def x | ||
@x | ||
end | ||
end | ||
Foo.new.x | ||
)) { int32 } | ||
end | ||
|
||
it "declares with constructor" do | ||
assert_type(%( | ||
@[Extern] | ||
struct Foo | ||
@x = uninitialized Int32 | ||
def initialize(@x) | ||
end | ||
def foo | ||
@x | ||
end | ||
end | ||
Foo.new(1).foo | ||
)) { int32 } | ||
end | ||
|
||
it "overrides getter" do | ||
assert_type(%( | ||
@[Extern] | ||
struct Foo | ||
@x = uninitialized Int32 | ||
def x | ||
'a' | ||
end | ||
end | ||
Foo.new.x | ||
)) { char } | ||
end | ||
|
||
it "can be passed to C fun" do | ||
assert_type(%( | ||
@[Extern] | ||
struct Foo | ||
@x = uninitialized Int32 | ||
end | ||
lib LibFoo | ||
fun foo(x : Foo) : Float64 | ||
end | ||
LibFoo.foo(Foo.new) | ||
)) { float64 } | ||
end | ||
|
||
it "can include module" do | ||
assert_type(%( | ||
module Moo | ||
@x = uninitialized Int32 | ||
def x | ||
@x | ||
end | ||
end | ||
@[Extern] | ||
struct Foo | ||
include Moo | ||
end | ||
Foo.new.x | ||
)) { int32 } | ||
end | ||
|
||
it "errors if using non-primitive for field type" do | ||
assert_error %( | ||
class Bar | ||
end | ||
@[Extern] | ||
struct Foo | ||
@x = uninitialized Bar | ||
end | ||
), | ||
"only primitive types, pointers, structs, unions, enums and tuples are allowed in extern struct declarations" | ||
end | ||
|
||
it "errors if using non-primitive for field type via module" do | ||
assert_error %( | ||
class Bar | ||
end | ||
module Moo | ||
@x = uninitialized Bar | ||
end | ||
@[Extern] | ||
struct Foo | ||
include Moo | ||
end | ||
), | ||
"only primitive types, pointers, structs, unions, enums and tuples are allowed in extern struct declarations" | ||
end | ||
|
||
it "errors if using non-primitive type in constructor" do | ||
assert_error %( | ||
class Bar | ||
end | ||
@[Extern] | ||
struct Foo | ||
def initialize | ||
@x = Bar.new | ||
end | ||
end | ||
), | ||
"only primitive types, pointers, structs, unions, enums and tuples are allowed in extern struct declarations" | ||
end | ||
|
||
it "declares extern union with no constructor" do | ||
assert_type(%( | ||
@[Extern(union: true)] | ||
struct Foo | ||
@x = uninitialized Int32 | ||
def x | ||
@x | ||
end | ||
end | ||
Foo.new.x | ||
)) { int32 } | ||
end | ||
|
||
it "can use extern struct in lib" do | ||
assert_type(%( | ||
@[Extern] | ||
struct Foo | ||
end | ||
lib LibFoo | ||
fun foo(x : Foo) : Foo | ||
end | ||
foo = Foo.new | ||
LibFoo.foo(foo) | ||
)) { types["Foo"] } | ||
end | ||
|
||
it "can new with named args" do | ||
assert_type(%( | ||
@[Extern] | ||
struct A | ||
def initialize(@x : Int32) | ||
end | ||
end | ||
A.new(x: 6) | ||
)) { types["A"] } | ||
end | ||
end |
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
Oops, something went wrong.
insance
->instance