ceu-lang / ceu Goto Github PK
View Code? Open in Web Editor NEWThe Programming Language Céu
Home Page: http://www.ceu-lang.org/
License: Other
The Programming Language Céu
Home Page: http://www.ceu-lang.org/
License: Other
event void c;
class Test with
event void a;
event void b;
do
par/or do
every a do
_printf("a\n");
end
with
await b;
end
end
watching c do
loop do
do Test;
end
end
Given the code above I get a line 17 : tight loop warning for the loop within the watching block although each trail within "Test" contains an "await" statement.
If I copy the execution body of "Test" directly into the loop within the watching block and declare the events a, b outside "Test", the warning disappears.
Played around with the alias operator within data types and vectors and noticed the following
data Test with
var u8& b;
end
var u8 b = 7;
var Test[3] v;
var Test t;
t.b = &b;
v = v .. [t];
// reassignments
b = 10; // OK
t.b = 88; // OK
v[0].b = 36; // invalid attribution : missing alias operator `&´
The third reassignment leads to a "missing alias operator" error. Why?
"v[0]" should be evaluated to "t" and "t.b = ..." works perfectly fine...
ceu_types.h
to ceu_platform.h
class T with do
async thread do
end
end
pause/if e do
var T t;
async thread do
end
end
It used to work.
Now the associated code is commented in CLEAR() inside code.lua
I used the following code to access the next organism within a pool:
class Job with
var u8 id = 0;
event void nextRequest;
do
// do job
await 1s;
end
pool Job[10] jobs;
pool Job[10]& jobs_alias = &jobs;
var Job&& ptr = null;
loop j in jobs do
ptr = j;
break;
end // ok, no compile error
ptr = null;
loop j in jobs_alias do
ptr = j;
break;
end // compile error occurs
When using the jobs_alias the following gcc compile errors occurs:
ceu --safety 1 application.ceu
WRN [0000] : pools_organisms.ceu : line 13 : WRN [0000] : pools_organisms.ceu : line 13 : `loop´ iteration is not reachable
WRN [0000] : pools_organisms.ceu : line 19 : WRN [0000] : pools_organisms.ceu : line 19 : `loop´ iteration is not reachable
gcc -pthread main.c env/eq.c env/sig.c env/wclock.c -Wall -lrt -DCEU_DEBUG -g
In file included from main.c:29:0:
pools_organisms.ceu: In function ‘ceu_app_go’:
pools_organisms.ceu:19:42: error: ‘tceu_vector’ undeclared (first use in this function)
loop j in jobs_alias do
^
pools_organisms.ceu:19:42: note: each undeclared identifier is reported only once for each function it appears in
pools_organisms.ceu:19:54: error: expected expression before ‘)’ token
loop j in jobs_alias do
^
pools_organisms.ceu:22:111: error: expected expression before ‘)’ token
end
^
In file included from main.c:29:0:
main.c: At top level:
application.ceu:6799:13: warning: ‘_ceu_pre_1’ defined but not used [-Wunused-function]
make: *** [all] Error 1
Some ideas to improve pools:
Now, we need to pre-declare them:
function ... f;
function ... f do
f();
end
class T with
static function ... f;
...
end
T.f();
Currently only one global Lua state for the whole program.
A Lua error crashes the program.
Support a script
block that creates a new/independent Lua state and captures Lua errors on statements and nested organisms:
(err,msg) = script do
par/or do
[[ ... ]]
var T t;
...
with
pool T ts;
...
end
end
if err then
puts(msg);
end
The error message should contain the class/line in which the error occurred.
In the following example the declaration of a pointer as event type for an internal event is allowed by the compiler.
event u8&& a; // allowed by compiler
var u8 k = 5;
emit a => &&k; // leads to compiler error
But when a is actually emitted the compiler throws an error wrong argument : cannot pass pointers. Why does the compiler allow the declaration of an internal event carrying a pointer but refuses the actual usage? Isn't it kind of inconsistent?
Example:
every SDL_REDRAW do
var _SDL_Surface* srf;
finalize
srf = _TTF_RenderText_Blended(fnt, str, clr);
with
_SDL_FreeSurface(srf); // isn't freed after iteration's end
end
end
I get this when trying to run "ceu barber_animator/barber.ceu" in github.com/johnicholas/jn_learns_ceu. I know that is a too-large testcase, and I will minimize it, but I wanted to open the issue.
input void OS_START;
event int* e;
var int ret = 0;
par/or do
do
var int x = 2; // old address
par/or do
await OS_START;
emit e => &x;
with
await e;
end
end
do
var int x = 1; // new address
await 1s;
ret = x;
end
with
var int* v = await e;
ret = *v; // takes new address
end
escape ret;
namespace X do
var int x;
class T <...>;
end
X/x = 1;
var X/T t;
When I assign null to the option pointer of a class I get an SEGFAULT error on runtime:
class Test with
do
end
var Test&&? a = null; // leads to segfault
If I use a data type or u8, int, etc. the error doesn't occur.
Is this possible and do you have any suggestions on setup?
Thanks!
loop i in [0,10[ do
...
end
data Frame with
tag DATA with
var u8 d1;
var u16 d2;
end
or
tag RAW with
var u8[3] bytes;
end
end
var Frame f;
f.DATA.d1 = 4; // runtime error: invalid tag
The code above generates a runtime error (invalid tag) when trying to access the DATA tag of frame f. No compiler error is thrown.
After removing native methods, are native bodies still required?
Sorry for being pedantic. Then again, programmers should be pedantic when it comes to grammar, no? ;)
The error is: "This is how Céu looks like". This is a classic mistake of non-native speakers of English (like myself). It should be either "how it looks" or "what it looks like", with subtle differences in meaning:
http://english.stackexchange.com/questions/55672/is-it-what-it-looks-like-or-how-it-looks-like
Make the `void´ parameter optional for functions that receive no parameters.
Hi,
the problem reported in #44 is fixed and doesn't appear anymore. But still my code doesn't behave the same way as it did before. So I guess issue #44 might not have been the root cause. I investigated the problem again and noticed that it appears in the following szenario:
input void KILL;
class OrgA with
event void evtA;
event void evtB;
do
loop do
watching evtA do
loop do
loop i in 3 do
await 1s;
_printf("work!\n");
end
emit evtB;
end
end
_printf("exit WATCHING\n");
end
end
class OrgB with
do
var OrgA a;
loop do
await a.evtB;
_printf("before EMIT\n");
emit a.evtA;
_printf("after EMIT\n");
end
end
var OrgB b;
await KILL;
escape 42;
This one provides the following output:
work!
work!
work!
before EMIT
exit WATCHING
work!
work!
work!
work!
work!
work!
... and so on ...
Means the emit a.evtA statement of 'OrgB' is never left! And this is exactly the problem I noticed in my code since I use newer versions of the Céu compiler.
I guess the problem might appear because evtB is emitted within the watching block in 'OrgA' and in the same reaction chain that processes evtB the wachting block is terminated by 'OrgB' by emitting evtA. So this might be some kind of "we are sawing off the branch we are sitting on" problem!?
In the older version 89af57d of the Céu compiler the same code generates the following output:
work!
work!
work!
before EMIT
exit WATCHING
after EMIT
work!
work!
work!
before EMIT
exit WATCHING
after EMIT
work!
work!
work!
before EMIT
exit WATCHING
after EMIT
work!
work!
work!
... and so on ...
The latest would be the expected behaviour (from my understanding).
So far, there is no syntax for initializing data types containing C arrays. But omitting the initialization leads to compiler errors such as invalid access to uninitialized variable.
data Test with
var _u8[10] v;
end
var Test t = Test(???);
In #45 you suggested: "I think we'll need a special syntax to prevent initializations errors for C types just because of vectors."
The same problem might also belong to classes.
data Frame with
var u8[3] bytes;
end
var Frame[10] frames;
var Frame f1;
f1.bytes = f1.bytes .. [5]; // runtime error: access out of bounds
frames = frames .. [f1];
When trying to append a new value to the vector "bytes" an "access out of bounds" error occurs during runtime. No compiler error is thrown.
I wrote the following code
var u8[5] foo = [1, 2, 3, 4];
loop i in $$foo do
_printf("(%d): %d\n", i, foo[i]);
end
escape 42;
resulting in the following output during runtime
(0): 1
(1): 2
(2): 3
(3): 4
[application.ceu:7] runtime error: access out of bounds
Segmentation fault (core dumped)
The access out of bounds exception is correct because we loop for the maximum length (= 5) but vector only has length of 4, so accessing foo[4] is illegal. But the segmentation fault should not appear and the Céu application should still escape value 42.
I don't know if this is a bug, or a misconception
// There are some other processes that are generating and sending pointers-to-int
class Queue with
event int* next;
do
// nothing
end
// The customer wants to consume one of the pointers-to-int,
// but it also wants to do something (twiddle thumbs) in the meantime.
class Customer with
var Queue& barbers;
do
var int* c = null;
par/or do
_printf("twiddle thumbs while waiting\n");
await FOREVER;
with
c = await barbers.next;
end
if c then
_printf("got one\n");
else
_printf("didn't get one\n");
end
end
This code gives me a "pointer access across await" error, and I don't know to rewrite it to do something equivalent that doesn't cause that error. Am I using Ceu wrongly, or is there a bug in the analysis?
With respect to the following post https://groups.google.com/forum/#!topic/ceu-lang/26ZdjnvEbuI it would be a nice feature to have an interface for Céu's request organisms to avoid using the Global interface. This way e.g. organisms could be easily injected into every anonymously spawned organism for request handling.
Maybe like in the following example:
class Test with
var u8 k;
do
<...>
end
var Test t_outer with
this.k = 5;
end;
input/output [10] (void)=>void RESOURCE with
var Test& t_inner = &t_outer;
do
t_inner.k = 13; // would like to be able to access t here
end
I was showing ceu to a friend o mine and got stuck trying to create single main.c to embed the hello world from ceu-lang.org site.
So, I'd like to suggest to add a minimum main.c + Makefile to the site, to embed the demos from the tutorial.
What is the likelihood of porting this to something like the ESP8266 which is already running Lua?
A pointer to a class field that is not accessed across reactions or that is watched should be safe:
class T with
var U* u;
do
watching u do
...
end
end
var U* u = ...
var T with
this.u := u;
end;
class Org with
do
end
var int n = 5;
pool Org[n] a;
This one leads to the following lua stack trace:
lua: /usr/local/bin/ceu:12656: attempt to concatenate field 'sval' (a nil value)
stack traceback:
/usr/local/bin/ceu:12656: in function 'tp2dcl'
/usr/local/bin/ceu:13130: in function 'pre'
/usr/local/bin/ceu:4478: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function 'visit_aux'
/usr/local/bin/ceu:4491: in function </usr/local/bin/ceu:4462>
(tail call): ?
/usr/local/bin/ceu:13174: in main chunk
[C]: ?
For sure, it is not allowed to specify a variable pool size (to get bounded memory) but I would expect an appropriate compiler error instead of a stack trace.
Edited:
The following code given
var int k = 5;
loop/10 i in k do
var int x = i + 2;
_printf("%d\n", x);
end
in the current master branch (150fea5) I receive the following compiler warning from gcc:
application.ceu:3:9: warning: unused variable ‘__57’ [-Wunused-variable]
loop/10 i in k do
^
So it states that 'i' is unused but this is obviously not the case.
I accidentally wrote the following code:
class Test with
var u8[10]& v;
do
v = [] .. v .. [4];
end
var u8[10]& v; // error: '&' must be deleted
do Test with
this.v = &v;
end;
The compiler didn't through any error but on runtime I got a SEGFAULT. Maybe there should be a compiler error to avoid that?
Given the following code
var u8[5] foo = [1, 2, 3, 4];
loop i in $$foo do
_printf("(%d): %d\n", i, foo[i]);
end
escape 42;
I retrieve a tight loop warning
ceu --safety 1 application.ceu
WRN [0000] : application.ceu : line 6 : WRN [0000] : application.ceu : line 6 : tight loop
gcc main.c
Is that correct? If I use $$foo, so the maximum length of the vector, this should be treated like using a #define instead because it can not be changed during runtime, can it? So when using $foo I would expect the warning but when using $$foo I wouldn't.
Accessing organism of a class with id > 127 using interface pointer or reference results in segfault.
// ... 127 classes defined here ...
interface ITarget with
function (void) => void method;
end
class Class128 with
interface ITarget;
event void quit;
do
function (void) => void method do end
await quit;
end
var Class128 instance;
var Class128* pointer = &instance;
var ITarget*? target = &instance;
instance.method(); // <<< doesn't crash
pointer:method(); // <<< doesn't crash
target:method(); // <<< crashes here
Example:
https://gist.github.com/Tkachov/f87272a3c5ce2db7a454
or https://tkachov.ru/files/classes_minimal_example.zip (with .cpp, Makefile, etc)
Consider the following example:
class Test with
var u8 k;
do
end
do TestX with
this.k = 5;
end;
For sure, this leads to an compiler error because TestX is misspelled. In this case I would expect the compiler to give me a hint that class TestX ist not defined. Instead, the Céu compiler issues:
variable/event "k" is not declared
The error message isn't wrong but it's kind of confusing since it doesn't inform about the root cause. I quite often struggled in such scenario looking for a misspelled interface variable being not aware of the typo in the class identifier.
In this case I got WRN : nondeterminism : variable/event rawWriteByte vs variable/event up which shouldn't appear:
class Receiver with
var Parser& up;
var Frame& rx;
emit void evtReady;
do
par do
every pB in up.evtByte do
rx.rawWriteByte(pB);
end
with
every up.evtStop do
emit evtReady;
end
end
end
struct s with
var int v;
var s* next;
end
Hi,
I currently made a pull on your current master (0f6a7e1) branch to get the latest bug fixes. After that I noticed that parts of my existing Céu code do not work anymore. I investigated the problem and noticed that it has to be associated with the internal event handling. Have a look at the following (senseless) code:
input void KILL;
class OrgC with
do
loop do
await 1s;
_printf("work\n");
end
end
class OrgA with
event void signal;
do
var int test = 0;
loop do
watching signal do
do OrgC;
end
test = test + 1;
_printf("exit (%d)\n", test);
end
end
class OrgB with
do
var OrgA a;
every 5s do
emit a.signal;
_printf("after EMIT\n");
end
end
var OrgB b;
await KILL;
escape 42;
This generates the following output:
work
work
work
work
work
exit (1)
exit (2)
after EMIT
work
work
work
work
work
exit (3)
exit (4)
after EMIT
work
work
work
work
work
exit (5)
exit (6)
after EMIT
work
work
work
work
work
exit (7)
exit (8)
after EMIT
... and so on ...
As far as I understood "exit (...)" should only appear once per emit. In this case it is printed twice which means the loop within 'OrgA' is executed twice within one reaction chain.
If I compile and execute the same Céu code with an older compiler version (df104da) I get
work
work
work
work
work
exit (1)
after EMIT
work
work
work
work
work
exit (2)
after EMIT
work
work
work
work
work
exit (3)
after EMIT
work
work
work
work
work
exit (4)
after EMIT
... and so on...
which I think is the expected behaviour!
Maybe you could have some investigations on this problem?
Thanks!
When compiling the following function
function (u8[] bytes)=>void build do
_printf("%d\n", $bytes);
end
I retrieved a lua stack trace on compilation:
ceu --safety 1 application.ceu
lua: /usr/local/bin/ceu:14126: attempt to concatenate field 'cval' (a nil value)
stack traceback:
/usr/local/bin/ceu:14126: in function 'pre'
/usr/local/bin/ceu:4658: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
...
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function 'visit_aux'
/usr/local/bin/ceu:4670: in function </usr/local/bin/ceu:4641>
(tail call): ?
/usr/local/bin/ceu:15694: in main chunk
[C]: ?
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
Remove all code relative to native methods, which are not supported anymore.
Add syntax to separate methods definitions from the class body.
Ex.:
class T with
<iface>
with
<meths>
do
<body>
end
Test { [[
interface Global with
var int& v;
end
class T with
var int v;
do
this.v = global:v;
end
var T t;
var int um = 111;
var int& v = um;
escape t.v;
]],
run = 111,
}
(SEGFAULT on 0x7fff36ba2480)
Allow the use of iterators with vectors in a similar fashion to pools:
loop <organism reference> in <vector> do
One question about expected behaviour might be if it should iterate from first to last index, or from oldest to newest like in pools. The latter would be more complicated, I presume.
Archival of request on Google Groups
When trying to access a pointer provided via an external event
input (char&&, u32) HTTP_GET;
loop do
var char&& p2Buff;
var u32 len;
(p2Buff, len) = await HTTP_GET;
var char c = p2Buff[0]; // doesn't work
end
I get the following compiler warning
application.ceu: In function ‘ceu_app_go’:
application.ceu:19:49: warning: passing argument 1 of ‘ceu_vector_geti_ex’ from incompatible pointer type
var char c = p2Buff[0];
^
In file included from main.c:30:0:
application.ceu:8438:7: note: expected ‘struct tceu_vector *’ but argument is of type ‘char **’
In file included from main.c:30:0:
application.ceu:15:10: warning: variable ‘__ceu_c_11’ set but not used [-Wunused-but-set-variable]
var char&& p2Buff;
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.