goscript 0.0.2

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 (160) hide show
  1. package/.aider-prompt +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +427 -0
  4. package/builtin/builtin.ts +507 -0
  5. package/cmd/goscript/cmd_compile.go +59 -0
  6. package/cmd/goscript/main.go +23 -0
  7. package/compiler/compile.go +183 -0
  8. package/compiler/compile_comment.go +41 -0
  9. package/compiler/compile_decls.go +72 -0
  10. package/compiler/compile_expr.go +831 -0
  11. package/compiler/compile_field.go +89 -0
  12. package/compiler/compile_spec.go +256 -0
  13. package/compiler/compile_stmt.go +1509 -0
  14. package/compiler/compiler.go +81 -0
  15. package/compiler/config.go +32 -0
  16. package/compiler/context.go +9 -0
  17. package/compiler/file_compiler.go +80 -0
  18. package/compiler/output_path.go +31 -0
  19. package/compiler/pkg_compiler.go +73 -0
  20. package/compiler/writer.go +90 -0
  21. package/compliance/COMPLIANCE.md +133 -0
  22. package/compliance/compliance.go +313 -0
  23. package/compliance/compliance_test.go +57 -0
  24. package/compliance/tests/array_literal/array_literal.go +15 -0
  25. package/compliance/tests/array_literal/array_literal.gs.ts +19 -0
  26. package/compliance/tests/array_literal/expected.log +3 -0
  27. package/compliance/tests/async_basic/async_basic.go +26 -0
  28. package/compliance/tests/async_basic/async_basic.gs.ts +30 -0
  29. package/compliance/tests/async_basic/expected.log +1 -0
  30. package/compliance/tests/basic_arithmetic/basic_arithmetic.go +15 -0
  31. package/compliance/tests/basic_arithmetic/basic_arithmetic.gs.ts +19 -0
  32. package/compliance/tests/basic_arithmetic/expected.log +5 -0
  33. package/compliance/tests/boolean_logic/boolean_logic.go +13 -0
  34. package/compliance/tests/boolean_logic/boolean_logic.gs.ts +17 -0
  35. package/compliance/tests/boolean_logic/expected.log +3 -0
  36. package/compliance/tests/channel_basic/channel_basic.go +12 -0
  37. package/compliance/tests/channel_basic/channel_basic.gs.ts +18 -0
  38. package/compliance/tests/channel_basic/expected.log +1 -0
  39. package/compliance/tests/composite_literal_assignment/composite_literal_assignment.go +20 -0
  40. package/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.ts +27 -0
  41. package/compliance/tests/composite_literal_assignment/expected.log +2 -0
  42. package/compliance/tests/constants/constants.go +18 -0
  43. package/compliance/tests/constants/constants.gs.ts +22 -0
  44. package/compliance/tests/constants/expected.log +3 -0
  45. package/compliance/tests/copy_independence/copy_independence.go +29 -0
  46. package/compliance/tests/copy_independence/copy_independence.gs.ts +36 -0
  47. package/compliance/tests/copy_independence/expected.log +4 -0
  48. package/compliance/tests/float64/expected.log +6 -0
  49. package/compliance/tests/float64/float64.go +28 -0
  50. package/compliance/tests/float64/float64.gs.ts +32 -0
  51. package/compliance/tests/for_loop_basic/expected.log +5 -0
  52. package/compliance/tests/for_loop_basic/for_loop_basic.go +9 -0
  53. package/compliance/tests/for_loop_basic/for_loop_basic.gs.ts +13 -0
  54. package/compliance/tests/for_loop_condition_only/expected.log +5 -0
  55. package/compliance/tests/for_loop_condition_only/main.go +9 -0
  56. package/compliance/tests/for_loop_condition_only/main.gs.ts +13 -0
  57. package/compliance/tests/for_range/expected.log +9 -0
  58. package/compliance/tests/for_range/for_range.go +26 -0
  59. package/compliance/tests/for_range/for_range.gs.ts +45 -0
  60. package/compliance/tests/for_range_index_use/expected.log +6 -0
  61. package/compliance/tests/for_range_index_use/for_range_index_use.go +11 -0
  62. package/compliance/tests/for_range_index_use/for_range_index_use.gs.ts +18 -0
  63. package/compliance/tests/func_literal/expected.log +1 -0
  64. package/compliance/tests/func_literal/func_literal.go +10 -0
  65. package/compliance/tests/func_literal/func_literal.gs.ts +15 -0
  66. package/compliance/tests/function_call_result_assignment/expected.log +2 -0
  67. package/compliance/tests/function_call_result_assignment/function_call_result_assignment.go +24 -0
  68. package/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.ts +31 -0
  69. package/compliance/tests/if_statement/expected.log +1 -0
  70. package/compliance/tests/if_statement/if_statement.go +11 -0
  71. package/compliance/tests/if_statement/if_statement.gs.ts +15 -0
  72. package/compliance/tests/interface_to_interface_type_assertion/expected.log +1 -0
  73. package/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.go +30 -0
  74. package/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.ts +41 -0
  75. package/compliance/tests/interface_type_assertion/expected.log +1 -0
  76. package/compliance/tests/interface_type_assertion/interface_type_assertion.go +26 -0
  77. package/compliance/tests/interface_type_assertion/interface_type_assertion.gs.ts +36 -0
  78. package/compliance/tests/map_support/expected.log +13 -0
  79. package/compliance/tests/map_support/map_support.go +89 -0
  80. package/compliance/tests/map_support/map_support.gs.ts +102 -0
  81. package/compliance/tests/method_call_on_pointer_receiver/expected.log +1 -0
  82. package/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.go +19 -0
  83. package/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.ts +27 -0
  84. package/compliance/tests/method_call_on_pointer_via_value/expected.log +1 -0
  85. package/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.go +29 -0
  86. package/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.ts +38 -0
  87. package/compliance/tests/method_call_on_value_receiver/expected.log +1 -0
  88. package/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.go +16 -0
  89. package/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.ts +24 -0
  90. package/compliance/tests/method_call_on_value_via_pointer/expected.log +2 -0
  91. package/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.go +30 -0
  92. package/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.ts +38 -0
  93. package/compliance/tests/multiple_return_values/expected.log +6 -0
  94. package/compliance/tests/multiple_return_values/multiple_return_values.go +19 -0
  95. package/compliance/tests/multiple_return_values/multiple_return_values.gs.ts +23 -0
  96. package/compliance/tests/pointer_assignment_no_copy/expected.log +2 -0
  97. package/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.go +28 -0
  98. package/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.ts +35 -0
  99. package/compliance/tests/pointer_composite_literal_assignment/expected.log +3 -0
  100. package/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.go +23 -0
  101. package/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.ts +30 -0
  102. package/compliance/tests/pointer_deref_multiassign/expected.log +0 -0
  103. package/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.go +17 -0
  104. package/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.ts +27 -0
  105. package/compliance/tests/pointer_initialization/expected.log +1 -0
  106. package/compliance/tests/pointer_initialization/pointer_initialization.go +16 -0
  107. package/compliance/tests/pointer_initialization/pointer_initialization.gs.ts +22 -0
  108. package/compliance/tests/select_receive_on_closed_channel_no_default/expected.log +1 -0
  109. package/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.go +15 -0
  110. package/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.ts +31 -0
  111. package/compliance/tests/select_send_on_full_buffered_channel_with_default/expected.log +1 -0
  112. package/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.go +13 -0
  113. package/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.ts +35 -0
  114. package/compliance/tests/select_statement/expected.log +9 -0
  115. package/compliance/tests/select_statement/select_statement.go +109 -0
  116. package/compliance/tests/select_statement/select_statement.gs.ts +239 -0
  117. package/compliance/tests/simple/expected.log +1 -0
  118. package/compliance/tests/simple/simple.go +5 -0
  119. package/compliance/tests/simple/simple.gs.ts +9 -0
  120. package/compliance/tests/simple_deref_assignment/expected.log +2 -0
  121. package/compliance/tests/simple_deref_assignment/simple_deref_assignment.go +19 -0
  122. package/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.ts +26 -0
  123. package/compliance/tests/slices/expected.log +7 -0
  124. package/compliance/tests/slices/slices.go +22 -0
  125. package/compliance/tests/slices/slices.gs.ts +26 -0
  126. package/compliance/tests/string_rune_conversion/expected.log +3 -0
  127. package/compliance/tests/string_rune_conversion/string_rune_conversion.go +16 -0
  128. package/compliance/tests/string_rune_conversion/string_rune_conversion.gs.ts +22 -0
  129. package/compliance/tests/struct_field_access/expected.log +2 -0
  130. package/compliance/tests/struct_field_access/struct_field_access.go +13 -0
  131. package/compliance/tests/struct_field_access/struct_field_access.gs.ts +20 -0
  132. package/compliance/tests/struct_value_init_clone/expected.log +5 -0
  133. package/compliance/tests/struct_value_init_clone/struct_value_init_clone.go +28 -0
  134. package/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.ts +35 -0
  135. package/compliance/tests/switch_statement/expected.log +14 -0
  136. package/compliance/tests/switch_statement/switch_statement.go +59 -0
  137. package/compliance/tests/switch_statement/switch_statement.gs.ts +85 -0
  138. package/compliance/tests/value_type_copy_behavior/expected.log +3 -0
  139. package/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.go +25 -0
  140. package/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.ts +34 -0
  141. package/design/DESIGN.md +599 -0
  142. package/example/simple/build.bash +10 -0
  143. package/example/simple/go.mod +23 -0
  144. package/example/simple/go.sum +39 -0
  145. package/example/simple/main.go +138 -0
  146. package/example/simple/main.gs.ts +133 -0
  147. package/example/simple/main.ts +3 -0
  148. package/example/simple/main_test.go +59 -0
  149. package/example/simple/main_tools.go +5 -0
  150. package/example/simple/package.json +7 -0
  151. package/example/simple/run.bash +6 -0
  152. package/example/simple/tsconfig.json +28 -0
  153. package/example/simple/yarn.lock +8 -0
  154. package/go.mod +22 -0
  155. package/go.sum +39 -0
  156. package/output/output.go +10 -0
  157. package/package.json +14 -0
  158. package/tsconfig.json +10 -0
  159. package/types/tokens.go +65 -0
  160. package/types/types.go +46 -0
