goscript 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +41 -0
  2. package/builtin/builtin.ts +368 -348
  3. package/cmd/goscript/main.js +37 -0
  4. package/compiler/compile_expr.go +3 -37
  5. package/compiler/index.test.ts +29 -0
  6. package/compiler/index.ts +85 -0
  7. package/dist/builtin/builtin.d.ts +168 -0
  8. package/dist/builtin/builtin.js +372 -0
  9. package/dist/builtin/builtin.js.map +1 -0
  10. package/dist/compiler/index.d.ts +26 -0
  11. package/dist/compiler/index.js +64 -0
  12. package/dist/compiler/index.js.map +1 -0
  13. package/package.json +71 -3
  14. package/.aider-prompt +0 -11
  15. package/compliance/COMPLIANCE.md +0 -133
  16. package/compliance/compliance.go +0 -313
  17. package/compliance/compliance_test.go +0 -57
  18. package/compliance/tests/array_literal/array_literal.go +0 -15
  19. package/compliance/tests/array_literal/array_literal.gs.ts +0 -19
  20. package/compliance/tests/array_literal/expected.log +0 -3
  21. package/compliance/tests/async_basic/async_basic.go +0 -26
  22. package/compliance/tests/async_basic/async_basic.gs.ts +0 -30
  23. package/compliance/tests/async_basic/expected.log +0 -1
  24. package/compliance/tests/basic_arithmetic/basic_arithmetic.go +0 -15
  25. package/compliance/tests/basic_arithmetic/basic_arithmetic.gs.ts +0 -19
  26. package/compliance/tests/basic_arithmetic/expected.log +0 -5
  27. package/compliance/tests/boolean_logic/boolean_logic.go +0 -13
  28. package/compliance/tests/boolean_logic/boolean_logic.gs.ts +0 -17
  29. package/compliance/tests/boolean_logic/expected.log +0 -3
  30. package/compliance/tests/channel_basic/channel_basic.go +0 -12
  31. package/compliance/tests/channel_basic/channel_basic.gs.ts +0 -18
  32. package/compliance/tests/channel_basic/expected.log +0 -1
  33. package/compliance/tests/composite_literal_assignment/composite_literal_assignment.go +0 -20
  34. package/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.ts +0 -27
  35. package/compliance/tests/composite_literal_assignment/expected.log +0 -2
  36. package/compliance/tests/constants/constants.go +0 -18
  37. package/compliance/tests/constants/constants.gs.ts +0 -22
  38. package/compliance/tests/constants/expected.log +0 -3
  39. package/compliance/tests/copy_independence/copy_independence.go +0 -29
  40. package/compliance/tests/copy_independence/copy_independence.gs.ts +0 -36
  41. package/compliance/tests/copy_independence/expected.log +0 -4
  42. package/compliance/tests/float64/expected.log +0 -6
  43. package/compliance/tests/float64/float64.go +0 -28
  44. package/compliance/tests/float64/float64.gs.ts +0 -32
  45. package/compliance/tests/for_loop_basic/expected.log +0 -5
  46. package/compliance/tests/for_loop_basic/for_loop_basic.go +0 -9
  47. package/compliance/tests/for_loop_basic/for_loop_basic.gs.ts +0 -13
  48. package/compliance/tests/for_loop_condition_only/expected.log +0 -5
  49. package/compliance/tests/for_loop_condition_only/main.go +0 -9
  50. package/compliance/tests/for_loop_condition_only/main.gs.ts +0 -13
  51. package/compliance/tests/for_range/expected.log +0 -9
  52. package/compliance/tests/for_range/for_range.go +0 -26
  53. package/compliance/tests/for_range/for_range.gs.ts +0 -45
  54. package/compliance/tests/for_range_index_use/expected.log +0 -6
  55. package/compliance/tests/for_range_index_use/for_range_index_use.go +0 -11
  56. package/compliance/tests/for_range_index_use/for_range_index_use.gs.ts +0 -18
  57. package/compliance/tests/func_literal/expected.log +0 -1
  58. package/compliance/tests/func_literal/func_literal.go +0 -10
  59. package/compliance/tests/func_literal/func_literal.gs.ts +0 -15
  60. package/compliance/tests/function_call_result_assignment/expected.log +0 -2
  61. package/compliance/tests/function_call_result_assignment/function_call_result_assignment.go +0 -24
  62. package/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.ts +0 -31
  63. package/compliance/tests/if_statement/expected.log +0 -1
  64. package/compliance/tests/if_statement/if_statement.go +0 -11
  65. package/compliance/tests/if_statement/if_statement.gs.ts +0 -15
  66. package/compliance/tests/interface_to_interface_type_assertion/expected.log +0 -1
  67. package/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.go +0 -30
  68. package/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.ts +0 -41
  69. package/compliance/tests/interface_type_assertion/expected.log +0 -1
  70. package/compliance/tests/interface_type_assertion/interface_type_assertion.go +0 -26
  71. package/compliance/tests/interface_type_assertion/interface_type_assertion.gs.ts +0 -36
  72. package/compliance/tests/map_support/expected.log +0 -13
  73. package/compliance/tests/map_support/map_support.go +0 -89
  74. package/compliance/tests/map_support/map_support.gs.ts +0 -102
  75. package/compliance/tests/method_call_on_pointer_receiver/expected.log +0 -1
  76. package/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.go +0 -19
  77. package/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.ts +0 -27
  78. package/compliance/tests/method_call_on_pointer_via_value/expected.log +0 -1
  79. package/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.go +0 -29
  80. package/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.ts +0 -38
  81. package/compliance/tests/method_call_on_value_receiver/expected.log +0 -1
  82. package/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.go +0 -16
  83. package/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.ts +0 -24
  84. package/compliance/tests/method_call_on_value_via_pointer/expected.log +0 -2
  85. package/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.go +0 -30
  86. package/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.ts +0 -38
  87. package/compliance/tests/multiple_return_values/expected.log +0 -6
  88. package/compliance/tests/multiple_return_values/multiple_return_values.go +0 -19
  89. package/compliance/tests/multiple_return_values/multiple_return_values.gs.ts +0 -23
  90. package/compliance/tests/pointer_assignment_no_copy/expected.log +0 -2
  91. package/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.go +0 -28
  92. package/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.ts +0 -35
  93. package/compliance/tests/pointer_composite_literal_assignment/expected.log +0 -3
  94. package/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.go +0 -23
  95. package/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.ts +0 -30
  96. package/compliance/tests/pointer_deref_multiassign/expected.log +0 -0
  97. package/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.go +0 -17
  98. package/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.ts +0 -27
  99. package/compliance/tests/pointer_initialization/expected.log +0 -1
  100. package/compliance/tests/pointer_initialization/pointer_initialization.go +0 -16
  101. package/compliance/tests/pointer_initialization/pointer_initialization.gs.ts +0 -22
  102. package/compliance/tests/select_receive_on_closed_channel_no_default/expected.log +0 -1
  103. package/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.go +0 -15
  104. package/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.ts +0 -31
  105. package/compliance/tests/select_send_on_full_buffered_channel_with_default/expected.log +0 -1
  106. package/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.go +0 -13
  107. package/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.ts +0 -35
  108. package/compliance/tests/select_statement/expected.log +0 -9
  109. package/compliance/tests/select_statement/select_statement.go +0 -109
  110. package/compliance/tests/select_statement/select_statement.gs.ts +0 -239
  111. package/compliance/tests/simple/expected.log +0 -1
  112. package/compliance/tests/simple/simple.go +0 -5
  113. package/compliance/tests/simple/simple.gs.ts +0 -9
  114. package/compliance/tests/simple_deref_assignment/expected.log +0 -2
  115. package/compliance/tests/simple_deref_assignment/simple_deref_assignment.go +0 -19
  116. package/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.ts +0 -26
  117. package/compliance/tests/slices/expected.log +0 -7
  118. package/compliance/tests/slices/slices.go +0 -22
  119. package/compliance/tests/slices/slices.gs.ts +0 -26
  120. package/compliance/tests/string_rune_conversion/expected.log +0 -3
  121. package/compliance/tests/string_rune_conversion/string_rune_conversion.go +0 -16
  122. package/compliance/tests/string_rune_conversion/string_rune_conversion.gs.ts +0 -22
  123. package/compliance/tests/struct_field_access/expected.log +0 -2
  124. package/compliance/tests/struct_field_access/struct_field_access.go +0 -13
  125. package/compliance/tests/struct_field_access/struct_field_access.gs.ts +0 -20
  126. package/compliance/tests/struct_value_init_clone/expected.log +0 -5
  127. package/compliance/tests/struct_value_init_clone/struct_value_init_clone.go +0 -28
  128. package/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.ts +0 -35
  129. package/compliance/tests/switch_statement/expected.log +0 -14
  130. package/compliance/tests/switch_statement/switch_statement.go +0 -59
  131. package/compliance/tests/switch_statement/switch_statement.gs.ts +0 -85
  132. package/compliance/tests/value_type_copy_behavior/expected.log +0 -3
  133. package/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.go +0 -25
  134. package/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.ts +0 -34
  135. package/design/DESIGN.md +0 -599
  136. package/example/simple/build.bash +0 -10
  137. package/example/simple/go.mod +0 -23
  138. package/example/simple/go.sum +0 -39
  139. package/example/simple/main.go +0 -138
  140. package/example/simple/main.gs.ts +0 -133
  141. package/example/simple/main.ts +0 -3
  142. package/example/simple/main_test.go +0 -59
  143. package/example/simple/main_tools.go +0 -5
  144. package/example/simple/package.json +0 -7
  145. package/example/simple/run.bash +0 -6
  146. package/example/simple/tsconfig.json +0 -28
  147. package/example/simple/yarn.lock +0 -8
  148. package/output/output.go +0 -10
  149. package/tsconfig.json +0 -10
  150. package/types/tokens.go +0 -65
  151. package/types/types.go +0 -46
