goscript 0.0.2 → 0.0.3

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 (150) hide show
  1. package/README.md +41 -0
  2. package/builtin/builtin.ts +368 -348
  3. package/compiler/compile_expr.go +3 -37
  4. package/compiler/index.test.ts +29 -0
  5. package/compiler/index.ts +85 -0
  6. package/dist/builtin/builtin.d.ts +168 -0
  7. package/dist/builtin/builtin.js +372 -0
  8. package/dist/builtin/builtin.js.map +1 -0
  9. package/dist/compiler/index.d.ts +26 -0
  10. package/dist/compiler/index.js +64 -0
  11. package/dist/compiler/index.js.map +1 -0
  12. package/package.json +68 -3
  13. package/.aider-prompt +0 -11
  14. package/compliance/COMPLIANCE.md +0 -133
  15. package/compliance/compliance.go +0 -313
  16. package/compliance/compliance_test.go +0 -57
  17. package/compliance/tests/array_literal/array_literal.go +0 -15
  18. package/compliance/tests/array_literal/array_literal.gs.ts +0 -19
  19. package/compliance/tests/array_literal/expected.log +0 -3
  20. package/compliance/tests/async_basic/async_basic.go +0 -26
  21. package/compliance/tests/async_basic/async_basic.gs.ts +0 -30
  22. package/compliance/tests/async_basic/expected.log +0 -1
  23. package/compliance/tests/basic_arithmetic/basic_arithmetic.go +0 -15
  24. package/compliance/tests/basic_arithmetic/basic_arithmetic.gs.ts +0 -19
  25. package/compliance/tests/basic_arithmetic/expected.log +0 -5
  26. package/compliance/tests/boolean_logic/boolean_logic.go +0 -13
  27. package/compliance/tests/boolean_logic/boolean_logic.gs.ts +0 -17
  28. package/compliance/tests/boolean_logic/expected.log +0 -3
  29. package/compliance/tests/channel_basic/channel_basic.go +0 -12
  30. package/compliance/tests/channel_basic/channel_basic.gs.ts +0 -18
  31. package/compliance/tests/channel_basic/expected.log +0 -1
  32. package/compliance/tests/composite_literal_assignment/composite_literal_assignment.go +0 -20
  33. package/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.ts +0 -27
  34. package/compliance/tests/composite_literal_assignment/expected.log +0 -2
  35. package/compliance/tests/constants/constants.go +0 -18
  36. package/compliance/tests/constants/constants.gs.ts +0 -22
  37. package/compliance/tests/constants/expected.log +0 -3
  38. package/compliance/tests/copy_independence/copy_independence.go +0 -29
  39. package/compliance/tests/copy_independence/copy_independence.gs.ts +0 -36
  40. package/compliance/tests/copy_independence/expected.log +0 -4
  41. package/compliance/tests/float64/expected.log +0 -6
  42. package/compliance/tests/float64/float64.go +0 -28
  43. package/compliance/tests/float64/float64.gs.ts +0 -32
  44. package/compliance/tests/for_loop_basic/expected.log +0 -5
  45. package/compliance/tests/for_loop_basic/for_loop_basic.go +0 -9
  46. package/compliance/tests/for_loop_basic/for_loop_basic.gs.ts +0 -13
  47. package/compliance/tests/for_loop_condition_only/expected.log +0 -5
  48. package/compliance/tests/for_loop_condition_only/main.go +0 -9
  49. package/compliance/tests/for_loop_condition_only/main.gs.ts +0 -13
  50. package/compliance/tests/for_range/expected.log +0 -9
  51. package/compliance/tests/for_range/for_range.go +0 -26
  52. package/compliance/tests/for_range/for_range.gs.ts +0 -45
  53. package/compliance/tests/for_range_index_use/expected.log +0 -6
  54. package/compliance/tests/for_range_index_use/for_range_index_use.go +0 -11
  55. package/compliance/tests/for_range_index_use/for_range_index_use.gs.ts +0 -18
  56. package/compliance/tests/func_literal/expected.log +0 -1
  57. package/compliance/tests/func_literal/func_literal.go +0 -10
  58. package/compliance/tests/func_literal/func_literal.gs.ts +0 -15
  59. package/compliance/tests/function_call_result_assignment/expected.log +0 -2
  60. package/compliance/tests/function_call_result_assignment/function_call_result_assignment.go +0 -24
  61. package/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.ts +0 -31
  62. package/compliance/tests/if_statement/expected.log +0 -1
  63. package/compliance/tests/if_statement/if_statement.go +0 -11
  64. package/compliance/tests/if_statement/if_statement.gs.ts +0 -15
  65. package/compliance/tests/interface_to_interface_type_assertion/expected.log +0 -1
  66. package/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.go +0 -30
  67. package/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.ts +0 -41
  68. package/compliance/tests/interface_type_assertion/expected.log +0 -1
  69. package/compliance/tests/interface_type_assertion/interface_type_assertion.go +0 -26
  70. package/compliance/tests/interface_type_assertion/interface_type_assertion.gs.ts +0 -36
  71. package/compliance/tests/map_support/expected.log +0 -13
  72. package/compliance/tests/map_support/map_support.go +0 -89
  73. package/compliance/tests/map_support/map_support.gs.ts +0 -102
  74. package/compliance/tests/method_call_on_pointer_receiver/expected.log +0 -1
  75. package/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.go +0 -19
  76. package/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.ts +0 -27
  77. package/compliance/tests/method_call_on_pointer_via_value/expected.log +0 -1
  78. package/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.go +0 -29
  79. package/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.ts +0 -38
  80. package/compliance/tests/method_call_on_value_receiver/expected.log +0 -1
  81. package/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.go +0 -16
  82. package/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.ts +0 -24
  83. package/compliance/tests/method_call_on_value_via_pointer/expected.log +0 -2
  84. package/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.go +0 -30
  85. package/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.ts +0 -38
  86. package/compliance/tests/multiple_return_values/expected.log +0 -6
  87. package/compliance/tests/multiple_return_values/multiple_return_values.go +0 -19
  88. package/compliance/tests/multiple_return_values/multiple_return_values.gs.ts +0 -23
  89. package/compliance/tests/pointer_assignment_no_copy/expected.log +0 -2
  90. package/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.go +0 -28
  91. package/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.ts +0 -35
  92. package/compliance/tests/pointer_composite_literal_assignment/expected.log +0 -3
  93. package/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.go +0 -23
  94. package/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.ts +0 -30
  95. package/compliance/tests/pointer_deref_multiassign/expected.log +0 -0
  96. package/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.go +0 -17
  97. package/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.ts +0 -27
  98. package/compliance/tests/pointer_initialization/expected.log +0 -1
  99. package/compliance/tests/pointer_initialization/pointer_initialization.go +0 -16
  100. package/compliance/tests/pointer_initialization/pointer_initialization.gs.ts +0 -22
  101. package/compliance/tests/select_receive_on_closed_channel_no_default/expected.log +0 -1
  102. package/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.go +0 -15
  103. package/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.ts +0 -31
  104. package/compliance/tests/select_send_on_full_buffered_channel_with_default/expected.log +0 -1
  105. package/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.go +0 -13
  106. package/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.ts +0 -35
  107. package/compliance/tests/select_statement/expected.log +0 -9
  108. package/compliance/tests/select_statement/select_statement.go +0 -109
  109. package/compliance/tests/select_statement/select_statement.gs.ts +0 -239
  110. package/compliance/tests/simple/expected.log +0 -1
  111. package/compliance/tests/simple/simple.go +0 -5
  112. package/compliance/tests/simple/simple.gs.ts +0 -9
  113. package/compliance/tests/simple_deref_assignment/expected.log +0 -2
  114. package/compliance/tests/simple_deref_assignment/simple_deref_assignment.go +0 -19
  115. package/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.ts +0 -26
  116. package/compliance/tests/slices/expected.log +0 -7
  117. package/compliance/tests/slices/slices.go +0 -22
  118. package/compliance/tests/slices/slices.gs.ts +0 -26
  119. package/compliance/tests/string_rune_conversion/expected.log +0 -3
  120. package/compliance/tests/string_rune_conversion/string_rune_conversion.go +0 -16
  121. package/compliance/tests/string_rune_conversion/string_rune_conversion.gs.ts +0 -22
  122. package/compliance/tests/struct_field_access/expected.log +0 -2
  123. package/compliance/tests/struct_field_access/struct_field_access.go +0 -13
  124. package/compliance/tests/struct_field_access/struct_field_access.gs.ts +0 -20
  125. package/compliance/tests/struct_value_init_clone/expected.log +0 -5
  126. package/compliance/tests/struct_value_init_clone/struct_value_init_clone.go +0 -28
  127. package/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.ts +0 -35
  128. package/compliance/tests/switch_statement/expected.log +0 -14
  129. package/compliance/tests/switch_statement/switch_statement.go +0 -59
  130. package/compliance/tests/switch_statement/switch_statement.gs.ts +0 -85
  131. package/compliance/tests/value_type_copy_behavior/expected.log +0 -3
  132. package/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.go +0 -25
  133. package/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.ts +0 -34
  134. package/design/DESIGN.md +0 -599
  135. package/example/simple/build.bash +0 -10
  136. package/example/simple/go.mod +0 -23
  137. package/example/simple/go.sum +0 -39
  138. package/example/simple/main.go +0 -138
  139. package/example/simple/main.gs.ts +0 -133
  140. package/example/simple/main.ts +0 -3
  141. package/example/simple/main_test.go +0 -59
  142. package/example/simple/main_tools.go +0 -5
  143. package/example/simple/package.json +0 -7
  144. package/example/simple/run.bash +0 -6
  145. package/example/simple/tsconfig.json +0 -28
  146. package/example/simple/yarn.lock +0 -8
  147. package/output/output.go +0 -10
  148. package/tsconfig.json +0 -10
  149. package/types/tokens.go +0 -65
  150. package/types/types.go +0 -46
