-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancements: - Consistently fold nulls and type mismatches to default values when casting to value types - Consistently fold nulls and type mismatches to default values when casting to or from generic argument types
- Loading branch information
Showing
26 changed files
with
467 additions
and
94 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
23 changes: 23 additions & 0 deletions
23
integration-tests/execution/cast-generic-argument-type/.vscode/tasks.json
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 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Run test", | ||
"command": "dotnet ghul-test \"${workspaceFolder}\"", | ||
"type": "shell", | ||
"group": { | ||
"kind": "test", | ||
"isDefault": true | ||
} | ||
}, | ||
{ | ||
"label": "Capture test expectation", | ||
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"", | ||
"type": "shell", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
Empty file.
3 changes: 3 additions & 0 deletions
3
integration-tests/execution/cast-generic-argument-type/ghul.json
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,3 @@ | ||
{ | ||
"compiler": "dotnet ../../../publish/ghul.dll" | ||
} |
Empty file.
Empty file.
39 changes: 39 additions & 0 deletions
39
integration-tests/execution/cast-generic-argument-type/run.expected
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,39 @@ | ||
cts object null | ||
cts array 1 2 3 | ||
cts 123 | ||
cts object o hello | ||
cts object p | ||
cts thing | ||
cti object null 0 | ||
cti array 1 2 3 0 | ||
cti 'hello' 0 | ||
cti object o 0 | ||
cti object p 123 | ||
cti thing 0 | ||
ctt object null THING #0 default | ||
ctt array 1 2 3 THING #0 default | ||
ctt 'hello' THING #0 default | ||
ctt object o THING #0 default | ||
ctt object p THING #0 default | ||
ctt thing THING #2 initialized | ||
cfo string object null | ||
cfo string array 1 2 3 | ||
cfo string 123 | ||
cfo string object o hello | ||
cfo string object p | ||
cfo string thing | ||
cfo int object null 0 | ||
cfo int array 1 2 3 0 | ||
cfo int 'hello' 0 | ||
cfo int object o 0 | ||
cfo int object p 123 | ||
cfo int thing 0 | ||
cfo THING object null THING #0 default | ||
cfo THING array 1 2 3 THING #0 default | ||
cfo THING 'hello' THING #0 default | ||
cfo THING object o THING #0 default | ||
cfo THING object p THING #0 default | ||
cfo THING thing THING #5 initialized | ||
cfs object hello hello | ||
cfs int hello 0 | ||
cfs THING hello THING #0 default |
79 changes: 79 additions & 0 deletions
79
integration-tests/execution/cast-generic-argument-type/test.ghul
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,79 @@ | ||
use IO.Std.write_line; | ||
|
||
entry() is | ||
let n: object = null; | ||
let a = [1, 2, 3]; | ||
|
||
let o: object = "hello"; | ||
let p: object = 123; | ||
|
||
write_line("cts object null {cast_to_string(n)}"); | ||
write_line("cts array 1 2 3 {cast_to_string(a)}"); | ||
write_line("cts 123 {cast_to_string(123)}"); | ||
write_line("cts object o {cast_to_string(o)}"); | ||
write_line("cts object p {cast_to_string(p)}"); | ||
write_line("cts thing {cast_to_string(THING())}"); | ||
|
||
write_line("cti object null {cast_to_int(n)}"); | ||
write_line("cti array 1 2 3 {cast_to_int(a)}"); | ||
write_line("cti 'hello' {cast_to_int("hello")}"); | ||
write_line("cti object o {cast_to_int(o)}"); | ||
write_line("cti object p {cast_to_int(p)}"); | ||
write_line("cti thing {cast_to_int(THING())}"); | ||
|
||
write_line("ctt object null {cast_to_thing(n)}"); | ||
write_line("ctt array 1 2 3 {cast_to_thing(a)}"); | ||
write_line("ctt 'hello' {cast_to_thing("hello")}"); | ||
write_line("ctt object o {cast_to_thing(o)}"); | ||
write_line("ctt object p {cast_to_thing(p)}"); | ||
write_line("ctt thing {cast_to_thing(THING())}"); | ||
|
||
write_line("cfo string object null {cast_from_object[string](null)}"); | ||
write_line("cfo string array 1 2 3 {cast_from_object[string](a)}"); | ||
write_line("cfo string 123 {cast_from_object[string](123)}"); | ||
write_line("cfo string object o {cast_from_object[string](o)}"); | ||
write_line("cfo string object p {cast_from_object[string](p)}"); | ||
write_line("cfo string thing {cast_from_object[string](THING())}"); | ||
|
||
write_line("cfo int object null {cast_from_object[int](null)}"); | ||
write_line("cfo int array 1 2 3 {cast_from_object[int](a)}"); | ||
write_line("cfo int 'hello' {cast_from_object[int]("hello")}"); | ||
write_line("cfo int object o {cast_from_object[int](o)}"); | ||
write_line("cfo int object p {cast_from_object[int](p)}"); | ||
write_line("cfo int thing {cast_from_object[int](THING())}"); | ||
|
||
write_line("cfo THING object null {cast_from_object[THING](null)}"); | ||
write_line("cfo THING array 1 2 3 {cast_from_object[THING](a)}"); | ||
write_line("cfo THING 'hello' {cast_from_object[THING]("hello")}"); | ||
write_line("cfo THING object o {cast_from_object[THING](o)}"); | ||
write_line("cfo THING object p {cast_from_object[THING](p)}"); | ||
write_line("cfo THING thing {cast_from_object[THING](THING())}"); | ||
|
||
// this is maybe not very useful, but is orthogonal | ||
write_line("cfs object hello {cast_from_string[object]("hello")}"); | ||
write_line("cfs int hello {cast_from_string[int]("hello")}"); | ||
write_line("cfs THING hello {cast_from_string[THING]("hello")}"); | ||
si | ||
|
||
struct THING is | ||
_not_default: bool; | ||
_next: int static; | ||
|
||
value: int; | ||
|
||
init() is | ||
value = _next; | ||
_next = _next + 1; | ||
_not_default = true; | ||
si | ||
|
||
to_string() -> string => | ||
"THING #{value} {if _not_default then "initialized" else "default" fi}"; | ||
si | ||
|
||
cast_to_string[T](value: T) -> string => cast string(value); | ||
cast_to_int[T](value: T) -> int => cast int(value); | ||
cast_to_thing[T](value: T) -> THING => cast THING(value); | ||
|
||
cast_from_object[T](value: object) -> T => cast T(value); | ||
cast_from_string[T](value: string) -> T => cast T(value); |
Empty file.
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 |
---|---|---|
@@ -1,6 +1,3 @@ | ||
{ | ||
"compiler": "dotnet ../../../publish/ghul.dll", | ||
"source": [ | ||
"." | ||
] | ||
"compiler": "dotnet ../../../publish/ghul.dll" | ||
} |
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 |
---|---|---|
@@ -1,4 +1,14 @@ | ||
.locals init (class ['System.Runtime']'System'.'Object' '.cast.0') | ||
ldloc 'o.1' | ||
unbox.any class ['System.Runtime']'System'.'Object' | ||
box valuetype 'convert_object_to_struct__test'.'STRUCT_THINGER' | ||
stloc 't.2' | ||
isinst valuetype 'convert_object_to_struct__test'.'STRUCT_THINGER' | ||
stloc '.cast.0' | ||
ldloc '.cast.0' | ||
brfalse L_0 | ||
ldloc '.cast.0' | ||
unbox.any valuetype 'convert_object_to_struct__test'.'STRUCT_THINGER' | ||
br L_1 | ||
L_0: | ||
.locals init (valuetype 'convert_object_to_struct__test'.'STRUCT_THINGER' '.default.1') | ||
ldloc '.default.1' | ||
L_1: | ||
stloc 't.2' |
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
15 changes: 0 additions & 15 deletions
15
integration-tests/il/convert-object-to-struct/test.ghulproj
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
namespace IR.Values is | ||
use Semantic.Types.Type; | ||
|
||
class DEFAULT: Value is | ||
has_type: bool => type?; | ||
type: Type; | ||
is_value_type: bool => type.is_value_type; | ||
is_value_tuple: bool => type.is_value_tuple; | ||
|
||
has_address: bool => true; | ||
|
||
init( | ||
type: Type | ||
) is | ||
super.init(); | ||
|
||
assert type? else "type is null"; | ||
|
||
self.type = type; | ||
si | ||
|
||
gen(context: IR.CONTEXT) is | ||
let id = TEMP.get_next_id(); | ||
|
||
context.write_line(".locals init ({type.get_il_type()} '.default.{id}')"); | ||
context.write_line("ldloc '.default.{id}'"); | ||
si | ||
|
||
gen_address(context: IR.CONTEXT) is | ||
let id = TEMP.get_next_id(); | ||
|
||
context.write_line(".locals init ({type.get_il_type()} '.default.{id}')"); | ||
context.write_line("ldloca '.default.{id}'"); | ||
si | ||
|
||
to_string() -> string => | ||
"default:[{type}]()"; | ||
si | ||
si |
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.