@@ -1,41 +0,0 @@
1
- // Generated file based on interface_to_interface_type_assertion.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- interface MyInterface
7
- {
8
- Method1(): number;
9
- }
10
-
11
- class MyStruct {
12
- public Value: number = 0;
13
-
14
- public Method1(): number {
15
- const m = this
16
- return m.Value
17
- }
18
-
19
- constructor(init?: Partial<MyStruct>) { if (init) Object.assign(this, init as any); }
20
- public clone(): MyStruct { return Object.assign(Object.create(MyStruct.prototype) as MyStruct, this); }
21
- }
22
-
23
- interface MyOtherInterface
24
- {
25
- Method1(): number;
26
- }
27
-
28
- export async function main(): Promise<void> {
29
- let i: MyInterface;
30
- let s = new MyStruct({ Value: 10 })
31
- i = s.clone()
32
-
33
- let ok: boolean = (i as any) satisfies MyOtherInterface
34
- let assertedValue: MyOtherInterface | null = ok ? (i as MyOtherInterface) : null
35
- if (ok) {
36
- console.log("Type assertion successful")
37
- } else {
38
- console.log("Type assertion failed")
39
- }
40
- }
41
-
@@ -1 +0,0 @@
1
- Type assertion successful
@@ -1,26 +0,0 @@
1
- package main
2
-
3
- type MyInterface interface {
4
- Method1() int
5
- }
6
-
7
- type MyStruct struct {
8
- Value int
9
- }
10
-
11
- func (m MyStruct) Method1() int {
12
- return m.Value
13
- }
14
-
15
- func main() {
16
- var i MyInterface
17
- s := MyStruct{Value: 10}
18
- i = s
19
-
20
- _, ok := i.(MyStruct)
21
- if ok {
22
- println("Type assertion successful")
23
- } else {
24
- println("Type assertion failed")
25
- }
26
- }
@@ -1,36 +0,0 @@
1
- // Generated file based on interface_type_assertion.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- interface MyInterface
7
- {
8
- Method1(): number;
9
- }
10
-
11
- class MyStruct {
12
- public Value: number = 0;
13
-
14
- public Method1(): number {
15
- const m = this
16
- return m.Value
17
- }
18
-
19
- constructor(init?: Partial<MyStruct>) { if (init) Object.assign(this, init as any); }
20
- public clone(): MyStruct { return Object.assign(Object.create(MyStruct.prototype) as MyStruct, this); }
21
- }
22
-
23
- export async function main(): Promise<void> {
24
- let i: MyInterface;
25
- let s = new MyStruct({ Value: 10 })
26
- i = s.clone()
27
-
28
- let ok: boolean = (i as any) satisfies MyStruct
29
- let assertedValue: MyStruct | null = ok ? (i as MyStruct) : null
30
- if (ok) {
31
- console.log("Type assertion successful")
32
- } else {
33
- console.log("Type assertion failed")
34
- }
35
- }
36
-
@@ -1,13 +0,0 @@
1
- Empty map created: Expected: true, Actual: true
2
- Map size after adding 3 items: Expected: 3, Actual: 3
3
- Alice's score: Expected: 90, Actual: 90
4
- Bob's score: Expected: 85, Actual: 85
5
- Bob's updated score: Expected: 88, Actual: 88
6
- Does David exist in map? Expected: false, Actual: false
7
- Value for non-existent key: Expected: 0, Actual: 0
8
- After delete, does Charlie exist? Expected: false, Actual: false
9
- Map literal size: Expected: 3, Actual: 3
10
- Color code for red: Expected: #ff0000, Actual: #ff0000
11
- Iterating over scores map:
12
- - Name: Alice Score: 90
13
- - Name: Bob Score: 88
@@ -1,89 +0,0 @@
1
- package main
2
-
3
- func main() {
4
- // Create map using make
5
- scores := make(map[string]int)
6
- println("Empty map created: Expected: true, Actual:", len(scores) == 0)
7
-
8
- // Add key-value pairs
9
- scores["Alice"] = 90
10
- scores["Bob"] = 85
11
- scores["Charlie"] = 92
12
-
13
- // Map size
14
- println("Map size after adding 3 items: Expected: 3, Actual:", len(scores))
15
-
16
- // Access values
17
- println("Alice's score: Expected: 90, Actual:", scores["Alice"])
18
- println("Bob's score: Expected: 85, Actual:", scores["Bob"])
19
-
20
- // Modify a value
21
- scores["Bob"] = 88
22
- println("Bob's updated score: Expected: 88, Actual:", scores["Bob"])
23
-
24
- // Check if key exists (comma-ok idiom)
25
- value, exists := scores["David"]
26
- println("Does David exist in map? Expected: false, Actual:", exists)
27
- println("Value for non-existent key: Expected: 0, Actual:", value)
28
-
29
- // Delete a key
30
- delete(scores, "Charlie")
31
- _, exists = scores["Charlie"]
32
- println("After delete, does Charlie exist? Expected: false, Actual:", exists)
33
-
34
- // Create map with literal syntax
35
- colors := map[string]string{
36
- "red": "#ff0000",
37
- "green": "#00ff00",
38
- "blue": "#0000ff",
39
- }
40
- println("Map literal size: Expected: 3, Actual:", len(colors))
41
- println("Color code for red: Expected: #ff0000, Actual:", colors["red"])
42
-
43
- // Iterate over a map with range
44
- println("Iterating over scores map:")
45
- // Note: Map iteration is not ordered in Go, so we will collect the results and sort them for consistent test output.
46
- var scoreResults []string
47
- for name, score := range scores {
48
- // Using string concatenation to build the output string
49
- result := " - Name: " + name + " Score: " + itoa(score)
50
- scoreResults = append(scoreResults, result)
51
- }
52
-
53
- // Inline bubble sort for string slice
54
- // (avoid importing sort package yet)
55
- n := len(scoreResults)
56
- for i := 0; i < n-1; i++ {
57
- for j := 0; j < n-i-1; j++ {
58
- if scoreResults[j] > scoreResults[j+1] {
59
- scoreResults[j], scoreResults[j+1] = scoreResults[j+1], scoreResults[j]
60
- }
61
- }
62
- }
63
-
64
- for _, result := range scoreResults {
65
- println(result)
66
- }
67
- }
68
-
69
- // Helper function to convert int to string
70
- // (avoid importing strings package)
71
- func itoa(i int) string {
72
- if i == 0 {
73
- return "0"
74
- }
75
- s := ""
76
- isNegative := false
77
- if i < 0 {
78
- isNegative = true
79
- i = -i
80
- }
81
- for i > 0 {
82
- s = string(rune(i%10+'0')) + s
83
- i /= 10
84
- }
85
- if isNegative {
86
- s = "-" + s
87
- }
88
- return s
89
- }
@@ -1,102 +0,0 @@
1
- // Generated file based on map_support.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- export async function main(): Promise<void> {
7
- // Create map using make
8
- let scores = goscript.makeMap("string", "int")
9
- console.log("Empty map created: Expected: true, Actual:", goscript.len(scores) == 0)
10
-
11
- // Add key-value pairs
12
- goscript.mapSet(scores, "Alice", 90)
13
- goscript.mapSet(scores, "Bob", 85)
14
- goscript.mapSet(scores, "Charlie", 92)
15
-
16
- // Map size
17
- console.log("Map size after adding 3 items: Expected: 3, Actual:", goscript.len(scores))
18
-
19
- // Access values
20
- console.log("Alice's score: Expected: 90, Actual:", scores.get("Alice"))
21
- console.log("Bob's score: Expected: 85, Actual:", scores.get("Bob"))
22
-
23
- // Modify a value
24
- goscript.mapSet(scores, "Bob", 88)
25
- console.log("Bob's updated score: Expected: 88, Actual:", scores.get("Bob"))
26
-
27
- // Check if key exists (comma-ok idiom)
28
- let value
29
- let exists
30
- exists = scores.has("David")
31
- value = scores.get("David") ?? 0
32
- console.log("Does David exist in map? Expected: false, Actual:", exists)
33
- console.log("Value for non-existent key: Expected: 0, Actual:", value)
34
-
35
- // Delete a key
36
- goscript.deleteMapEntry(scores, "Charlie")
37
- exists = scores.has("Charlie")
38
- console.log("After delete, does Charlie exist? Expected: false, Actual:", exists)
39
-
40
- // Create map with literal syntax
41
- let colors = new Map([["red", "#ff0000"], ["green", "#00ff00"], ["blue", "#0000ff"]])
42
- console.log("Map literal size: Expected: 3, Actual:", goscript.len(colors))
43
- console.log("Color code for red: Expected: #ff0000, Actual:", colors.get("red"))
44
-
45
- // Iterate over a map with range
46
- console.log("Iterating over scores map:")
47
- // Note: Map iteration is not ordered in Go, so we will collect the results and sort them for consistent test output.
48
- let scoreResults: string[] = [];
49
-
50
- // Using string concatenation to build the output string
51
- for (const [k, v] of scores.entries()) {
52
- const name = k
53
- const score = v
54
- {
55
- // Using string concatenation to build the output string
56
- let result = " - Name: " + name + " Score: " + itoa(score)
57
- scoreResults = goscript.append(scoreResults, result)
58
- }
59
- }
60
-
61
- // Inline bubble sort for string slice
62
- // (avoid importing sort package yet)
63
- let n = goscript.len(scoreResults)
64
- for (let i = 0; i < n - 1; i++) {
65
- for (let j = 0; j < n - i - 1; j++) {
66
- if (scoreResults[j] > scoreResults[j + 1]) {
67
- scoreResults[j] = scoreResults[j + 1]
68
- scoreResults[j + 1] = scoreResults[j]
69
- }
70
- }
71
- }
72
-
73
- for (let i = 0; i < scoreResults.length; i++) {
74
- const result = scoreResults[i]
75
- {
76
- console.log(result)
77
- }
78
- }
79
- }
80
-
81
- // Helper function to convert int to string
82
- // (avoid importing strings package)
83
- function itoa(i: number): string {
84
- if (i == 0) {
85
- return "0"
86
- }
87
- let s = ""
88
- let isNegative = false
89
- if (i < 0) {
90
- isNegative = true
91
- i = -i
92
- }
93
- for (; i > 0; ) {
94
- s = String.fromCharCode(i % 10 + 48) + s
95
- i = Math.floor(i / 10)
96
- }
97
- if (isNegative) {
98
- s = "-" + s
99
- }
100
- return s
101
- }
102
-
@@ -1 +0,0 @@
1
- Method call on pointer (structPointer): Expected: hello world, Actual: hello world
@@ -1,19 +0,0 @@
1
- package main
2
-
3
- type MyStruct struct {
4
- MyInt int
5
- MyString string
6
- myBool bool
7
- }
8
-
9
- // GetMyString returns the MyString field.
10
- func (m *MyStruct) GetMyString() string {
11
- return m.MyString
12
- }
13
-
14
- func main() {
15
- structPointer := &MyStruct{MyInt: 4, MyString: "hello world"}
16
- // === Method Call on Pointer Receiver ===
17
- // Calling a method with a pointer receiver (*MyStruct) using a pointer variable.
18
- println("Method call on pointer (structPointer): Expected: hello world, Actual: " + structPointer.GetMyString())
19
- }
@@ -1,27 +0,0 @@
1
- // Generated file based on method_call_on_pointer_receiver.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- class MyStruct {
7
- public MyInt: number = 0;
8
- public MyString: string = "";
9
- private myBool: boolean = false;
10
-
11
- // GetMyString returns the MyString field.
12
- public GetMyString(): string {
13
- const m = this
14
- return m.MyString
15
- }
16
-
17
- constructor(init?: Partial<MyStruct>) { if (init) Object.assign(this, init as any); }
18
- public clone(): MyStruct { return Object.assign(Object.create(MyStruct.prototype) as MyStruct, this); }
19
- }
20
-
21
- export async function main(): Promise<void> {
22
- let structPointer = new MyStruct({ MyInt: 4, MyString: "hello world" })
23
- // === Method Call on Pointer Receiver ===
24
- // Calling a method with a pointer receiver (*MyStruct) using a pointer variable.
25
- console.log("Method call on pointer (structPointer): Expected: hello world, Actual: " + structPointer.GetMyString())
26
- }
27
-
@@ -1 +0,0 @@
1
- Value after pointer method call via value: Expected: 200, Actual: 200
@@ -1,29 +0,0 @@
1
- package main
2
-
3
- type MyStruct struct {
4
- MyInt int
5
- }
6
-
7
- // SetValue sets the MyInt field (pointer receiver).
8
- func (m *MyStruct) SetValue(v int) {
9
- m.MyInt = v
10
- }
11
-
12
- // GetValue returns the MyInt field (value receiver for verification).
13
- func (m MyStruct) GetValue() int {
14
- return m.MyInt
15
- }
16
-
17
- func main() {
18
- // Create a struct value
19
- msValue := MyStruct{MyInt: 100}
20
-
21
- // === Method Call on Pointer Receiver via Value ===
22
- // Call the pointer-receiver method using the value variable.
23
- // Go implicitly takes the address of msValue (&msValue) to call SetValue.
24
- msValue.SetValue(200)
25
-
26
- // Verify the value was modified through the method call.
27
- // Expected: 200
28
- println("Value after pointer method call via value: Expected: 200, Actual:", msValue.GetValue())
29
- }
@@ -1,38 +0,0 @@
1
- // Generated file based on method_call_on_pointer_via_value.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- class MyStruct {
7
- public MyInt: number = 0;
8
-
9
- // SetValue sets the MyInt field (pointer receiver).
10
- public SetValue(v: number): void {
11
- const m = this
12
- m.MyInt = v
13
- }
14
-
15
- // GetValue returns the MyInt field (value receiver for verification).
16
- public GetValue(): number {
17
- const m = this
18
- return m.MyInt
19
- }
20
-
21
- constructor(init?: Partial<MyStruct>) { if (init) Object.assign(this, init as any); }
22
- public clone(): MyStruct { return Object.assign(Object.create(MyStruct.prototype) as MyStruct, this); }
23
- }
24
-
25
- export async function main(): Promise<void> {
26
- // Create a struct value
27
- let msValue = new MyStruct({ MyInt: 100 })
28
-
29
- // === Method Call on Pointer Receiver via Value ===
30
- // Call the pointer-receiver method using the value variable.
31
- // Go implicitly takes the address of msValue (&msValue) to call SetValue.
32
- msValue.SetValue(200)
33
-
34
- // Verify the value was modified through the method call.
35
- // Expected: 200
36
- console.log("Value after pointer method call via value: Expected: 200, Actual:", msValue.GetValue())
37
- }
38
-
@@ -1 +0,0 @@
1
- Method call on value: Expected: bar, Actual: bar
@@ -1,16 +0,0 @@
1
- package main
2
-
3
- type MyStruct struct {
4
- MyInt int
5
- MyString string
6
- }
7
-
8
- // GetMyString returns the MyString field.
9
- func (m MyStruct) GetMyString() string {
10
- return m.MyString
11
- }
12
-
13
- func main() {
14
- ms := MyStruct{MyInt: 1, MyString: "bar"}
15
- println("Method call on value: Expected: bar, Actual:", ms.GetMyString())
16
- }
@@ -1,24 +0,0 @@
1
- // Generated file based on method_call_on_value_receiver.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- class MyStruct {
7
- public MyInt: number = 0;
8
- public MyString: string = "";
9
-
10
- // GetMyString returns the MyString field.
11
- public GetMyString(): string {
12
- const m = this
13
- return m.MyString
14
- }
15
-
16
- constructor(init?: Partial<MyStruct>) { if (init) Object.assign(this, init as any); }
17
- public clone(): MyStruct { return Object.assign(Object.create(MyStruct.prototype) as MyStruct, this); }
18
- }
19
-
20
- export async function main(): Promise<void> {
21
- let ms = new MyStruct({ MyInt: 1, MyString: "bar" })
22
- console.log("Method call on value: Expected: bar, Actual:", ms.GetMyString())
23
- }
24
-
@@ -1,2 +0,0 @@
1
- Value via pointer call: Expected: 100, Actual: 100
2
- Value via pointer call after modification: Expected: 200, Actual: 200
@@ -1,30 +0,0 @@
1
- package main
2
-
3
- type MyStruct struct {
4
- MyInt int
5
- }
6
-
7
- // GetValue returns the MyInt field (value receiver).
8
- func (m MyStruct) GetValue() int {
9
- return m.MyInt
10
- }
11
-
12
- func main() {
13
- // Create a struct value
14
- msValue := MyStruct{MyInt: 100}
15
- // Create a pointer to the struct value
16
- msPointer := &msValue
17
-
18
- // === Method Call on Value Receiver via Pointer ===
19
- // Call the value-receiver method using the pointer variable.
20
- // Go implicitly dereferences msPointer to call GetValue on the value.
21
- // Expected: 100
22
- println("Value via pointer call: Expected: 100, Actual:", msPointer.GetValue())
23
-
24
- // Modify the value through the original value variable
25
- msValue.MyInt = 200
26
-
27
- // The pointer still points to the modified value
28
- // Expected: 200
29
- println("Value via pointer call after modification: Expected: 200, Actual:", msPointer.GetValue())
30
- }
@@ -1,38 +0,0 @@
1
- // Generated file based on method_call_on_value_via_pointer.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- class MyStruct {
7
- public MyInt: number = 0;
8
-
9
- // GetValue returns the MyInt field (value receiver).
10
- public GetValue(): number {
11
- const m = this
12
- return m.MyInt
13
- }
14
-
15
- constructor(init?: Partial<MyStruct>) { if (init) Object.assign(this, init as any); }
16
- public clone(): MyStruct { return Object.assign(Object.create(MyStruct.prototype) as MyStruct, this); }
17
- }
18
-
19
- export async function main(): Promise<void> {
20
- // Create a struct value
21
- let msValue = new MyStruct({ MyInt: 100 })
22
- // Create a pointer to the struct value
23
- let msPointer = msValue
24
-
25
- // === Method Call on Value Receiver via Pointer ===
26
- // Call the value-receiver method using the pointer variable.
27
- // Go implicitly dereferences msPointer to call GetValue on the value.
28
- // Expected: 100
29
- console.log("Value via pointer call: Expected: 100, Actual:", msPointer.GetValue())
30
-
31
- // Modify the value through the original value variable
32
- msValue.MyInt = 200
33
-
34
- // The pointer still points to the modified value
35
- // Expected: 200
36
- console.log("Value via pointer call after modification: Expected: 200, Actual:", msPointer.GetValue())
37
- }
38
-
@@ -1,6 +0,0 @@
1
- 42
2
- hello
3
- true
4
- 42
5
- true
6
- hello
@@ -1,19 +0,0 @@
1
- package main
2
-
3
- func multipleReturnValues() (int, string, bool) {
4
- return 42, "hello", true
5
- }
6
-
7
- func main() {
8
- a, b, c := multipleReturnValues()
9
- println(a)
10
- println(b)
11
- println(c)
12
-
13
- x, _, z := multipleReturnValues()
14
- println(x)
15
- println(z)
16
-
17
- _, y, _ := multipleReturnValues()
18
- println(y)
19
- }
@@ -1,23 +0,0 @@
1
- // Generated file based on multiple_return_values.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- function multipleReturnValues(): [number, string, boolean] {
7
- return [42, "hello", true]
8
- }
9
-
10
- export async function main(): Promise<void> {
11
- let [a, b, c] = multipleReturnValues()
12
- console.log(a)
13
- console.log(b)
14
- console.log(c)
15
-
16
- let [x, , z] = multipleReturnValues()
17
- console.log(x)
18
- console.log(z)
19
-
20
- let [, y, ] = multipleReturnValues()
21
- console.log(y)
22
- }
23
-
@@ -1,2 +0,0 @@
1
- Pointer copy value: Expected: modified original, Actual: modified original
2
- Original value after pointer copy modification: Expected: 20, Actual: 20
@@ -1,28 +0,0 @@
1
- package main
2
-
3
- type MyStruct struct {
4
- MyInt int
5
- MyString string
6
- }
7
-
8
- func main() {
9
- original := &MyStruct{MyInt: 10, MyString: "original"}
10
-
11
- // === Pointer Assignment (No Copy) ===
12
- // Assigning a pointer variable to another pointer variable.
13
- pointerCopy := original
14
-
15
- // Modify the struct through the original pointer.
16
- original.MyString = "modified original"
17
-
18
- // The change should be reflected when accessing through the copied pointer.
19
- // Expected: "modified original"
20
- println("Pointer copy value: Expected: modified original, Actual: " + pointerCopy.MyString)
21
-
22
- // Modify the struct through the copied pointer.
23
- pointerCopy.MyInt = 20
24
-
25
- // The change should be reflected when accessing through the original pointer.
26
- // Expected: 20
27
- println("Original value after pointer copy modification: Expected: 20, Actual:", original.MyInt)
28
- }
@@ -1,35 +0,0 @@
1
- // Generated file based on pointer_assignment_no_copy.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- class MyStruct {
7
- public MyInt: number = 0;
8
- public MyString: string = "";
9
-
10
- constructor(init?: Partial<MyStruct>) { if (init) Object.assign(this, init as any); }
11
- public clone(): MyStruct { return Object.assign(Object.create(MyStruct.prototype) as MyStruct, this); }
12
- }
13
-
14
- export async function main(): Promise<void> {
15
- let original = new MyStruct({ MyInt: 10, MyString: "original" })
16
-
17
- // === Pointer Assignment (No Copy) ===
18
- // Assigning a pointer variable to another pointer variable.
19
- let pointerCopy = original
20
-
21
- // Modify the struct through the original pointer.
22
- original.MyString = "modified original"
23
-
24
- // The change should be reflected when accessing through the copied pointer.
25
- // Expected: "modified original"
26
- console.log("Pointer copy value: Expected: modified original, Actual: " + pointerCopy.MyString)
27
-
28
- // Modify the struct through the copied pointer.
29
- pointerCopy.MyInt = 20
30
-
31
- // The change should be reflected when accessing through the original pointer.
32
- // Expected: 20
33
- console.log("Original value after pointer copy modification: Expected: 20, Actual:", original.MyInt)
34
- }
35
-