cognate-lang / cognate Goto Github PK
View Code? Open in Web Editor NEWA human readable quasi-concatenative programming language
License: BSD 2-Clause "Simplified" License
A human readable quasi-concatenative programming language
License: BSD 2-Clause "Simplified" License
From the readme:
CognaC (the Cognate Compiler) compiles Cognate sources directly into C. This produces very small and rather fast binaries, allowing Cognate to outperform most dynamic languages. This also makes Cognate a candidate for scripting in embedded environments, such as microcontrollers.
... but microcontrollers can't compile and run C. Is there a "pure interpreter" for a microcontroller somewhere that actually executes the code instead of transpiling it to C? If there isn't, how do I make one out of this code here?
Due to potentially being called a lot in large programs, the speed of restrict_chars could be extremely important. Is there a reason for the replacement words, here:
char* with[] = {"DASH", "XMARK", "QMARK", "EQ", "LT", "GT", "PLUS", "STAR", "SLASH"};
to be full strings, instead of say, 'D', 'X', 'Q', 'E', 'L', 'G', 'P', 'S', 'H'
?
The only thing I can think of is debugging.
If these were to be replaced with single char versions, you'd be able to much more quickly remove them.
Note this will not affect other variables, due to the sanitation process - I can provide examples if needed.
We could always provide two versions, using a flag like DEBUG
to enable the slower version.
There isn't any documentation on each builtin word, and so for the ones that take and/or return blocks, the semantics are very confusing. Case
in particular. What are the semantics of that, and everything else? Writing it as Forth stack-effect diagrams or just some example code would help.
Cognate looks really cool. The one place I think the literate aspect can be improved is with the binary operators, which are hard to read in a sentence as prefix symbols.
Print * 3 by - 7 2;
If the following looks nice, I will make a pull request to add synonyms like this:
Print Multiply 3 by Subtract 7 from 2;
and so on, +
would be Add
, Inequal?
and Equal?
for !=
and ==
, because of the same for While (!= "done" Twin Input)
I noticed a weird segfault that appeared in my code. Here is a small reproduction:
This segfaults when ran, yet
Def Push-op as (Let Op; Push Op);
Let Commands be List ("+" "-" "%" "*")
Let Error be False;
List ();
For command in Commands
Case "+" (Push-op)
Case "-" (Push-op)
Case "*" (Push-op)
else (Set Bad-command; Set Error to True; Prints ("Error: Unknown Command " Bad-command "\n"));
Do If Not Error
(Set Commands; For command in Commands Print)
(Print "");
Clear;
This code works,
Def Push-op as (Let Op; Push Op);
Let Commands be List ("+" "-" "%" "*");
Let Error be False;
List ();
For command in Commands
Case "+" (Push-op)
Case "-" (Push-op)
Case "*" (Push-op)
else (Set Error to True; Put "Error: Unknown Command "; Print);
If Not Error
(Set Commands; For command in Commands Print)
(Print "");
Clear;
and the only difference seems to be this code which causes the segfault
else (Set Bad-command; Set Error to True; Prints ("Error: Unknown Command " Bad-command "\n"));
as opposed to this code which works.
else (Set Error to True; Put "Error: Unknown Command "; Print);
Further information: Prints
doesn't segfault by itself, based on this reproduction I made that works,
Let Bar be "Bar"; Prints ("hielo " Bar "\n");
In the C23 standard, functions without prototypes (int func()
instead of int func(void)
) are removed. Clang has deprecated the feature all versions of C as a result. When I try to compile the hello world example with cognac, I get the following error log:
hello.c:41:21: error: a block declaration without a prototype is deprecated [-Werror,-Wstrict-prototypes]
typedef void(^BLOCK)();
^
void
hello.c:323:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void assert_impure();
^
void
hello.c:409:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void debugger_step()
^
void
hello.c:605:26: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void assert_impure()
^
void
hello.c:1971:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void VAR(debug)()
^
void
5 errors generated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.