Browse Source

add map function

develop-theo
Sebeck10 2 years ago
parent
commit
985453defb
3 changed files with 13 additions and 17 deletions
  1. +5
    -5
      ccmeta.leg
  2. +8
    -0
      tests-parsimony/map.c
  3. +0
    -12
      tests-parsimony/tmp.c

+ 5
- 5
ccmeta.leg View File

@ -1298,18 +1298,17 @@ language printLang = C;
oop outputProgram= 0;
oop mapFunction(oop func, oop args) {
println(args);
oop mapValue = makeMap();
oop argsObj = eval(globals, args);
int size = map_size(argsObj);
int size = map_size(eval(globals, args));
for(int i = 0; i < size; i++) {
oop oopInt = makeInteger(i);
oop obj = map_get(map_get(args, value_symbol), oopInt);
obj = newCall(func, obj);
oop test = makeMap();
map_append(test, obj);
obj = newCall(func, test);
map_append(mapValue, obj);
}
map_set(args, value_symbol, mapValue);
println(args);
return args;
}
@ -2694,6 +2693,7 @@ oop mulOperation(oop lhs, oop rhs)
CASE(Float , Float ): return makeFloat(get(lhs, Float, _value) * get(rhs, Float, _value));
CASE(String , Integer): return string_mul(lhs, rhs);
CASE(Integer, String ): return string_mul(rhs, lhs);
CASE(Undefined, Integer): return makeInteger(getInteger(rhs));
}
runtimeError("multiplication between two incompatible types");
return NULL; // to prevent: control may reach end of non-void function

+ 8
- 0
tests-parsimony/map.c View File

@ -0,0 +1,8 @@
@{
test(foo) {
foo * 10;
}
}
@{print(map(test, [1, 2, 3]));}

+ 0
- 12
tests-parsimony/tmp.c View File

@ -1,12 +0,0 @@
@{
test(foo) {
foo * 2;
}
// print("after test decl\n");
// a = [1, 2, 3];
// print(a[3]);
// print("\n");
}
@{print(map(test, [1, 2, 3]));}
// @{print(test(1));}

Loading…
Cancel
Save