commit 3fd2d11
0uppy
·
2026-09-13 18:37:09 +0000 UTC
parent e63e81b
cot & docs - added 3 new cog to cot, changed how comments work and updated the docs
8 files changed,
+55,
-15
+1,
-1
1@@ -31,7 +31,7 @@ honestly i dont have a whole lot to put here for the time being as im afraid to
2
3 * Figure out what i wanna do with the syntax (kinda experimental atm) [ ]
4 * Add more features to cot as it is somewhat barebones as of now [ ]
5-* Split(?) `interpreter.c` so as to keep everything tidy and organised [ ]
6+* Split(?) `interpreter.c` so as to keep everything tidy and organised [X]
7 * HOPEFULLY and EVENTUALLY one day, some time soon(TM) figure out how to compile cot to uxntal [ ]
8
9 ## misc but still related to the project:
+9,
-3
1@@ -15,7 +15,7 @@ the other in mind
2
3 in cot, "words" are refered to as cogs - as such, there are two types of cogs:
4
5-.B1 -tag -width "Cogs"
6+.Bl -tag -width "Cogs"
7 .It Cogs
8 Hardcoded words into cot, so, words that already come with base cot
9 .It UCogs
10@@ -32,14 +32,18 @@ Words processed at compile time to handle control flow and the program's structu
11
12 .Sh COGS
13 .Bl -tag -width "-> (slot)"
14-.It Ic + , - , * , /
15+.It Ic + , - , * , /, %
16 Pops two values, performs arithmetic, and pushes the result
17+.It Ic --
18+Comments out a line, currently there isn't any multiline support,, sowe,,
19 .It Ic dup
20 Duplicates the top value on the stack
21 .It Ic swap
22 Swaps the top two values on the stack
23 .It Ic drop
24 Discards/drops the top value on the stack
25+.It Ic rot
26+Pops three values, rotates them around, so, the top-most value goes to the bottom and the latter two go up
27 .It Ic ->
28 Pops a value and a slot index, then stores the value in that same variable slot
29 .It Ic @
30@@ -47,7 +51,9 @@ Pops a slot index and pushes the stored value back onto the stack
31 .It Ic .n
32 Prints a number
33 .It Ic .s
34-Prints a string
35+Prints a string
36+.It Ic nl
37+Meant to be used alongside .s, makes strings print in a new line
38 .It Ic ? if
39 Pops a value, if it's not zero, then it executes the block after it
40 .It Ic else
+2,
-1
1@@ -1,3 +1,4 @@
2 5 3 > ? if 1 . end
3 5 3 < ? if 1 . else 0 . end
4-// testing conditionals,..,
5+
6+-- testing conditionals,..,
+5,
-5
1@@ -1,19 +1,19 @@
2-// those who loop through the cotrooms hashtag awesome reference
3+-- those who loop through the cotrooms hashtag awesome reference
4
5-"kurukuru kurukuru" .s
6+"kurukuru kurukuru" .s nl
7
8 0 0 ->
9 loop
10-"kurikaesu" .s
11+"kurikaesu" .s nl
12 0 @ 1 + 0 ->
13 0 @ 4 =
14 until
15
16-"furafura furafura" .s
17+"furafura furafura" .s nl
18
19 0 0 ->
20 loop
21-"furakutaru" .s
22+"furakutaru" .s nl
23 0 @ 1 + 0 ->
24 0 @ 4 =
25 until
+1,
-1
1@@ -1,4 +1,4 @@
2 6 7 + .
3 6 9 swap . .
4
5-//im so funny aren't i
6+-- im so funny aren't i
+5,
-1
1@@ -1 +1,5 @@
2-"hallo from neu cot" .s
3+"hallo from neu cot" .s nl
4+
5+"hallo again from neu cot" .s nl
6+
7+-- rn you can't have a string that doesnt use nl be followed by a string without nl or else they both appear on the same line.,., smth i ought to look into some time soon :P
+1,
-1
1@@ -15,7 +15,7 @@ void cotton_compile
2 (Cotton *c, char *line)
3 {
4 line[strcspn(line, "\r\n")] = 0;
5- if (line[0] == '\0' || (line[0] == '/' && line[1] == '/')) return;
6+ if (line[0] == '\0' || (line[0] == '-' && line[1] == '-')) return; // i like lua's comments, i think they'd fit cot better than C's
7
8 // this part of the compiling process is just for cotton to find strings
9
+31,
-2
1@@ -45,6 +45,15 @@ void cog_div
2 push(c, a / b);
3 }
4
5+void cog_mod
6+(Cotton *c)
7+{
8+ int b = pop(c);
9+ int a = pop(c);
10+
11+ push(c, a % b);
12+}
13+
14 void cog_dotnum
15 (Cotton *c)
16 {
17@@ -62,7 +71,12 @@ void cog_dotstr
18
19 ptr++;
20 }
21+}
22
23+// im aware c goes unused here and hence this gives a warning, yes im lazy, might do smth about it another time
24+void cog_newline
25+(Cotton *c)
26+{
27 printf("\n");
28 }
29
30@@ -125,6 +139,18 @@ void cog_swap
31 push(c, a);
32 }
33
34+void cog_rotate
35+(Cotton *c)
36+{
37+ int a = pop(c);
38+ int b = pop(c);
39+ int c_ = pop(c);
40+
41+ push(c, b);
42+ push(c, c_);
43+ push(c, a);
44+}
45+
46 void cog_equal
47 (Cotton *c)
48 {
49@@ -157,13 +183,16 @@ Cog builtins[] = {
50 {"-", cog_sub},
51 {"*", cog_mul},
52 {"/", cog_div},
53- {".n", cog_dotnum},
54- {".s", cog_dotstr},
55+ {"%", cog_mod},
56+ {".n", cog_dotnum},
57+ {".s", cog_dotstr},
58+ {"nl", cog_newline},
59 {"->", cog_store},
60 {"@", cog_fetch},
61 {"dup", cog_dup},
62 {"drop", cog_drop},
63 {"swap", cog_swap},
64+ {"rot", cog_rotate},
65 {"=", cog_equal},
66 {"<", cog_lssr},
67 {">", cog_grtr},