@@ -0,0 +1,16 @@
1
+ package main
2
+
3
+ // MyStruct demonstrates a simple struct with public and private fields.
4
+ type MyStruct struct {
5
+ MyInt int
6
+ MyString string
7
+ myBool bool
8
+ }
9
+
10
+ func main() {
11
+ // === Pointer Initialization ===
12
+ // Create a pointer to a MyStruct instance using a composite literal.
13
+ structPointer := &MyStruct{MyInt: 4, MyString: "hello world"}
14
+ // Expected: "hello world"
15
+ println("Initial MyString (via pointer): Expected: hello world, Actual: " + structPointer.MyString)
16
+ }
@@ -0,0 +1,22 @@
1
+ // Generated file based on pointer_initialization.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
+ constructor(init?: Partial<MyStruct>) { if (init) Object.assign(this, init as any); }
12
+ public clone(): MyStruct { return Object.assign(Object.create(MyStruct.prototype) as MyStruct, this); }
13
+ }
14
+
15
+ export async function main(): Promise<void> {
16
+ // === Pointer Initialization ===
17
+ // Create a pointer to a MyStruct instance using a composite literal.
18
+ let structPointer = new MyStruct({ MyInt: 4, MyString: "hello world" })
19
+ // Expected: "hello world"
20
+ console.log("Initial MyString (via pointer): Expected: hello world, Actual: " + structPointer.MyString)
21
+ }
22
+
@@ -0,0 +1 @@
1
+ Received zero value with ok==false: 0
@@ -0,0 +1,15 @@
1
+ package main
2
+
3
+ func main() {
4
+ ch := make(chan int) // Unbuffered
5
+ close(ch)
6
+
7
+ select {
8
+ case val, ok := <-ch:
9
+ if ok {
10
+ println("Received value with ok==true:", val) // Should not be reached
11
+ } else {
12
+ println("Received zero value with ok==false:", val) // Should be reached
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,31 @@
1
+ // Generated file based on select_receive_on_closed_channel_no_default.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
+ let ch = goscript.makeChannel<number>(0, 0) // Unbuffered
8
+ ch.close()
9
+
10
+ // Should not be reached
11
+
12
+ // Should be reached
13
+ const _tempVar1: goscript.SelectCase<any>[] = []
14
+ _tempVar1.push({
15
+ id: 0,
16
+ isSend: false,
17
+ channel: ch,
18
+ onSelected: async (result) => {
19
+ const val = result.value
20
+ const ok = result.ok
21
+ if (ok) {
22
+ console.log("Received value with ok==true:", val) // Should not be reached
23
+ } else {
24
+ console.log("Received zero value with ok==false:", val) // Should be reached
25
+ }
26
+ }
27
+ }),
28
+
29
+ await goscript.selectStatement(_tempVar1, false)
30
+ }
31
+
@@ -0,0 +1,13 @@
1
+ package main
2
+
3
+ func main() {
4
+ ch := make(chan int, 1)
5
+ ch <- 1 // Fill the buffer
6
+
7
+ select {
8
+ case ch <- 2:
9
+ println("Sent value") // Should not be reached
10
+ default:
11
+ println("Default case hit") // Should be reached
12
+ }
13
+ }
@@ -0,0 +1,35 @@
1
+ // Generated file based on select_send_on_full_buffered_channel_with_default.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
+ let ch = goscript.makeChannel<number>(1, 0)
8
+ await ch.send(1)
9
+
10
+ // Should not be reached
11
+
12
+ // Should be reached
13
+ const _tempVar1: goscript.SelectCase<any>[] = []
14
+ _tempVar1.push({
15
+ id: 0,
16
+ isSend: true,
17
+ channel: ch,
18
+ value: 2,
19
+ onSelected: async (result) => {
20
+ console.log("Sent value")
21
+ }
22
+ }),
23
+
24
+ _tempVar1.push({
25
+ id: -1,
26
+ isSend: false,
27
+ channel: null,
28
+ onSelected: async (result) => {
29
+ console.log("Default case hit")
30
+ }
31
+ }),
32
+
33
+ await goscript.selectStatement(_tempVar1, true)
34
+ }
35
+
@@ -0,0 +1,9 @@
1
+ TEST1: Default case hit correctly
2
+ TEST2: Received expected value: hello
3
+ TEST3: Received buffered value with ok==true: 42
4
+ TEST4: Received zero value with ok==false: 0
5
+ TEST5: Sent value successfully
6
+ TEST6: Default hit correctly (channel full)
7
+ TEST7: Selected ch4 correctly: from ch4
8
+ TEST8: Selected ch5 correctly: from ch5
9
+ TEST9: Channel is closed, ok is false, val: false
@@ -0,0 +1,109 @@
1
+ package main
2
+
3
+ func main() {
4
+ // Test 1: Simple deterministic select with default
5
+ // Create a buffered channel so sends don't block
6
+ ch1 := make(chan string, 1)
7
+
8
+ // First test: empty channel, should hit default
9
+ select {
10
+ case msg := <-ch1:
11
+ println("TEST1: Received unexpected value:", msg)
12
+ default:
13
+ println("TEST1: Default case hit correctly")
14
+ }
15
+
16
+ // Now put something in the channel
17
+ ch1 <- "hello"
18
+
19
+ // Second test: should read from channel
20
+ select {
21
+ case msg := <-ch1:
22
+ println("TEST2: Received expected value:", msg)
23
+ default:
24
+ println("TEST2: Default case hit unexpectedly")
25
+ }
26
+
27
+ // Test 3: Select with channel closing and ok value
28
+ ch2 := make(chan int, 1)
29
+ ch2 <- 42
30
+ close(ch2)
31
+
32
+ // First receive gets the buffered value
33
+ select {
34
+ case val, ok := <-ch2:
35
+ if ok {
36
+ println("TEST3: Received buffered value with ok==true:", val)
37
+ } else {
38
+ println("TEST3: Unexpected ok==false")
39
+ }
40
+ default:
41
+ println("TEST3: Default hit unexpectedly")
42
+ }
43
+
44
+ // Second receive gets the zero value with ok==false
45
+ select {
46
+ case val, ok := <-ch2:
47
+ if ok {
48
+ println("TEST4: Unexpected ok==true:", val)
49
+ } else {
50
+ println("TEST4: Received zero value with ok==false:", val)
51
+ }
52
+ default:
53
+ println("TEST4: Default hit unexpectedly")
54
+ }
55
+
56
+ // Test 5: Send operations
57
+ ch3 := make(chan int, 1)
58
+
59
+ // First send should succeed (buffer not full)
60
+ select {
61
+ case ch3 <- 5:
62
+ println("TEST5: Sent value successfully")
63
+ default:
64
+ println("TEST5: Default hit unexpectedly")
65
+ }
66
+
67
+ // Second send should hit default (buffer full)
68
+ select {
69
+ case ch3 <- 10:
70
+ println("TEST6: Sent unexpectedly")
71
+ default:
72
+ println("TEST6: Default hit correctly (channel full)")
73
+ }
74
+
75
+ // Test 7: Multiple channel select (with known values)
76
+ ch4 := make(chan string, 1)
77
+ ch5 := make(chan string, 1)
78
+
79
+ ch4 <- "from ch4"
80
+
81
+ // Should select ch4 because it has data, ch5 is empty
82
+ select {
83
+ case msg := <-ch4:
84
+ println("TEST7: Selected ch4 correctly:", msg)
85
+ case msg := <-ch5:
86
+ println("TEST7: Selected ch5 unexpectedly:", msg)
87
+ }
88
+
89
+ // Now ch4 is empty and ch5 is empty
90
+ ch5 <- "from ch5"
91
+
92
+ // Should select ch5 because it has data, ch4 is empty
93
+ select {
94
+ case msg := <-ch4:
95
+ println("TEST8: Selected ch4 unexpectedly:", msg)
96
+ case msg := <-ch5:
97
+ println("TEST8: Selected ch5 correctly:", msg)
98
+ }
99
+
100
+ // Test 9: Channel closing test case for a separate test
101
+ chClose := make(chan bool)
102
+ close(chClose)
103
+ val, ok := <-chClose
104
+ if !ok {
105
+ println("TEST9: Channel is closed, ok is false, val:", val)
106
+ } else {
107
+ println("TEST9: Channel reports as not closed")
108
+ }
109
+ }
@@ -0,0 +1,239 @@
1
+ // Generated file based on select_statement.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
+ // Test 1: Simple deterministic select with default
8
+ // Create a buffered channel so sends don't block
9
+ let ch1 = goscript.makeChannel<string>(1, "")
10
+
11
+ // First test: empty channel, should hit default
12
+ const _tempVar1: goscript.SelectCase<any>[] = []
13
+ _tempVar1.push({
14
+ id: 0,
15
+ isSend: false,
16
+ channel: ch1,
17
+ onSelected: async (result) => {
18
+ const msg = result.value
19
+ console.log("TEST1: Received unexpected value:", msg)
20
+ }
21
+ }),
22
+
23
+ _tempVar1.push({
24
+ id: -1,
25
+ isSend: false,
26
+ channel: null,
27
+ onSelected: async (result) => {
28
+ console.log("TEST1: Default case hit correctly")
29
+ }
30
+ }),
31
+
32
+ await goscript.selectStatement(_tempVar1, true)
33
+
34
+ // Now put something in the channel
35
+ await ch1.send("hello")
36
+
37
+ // Second test: should read from channel
38
+ const _tempVar2: goscript.SelectCase<any>[] = []
39
+ _tempVar2.push({
40
+ id: 0,
41
+ isSend: false,
42
+ channel: ch1,
43
+ onSelected: async (result) => {
44
+ const msg = result.value
45
+ console.log("TEST2: Received expected value:", msg)
46
+ }
47
+ }),
48
+
49
+ _tempVar2.push({
50
+ id: -1,
51
+ isSend: false,
52
+ channel: null,
53
+ onSelected: async (result) => {
54
+ console.log("TEST2: Default case hit unexpectedly")
55
+ }
56
+ }),
57
+
58
+ await goscript.selectStatement(_tempVar2, true)
59
+
60
+ // Test 3: Select with channel closing and ok value
61
+ let ch2 = goscript.makeChannel<number>(1, 0)
62
+ await ch2.send(42)
63
+ ch2.close()
64
+
65
+ // First receive gets the buffered value
66
+ const _tempVar3: goscript.SelectCase<any>[] = []
67
+ _tempVar3.push({
68
+ id: 0,
69
+ isSend: false,
70
+ channel: ch2,
71
+ onSelected: async (result) => {
72
+ const val = result.value
73
+ const ok = result.ok
74
+ if (ok) {
75
+ console.log("TEST3: Received buffered value with ok==true:", val)
76
+ } else {
77
+ console.log("TEST3: Unexpected ok==false")
78
+ }
79
+ }
80
+ }),
81
+
82
+ _tempVar3.push({
83
+ id: -1,
84
+ isSend: false,
85
+ channel: null,
86
+ onSelected: async (result) => {
87
+ console.log("TEST3: Default hit unexpectedly")
88
+ }
89
+ }),
90
+
91
+ await goscript.selectStatement(_tempVar3, true)
92
+
93
+ // Second receive gets the zero value with ok==false
94
+ const _tempVar4: goscript.SelectCase<any>[] = []
95
+ _tempVar4.push({
96
+ id: 0,
97
+ isSend: false,
98
+ channel: ch2,
99
+ onSelected: async (result) => {
100
+ const val = result.value
101
+ const ok = result.ok
102
+ if (ok) {
103
+ console.log("TEST4: Unexpected ok==true:", val)
104
+ } else {
105
+ console.log("TEST4: Received zero value with ok==false:", val)
106
+ }
107
+ }
108
+ }),
109
+
110
+ _tempVar4.push({
111
+ id: -1,
112
+ isSend: false,
113
+ channel: null,
114
+ onSelected: async (result) => {
115
+ console.log("TEST4: Default hit unexpectedly")
116
+ }
117
+ }),
118
+
119
+ await goscript.selectStatement(_tempVar4, true)
120
+
121
+ // Test 5: Send operations
122
+ let ch3 = goscript.makeChannel<number>(1, 0)
123
+
124
+ // First send should succeed (buffer not full)
125
+ const _tempVar5: goscript.SelectCase<any>[] = []
126
+ _tempVar5.push({
127
+ id: 0,
128
+ isSend: true,
129
+ channel: ch3,
130
+ value: 5,
131
+ onSelected: async (result) => {
132
+ console.log("TEST5: Sent value successfully")
133
+ }
134
+ }),
135
+
136
+ _tempVar5.push({
137
+ id: -1,
138
+ isSend: false,
139
+ channel: null,
140
+ onSelected: async (result) => {
141
+ console.log("TEST5: Default hit unexpectedly")
142
+ }
143
+ }),
144
+
145
+ await goscript.selectStatement(_tempVar5, true)
146
+
147
+ // Second send should hit default (buffer full)
148
+ const _tempVar6: goscript.SelectCase<any>[] = []
149
+ _tempVar6.push({
150
+ id: 0,
151
+ isSend: true,
152
+ channel: ch3,
153
+ value: 10,
154
+ onSelected: async (result) => {
155
+ console.log("TEST6: Sent unexpectedly")
156
+ }
157
+ }),
158
+
159
+ _tempVar6.push({
160
+ id: -1,
161
+ isSend: false,
162
+ channel: null,
163
+ onSelected: async (result) => {
164
+ console.log("TEST6: Default hit correctly (channel full)")
165
+ }
166
+ }),
167
+
168
+ await goscript.selectStatement(_tempVar6, true)
169
+
170
+ // Test 7: Multiple channel select (with known values)
171
+ let ch4 = goscript.makeChannel<string>(1, "")
172
+ let ch5 = goscript.makeChannel<string>(1, "")
173
+
174
+ await ch4.send("from ch4")
175
+
176
+ // Should select ch4 because it has data, ch5 is empty
177
+ const _tempVar7: goscript.SelectCase<any>[] = []
178
+ _tempVar7.push({
179
+ id: 0,
180
+ isSend: false,
181
+ channel: ch4,
182
+ onSelected: async (result) => {
183
+ const msg = result.value
184
+ console.log("TEST7: Selected ch4 correctly:", msg)
185
+ }
186
+ }),
187
+
188
+ _tempVar7.push({
189
+ id: 1,
190
+ isSend: false,
191
+ channel: ch5,
192
+ onSelected: async (result) => {
193
+ const msg = result.value
194
+ console.log("TEST7: Selected ch5 unexpectedly:", msg)
195
+ }
196
+ }),
197
+
198
+ await goscript.selectStatement(_tempVar7, false)
199
+
200
+ // Now ch4 is empty and ch5 is empty
201
+ await ch5.send("from ch5")
202
+
203
+ // Should select ch5 because it has data, ch4 is empty
204
+ const _tempVar8: goscript.SelectCase<any>[] = []
205
+ _tempVar8.push({
206
+ id: 0,
207
+ isSend: false,
208
+ channel: ch4,
209
+ onSelected: async (result) => {
210
+ const msg = result.value
211
+ console.log("TEST8: Selected ch4 unexpectedly:", msg)
212
+ }
213
+ }),
214
+
215
+ _tempVar8.push({
216
+ id: 1,
217
+ isSend: false,
218
+ channel: ch5,
219
+ onSelected: async (result) => {
220
+ const msg = result.value
221
+ console.log("TEST8: Selected ch5 correctly:", msg)
222
+ }
223
+ }),
224
+
225
+ await goscript.selectStatement(_tempVar8, false)
226
+
227
+ // Test 9: Channel closing test case for a separate test
228
+ let chClose = goscript.makeChannel<boolean>(0, false)
229
+ chClose.close()
230
+ const _tempVar9 = await chClose.receiveWithOk()
231
+ let val = _tempVar9.value
232
+ let ok = _tempVar9.ok
233
+ if (!ok) {
234
+ console.log("TEST9: Channel is closed, ok is false, val:", val)
235
+ } else {
236
+ console.log("TEST9: Channel reports as not closed")
237
+ }
238
+ }
239
+
@@ -0,0 +1 @@
1
+ Hello world!
@@ -0,0 +1,5 @@
1
+ package main
2
+
3
+ func main() {
4
+ println("Hello world!")
5
+ }
@@ -0,0 +1,9 @@
1
+ // Generated file based on simple.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
+ console.log("Hello world!")
8
+ }
9
+
@@ -0,0 +1,2 @@
1
+ Original structPointer after modifying simpleDereferencedCopy: Expected: hello world, Actual: hello world
2
+ Simple Dereferenced Copy: Expected: modified dereferenced copy, Actual: modified dereferenced copy
@@ -0,0 +1,19 @@
1
+ package main
2
+
3
+ type MyStruct struct {
4
+ MyInt int
5
+ MyString string
6
+ myBool bool
7
+ }
8
+
9
+ func main() {
10
+ structPointer := &MyStruct{MyInt: 4, MyString: "hello world"}
11
+ // === Simple Dereference Assignment (Value Copy) ===
12
+ simpleDereferencedCopy := *structPointer
13
+ // Modifying the copy does not affect the original struct pointed to by structPointer.
14
+ simpleDereferencedCopy.MyString = "modified dereferenced copy"
15
+ // Expected: "hello world"
16
+ println("Original structPointer after modifying simpleDereferencedCopy: Expected: hello world, Actual: " + structPointer.MyString)
17
+ // Expected: "modified dereferenced copy"
18
+ println("Simple Dereferenced Copy: Expected: modified dereferenced copy, Actual: " + simpleDereferencedCopy.MyString)
19
+ }
@@ -0,0 +1,26 @@
1
+ // Generated file based on simple_deref_assignment.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
+ constructor(init?: Partial<MyStruct>) { if (init) Object.assign(this, init as any); }
12
+ public clone(): MyStruct { return Object.assign(Object.create(MyStruct.prototype) as MyStruct, this); }
13
+ }
14
+
15
+ export async function main(): Promise<void> {
16
+ let structPointer = new MyStruct({ MyInt: 4, MyString: "hello world" })
17
+ // === Simple Dereference Assignment (Value Copy) ===
18
+ let simpleDereferencedCopy = structPointer.clone()
19
+ // Modifying the copy does not affect the original struct pointed to by structPointer.
20
+ simpleDereferencedCopy.MyString = "modified dereferenced copy"
21
+ // Expected: "hello world"
22
+ console.log("Original structPointer after modifying simpleDereferencedCopy: Expected: hello world, Actual: " + structPointer.MyString)
23
+ // Expected: "modified dereferenced copy"
24
+ console.log("Simple Dereferenced Copy: Expected: modified dereferenced copy, Actual: " + simpleDereferencedCopy.MyString)
25
+ }
26
+
@@ -0,0 +1,7 @@
1
+ 5
2
+ 10
3
+ 3
4
+ 3
5
+ 10
6
+ 20
7
+ hello
@@ -0,0 +1,22 @@
1
+ package main
2
+
3
+ func main() {
4
+ // Create a slice of integers with length 5 and capacity 10
5
+ s := make([]int, 5, 10)
6
+ println(len(s))
7
+ println(cap(s))
8
+
9
+ // Create a slice of strings with length 3
10
+ s2 := make([]string, 3)
11
+ println(len(s2))
12
+ println(cap(s2))
13
+
14
+ // Assign values
15
+ s[0] = 10
16
+ s[4] = 20
17
+ s2[1] = "hello"
18
+
19
+ println(s[0])
20
+ println(s[4])
21
+ println(s2[1])
22
+ }
@@ -0,0 +1,26 @@
1
+ // Generated file based on slices.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 a slice of integers with length 5 and capacity 10
8
+ let s = goscript.makeSlice("int", 5, 10)
9
+ console.log(goscript.len(s))
10
+ console.log(goscript.cap(s))
11
+
12
+ // Create a slice of strings with length 3
13
+ let s2 = goscript.makeSlice("string", 3)
14
+ console.log(goscript.len(s2))
15
+ console.log(goscript.cap(s2))
16
+
17
+ // Assign values
18
+ s[0] = 10
19
+ s[4] = 20
20
+ s2[1] = "hello"
21
+
22
+ console.log(s[0])
23
+ console.log(s[4])
24
+ console.log(s2[1])
25
+ }
26
+
@@ -0,0 +1,16 @@
1
+ package main
2
+
3
+ func main() {
4
+ // === string(rune) Conversion ===
5
+ var r rune = 'A'
6
+ s := string(r)
7
+ println(s)
8
+
9
+ var r2 rune = 97 // 'a'
10
+ s2 := string(r2)
11
+ println(s2)
12
+
13
+ var r3 rune = 0x20AC // '€'
14
+ s3 := string(r3)
15
+ println(s3)
16
+ }
@@ -0,0 +1,22 @@
1
+ // Generated file based on string_rune_conversion.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
+ // === string(rune) Conversion ===
8
+ let r: number = 65;
9
+ let s = String.fromCharCode(r)
10
+ console.log(s)
11
+
12
+ // 'a'
13
+ let r2: number = 97;
14
+ let s2 = String.fromCharCode(r2)
15
+ console.log(s2)
16
+
17
+ // '€'
18
+ let r3: number = 0x20AC;
19
+ let s3 = String.fromCharCode(r3)
20
+ console.log(s3)
21
+ }
22
+
@@ -0,0 +1,2 @@
1
+ MyInt: Expected: 42, Actual: 42
2
+ MyString: Expected: foo, Actual: foo