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.
- package/README.md +41 -0
- package/builtin/builtin.ts +368 -348
- package/compiler/compile_expr.go +3 -37
- package/compiler/index.test.ts +29 -0
- package/compiler/index.ts +85 -0
- package/dist/builtin/builtin.d.ts +168 -0
- package/dist/builtin/builtin.js +372 -0
- package/dist/builtin/builtin.js.map +1 -0
- package/dist/compiler/index.d.ts +26 -0
- package/dist/compiler/index.js +64 -0
- package/dist/compiler/index.js.map +1 -0
- package/package.json +68 -3
- package/.aider-prompt +0 -11
- package/compliance/COMPLIANCE.md +0 -133
- package/compliance/compliance.go +0 -313
- package/compliance/compliance_test.go +0 -57
- package/compliance/tests/array_literal/array_literal.go +0 -15
- package/compliance/tests/array_literal/array_literal.gs.ts +0 -19
- package/compliance/tests/array_literal/expected.log +0 -3
- package/compliance/tests/async_basic/async_basic.go +0 -26
- package/compliance/tests/async_basic/async_basic.gs.ts +0 -30
- package/compliance/tests/async_basic/expected.log +0 -1
- package/compliance/tests/basic_arithmetic/basic_arithmetic.go +0 -15
- package/compliance/tests/basic_arithmetic/basic_arithmetic.gs.ts +0 -19
- package/compliance/tests/basic_arithmetic/expected.log +0 -5
- package/compliance/tests/boolean_logic/boolean_logic.go +0 -13
- package/compliance/tests/boolean_logic/boolean_logic.gs.ts +0 -17
- package/compliance/tests/boolean_logic/expected.log +0 -3
- package/compliance/tests/channel_basic/channel_basic.go +0 -12
- package/compliance/tests/channel_basic/channel_basic.gs.ts +0 -18
- package/compliance/tests/channel_basic/expected.log +0 -1
- package/compliance/tests/composite_literal_assignment/composite_literal_assignment.go +0 -20
- package/compliance/tests/composite_literal_assignment/composite_literal_assignment.gs.ts +0 -27
- package/compliance/tests/composite_literal_assignment/expected.log +0 -2
- package/compliance/tests/constants/constants.go +0 -18
- package/compliance/tests/constants/constants.gs.ts +0 -22
- package/compliance/tests/constants/expected.log +0 -3
- package/compliance/tests/copy_independence/copy_independence.go +0 -29
- package/compliance/tests/copy_independence/copy_independence.gs.ts +0 -36
- package/compliance/tests/copy_independence/expected.log +0 -4
- package/compliance/tests/float64/expected.log +0 -6
- package/compliance/tests/float64/float64.go +0 -28
- package/compliance/tests/float64/float64.gs.ts +0 -32
- package/compliance/tests/for_loop_basic/expected.log +0 -5
- package/compliance/tests/for_loop_basic/for_loop_basic.go +0 -9
- package/compliance/tests/for_loop_basic/for_loop_basic.gs.ts +0 -13
- package/compliance/tests/for_loop_condition_only/expected.log +0 -5
- package/compliance/tests/for_loop_condition_only/main.go +0 -9
- package/compliance/tests/for_loop_condition_only/main.gs.ts +0 -13
- package/compliance/tests/for_range/expected.log +0 -9
- package/compliance/tests/for_range/for_range.go +0 -26
- package/compliance/tests/for_range/for_range.gs.ts +0 -45
- package/compliance/tests/for_range_index_use/expected.log +0 -6
- package/compliance/tests/for_range_index_use/for_range_index_use.go +0 -11
- package/compliance/tests/for_range_index_use/for_range_index_use.gs.ts +0 -18
- package/compliance/tests/func_literal/expected.log +0 -1
- package/compliance/tests/func_literal/func_literal.go +0 -10
- package/compliance/tests/func_literal/func_literal.gs.ts +0 -15
- package/compliance/tests/function_call_result_assignment/expected.log +0 -2
- package/compliance/tests/function_call_result_assignment/function_call_result_assignment.go +0 -24
- package/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.ts +0 -31
- package/compliance/tests/if_statement/expected.log +0 -1
- package/compliance/tests/if_statement/if_statement.go +0 -11
- package/compliance/tests/if_statement/if_statement.gs.ts +0 -15
- package/compliance/tests/interface_to_interface_type_assertion/expected.log +0 -1
- package/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.go +0 -30
- package/compliance/tests/interface_to_interface_type_assertion/interface_to_interface_type_assertion.gs.ts +0 -41
- package/compliance/tests/interface_type_assertion/expected.log +0 -1
- package/compliance/tests/interface_type_assertion/interface_type_assertion.go +0 -26
- package/compliance/tests/interface_type_assertion/interface_type_assertion.gs.ts +0 -36
- package/compliance/tests/map_support/expected.log +0 -13
- package/compliance/tests/map_support/map_support.go +0 -89
- package/compliance/tests/map_support/map_support.gs.ts +0 -102
- package/compliance/tests/method_call_on_pointer_receiver/expected.log +0 -1
- package/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.go +0 -19
- package/compliance/tests/method_call_on_pointer_receiver/method_call_on_pointer_receiver.gs.ts +0 -27
- package/compliance/tests/method_call_on_pointer_via_value/expected.log +0 -1
- package/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.go +0 -29
- package/compliance/tests/method_call_on_pointer_via_value/method_call_on_pointer_via_value.gs.ts +0 -38
- package/compliance/tests/method_call_on_value_receiver/expected.log +0 -1
- package/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.go +0 -16
- package/compliance/tests/method_call_on_value_receiver/method_call_on_value_receiver.gs.ts +0 -24
- package/compliance/tests/method_call_on_value_via_pointer/expected.log +0 -2
- package/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.go +0 -30
- package/compliance/tests/method_call_on_value_via_pointer/method_call_on_value_via_pointer.gs.ts +0 -38
- package/compliance/tests/multiple_return_values/expected.log +0 -6
- package/compliance/tests/multiple_return_values/multiple_return_values.go +0 -19
- package/compliance/tests/multiple_return_values/multiple_return_values.gs.ts +0 -23
- package/compliance/tests/pointer_assignment_no_copy/expected.log +0 -2
- package/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.go +0 -28
- package/compliance/tests/pointer_assignment_no_copy/pointer_assignment_no_copy.gs.ts +0 -35
- package/compliance/tests/pointer_composite_literal_assignment/expected.log +0 -3
- package/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.go +0 -23
- package/compliance/tests/pointer_composite_literal_assignment/pointer_composite_literal_assignment.gs.ts +0 -30
- package/compliance/tests/pointer_deref_multiassign/expected.log +0 -0
- package/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.go +0 -17
- package/compliance/tests/pointer_deref_multiassign/pointer_deref_multiassign.gs.ts +0 -27
- package/compliance/tests/pointer_initialization/expected.log +0 -1
- package/compliance/tests/pointer_initialization/pointer_initialization.go +0 -16
- package/compliance/tests/pointer_initialization/pointer_initialization.gs.ts +0 -22
- package/compliance/tests/select_receive_on_closed_channel_no_default/expected.log +0 -1
- package/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.go +0 -15
- package/compliance/tests/select_receive_on_closed_channel_no_default/select_receive_on_closed_channel_no_default.gs.ts +0 -31
- package/compliance/tests/select_send_on_full_buffered_channel_with_default/expected.log +0 -1
- package/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.go +0 -13
- package/compliance/tests/select_send_on_full_buffered_channel_with_default/select_send_on_full_buffered_channel_with_default.gs.ts +0 -35
- package/compliance/tests/select_statement/expected.log +0 -9
- package/compliance/tests/select_statement/select_statement.go +0 -109
- package/compliance/tests/select_statement/select_statement.gs.ts +0 -239
- package/compliance/tests/simple/expected.log +0 -1
- package/compliance/tests/simple/simple.go +0 -5
- package/compliance/tests/simple/simple.gs.ts +0 -9
- package/compliance/tests/simple_deref_assignment/expected.log +0 -2
- package/compliance/tests/simple_deref_assignment/simple_deref_assignment.go +0 -19
- package/compliance/tests/simple_deref_assignment/simple_deref_assignment.gs.ts +0 -26
- package/compliance/tests/slices/expected.log +0 -7
- package/compliance/tests/slices/slices.go +0 -22
- package/compliance/tests/slices/slices.gs.ts +0 -26
- package/compliance/tests/string_rune_conversion/expected.log +0 -3
- package/compliance/tests/string_rune_conversion/string_rune_conversion.go +0 -16
- package/compliance/tests/string_rune_conversion/string_rune_conversion.gs.ts +0 -22
- package/compliance/tests/struct_field_access/expected.log +0 -2
- package/compliance/tests/struct_field_access/struct_field_access.go +0 -13
- package/compliance/tests/struct_field_access/struct_field_access.gs.ts +0 -20
- package/compliance/tests/struct_value_init_clone/expected.log +0 -5
- package/compliance/tests/struct_value_init_clone/struct_value_init_clone.go +0 -28
- package/compliance/tests/struct_value_init_clone/struct_value_init_clone.gs.ts +0 -35
- package/compliance/tests/switch_statement/expected.log +0 -14
- package/compliance/tests/switch_statement/switch_statement.go +0 -59
- package/compliance/tests/switch_statement/switch_statement.gs.ts +0 -85
- package/compliance/tests/value_type_copy_behavior/expected.log +0 -3
- package/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.go +0 -25
- package/compliance/tests/value_type_copy_behavior/value_type_copy_behavior.gs.ts +0 -34
- package/design/DESIGN.md +0 -599
- package/example/simple/build.bash +0 -10
- package/example/simple/go.mod +0 -23
- package/example/simple/go.sum +0 -39
- package/example/simple/main.go +0 -138
- package/example/simple/main.gs.ts +0 -133
- package/example/simple/main.ts +0 -3
- package/example/simple/main_test.go +0 -59
- package/example/simple/main_tools.go +0 -5
- package/example/simple/package.json +0 -7
- package/example/simple/run.bash +0 -6
- package/example/simple/tsconfig.json +0 -28
- package/example/simple/yarn.lock +0 -8
- package/output/output.go +0 -10
- package/tsconfig.json +0 -10
- package/types/tokens.go +0 -65
- package/types/types.go +0 -46
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
package main
|
|
2
|
-
|
|
3
|
-
type MyStruct struct {
|
|
4
|
-
MyInt int
|
|
5
|
-
MyString string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
func main() {
|
|
9
|
-
// === Pointer Composite Literal Assignment ===
|
|
10
|
-
// Creating a pointer to a struct directly using a composite literal with &
|
|
11
|
-
structPointer := &MyStruct{MyInt: 42, MyString: "composite literal pointer"}
|
|
12
|
-
|
|
13
|
-
// Access fields through the pointer
|
|
14
|
-
// Expected: 42
|
|
15
|
-
println("MyInt via pointer: Expected: 42, Actual:", structPointer.MyInt)
|
|
16
|
-
// Expected: "composite literal pointer"
|
|
17
|
-
println("MyString via pointer: Expected: composite literal pointer, Actual: " + structPointer.MyString)
|
|
18
|
-
|
|
19
|
-
// Modify through the pointer
|
|
20
|
-
structPointer.MyInt = 99
|
|
21
|
-
// Expected: 99
|
|
22
|
-
println("MyInt after modification: Expected: 99, Actual:", structPointer.MyInt)
|
|
23
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Generated file based on pointer_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
|
-
|
|
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
|
-
// === Pointer Composite Literal Assignment ===
|
|
16
|
-
// Creating a pointer to a struct directly using a composite literal with &
|
|
17
|
-
let structPointer = new MyStruct({ MyInt: 42, MyString: "composite literal pointer" })
|
|
18
|
-
|
|
19
|
-
// Access fields through the pointer
|
|
20
|
-
// Expected: 42
|
|
21
|
-
console.log("MyInt via pointer: Expected: 42, Actual:", structPointer.MyInt)
|
|
22
|
-
// Expected: "composite literal pointer"
|
|
23
|
-
console.log("MyString via pointer: Expected: composite literal pointer, Actual: " + structPointer.MyString)
|
|
24
|
-
|
|
25
|
-
// Modify through the pointer
|
|
26
|
-
structPointer.MyInt = 99
|
|
27
|
-
// Expected: 99
|
|
28
|
-
console.log("MyInt after modification: Expected: 99, Actual:", structPointer.MyInt)
|
|
29
|
-
}
|
|
30
|
-
|
|
File without changes
|
|
@@ -1,17 +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
|
-
structPointer := &MyStruct{MyInt: 4, MyString: "hello world"}
|
|
11
|
-
// === Pointer Dereference and Multi-Assignment ===
|
|
12
|
-
// Dereference structPointer to get a copy of the struct.
|
|
13
|
-
// Also demonstrates multi-variable assignment and the use of the blank identifier '_'.
|
|
14
|
-
dereferencedStructCopy, _, _, unusedString := *structPointer, structPointer.myBool, structPointer.MyInt, "hello" // testing _ set
|
|
15
|
-
_ = unusedString // Explicitly ignore unusedString to satisfy linters
|
|
16
|
-
_ = dereferencedStructCopy
|
|
17
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// Generated file based on pointer_deref_multiassign.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
|
-
// === Pointer Dereference and Multi-Assignment ===
|
|
18
|
-
// Dereference structPointer to get a copy of the struct.
|
|
19
|
-
// Also demonstrates multi-variable assignment and the use of the blank identifier '_'.
|
|
20
|
-
let dereferencedStructCopy = structPointer.clone()
|
|
21
|
-
structPointer.myBool/* discarded value */
|
|
22
|
-
structPointer.MyInt/* discarded value */
|
|
23
|
-
let unusedString = "hello" // testing _ set
|
|
24
|
-
unusedString/* discarded value */
|
|
25
|
-
dereferencedStructCopy/* discarded value */
|
|
26
|
-
}
|
|
27
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Initial MyString (via pointer): Expected: hello world, Actual: hello world
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Received zero value with ok==false: 0
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Default case hit
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1,109 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,239 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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
|
-
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
|
-
}
|