@@ -1,3 +0,0 @@
1
- AND: Expected: false, Actual: false
2
- OR: Expected: true, Actual: true
3
- NOT: Expected: false, Actual: false
@@ -1,12 +0,0 @@
1
- package main
2
-
3
- func main() {
4
- messages := make(chan string)
5
-
6
- go func() {
7
- messages <- "ping"
8
- }()
9
-
10
- msg := <-messages
11
- println(msg)
12
- }
@@ -1,18 +0,0 @@
1
- // Generated file based on channel_basic.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 messages = goscript.makeChannel<string>(0)
8
-
9
- queueMicrotask(async () => {
10
- {
11
- await messages.send("ping")
12
- }
13
- })
14
-
15
- let msg = await messages.receive()
16
- console.log(msg)
17
- }
18
-
@@ -1 +0,0 @@
1
- ping
@@ -1,20 +0,0 @@
1
- package main
2
-
3
- type MyStruct struct {
4
- MyInt int
5
- MyString string
6
- myBool bool
7
- }
8
-
9
- func main() {
10
- // === Composite Literal Assignment (Value Copy) ===
11
- // Creating a struct directly using a composite literal.
12
- structLiteral := MyStruct{MyString: "composite literal"}
13
- // Assigning it creates another independent copy.
14
- structLiteralCopy := structLiteral
15
- structLiteralCopy.MyString = "modified composite literal copy"
16
- // Expected: "composite literal"
17
- println("Original struct literal: Expected: composite literal, Actual: " + structLiteral.MyString)
18
- // Expected: "modified composite literal copy"
19
- println("Modified struct literal copy: Expected: modified composite literal copy, Actual: " + structLiteralCopy.MyString)
20
- }
@@ -1,27 +0,0 @@
1
- // Generated file based on composite_literal_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
- // === Composite Literal Assignment (Value Copy) ===
17
- // Creating a struct directly using a composite literal.
18
- let structLiteral = new MyStruct({ MyString: "composite literal" })
19
- // Assigning it creates another independent copy.
20
- let structLiteralCopy = structLiteral.clone()
21
- structLiteralCopy.MyString = "modified composite literal copy"
22
- // Expected: "composite literal"
23
- console.log("Original struct literal: Expected: composite literal, Actual: " + structLiteral.MyString)
24
- // Expected: "modified composite literal copy"
25
- console.log("Modified struct literal copy: Expected: modified composite literal copy, Actual: " + structLiteralCopy.MyString)
26
- }
27
-
@@ -1,2 +0,0 @@
1
- Original struct literal: Expected: composite literal, Actual: composite literal
2
- Modified struct literal copy: Expected: modified composite literal copy, Actual: modified composite literal copy
@@ -1,18 +0,0 @@
1
- package main
2
-
3
- const (
4
- Pi = 3.14
5
- Truth = false
6
- // TODO: Handle large integer constants and bit shifts exceeding JS number limits.
7
- // Big = 1 << 60
8
- // Small = Big >> 59 // Commented out as it depends on Big
9
- Greeting = "Hello, Constants!"
10
- )
11
-
12
- func main() {
13
- println(Pi)
14
- println(Truth)
15
- // println(Big) // Commented out until large integer handling is implemented
16
- // println(Small) // Commented out as it depends on Big
17
- println(Greeting)
18
- }
@@ -1,22 +0,0 @@
1
- // Generated file based on constants.go
2
- // Updated when compliance tests are re-run, DO NOT EDIT!
3
-
4
- import * as goscript from "@go/builtin";
5
-
6
- let Pi = 3.14;
7
-
8
- let Truth = false;
9
-
10
- // TODO: Handle large integer constants and bit shifts exceeding JS number limits.
11
- // Big = 1 << 60
12
- // Small = Big >> 59 // Commented out as it depends on Big
13
- let Greeting = "Hello, Constants!";
14
-
15
- export async function main(): Promise<void> {
16
- console.log(Pi)
17
- console.log(Truth)
18
- // println(Big) // Commented out until large integer handling is implemented
19
- // println(Small) // Commented out as it depends on Big
20
- console.log(Greeting)
21
- }
22
-
@@ -1,3 +0,0 @@
1
- 3.14
2
- false
3
- Hello, Constants!
@@ -1,29 +0,0 @@
1
- package main
2
-
3
- type MyStruct struct {
4
- MyInt int
5
- MyString string
6
- myBool bool
7
- }
8
-
9
- func main() {
10
- // Setup from previous steps (simplified for this test)
11
- structPointer := &MyStruct{MyInt: 4, MyString: "hello world"}
12
- dereferencedStructCopy := *structPointer
13
- dereferencedStructCopy.MyString = "original dereferenced copy modified"
14
- valueCopy1 := dereferencedStructCopy
15
- valueCopy1.MyString = "value copy 1"
16
- valueCopy2 := dereferencedStructCopy
17
- valueCopy2.MyString = "value copy 2"
18
- pointerCopy := structPointer
19
-
20
- // === Verifying Copy Independence ===
21
- // Expected: "hello world"
22
- println("pointerCopy (points to original structPointer): Expected: hello world, Actual: " + pointerCopy.MyString)
23
- // Expected: "original dereferenced copy modified"
24
- println("dereferencedStructCopy (modified after copies were made): Expected: original dereferenced copy modified, Actual: " + dereferencedStructCopy.MyString)
25
- // Expected: "value copy 1"
26
- println("valueCopy1: Expected: value copy 1, Actual: " + valueCopy1.MyString)
27
- // Expected: "value copy 2"
28
- println("valueCopy2: Expected: value copy 2, Actual: " + valueCopy2.MyString)
29
- }
@@ -1,36 +0,0 @@
1
- // Generated file based on copy_independence.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
- // Setup from previous steps (simplified for this test)
17
- let structPointer = new MyStruct({ MyInt: 4, MyString: "hello world" })
18
- let dereferencedStructCopy = structPointer.clone()
19
- dereferencedStructCopy.MyString = "original dereferenced copy modified"
20
- let valueCopy1 = dereferencedStructCopy.clone()
21
- valueCopy1.MyString = "value copy 1"
22
- let valueCopy2 = dereferencedStructCopy.clone()
23
- valueCopy2.MyString = "value copy 2"
24
- let pointerCopy = structPointer
25
-
26
- // === Verifying Copy Independence ===
27
- // Expected: "hello world"
28
- console.log("pointerCopy (points to original structPointer): Expected: hello world, Actual: " + pointerCopy.MyString)
29
- // Expected: "original dereferenced copy modified"
30
- console.log("dereferencedStructCopy (modified after copies were made): Expected: original dereferenced copy modified, Actual: " + dereferencedStructCopy.MyString)
31
- // Expected: "value copy 1"
32
- console.log("valueCopy1: Expected: value copy 1, Actual: " + valueCopy1.MyString)
33
- // Expected: "value copy 2"
34
- console.log("valueCopy2: Expected: value copy 2, Actual: " + valueCopy2.MyString)
35
- }
36
-
@@ -1,4 +0,0 @@
1
- pointerCopy (points to original structPointer): Expected: hello world, Actual: hello world
2
- dereferencedStructCopy (modified after copies were made): Expected: original dereferenced copy modified, Actual: original dereferenced copy modified
3
- valueCopy1: Expected: value copy 1, Actual: value copy 1
4
- valueCopy2: Expected: value copy 2, Actual: value copy 2
@@ -1,6 +0,0 @@
1
- a + b = 5.789999999999999
2
- a - b = -3.3299999999999996
3
- a * b = 5.6088
4
- a / b = 0.26973684210526316
5
- c = 7.89
6
- (a + b) * (c - d) / a = 0
@@ -1,28 +0,0 @@
1
- package main
2
-
3
- func main() {
4
- var a float64 = 1.23
5
- b := 4.56
6
- var c float64
7
-
8
- c = a + b
9
- println("a + b =", c)
10
-
11
- c = a - b
12
- println("a - b =", c)
13
-
14
- c = a * b
15
- println("a * b =", c)
16
-
17
- c = a / b
18
- println("a / b =", c)
19
-
20
- // Assignment
21
- d := 7.89
22
- c = d
23
- println("c =", c)
24
-
25
- // More complex expression
26
- e := (a + b) * (c - d) / a
27
- println("(a + b) * (c - d) / a =", e)
28
- }
@@ -1,32 +0,0 @@
1
- // Generated file based on float64.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 a: number = 1.23;
8
- let b = 4.56
9
- let c: number;
10
-
11
- c = a + b
12
- console.log("a + b =", c)
13
-
14
- c = a - b
15
- console.log("a - b =", c)
16
-
17
- c = a * b
18
- console.log("a * b =", c)
19
-
20
- c = a / b
21
- console.log("a / b =", c)
22
-
23
- // Assignment
24
- let d = 7.89
25
- c = d
26
- console.log("c =", c)
27
-
28
- // More complex expression
29
- let e = (a + b) * (c - d) / a
30
- console.log("(a + b) * (c - d) / a =", e)
31
- }
32
-
@@ -1,5 +0,0 @@
1
- Starting loop
2
- Iteration: 0
3
- Iteration: 1
4
- Iteration: 2
5
- Loop finished
@@ -1,9 +0,0 @@
1
- package main
2
-
3
- func main() {
4
- println("Starting loop")
5
- for i := 0; i < 3; i++ {
6
- println("Iteration:", i)
7
- }
8
- println("Loop finished")
9
- }
@@ -1,13 +0,0 @@
1
- // Generated file based on for_loop_basic.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("Starting loop")
8
- for (let i = 0; i < 3; i++) {
9
- console.log("Iteration:", i)
10
- }
11
- console.log("Loop finished")
12
- }
13
-
@@ -1,9 +0,0 @@
1
- package main
2
-
3
- func main() {
4
- i := 0
5
- for i < 5 {
6
- println(i)
7
- i++
8
- }
9
- }
@@ -1,13 +0,0 @@
1
- // Generated file based on main.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 i = 0
8
- for (; i < 5; ) {
9
- console.log(i)
10
- i++
11
- }
12
- }
13
-
@@ -1,9 +0,0 @@
1
- sum: 9
2
- index: 0 value: 2
3
- index: 1 value: 3
4
- index: 2 value: 4
5
- index: 0 value: a
6
- index: 1 value: b
7
- index: 2 value: c
8
- index: 0 value: 103
9
- index: 1 value: 111
@@ -1,26 +0,0 @@
1
- package main
2
-
3
- func main() {
4
- nums := []int{2, 3, 4}
5
- sum := 0
6
- for _, num := range nums {
7
- sum += num
8
- }
9
- println("sum:", sum)
10
-
11
- for i, num := range nums {
12
- println("index:", i, "value:", num)
13
- }
14
-
15
- // Test ranging over an array
16
- arr := [3]string{"a", "b", "c"}
17
- for i, s := range arr {
18
- println("index:", i, "value:", s)
19
- }
20
-
21
- // Test ranging over a string
22
- str := "go"
23
- for i, c := range str {
24
- println("index:", i, "value:", c) // Note: c will be a rune (int32)
25
- }
26
- }
@@ -1,45 +0,0 @@
1
- // Generated file based on for_range.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 nums = [2, 3, 4]
8
- let sum = 0
9
- for (let i = 0; i < nums.length; i++) {
10
- const num = nums[i]
11
- {
12
- sum += num
13
- }
14
- }
15
- console.log("sum:", sum)
16
-
17
- for (let i = 0; i < nums.length; i++) {
18
- const num = nums[i]
19
- {
20
- console.log("index:", i, "value:", num)
21
- }
22
- }
23
-
24
- // Test ranging over an array
25
- let arr = ["a", "b", "c"]
26
- for (let i = 0; i < arr.length; i++) {
27
- const s = arr[i]
28
- {
29
- console.log("index:", i, "value:", s)
30
- }
31
- }
32
-
33
- // Test ranging over a string
34
- let str = "go"
35
-
36
- // Note: c will be a rune (int32)
37
- const _runes = goscript.stringToRunes(str)
38
- for (let i = 0; i < _runes.length; i++) {
39
- const c = _runes[i]
40
- {
41
- console.log("index:", i, "value:", c) // Note: c will be a rune (int32)
42
- }
43
- }
44
- }
45
-
@@ -1,6 +0,0 @@
1
- Range idx: 0 val: 10
2
- Range idx: 1 val: 20
3
- Range idx: 2 val: 30
4
- Range idx: 3 val: 40
5
- Range idx: 4 val: 50
6
- Sum: 150
@@ -1,11 +0,0 @@
1
- package main
2
-
3
- func main() {
4
- slice := []int{10, 20, 30, 40, 50}
5
- sum := 0
6
- for idx, val := range slice {
7
- sum += val
8
- println("Range idx:", idx, "val:", val)
9
- }
10
- println("Sum:", sum)
11
- }
@@ -1,18 +0,0 @@
1
- // Generated file based on for_range_index_use.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 slice = [10, 20, 30, 40, 50]
8
- let sum = 0
9
- for (let idx = 0; idx < slice.length; idx++) {
10
- const val = slice[idx]
11
- {
12
- sum += val
13
- console.log("Range idx:", idx, "val:", val)
14
- }
15
- }
16
- console.log("Sum:", sum)
17
- }
18
-
@@ -1 +0,0 @@
1
- Hello, world
@@ -1,10 +0,0 @@
1
- package main
2
-
3
- func main() {
4
- greet := func(name string) string {
5
- return "Hello, " + name
6
- }
7
-
8
- message := greet("world")
9
- println(message)
10
- }
@@ -1,15 +0,0 @@
1
- // Generated file based on func_literal.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 greet = (name: string) => {
8
- return "Hello, " + name
9
- }
10
-
11
-
12
- let message = greet("world")
13
- console.log(message)
14
- }
15
-
@@ -1,2 +0,0 @@
1
- Original struct from function: Expected: function result, Actual: function result
2
- Modified struct from function copy: Expected: modified function result copy, Actual: modified function result copy
@@ -1,24 +0,0 @@
1
- package main
2
-
3
- type MyStruct struct {
4
- MyInt int
5
- MyString string
6
- myBool bool
7
- }
8
-
9
- // NewMyStruct creates a new MyStruct instance.
10
- func NewMyStruct(s string) MyStruct {
11
- return MyStruct{MyString: s}
12
- }
13
-
14
- func main() {
15
- // === Function Call Result Assignment (Value Copy) ===
16
- // Assigning the result of a function that returns a struct creates a copy.
17
- structFromFunc := NewMyStruct("function result")
18
- structFromFuncCopy := structFromFunc
19
- structFromFuncCopy.MyString = "modified function result copy"
20
- // Expected: "function result"
21
- println("Original struct from function: Expected: function result, Actual: " + structFromFunc.MyString)
22
- // Expected: "modified function result copy"
23
- println("Modified struct from function copy: Expected: modified function result copy, Actual: " + structFromFuncCopy.MyString)
24
- }
@@ -1,31 +0,0 @@
1
- // Generated file based on function_call_result_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
- // NewMyStruct creates a new MyStruct instance.
16
- export function NewMyStruct(s: string): MyStruct {
17
- return new MyStruct({ MyString: s })
18
- }
19
-
20
- export async function main(): Promise<void> {
21
- // === Function Call Result Assignment (Value Copy) ===
22
- // Assigning the result of a function that returns a struct creates a copy.
23
- let structFromFunc = NewMyStruct("function result").clone()
24
- let structFromFuncCopy = structFromFunc.clone()
25
- structFromFuncCopy.MyString = "modified function result copy"
26
- // Expected: "function result"
27
- console.log("Original struct from function: Expected: function result, Actual: " + structFromFunc.MyString)
28
- // Expected: "modified function result copy"
29
- console.log("Modified struct from function copy: Expected: modified function result copy, Actual: " + structFromFuncCopy.MyString)
30
- }
31
-
@@ -1 +0,0 @@
1
- Odd: Expected: Odd, Actual: Odd
@@ -1,11 +0,0 @@
1
- package main
2
-
3
- func main() {
4
- // === If Statement ===
5
- n := 7
6
- if n%2 == 0 {
7
- println("Even: Expected: (no output)")
8
- } else {
9
- println("Odd: Expected: Odd, Actual: Odd")
10
- }
11
- }
@@ -1,15 +0,0 @@
1
- // Generated file based on if_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
- // === If Statement ===
8
- let n = 7
9
- if (n % 2 == 0) {
10
- console.log("Even: Expected: (no output)")
11
- } else {
12
- console.log("Odd: Expected: Odd, Actual: Odd")
13
- }
14
- }
15
-
@@ -1 +0,0 @@
1
- Type assertion successful
@@ -1,30 +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
- type MyOtherInterface interface {
16
- Method1() int
17
- }
18
-
19
- func main() {
20
- var i MyInterface
21
- s := MyStruct{Value: 10}
22
- i = s
23
-
24
- _, ok := i.(MyOtherInterface)
25
- if ok {
26
- println("Type assertion successful")
27
- } else {
28
- println("Type assertion failed")
29
- }
30
- }