commit c73cba3

0uppy  ·  2026-09-12 18:24:34 +0000 UTC
parent eb98dc9
cotton - added loops and raised the specs of cotton a wee bit more for bigger programs in the future ^^
5 files changed,  +39, -21
+0, -17
 1@@ -1,17 +0,0 @@
 2-"Hallo from Cot this is a little test program to show off the syntax :D" 0 ->
 3-
 4-34 2 * 1 -
 5-
 6-dup
 7-
 8-30 > ? if
 9-
10-.n
11-
12-0 @ .s
13-
14-else
15-
16-drop
17-
18-end
+9, -0
 1@@ -0,0 +1,9 @@
 2+0 0 ->
 3+
 4+loop
 5+
 6+0 @ .n
 7+0 @ 1 + 0 ->
 8+0 @ 6 =
 9+
10+until
+9, -0
 1@@ -0,0 +1,9 @@
 2+0 0 ->
 3+
 4+loop
 5+
 6+0 @ .n
 7+0 @ 1 + 0 ->
 8+0 @ 6 =
 9+
10+until
+4, -4
 1@@ -8,10 +8,10 @@
 2 #define OP_FJMP        4
 3 #define OP_PUSH_STR	   5
 4 
 5-#define STACK_SIZE     64
 6-#define JMP_STACK_SIZE 32
 7-#define MEM_SIZE       1024
 8-#define VARS_SIZE      64
 9+#define STACK_SIZE     256
10+#define JMP_STACK_SIZE 64
11+#define MEM_SIZE       4096
12+#define VARS_SIZE      256
13 
14 typedef struct Cotton Cotton;
15 
+17, -0
 1@@ -224,10 +224,27 @@ static void word_end
 2     c->mem[target] = c->mem_len;
 3 }
 4 
 5+static void word_loop
 6+(Cotton *c)
 7+{
 8+	c->jmp_stack[c->jmp_stack_p++] = c->mem_len;
 9+}
10+
11+static void word_until
12+(Cotton *c)
13+{
14+	int loop_back = c->jmp_stack[--c->jmp_stack_p];
15+
16+	c->mem[c->mem_len++] = OP_FJMP;
17+	c->mem[c->mem_len++] = loop_back;
18+}
19+
20 static Word immediates[] = {
21     {"if", word_if},
22     {"else", word_else},
23     {"end", word_end},
24+    {"loop", word_loop},
25+    {"until", word_until},
26     {NULL, NULL}
27 };
28