From 8cfdfc92fcf41f5db6d30015b20457ca64f0c3ce Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 8 Mar 2025 13:39:40 +0000 Subject: Support method calls from other namespaces (without Wasm support) --- .../40-imported-struct-methods/shed-examples.json5 | 9 ++++++++ examples/40-imported-struct-methods/shed.json5 | 8 +++++++ .../40-imported-struct-methods/src/Counting.shed | 11 ++++++++++ .../40-imported-struct-methods/src/HelloWorld.shed | 7 ++++++ .../shed-examples.json5 | 9 -------- examples/40-struct-method-references/shed.json5 | 8 ------- .../src/HelloWorld.shed | 25 ---------------------- .../41-generic-struct-methods/shed-examples.json5 | 9 -------- examples/41-generic-struct-methods/shed.json5 | 8 ------- .../41-generic-struct-methods/src/HelloWorld.shed | 11 ---------- .../shed-examples.json5 | 9 ++++++++ examples/41-struct-method-references/shed.json5 | 8 +++++++ .../src/HelloWorld.shed | 25 ++++++++++++++++++++++ .../shed-examples.json5 | 9 -------- examples/42-generic-struct-methods-this/shed.json5 | 8 ------- .../src/HelloWorld.shed | 15 ------------- .../42-generic-struct-methods/shed-examples.json5 | 9 ++++++++ examples/42-generic-struct-methods/shed.json5 | 8 +++++++ .../42-generic-struct-methods/src/HelloWorld.shed | 11 ++++++++++ .../shed-examples.json5 | 9 ++++++++ examples/43-generic-struct-methods-this/shed.json5 | 8 +++++++ .../src/HelloWorld.shed | 15 +++++++++++++ examples/43-native-code/shed-examples.json5 | 9 -------- examples/43-native-code/shed.json5 | 11 ---------- examples/43-native-code/src/False.shed | 5 ----- examples/44-native-code/shed-examples.json5 | 9 ++++++++ examples/44-native-code/shed.json5 | 11 ++++++++++ examples/44-native-code/src/False.shed | 5 +++++ 28 files changed, 162 insertions(+), 127 deletions(-) create mode 100644 examples/40-imported-struct-methods/shed-examples.json5 create mode 100644 examples/40-imported-struct-methods/shed.json5 create mode 100644 examples/40-imported-struct-methods/src/Counting.shed create mode 100644 examples/40-imported-struct-methods/src/HelloWorld.shed delete mode 100644 examples/40-struct-method-references/shed-examples.json5 delete mode 100644 examples/40-struct-method-references/shed.json5 delete mode 100644 examples/40-struct-method-references/src/HelloWorld.shed delete mode 100644 examples/41-generic-struct-methods/shed-examples.json5 delete mode 100644 examples/41-generic-struct-methods/shed.json5 delete mode 100644 examples/41-generic-struct-methods/src/HelloWorld.shed create mode 100644 examples/41-struct-method-references/shed-examples.json5 create mode 100644 examples/41-struct-method-references/shed.json5 create mode 100644 examples/41-struct-method-references/src/HelloWorld.shed delete mode 100644 examples/42-generic-struct-methods-this/shed-examples.json5 delete mode 100644 examples/42-generic-struct-methods-this/shed.json5 delete mode 100644 examples/42-generic-struct-methods-this/src/HelloWorld.shed create mode 100644 examples/42-generic-struct-methods/shed-examples.json5 create mode 100644 examples/42-generic-struct-methods/shed.json5 create mode 100644 examples/42-generic-struct-methods/src/HelloWorld.shed create mode 100644 examples/43-generic-struct-methods-this/shed-examples.json5 create mode 100644 examples/43-generic-struct-methods-this/shed.json5 create mode 100644 examples/43-generic-struct-methods-this/src/HelloWorld.shed delete mode 100644 examples/43-native-code/shed-examples.json5 delete mode 100644 examples/43-native-code/shed.json5 delete mode 100644 examples/43-native-code/src/False.shed create mode 100644 examples/44-native-code/shed-examples.json5 create mode 100644 examples/44-native-code/shed.json5 create mode 100644 examples/44-native-code/src/False.shed (limited to 'examples') diff --git a/examples/40-imported-struct-methods/shed-examples.json5 b/examples/40-imported-struct-methods/shed-examples.json5 new file mode 100644 index 00000000..95fb0a97 --- /dev/null +++ b/examples/40-imported-struct-methods/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "one\ntwo\nmany", + }, + ], +} diff --git a/examples/40-imported-struct-methods/shed.json5 b/examples/40-imported-struct-methods/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/40-imported-struct-methods/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/40-imported-struct-methods/src/Counting.shed b/examples/40-imported-struct-methods/src/Counting.shed new file mode 100644 index 00000000..ac97df14 --- /dev/null +++ b/examples/40-imported-struct-methods/src/Counting.shed @@ -0,0 +1,11 @@ +pub struct Count(value: Int) { + fun message(this) -> String { + if (this.value == 1) { + "one\n" + } else if (this.value == 2) { + "two\n" + } else { + "many\n" + } + } +} diff --git a/examples/40-imported-struct-methods/src/HelloWorld.shed b/examples/40-imported-struct-methods/src/HelloWorld.shed new file mode 100644 index 00000000..6d9de22c --- /dev/null +++ b/examples/40-imported-struct-methods/src/HelloWorld.shed @@ -0,0 +1,7 @@ +import Counting; + +pub fun main() ! Io -> Unit { + print!(Counting.Count(1).message()); + print!(Counting.Count(2).message()); + print!(Counting.Count(3).message()); +} diff --git a/examples/40-struct-method-references/shed-examples.json5 b/examples/40-struct-method-references/shed-examples.json5 deleted file mode 100644 index a57c4749..00000000 --- a/examples/40-struct-method-references/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "one apple\ntwo bananas\nmany coconuts!", - }, - ], -} diff --git a/examples/40-struct-method-references/shed.json5 b/examples/40-struct-method-references/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/40-struct-method-references/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/40-struct-method-references/src/HelloWorld.shed b/examples/40-struct-method-references/src/HelloWorld.shed deleted file mode 100644 index 5bfd3631..00000000 --- a/examples/40-struct-method-references/src/HelloWorld.shed +++ /dev/null @@ -1,25 +0,0 @@ -pub fun main() ! Io -> Unit { - val one = Count(1).message; - val two = Count(2).message; - val three = Count(3).message; - - print!(one("apple", .exclaim = false)); - print!(two("bananas", .exclaim = false)); - print!(three("coconuts", .exclaim = true)); -} - -struct Count(value: Int) { - fun message(this, noun: String, .exclaim: Bool) -> String { - val prefix = if (this.value == 1) { - "one" - } else if (this.value == 2) { - "two" - } else { - "many" - }; - - val exclamation = if (exclaim) { "!" } else { "" }; - - prefix + " " + noun + exclamation + "\n" - } -} diff --git a/examples/41-generic-struct-methods/shed-examples.json5 b/examples/41-generic-struct-methods/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/41-generic-struct-methods/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/41-generic-struct-methods/shed.json5 b/examples/41-generic-struct-methods/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/41-generic-struct-methods/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/41-generic-struct-methods/src/HelloWorld.shed b/examples/41-generic-struct-methods/src/HelloWorld.shed deleted file mode 100644 index a4e808e1..00000000 --- a/examples/41-generic-struct-methods/src/HelloWorld.shed +++ /dev/null @@ -1,11 +0,0 @@ -pub fun main() ! Io -> Unit { - val messageBox = Box("hello, world"); - - print!(messageBox.get()); -} - -struct Box[T](value: T) { - fun get(this) -> T { - this.value - } -} diff --git a/examples/41-struct-method-references/shed-examples.json5 b/examples/41-struct-method-references/shed-examples.json5 new file mode 100644 index 00000000..a57c4749 --- /dev/null +++ b/examples/41-struct-method-references/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "one apple\ntwo bananas\nmany coconuts!", + }, + ], +} diff --git a/examples/41-struct-method-references/shed.json5 b/examples/41-struct-method-references/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/41-struct-method-references/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/41-struct-method-references/src/HelloWorld.shed b/examples/41-struct-method-references/src/HelloWorld.shed new file mode 100644 index 00000000..5bfd3631 --- /dev/null +++ b/examples/41-struct-method-references/src/HelloWorld.shed @@ -0,0 +1,25 @@ +pub fun main() ! Io -> Unit { + val one = Count(1).message; + val two = Count(2).message; + val three = Count(3).message; + + print!(one("apple", .exclaim = false)); + print!(two("bananas", .exclaim = false)); + print!(three("coconuts", .exclaim = true)); +} + +struct Count(value: Int) { + fun message(this, noun: String, .exclaim: Bool) -> String { + val prefix = if (this.value == 1) { + "one" + } else if (this.value == 2) { + "two" + } else { + "many" + }; + + val exclamation = if (exclaim) { "!" } else { "" }; + + prefix + " " + noun + exclamation + "\n" + } +} diff --git a/examples/42-generic-struct-methods-this/shed-examples.json5 b/examples/42-generic-struct-methods-this/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/42-generic-struct-methods-this/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/42-generic-struct-methods-this/shed.json5 b/examples/42-generic-struct-methods-this/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/42-generic-struct-methods-this/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/42-generic-struct-methods-this/src/HelloWorld.shed b/examples/42-generic-struct-methods-this/src/HelloWorld.shed deleted file mode 100644 index b114d85a..00000000 --- a/examples/42-generic-struct-methods-this/src/HelloWorld.shed +++ /dev/null @@ -1,15 +0,0 @@ -pub fun main() ! Io -> Unit { - val messageBox = Box("hello, world"); - - print!(messageBox.me().get()); -} - -struct Box[T](value: T) { - fun me(this) -> Box[T] { - this - } - - fun get(this) -> T { - this.value - } -} diff --git a/examples/42-generic-struct-methods/shed-examples.json5 b/examples/42-generic-struct-methods/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/42-generic-struct-methods/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/42-generic-struct-methods/shed.json5 b/examples/42-generic-struct-methods/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/42-generic-struct-methods/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/42-generic-struct-methods/src/HelloWorld.shed b/examples/42-generic-struct-methods/src/HelloWorld.shed new file mode 100644 index 00000000..a4e808e1 --- /dev/null +++ b/examples/42-generic-struct-methods/src/HelloWorld.shed @@ -0,0 +1,11 @@ +pub fun main() ! Io -> Unit { + val messageBox = Box("hello, world"); + + print!(messageBox.get()); +} + +struct Box[T](value: T) { + fun get(this) -> T { + this.value + } +} diff --git a/examples/43-generic-struct-methods-this/shed-examples.json5 b/examples/43-generic-struct-methods-this/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/43-generic-struct-methods-this/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/43-generic-struct-methods-this/shed.json5 b/examples/43-generic-struct-methods-this/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/43-generic-struct-methods-this/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/43-generic-struct-methods-this/src/HelloWorld.shed b/examples/43-generic-struct-methods-this/src/HelloWorld.shed new file mode 100644 index 00000000..b114d85a --- /dev/null +++ b/examples/43-generic-struct-methods-this/src/HelloWorld.shed @@ -0,0 +1,15 @@ +pub fun main() ! Io -> Unit { + val messageBox = Box("hello, world"); + + print!(messageBox.me().get()); +} + +struct Box[T](value: T) { + fun me(this) -> Box[T] { + this + } + + fun get(this) -> T { + this.value + } +} diff --git a/examples/43-native-code/shed-examples.json5 b/examples/43-native-code/shed-examples.json5 deleted file mode 100644 index 1b45c0b5..00000000 --- a/examples/43-native-code/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "false", - expectedExitCode: 42, - }, - ], -} diff --git a/examples/43-native-code/shed.json5 b/examples/43-native-code/shed.json5 deleted file mode 100644 index b07dcaed..00000000 --- a/examples/43-native-code/shed.json5 +++ /dev/null @@ -1,11 +0,0 @@ -{ - bins: [ - { - name: "false", - mainNamespace: "False", - }, - ], - dependencies: [ - {path: "../../projects/std"}, - ], -} diff --git a/examples/43-native-code/src/False.shed b/examples/43-native-code/src/False.shed deleted file mode 100644 index 75dc7a89..00000000 --- a/examples/43-native-code/src/False.shed +++ /dev/null @@ -1,5 +0,0 @@ -import Std/Process; - -pub fun main() ! Io -> Unit { - Process.exit!(42); -} diff --git a/examples/44-native-code/shed-examples.json5 b/examples/44-native-code/shed-examples.json5 new file mode 100644 index 00000000..1b45c0b5 --- /dev/null +++ b/examples/44-native-code/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "false", + expectedExitCode: 42, + }, + ], +} diff --git a/examples/44-native-code/shed.json5 b/examples/44-native-code/shed.json5 new file mode 100644 index 00000000..b07dcaed --- /dev/null +++ b/examples/44-native-code/shed.json5 @@ -0,0 +1,11 @@ +{ + bins: [ + { + name: "false", + mainNamespace: "False", + }, + ], + dependencies: [ + {path: "../../projects/std"}, + ], +} diff --git a/examples/44-native-code/src/False.shed b/examples/44-native-code/src/False.shed new file mode 100644 index 00000000..75dc7a89 --- /dev/null +++ b/examples/44-native-code/src/False.shed @@ -0,0 +1,5 @@ +import Std/Process; + +pub fun main() ! Io -> Unit { + Process.exit!(42); +} -- cgit v1.2.3