Skip to content

Commit e55d43f

Browse files
committed
Allow accessing multiple return items (#330)
1 parent a67409e commit e55d43f

File tree

7 files changed

+15
-5
lines changed

7 files changed

+15
-5
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 2-Clause License
22

3-
Copyright (c) 2020-2023, Vasiliy Tereshkov
3+
Copyright (c) 2020-2024, Vasiliy Tereshkov
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

doc/lang.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,9 @@ m["Hello"]
943943

944944
#### Field or method selector
945945

946-
The field or method selector `.` accesses a field or method. For accessing a field, it can be applied to a structure that has this field or to a pointer to such a structure. For accessing a method, it can be applied to any declared type `T` or `^T` such that `^T` is compatible with the type that implements this method. If neither field nor method with the specified name is found, an error is triggered.
946+
The field or method selector `.` accesses a field or method. For accessing a field, it can be applied to a structure that has this field or to a pointer to such a structure. For accessing a method, it can be applied to any declared type `T` or `^T` such that `^T` is compatible with the type that implements this method. If neither field nor method with the specified name is found, an error is triggered.
947+
948+
As a special case, the field selector can be applied to the result of a function call that returns an expression list. This expression list is treated as if it were a structure with the fields named `item0`, `item1`, etc.
947949

948950
Syntax:
949951

@@ -956,6 +958,7 @@ Examples:
956958
```
957959
v.x
958960
data.print
961+
f().item2
959962
```
960963

961964
#### Call selector

playground/umka.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/umka.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum
1717
void help(void)
1818
{
1919
printf("%s\n", umkaGetVersion());
20-
printf("(C) Vasiliy Tereshkov, 2020-2023\n");
20+
printf("(C) Vasiliy Tereshkov, 2020-2024\n");
2121
printf("Usage: umka [<parameters>] <file.um> [<script-parameters>]\n");
2222
printf("Parameters:\n");
2323
printf(" -stack <stack-size> - Set stack size\n");

src/umka_types.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ Field *typeAddField(Types *types, Type *structType, Type *fieldType, const char
609609
else
610610
{
611611
// Automatic field naming
612-
snprintf(fieldNameBuf, DEFAULT_STR_LEN + 1, "__field%d", structType->numItems);
612+
snprintf(fieldNameBuf, DEFAULT_STR_LEN + 1, "item%d", structType->numItems);
613613
name = fieldNameBuf;
614614
}
615615

tests/expected.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ World Hello
333333
23 45.6 "Hello" 'z'
334334
['a' 'b'] ['c' 'd'] ['e' 'f']
335335
12 -3 17
336+
8.5 "43"
336337

337338

338339
>>> Language tour

tests/multret.um

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ p := 'z'
88
var i, j, k: [2]char = [2]char{'a', 'b'}, [2]char{'c', 'd'}, [2]char{'e', 'f'}
99
var l, m, n: real = 12, -3, 17
1010

11+
fn foo(x: int): (real, str) {
12+
return x + 1, sprintf("[%v]", x + 1)
13+
}
14+
1115
fn test*() {
1216
if a, b, c := f(3, false); a < 3 {
1317
printf("%v %v %v\n", a, b, c)
@@ -34,6 +38,8 @@ fn test*() {
3438
printf("%v %v %v %v\n", u, v, w, p)
3539
printf("%v %v %v\n", i, j, k)
3640
printf("%v %v %v\n", l, m, n)
41+
42+
printf("%v %v\n", foo(7).item0 + 0.5, slice(foo(42).item1, 1, 3))
3743
}
3844

3945
fn main() {

0 commit comments

Comments
 (0)