mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added examples.
This commit is contained in:
28
resources/examples/contextfree/dynscope.c3
Normal file
28
resources/examples/contextfree/dynscope.c3
Normal file
@@ -0,0 +1,28 @@
|
||||
module foo;
|
||||
import std::io;
|
||||
|
||||
tlocal char[] context_user = "safe";
|
||||
|
||||
macro long perform(task)
|
||||
{
|
||||
io::printf("%s: %s\n", context_user, task);
|
||||
return task.len;
|
||||
}
|
||||
|
||||
macro @with_mode(char[] user, #action, arg)
|
||||
{
|
||||
@scope(context_user)
|
||||
{
|
||||
context_user = user;
|
||||
return #action(arg);
|
||||
};
|
||||
}
|
||||
|
||||
fn void main()
|
||||
{
|
||||
long result = perform("something!");
|
||||
result += @with_mode("faster", perform, "reliable");
|
||||
result += perform(char[][] {"again", "more"});
|
||||
result += perform(int[<2>] { 56, 99 });
|
||||
io::printf("Result: %d\n", result);
|
||||
}
|
||||
27
resources/examples/contextfree/multi.c3
Normal file
27
resources/examples/contextfree/multi.c3
Normal file
@@ -0,0 +1,27 @@
|
||||
module test;
|
||||
import std::io;
|
||||
|
||||
fn void main()
|
||||
{
|
||||
/*
|
||||
Here's a comment.
|
||||
/*
|
||||
And a nested comment.
|
||||
*/
|
||||
*/
|
||||
char[] text = `
|
||||
function hello() {
|
||||
console.log("name`"\t"`age");
|
||||
}
|
||||
|
||||
hello();
|
||||
`;
|
||||
io::println(text);
|
||||
|
||||
// Binary
|
||||
const DATA = x"4749463839610100010080"
|
||||
x"0100ffffff00000021f904"
|
||||
x"010a0001002c0000000001"
|
||||
x"0001000002024c01003b";
|
||||
io::printf("%d\n", DATA.len);
|
||||
}
|
||||
Reference in New Issue
Block a user