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,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,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,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,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,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,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,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,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,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,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
|
-
}
|
package/compliance/tests/function_call_result_assignment/function_call_result_assignment.gs.ts
DELETED
|
@@ -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,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
|
-
}
|