Skip to content

Commit

Permalink
some work on documentation generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakz committed Jun 29, 2019
1 parent f326c82 commit ec41663
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ void Help::init()

addOperator("<>", OpHelpEntry::binary(TYPE_LAMBDA, TYPE_LAMBDA, TYPE_UNKNOWN, "while", Topic::FUNCTIONAL, "executes second lambda while first lambda evaluates to true", "", ""));
addOperator("<>", OpHelpEntry::binary(TYPE_INT, TYPE_LAMBDA, TYPE_UNKNOWN, "counter", Topic::FUNCTIONAL, "executes second lambda a number of times specified by integer", "", ""));
addOperator("<>", OpHelpEntry::binaryO(TYPE_LIST, TYPE_LAMBDA, TYPE_LIST, TYPE_LIST, "partition", Topic::COLLECTIONS, "partition a list according to predicate given by lambda", "", ""));
addOperator("<>", OpHelpEntry::binaryO(TYPE_ARRAY, TYPE_LAMBDA, TYPE_ARRAY, TYPE_ARRAY, "partition", Topic::COLLECTIONS, "partition an array according to predicate given by lambda", "", ""));
addOperator("<>", OpHelpEntry::binary(TYPE_LAZY_ARRAY, TYPE_LAMBDA, TYPE_LAZY_ARRAY, "generate", Topic::COLLECTIONS, "generates terms from a lazy array until predicate over the value becomes false", "", ""));
addOperator("<>", OpHelpEntry::binary(TYPE_LAZY_ARRAY, TYPE_INT, TYPE_LAZY_ARRAY, "generate", Topic::COLLECTIONS, "generates terms until size of the lazy array is equal to specified integer", "", ""));
addOperator("<>", OpHelpEntry::unary(TYPE_INT, TYPE_GENERIC, "inner get", Topic::FUNCTIONAL, "(ONLY AVAILABLE INSIDE A LAZY LIST DECLARATION) fetches a previous element from the lazy list", "", ""));
Expand Down
11 changes: 6 additions & 5 deletions src/microcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ void registerFunctions(MicroCode& mc)

Traits::Appendable* partition = nullptr;

/* search group for value returned by lambda or generate new one */
auto pit = partitions.find(v);

if (pit == partitions.end())
Expand Down Expand Up @@ -523,8 +524,8 @@ void registerFunctions(MicroCode& mc)
});

/* fetch from tuple */
registerUnary(mc, {OP_ANY, TYPE_TUPLE}, { TRAIT_ANY_TYPE }, [](VM* vm, V v1) { vm->push(v1.tuple()->at(0)); });
registerUnary(mc, {OP_EVERY, TYPE_TUPLE}, { TRAIT_ANY_TYPE }, [](VM* vm, V v1) { vm->push(v1.tuple()->at(1)); });
registerUnary(mc, Topic::COLLECTIONS, "first", "get first element from tuple", {}, { OP_ANY, TYPE_TUPLE }, { TRAIT_ANY_TYPE }, [](VM* vm, V v1) { vm->push(v1.tuple()->at(0)); });
registerUnary(mc, Topic::COLLECTIONS, "second", "get second element from tuple", {}, { OP_EVERY, TYPE_TUPLE }, { TRAIT_ANY_TYPE }, [](VM* vm, V v1) { vm->push(v1.tuple()->at(1)); });

registerStackFunctions(mc);
registerNumericFunctions(mc);
Expand Down Expand Up @@ -566,14 +567,14 @@ void registerNumericFunctions(MicroCode& mc)

registerUnary(mc, {OP_NOT, TYPE_FLOAT }, { TYPE_FLOAT }, [](VM* vm, V v) { vm->push(1.0 / v.real()); });

registerBinary(mc, {OP_MOD, TYPE_INT, TYPE_INT }, { TYPE_INT }, [](VM* vm, V v1, V v2) { vm->push(v1.integral() % v2.integral()); });
registerUnary(mc, {OP_MOD, TYPE_FLOAT }, { TYPE_TUPLE }, [](VM* vm, V v) {
registerBinary(mc, Topic::NUMERICS, "mod", "modulus of integral division", {}, {OP_MOD, TYPE_INT, TYPE_INT }, { TYPE_INT }, [](VM* vm, V v1, V v2) { vm->push(v1.integral() % v2.integral()); });
registerUnary(mc, Topic::NUMERICS, "mod", "tuple containing integral and fractional part of real number", {}, {OP_MOD, TYPE_FLOAT }, { TYPE_TUPLE }, [](VM* vm, V v) {
real_t i, f;
f = modf(v.real(), &i);
vm->push(new Tuple(i, f));
});

registerUnary(mc, {OP_BANG, TYPE_INT}, { TYPE_INT }, [](VM* vm, V vv) {
registerUnary(mc, Topic::NUMERICS, "factorial", "factorial of integral", {}, {OP_BANG, TYPE_INT}, { TYPE_INT }, [](VM* vm, V vv) {
integral_t res = 1;
integral_t v = vv.integral();
while (v > 1) res *= v--;
Expand Down
5 changes: 5 additions & 0 deletions src/semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ struct SignatureType
{
return (isType() && this->type() == type) || (!isType() && TypeInfo(type).operator<(trait()));
}

struct hash
{
size_t operator()(const SignatureType& v) const { return static_cast<size_t>(v.value); }
};
};

using ArgumentType = Type;
Expand Down
19 changes: 16 additions & 3 deletions src/tests/documentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,26 @@ int main(int argc, char* argv[])
registerFunctions(mc);
Help::init();

/*

std::unordered_map<SignatureType, std::vector<OpHelpEntry>, SignatureType::hash> operatorsByType;

const auto& operators = Help::ops();
for (const auto& entry : operators)
{
std::cout << entry.first << std::endl;
if (entry.second.i.count() > 0)
operatorsByType[entry.second.i[0]].push_back(entry.second);
}

for (auto& entry : operatorsByType)
{
std::sort(entry.second.begin(), entry.second.end(), [](const OpHelpEntry& e1, const OpHelpEntry& e2) { return e1.ident < e2.ident; });

std::cout << TypeTraits::nameForSignatureType(entry.first) << std::endl;
for (const auto& op : entry.second)
std::cout << " " << op.ident << std::endl;
std::cout << std::endl;
}
*/


getchar();

Expand Down

0 comments on commit ec41663

Please sign in to comment.