Commit 45b2445a authored by Victor Yacovlev's avatar Victor Yacovlev

Implemented printing main algorithm out-values

parent 7fcdc31f
...@@ -370,7 +370,7 @@ void Generator::addKumirModule(int id, const AST::Module *mod) ...@@ -370,7 +370,7 @@ void Generator::addKumirModule(int id, const AST::Module *mod)
Bytecode::ElemType ft = Bytecode::EL_FUNCTION; Bytecode::ElemType ft = Bytecode::EL_FUNCTION;
if (mod->header.name.isEmpty() && i==0) { if (mod->header.name.isEmpty() && i==0) {
ft = Bytecode::EL_MAIN; ft = Bytecode::EL_MAIN;
if (!alg->header.arguments.isEmpty()) if (!alg->header.arguments.isEmpty() || alg->header.returnType.kind!=AST::TypeNone)
{ {
mainMod = mod; mainMod = mod;
mainAlg = alg; mainAlg = alg;
......
...@@ -217,6 +217,103 @@ bool Run::makeInputArgument(Variable & reference) ...@@ -217,6 +217,103 @@ bool Run::makeInputArgument(Variable & reference)
return true; return true;
} }
bool Run::makeOutputArgument(const Variable & reference) {
QString repr;
emit output(QString::fromStdWString(reference.name())+" = ");
if (reference.dimension()==0) {
if (reference.hasValue()) {
repr = QString::fromStdWString(reference.value().toString());
if (reference.baseType()==Bytecode::VT_string)
repr = "\"" + repr + "\"";
else if (reference.baseType()==Bytecode::VT_char)
repr = "'" + repr + "'";
}
emit output(repr);
}
else if (reference.dimension()==1) {
int bounds[7];
reference.getEffectiveBounds(bounds);
emit output("{ ");
for (int x=bounds[0]; x<=bounds[1]; x++) {
repr = "";
if (reference.hasValue(x)) {
repr = QString::fromStdWString(reference.value(x).toString());
if (reference.baseType()==Bytecode::VT_string)
repr = "\"" + repr + "\"";
else if (reference.baseType()==Bytecode::VT_char)
repr = "'" + repr + "'";
}
emit output(repr);
if (x<bounds[1]) {
emit output(", ");
}
}
emit output(" }");
}
else if (reference.dimension()==2) {
int bounds[7];
reference.getEffectiveBounds(bounds);
emit output("{ ");
for (int y=bounds[0]; y<=bounds[1]; y++) {
emit output("{ ");
for (int x=bounds[2]; x<=bounds[3]; x++) {
repr = "";
if (reference.hasValue(y,x)) {
repr = QString::fromStdWString(reference.value(y,x).toString());
if (reference.baseType()==Bytecode::VT_string)
repr = "\"" + repr + "\"";
else if (reference.baseType()==Bytecode::VT_char)
repr = "'" + repr + "'";
}
emit output(repr);
if (x<bounds[1]) {
emit output(", ");
}
}
emit output(" }");
if (y<bounds[1]) {
emit output(", ");
}
}
emit output(" }");
}
else if (reference.dimension()==3) {
int bounds[7];
reference.getEffectiveBounds(bounds);
emit output("{ ");
for (int z=bounds[0]; z<=bounds[1]; z++) {
emit output("{ ");
for (int y=bounds[2]; y<=bounds[3]; y++) {
emit output("{ ");
for (int x=bounds[4]; x<=bounds[5]; x++) {
repr = "";
if (reference.hasValue(z,y,x)) {
repr = QString::fromStdWString(reference.value(z,y,x).toString());
if (reference.baseType()==Bytecode::VT_string)
repr = "\"" + repr + "\"";
else if (reference.baseType()==Bytecode::VT_char)
repr = "'" + repr + "'";
}
emit output(repr);
if (x<bounds[1]) {
emit output(", ");
}
}
emit output(" }");
if (y<bounds[1]) {
emit output(", ");
}
}
emit output(" }");
if (z<bounds[1]) {
emit output(", ");
}
}
emit output(" }");
}
emit output("\n");
return true;
}
bool Run::makeInput(std::deque<Variable> & references) bool Run::makeInput(std::deque<Variable> & references)
......
...@@ -54,6 +54,7 @@ public slots: ...@@ -54,6 +54,7 @@ public slots:
std::deque<Variable> & /*references*/ std::deque<Variable> & /*references*/
); );
bool makeInputArgument(Variable & /*reference*/); bool makeInputArgument(Variable & /*reference*/);
bool makeOutputArgument(const Variable & /*reference*/);
bool inputScalarArgument(const QString & message, const QString & format, AnyValue & value); bool inputScalarArgument(const QString & message, const QString & format, AnyValue & value);
void handleInputArgumentRequest(int localId, void handleInputArgumentRequest(int localId,
const QString & varName, const QString & varName,
......
...@@ -27,7 +27,10 @@ class InteractionHandler ...@@ -27,7 +27,10 @@ class InteractionHandler
public: public:
explicit InteractionHandler(int argc, char *argv[]); explicit InteractionHandler(int argc, char *argv[]);
bool makeInputArgument(VM::Variable & reference); bool makeInputArgument(VM::Variable & reference);
bool makeOutputArgument(const VM::Variable & reference);
private: private:
void output(const Kumir::String & s);
inline void output(const std::string & s) { output(Kumir::Core::fromAscii(s)); }
bool readScalarArgument(const Kumir::String & message, const Kumir::String & name, VM::ValueType type, VM::AnyValue & val); bool readScalarArgument(const Kumir::String & message, const Kumir::String & name, VM::ValueType type, VM::AnyValue & val);
std::deque< Kumir::String > m_arguments; std::deque< Kumir::String > m_arguments;
size_t i_currentArgument; size_t i_currentArgument;
...@@ -222,6 +225,111 @@ bool InteractionHandler::makeInputArgument(VM::Variable &reference) ...@@ -222,6 +225,111 @@ bool InteractionHandler::makeInputArgument(VM::Variable &reference)
return true; return true;
} }
bool InteractionHandler::makeOutputArgument(const VM::Variable & reference) {
Kumir::String repr;
output(reference.name()+Kumir::Core::fromAscii(" = "));
if (reference.dimension()==0) {
if (reference.hasValue()) {
repr = reference.value().toString();
if (reference.baseType()==Bytecode::VT_string)
repr = Kumir::Core::fromAscii("\"") + repr + Kumir::Core::fromAscii("\"");
else if (reference.baseType()==Bytecode::VT_char)
repr = Kumir::Core::fromAscii("'") + repr + Kumir::Core::fromAscii("'");
}
output(repr);
}
else if (reference.dimension()==1) {
int bounds[7];
reference.getEffectiveBounds(bounds);
output("{ ");
for (int x=bounds[0]; x<=bounds[1]; x++) {
repr.clear();
if (reference.hasValue(x)) {
repr = reference.value(x).toString();
if (reference.baseType()==Bytecode::VT_string)
repr = Kumir::Core::fromAscii("\"") + repr + Kumir::Core::fromAscii("\"");
else if (reference.baseType()==Bytecode::VT_char)
repr = Kumir::Core::fromAscii("'") + repr + Kumir::Core::fromAscii("'");
}
output(repr);
if (x<bounds[1]) {
output(", ");
}
}
output(" }");
}
else if (reference.dimension()==2) {
int bounds[7];
reference.getEffectiveBounds(bounds);
output("{ ");
for (int y=bounds[0]; y<=bounds[1]; y++) {
output("{ ");
for (int x=bounds[2]; x<=bounds[3]; x++) {
repr.clear();
if (reference.hasValue(y,x)) {
repr = reference.value(y,x).toString();
if (reference.baseType()==Bytecode::VT_string)
repr = Kumir::Core::fromAscii("\"") + repr + Kumir::Core::fromAscii("\"");
else if (reference.baseType()==Bytecode::VT_char)
repr = Kumir::Core::fromAscii("'") + repr + Kumir::Core::fromAscii("'");
}
output(repr);
if (x<bounds[1]) {
output(", ");
}
}
output(" }");
if (y<bounds[1]) {
output(", ");
}
}
output(" }");
}
else if (reference.dimension()==3) {
int bounds[7];
reference.getEffectiveBounds(bounds);
output("{ ");
for (int z=bounds[0]; z<=bounds[1]; z++) {
output("{ ");
for (int y=bounds[2]; y<=bounds[3]; y++) {
output("{ ");
for (int x=bounds[4]; x<=bounds[5]; x++) {
repr.clear();
if (reference.hasValue(z,y,x)) {
repr = reference.value(z,y,x).toString();
if (reference.baseType()==Bytecode::VT_string)
repr = Kumir::Core::fromAscii("\"") + repr + Kumir::Core::fromAscii("\"");
else if (reference.baseType()==Bytecode::VT_char)
repr = Kumir::Core::fromAscii("'") + repr + Kumir::Core::fromAscii("'");
}
output(repr);
if (x<bounds[1]) {
output(", ");
}
}
output(" }");
if (y<bounds[1]) {
output(", ");
}
}
output(" }");
if (z<bounds[1]) {
output(", ");
}
}
output(" }");
}
output("\n");
return true;
}
void InteractionHandler::output(const Kumir::String &s)
{
const std::string localstring = Kumir::Coder::encode(LOCALE, s);
std::cout << localstring;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
// sleep(15); // for remote debugger // sleep(15); // for remote debugger
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment