Explorar el Código

Merge branch 'master' into fix-whitespace-bug

Lucas Mendonça hace 5 años
padre
commit
a78ac2c63f

+ 6 - 1
css/ivprog-term.css

@@ -86,6 +86,7 @@
 .bash {
   box-shadow: 0 0 30px rgba(0,0,0,0.4);
   border-radius: 3px;
+  font-family: "Andale Mono", Consolas, "Courier New" !important;
 }
 
 .bash-title {
@@ -192,4 +193,8 @@
 }
 .assessment-div-detail:hover > span {
   text-decoration: underline;
-}
+}
+
+.bash span {
+  font-family: 'Courier New', Courier, monospace;
+}

+ 1 - 0
i18n/ui.csv

@@ -137,3 +137,4 @@ text_for_from,de,from,
 text_for_to,até,to,
 text_for_pass,passo,pass,
 text_relational_expression,Relacionais,Relational,
+initial_program_code,"programa {\n\n\t\tfuncao vazio inicio () {\n\t\t\t// Inicie seu codigo aqui!\n\t\t}\n}","program {\n\n\t\tfunction void main () {\n\t\t\t// Start your code here!\n\t\t}\n}",

+ 8 - 1
js/iassign-integration-functions.js

@@ -387,7 +387,14 @@ function ivprogTextualOrVisual () {
       $('.textual_coding_button').addClass('active');
       $('.visual_coding_button').addClass('disabled');
 
-      ivprogCore.CodeEditor.setCode(algorithm_in_ilm);
+      let textual_code = algorithm_in_ilm;
+      if(!textual_code) {
+        textual_code = ivprogCore.LocalizedStrings.getUI("initial_program_code");
+        textual_code = textual_code.replace(/\\n/g,"\n");
+        textual_code = textual_code.replace(/\\t/g,"\t");
+      }
+      
+      ivprogCore.CodeEditor.setCode(textual_code);
       ivprogCore.CodeEditor.disable(false);
     }
     if (settingsProgrammingTypes == "visual") {

+ 1 - 0
js/main.js

@@ -11,6 +11,7 @@ import * as CodeEditorAll from "./visualUI/text_editor";
 import {autoGenerateTestCaseOutput} from './util/auto_gen_output';
 
 const CodeEditor = {
+  initTextEditor: CodeEditorAll.initTextEditor,
   setCode: CodeEditorAll.setCode,
   getCode: CodeEditorAll.getCode,
   updateEditor: CodeEditorAll.updateEditor,

+ 31 - 11
js/processor/ivprogProcessor.js

@@ -350,24 +350,44 @@ export class IVProgProcessor {
     //BEGIN for -> while rewrite
     const initCmd = new Commands.Assign(cmd.for_id.id, cmd.for_from);
     initCmd.sourceInfo = cmd.sourceInfo;
-    const is_forward_exp = new Expressions.InfixApp(Operators.GE, cmd.for_to, cmd.for_from);
-    return this.evaluateExpression(store, is_forward_exp).then (result => {
-      const is_forward = result.value;
+    const expression_tuple = []; //(for conditional, is for increasing)
+    if(cmd.for_pass == null) {
+      expression_tuple.push(Promise.resolve(null));
+      expression_tuple.push(this.evaluateExpression(store, new Expressions.InfixApp(Operators.GE, cmd.for_to, cmd.for_from)));
+    } else {
+      expression_tuple.push(this.evaluateExpression(store, new Expressions.InfixApp(Operators.GE, cmd.for_pass, new Expressions.IntLiteral(toInt(0)))));
+      expression_tuple.push(Promise.resolve(null));
+    }
+    
+    return Promise.all(expression_tuple).then (results => {
+      console.log(results);
+      let is_forward = true;
+      let is_end_gt_init = undefined;
       let condition = null;
-      if (is_forward) {
-        condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
+      let pass_value = cmd.for_pass;
+      if (results[0] == null) {
+        // pass is null, we need to deduce a value for it
+        is_end_gt_init = results[1].value;
       } else {
-        condition = new Expressions.InfixApp(Operators.GE, cmd.for_id, cmd.for_to);
+        is_forward = results[0].value
       }
-      condition.sourceInfo = cmd.sourceInfo;
-      let pass_value = cmd.for_pass;
-      if(pass_value == null) {
+
+      if(is_end_gt_init == null) {
+        console.log("pass is not null and is forward? ", is_forward);
         if(is_forward) {
-          pass_value = new Expressions.IntLiteral(toInt(1));
+          condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
         } else {
-          pass_value = new Expressions.IntLiteral(toInt(-1));
+          condition = new Expressions.InfixApp(Operators.GE, cmd.for_id, cmd.for_to);
         }
+        console.log("Cond", condition);
+      } else if(is_end_gt_init) {
+        pass_value = new Expressions.IntLiteral(toInt(1));
+        condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
+      } else {
+        pass_value = new Expressions.IntLiteral(toInt(-1));
+        condition = new Expressions.InfixApp(Operators.GE, cmd.for_id, cmd.for_to);
       }
+      condition.sourceInfo = cmd.sourceInfo;
       const increment = new Commands.Assign(cmd.for_id.id,
         new Expressions.InfixApp(Operators.ADD, cmd.for_id, pass_value));
         increment.sourceInfo = cmd.sourceInfo;

+ 0 - 1
js/visualUI/functions.js

@@ -873,7 +873,6 @@ export function initVisualUI () {
     }
   });
 
-  TextEditor.initTextEditor("ivprog-text-editor");
 }
 
 export function setTestCases (testCases) {

+ 1 - 0
templates/index.html

@@ -152,6 +152,7 @@
         $('.created_element').css('left', mouseX);*/
       });
       ivprogCore.LocalizedStrings.updateTagText();
+      ivprogCore.CodeEditor.initTextEditor("ivprog-text-editor");
       iassingIntegration();
       if (iLMparameters.iLM_PARAM_TeacherAutoEval == null) {
         ivprogCore.initVisualUI();