Skip to content

Commit fa2295a

Browse files
committed
Присвоение значений для map
1 parent 09556f7 commit fa2295a

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

program.own

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ for i = 0, i < 4, i = i + 1 {
8585

8686
// map
8787
map = {"+" : add, "-" : sub. "*" : mul, "/" : div}
88+
map["%"] = def(x,y) = x % y
89+
map["pow"] = def(x,y) = pow(x, y)
8890
//print map["+"]
8991
print "\n"
9092
print function(map["+"], 4, 5)
@@ -97,4 +99,5 @@ arr1 = arr1 :: 4
9799
arr2 = [5,6,7]
98100
print arr1
99101
print "\n"
100-
print arr1 << arr2
102+
print arr1 << arr2
103+

src/com/annimon/ownlang/parser/ast/ArrayAccessExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private ArrayValue consumeArray(Value value) {
5454
}
5555
}
5656

57-
private MapValue consumeMap(Value value) {
57+
public MapValue consumeMap(Value value) {
5858
if (value instanceof MapValue) {
5959
return (MapValue) value;
6060
} else {

src/com/annimon/ownlang/parser/ast/ArrayAssignmentStatement.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.annimon.ownlang.parser.ast;
22

3+
import com.annimon.ownlang.lib.ArrayValue;
4+
import com.annimon.ownlang.lib.Value;
5+
import com.annimon.ownlang.lib.Variables;
6+
37
/**
48
*
59
* @author aNNiMON
@@ -16,7 +20,12 @@ public ArrayAssignmentStatement(ArrayAccessExpression array, Expression expressi
1620

1721
@Override
1822
public void execute() {
19-
array.getArray().set(array.lastIndex(), expression.eval());
23+
final Value container = Variables.get(array.variable);
24+
if (container instanceof ArrayValue) {
25+
array.getArray().set(array.lastIndex(), expression.eval());
26+
return;
27+
}
28+
array.consumeMap(container).set(array.indices.get(0).eval(), expression.eval());
2029
}
2130

2231
@Override

0 commit comments

Comments
 (0)