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,26 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
package main
|
|
2
|
-
|
|
3
|
-
type MyStruct struct {
|
|
4
|
-
MyInt int
|
|
5
|
-
MyString string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
func main() {
|
|
9
|
-
// === Struct Field Access ===
|
|
10
|
-
ms := MyStruct{MyInt: 42, MyString: "foo"}
|
|
11
|
-
println("MyInt: Expected: 42, Actual:", ms.MyInt)
|
|
12
|
-
println("MyString: Expected: foo, Actual:", ms.MyString)
|
|
13
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Generated file based on struct_field_access.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
|
-
// === Struct Field Access ===
|
|
16
|
-
let ms = new MyStruct({ MyInt: 42, MyString: "foo" })
|
|
17
|
-
console.log("MyInt: Expected: 42, Actual:", ms.MyInt)
|
|
18
|
-
console.log("MyString: Expected: foo, Actual:", ms.MyString)
|
|
19
|
-
}
|
|
20
|
-
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
package main
|
|
2
|
-
|
|
3
|
-
type Point struct {
|
|
4
|
-
X int
|
|
5
|
-
Y int
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
func main() {
|
|
9
|
-
// Initialize directly
|
|
10
|
-
p1 := Point{X: 1, Y: 2}
|
|
11
|
-
println("p1:", p1.X, p1.Y)
|
|
12
|
-
|
|
13
|
-
// Assign to another variable (should trigger clone)
|
|
14
|
-
p2 := p1
|
|
15
|
-
p2.X = 10 // Modify the copy
|
|
16
|
-
|
|
17
|
-
// Print both to show they are independent
|
|
18
|
-
println("p1 after p2 mod:", p1.X, p1.Y)
|
|
19
|
-
println("p2:", p2.X, p2.Y)
|
|
20
|
-
|
|
21
|
-
// Initialize via variable assignment
|
|
22
|
-
v := Point{X: 3, Y: 4}
|
|
23
|
-
p3 := v // Should trigger clone
|
|
24
|
-
p3.Y = 40 // Modify the copy
|
|
25
|
-
|
|
26
|
-
println("v after p3 mod:", v.X, v.Y)
|
|
27
|
-
println("p3:", p3.X, p3.Y)
|
|
28
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// Generated file based on struct_value_init_clone.go
|
|
2
|
-
// Updated when compliance tests are re-run, DO NOT EDIT!
|
|
3
|
-
|
|
4
|
-
import * as goscript from "@go/builtin";
|
|
5
|
-
|
|
6
|
-
class Point {
|
|
7
|
-
public X: number = 0;
|
|
8
|
-
public Y: number = 0;
|
|
9
|
-
|
|
10
|
-
constructor(init?: Partial<Point>) { if (init) Object.assign(this, init as any); }
|
|
11
|
-
public clone(): Point { return Object.assign(Object.create(Point.prototype) as Point, this); }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function main(): Promise<void> {
|
|
15
|
-
// Initialize directly
|
|
16
|
-
let p1 = new Point({ X: 1, Y: 2 })
|
|
17
|
-
console.log("p1:", p1.X, p1.Y)
|
|
18
|
-
|
|
19
|
-
// Assign to another variable (should trigger clone)
|
|
20
|
-
let p2 = p1.clone()
|
|
21
|
-
p2.X = 10 // Modify the copy
|
|
22
|
-
|
|
23
|
-
// Print both to show they are independent
|
|
24
|
-
console.log("p1 after p2 mod:", p1.X, p1.Y)
|
|
25
|
-
console.log("p2:", p2.X, p2.Y)
|
|
26
|
-
|
|
27
|
-
// Initialize via variable assignment
|
|
28
|
-
let v = new Point({ X: 3, Y: 4 })
|
|
29
|
-
let p3 = v.clone() // Should trigger clone
|
|
30
|
-
p3.Y = 40 // Modify the copy
|
|
31
|
-
|
|
32
|
-
console.log("v after p3 mod:", v.X, v.Y)
|
|
33
|
-
console.log("p3:", p3.X, p3.Y)
|
|
34
|
-
}
|
|
35
|
-
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
package main
|
|
2
|
-
|
|
3
|
-
func main() {
|
|
4
|
-
i := 2
|
|
5
|
-
println("Integer switch:")
|
|
6
|
-
switch i {
|
|
7
|
-
case 1:
|
|
8
|
-
println("one")
|
|
9
|
-
case 2:
|
|
10
|
-
println("two")
|
|
11
|
-
case 3:
|
|
12
|
-
println("three")
|
|
13
|
-
default:
|
|
14
|
-
println("other integer")
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
s := "hello"
|
|
18
|
-
println("\nString switch:")
|
|
19
|
-
switch s {
|
|
20
|
-
case "world":
|
|
21
|
-
println("world")
|
|
22
|
-
case "hello":
|
|
23
|
-
println("hello")
|
|
24
|
-
default:
|
|
25
|
-
println("other string")
|
|
26
|
-
}
|
|
27
|
-
x := -5
|
|
28
|
-
println("\nSwitch without expression:")
|
|
29
|
-
switch {
|
|
30
|
-
case x < 0:
|
|
31
|
-
println("negative")
|
|
32
|
-
case x == 0:
|
|
33
|
-
println("zero")
|
|
34
|
-
default: // x > 0
|
|
35
|
-
println("positive")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
x = 0
|
|
39
|
-
println("\nSwitch without expression (zero):")
|
|
40
|
-
switch {
|
|
41
|
-
case x < 0:
|
|
42
|
-
println("negative")
|
|
43
|
-
case x == 0:
|
|
44
|
-
println("zero")
|
|
45
|
-
default: // x > 0
|
|
46
|
-
println("positive")
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
x = 10
|
|
50
|
-
println("\nSwitch without expression (positive):")
|
|
51
|
-
switch {
|
|
52
|
-
case x < 0:
|
|
53
|
-
println("negative")
|
|
54
|
-
case x == 0:
|
|
55
|
-
println("zero")
|
|
56
|
-
default: // x > 0
|
|
57
|
-
println("positive")
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
// Generated file based on switch_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
|
-
let i = 2
|
|
8
|
-
console.log("Integer switch:")
|
|
9
|
-
switch (i) {
|
|
10
|
-
case 1:
|
|
11
|
-
console.log("one")
|
|
12
|
-
break
|
|
13
|
-
case 2:
|
|
14
|
-
console.log("two")
|
|
15
|
-
break
|
|
16
|
-
case 3:
|
|
17
|
-
console.log("three")
|
|
18
|
-
break
|
|
19
|
-
default:
|
|
20
|
-
console.log("other integer")
|
|
21
|
-
break
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let s = "hello"
|
|
25
|
-
console.log("\nString switch:")
|
|
26
|
-
switch (s) {
|
|
27
|
-
case "world":
|
|
28
|
-
console.log("world")
|
|
29
|
-
break
|
|
30
|
-
case "hello":
|
|
31
|
-
console.log("hello")
|
|
32
|
-
break
|
|
33
|
-
default:
|
|
34
|
-
console.log("other string")
|
|
35
|
-
break
|
|
36
|
-
}
|
|
37
|
-
let x = -5
|
|
38
|
-
console.log("\nSwitch without expression:")
|
|
39
|
-
|
|
40
|
-
// x > 0
|
|
41
|
-
switch (true) {
|
|
42
|
-
case x < 0:
|
|
43
|
-
console.log("negative")
|
|
44
|
-
break
|
|
45
|
-
case x == 0:
|
|
46
|
-
console.log("zero")
|
|
47
|
-
break
|
|
48
|
-
default:
|
|
49
|
-
console.log("positive")
|
|
50
|
-
break
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
x = 0
|
|
54
|
-
console.log("\nSwitch without expression (zero):")
|
|
55
|
-
|
|
56
|
-
// x > 0
|
|
57
|
-
switch (true) {
|
|
58
|
-
case x < 0:
|
|
59
|
-
console.log("negative")
|
|
60
|
-
break
|
|
61
|
-
case x == 0:
|
|
62
|
-
console.log("zero")
|
|
63
|
-
break
|
|
64
|
-
default:
|
|
65
|
-
console.log("positive")
|
|
66
|
-
break
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
x = 10
|
|
70
|
-
console.log("\nSwitch without expression (positive):")
|
|
71
|
-
|
|
72
|
-
// x > 0
|
|
73
|
-
switch (true) {
|
|
74
|
-
case x < 0:
|
|
75
|
-
console.log("negative")
|
|
76
|
-
break
|
|
77
|
-
case x == 0:
|
|
78
|
-
console.log("zero")
|
|
79
|
-
break
|
|
80
|
-
default:
|
|
81
|
-
console.log("positive")
|
|
82
|
-
break
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
@@ -1,25 +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
|
-
dereferencedStructCopy := MyStruct{MyString: "original"}
|
|
11
|
-
// === Value-Type Copy Behavior ===
|
|
12
|
-
// Assigning a struct (value type) creates independent copies.
|
|
13
|
-
valueCopy1, valueCopy2, pointerCopy := dereferencedStructCopy, dereferencedStructCopy, &dereferencedStructCopy
|
|
14
|
-
// Modifications to one copy do not affect others or the original.
|
|
15
|
-
valueCopy1.MyString = "value copy 1"
|
|
16
|
-
dereferencedStructCopy.MyString = "original dereferenced copy modified" // Modify the source of the copies
|
|
17
|
-
valueCopy2.MyString = "value copy 2"
|
|
18
|
-
// Expected: "value copy 1"
|
|
19
|
-
println("valueCopy1: Expected: value copy 1, Actual: " + valueCopy1.MyString)
|
|
20
|
-
// Expected: "original dereferenced copy modified"
|
|
21
|
-
println("dereferencedStructCopy (modified after copies were made): Expected: original dereferenced copy modified, Actual: " + dereferencedStructCopy.MyString)
|
|
22
|
-
// Expected: "value copy 2"
|
|
23
|
-
println("valueCopy2: Expected: value copy 2, Actual: " + valueCopy2.MyString)
|
|
24
|
-
_ = pointerCopy
|
|
25
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Generated file based on value_type_copy_behavior.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 dereferencedStructCopy = new MyStruct({ MyString: "original" })
|
|
17
|
-
// === Value-Type Copy Behavior ===
|
|
18
|
-
// Assigning a struct (value type) creates independent copies.
|
|
19
|
-
let valueCopy1 = dereferencedStructCopy.clone()
|
|
20
|
-
let valueCopy2 = dereferencedStructCopy.clone()
|
|
21
|
-
let pointerCopy = dereferencedStructCopy
|
|
22
|
-
// Modifications to one copy do not affect others or the original.
|
|
23
|
-
valueCopy1.MyString = "value copy 1"
|
|
24
|
-
dereferencedStructCopy.MyString = "original dereferenced copy modified" // Modify the source of the copies
|
|
25
|
-
valueCopy2.MyString = "value copy 2"
|
|
26
|
-
// Expected: "value copy 1"
|
|
27
|
-
console.log("valueCopy1: Expected: value copy 1, Actual: " + valueCopy1.MyString)
|
|
28
|
-
// Expected: "original dereferenced copy modified"
|
|
29
|
-
console.log("dereferencedStructCopy (modified after copies were made): Expected: original dereferenced copy modified, Actual: " + dereferencedStructCopy.MyString)
|
|
30
|
-
// Expected: "value copy 2"
|
|
31
|
-
console.log("valueCopy2: Expected: value copy 2, Actual: " + valueCopy2.MyString)
|
|
32
|
-
pointerCopy/* discarded value */
|
|
33
|
-
}
|
|
34
|
-
|