aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/namespacing.md59
1 files changed, 31 insertions, 28 deletions
diff --git a/docs/namespacing.md b/docs/namespacing.md
index 91a8d472..381956d8 100644
--- a/docs/namespacing.md
+++ b/docs/namespacing.md
@@ -11,51 +11,54 @@ segments its imports into different namespaces. For example `Foo$Baz` would be
the identifier `Baz` in the namespace `Foo`, and would be guaranteed to not
collide with a user-chosen name like `FooBaz`.
-```
-// File: foo.nl
+```tomo
+// File: foo.tm
+my_var := 123
+
struct Baz(x:Int):
member := 5
func frob(b:Baz)->Int:
return b.x
+```
-qux := "Loaded!"
-say(qux)
-
-// File: foo.nl.h
+```C
+// File: foo.tm.h
...
typedef struct foo$Baz_s foo$Baz_t;
-#define foo$Baz(...) (foo$Baz_t){__VA_ARGS__}
struct foo$Baz_s {
- Int_t x;
+ Int_t $x;
};
+
+extern Int_t foo$my_var;
+extern const TypeInfo foo$Baz;
+
extern Int_t foo$Baz$member;
-Int_t foo$Baz$frob(foo$Baz_t b);
+Int_t foo$Baz$frob(struct foo$Baz_s $b);
+void foo$main();
...
+```
-// File: foo.nl.c
-#include "foo.nl.h"
-Int_t foo$Baz$member = 5;
+```C
+// File: foo.tm.c
+...
+Int_t foo$my_var = I_small(123);
+Int_t foo$Baz$member = I_small(5);
-Int_t foo$Baz$frob(foo$Baz_t b) {
- return b.x;
+static CORD foo$Baz$as_text(foo$Baz_t *obj, bool use_color)
+{
+ if (!obj)
+ return "Baz";
+ return CORD_all(use_color ? "\x1b[0;1mBaz\x1b[m(" : "Baz(", "x=",
+ Int$as_text(stack(obj->$x), use_color, &$Int), ")");
}
-void use$foo(void) {
- static enum {UNLOADED, LOADING, LOADED} $state = UNLOADED;
- if ($state == LOADING)
- fail("Circular import");
- else if ($state == LOADED)
- return;
-
- $state = LOADING;
- { // Top-level code:
- Str qux = "Loaded!";
- say(qux);
- }
- $state = LOADED;
+public Int_t foo$Baz$frob(struct foo$Baz_s $b)
+{
+ return ($b).$x;
}
+...
```
-And on the usage site, the code `use ./foo.tm` compiles to `#include
+And on the usage site, the code `include ./foo.tm` compiles to `#include
"./foo.tm.h"` in the header and `use$foo()` in the code that is executed.