91
Ideas / Re: Function inside function
« on: November 14, 2018, 06:30:42 PM »
This C feature is only in GCC/Clang or?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
double f = (double)(3 + (unsigned)foo());
Bar bar = bars[(size_t)i];
d64 f = cast((3 + cast(foo() as u32)) as d64);
Bar bar = bars[cast(i as size_t)];
d64 f = cast(3 + cast(foo(), u32), d64);
Bar bar = bars[cast(i, usize)];
d64 f = (3 + foo()->u32)->d64;
Bar bar = bars[i->usize];
d64 f = (3 + (foo():u32)):d64);
Bar bar = bars[(i:usize)];
d64 f = cast(3 + cast(foo():u32)):d64);
Bar bar = bars[cast(i:usize)];
d64 f = (3 + (foo()::u32))::d64);
Bar bar = bars[(i::usize)];
d64 f = cast(3 + cast(foo()::u32))::d64);
Bar bar = bars[cast(i::usize)];
d64 f = (3 + foo().as(u32)).as(d64);
Bar bar = bars[i.as(usize)];
d64 f = cast((3 + (foo() :> u32)) :> d64);
Bar bar = bars[(i :> size_t)];
type Foo interface {
void foo($Foo foo);
void bar($Foo foo);
}
type X struct {
i32 a;
i32 b;
}
type Y struct {
i32 a;
i32 b;
}
func X.foo(X* x) { ... }
func X.bar(X* x) { ... }
func Y.foo(Y* x) { ... }
func Y.bar(Y* x, i32 z) { ... }
func void getFoo($Foo a) // <- Use a sigil to indicate that this is NOT a struct!!!
{
a.foo();
a.bar();
}
X x;
$Foo foo = $Foo(&x);
$Foo foo2 = $Foo(&y) // ERROR!
getFoo(x); // Fine! (Implicit wrap)
getFoo(y); // BAD
struct __interface_Foo {
uint32_t identifier;
uint32_t bitfield; // 1 has optionals, rest is available
void (*foo)(void *);
void (*bar)(void *);
uint8_t[] optionalBitmap;
}
struct {
void *instance;
struct __interface_Foo *interface;
}
type shapeKind = (square, rectangle, circle);
shape = record
centerx : integer;
centery : integer;
case kind : shapeKind of
square : (side : integer);
rectangle : (length, height : integer);
circle : (radius : integer);
end;
type enum ShapeKind {
SQUARE,
CIRCLE,
RECTANGLE
}
type Shape struct {
i32 centerX;
i32 centerY;
ShapeKind kind;
union (kind) {
case SHAPE:
i32 side;
case RECTANGLE:
i32 length, height;
case CIRCLE:
i32 radius;
}
}
type Shape struct {
i32 centerX;
i32 centerY;
i8 kind; // Just like this? Have the enum be implicitly created?
union (kind) {
square: { i32 side; }
rectangle: { i32 length, height; }
circle: { i32 radius; }
}
}