Ver Fonte

Implement S

Implemented the sleep function. This required moving the logic for
the engine loop out of ParseCodeBox and into a dedicated Run function.
This was long overdue, anyway.
ApisNecros há 1 ano atrás
pai
commit
bb215e7fcb
2 ficheiros alterados com 27 adições e 16 exclusões
  1. 7 5
      examples.txt
  2. 20 11
      starfish.js

+ 7 - 5
examples.txt

@@ -1,9 +1,9 @@
-|;n*84			prints "32"
+|;n*84				prints "32"
 
-\;nf			prints "15"
+\;nf				prints "15"
 \|
 
->11+nv			prints "2 5 28 2.25 3"
+>11+nv				prints "2 5 28 2.25 3"
 /o*84<
 \72-n\
 /o*84<
@@ -16,7 +16,7 @@
 abcdef0983[D3[DII;      prints nothing, but should have three stacks [[10, 11, 12], [13, 14, 15], [0, 9, 8]]
 abcdef0983[D3[DIID]I];  prints nothing, and ends with the stack in the same order. Splits it and collapse it several times, though.
 
-c22g\           prints "5011012", or what should be read as "50", "110", and "12"
+c22g\           	prints "5011012", or what should be read as "50", "110", and "12"
 /g32/
 \nnn;
   2
@@ -27,4 +27,6 @@ abcdefr&r3[D&n; 	prints "10"
 
 10772**01p;     	prints nothing, but after running cb.box should have two rows, and [1][0] == 'b'
 
-s":"m":"hnonon;		prints whatever your current time is
+s":"m":"hnonon;		prints whatever your current time is
+
+aa*Sfn;				prints "15" after 10 seconds

+ 20 - 11
starfish.js

@@ -134,17 +134,8 @@ class CodeBox {
 
         this.maxBoxWidth = maxRowLength - 1;
         this.maxBoxHeight = this.box.length - 1;
-        
-        let fin = null;
 
-        try {
-            while(!fin) {
-                fin = this.Swim();
-            }
-        }
-        catch(e) {
-            console.error(e);
-        }
+        this.Run();
     }
 
     /**
@@ -180,6 +171,22 @@ class CodeBox {
         this.outputDOM.value += value;
     }
 
+    /**
+     * The main loop for the engine 
+     */
+    Run() {
+        let fin = null;
+
+        try {
+            while(!fin) {
+                fin = this.Swim();
+            }
+        }
+        catch(e) {
+            console.error(e);
+        }
+    }
+
     Execute(instruction) {
         let output = null;
         try{
@@ -360,7 +367,9 @@ class CodeBox {
                     break;
                 // Time
                 case "S":
-                    // TODO
+                    setTimeout(this.Run.bind(this), this.stacks[this.curr_stack].Pop() * 100);
+                    this.Move();
+                    output = true;
                     break;
                 case "h":
                     this.stacks[this.curr_stack].Push(this.datetime.getUTCHours());