meowlang/compiler/example.mew
Gwendolyn d6bdd08002 loooots of stuff
the typechecker project can collect all the top level types from a file, which is pretty cool I think
(except for pointers, those aren't implemented yet...)
2022-02-13 02:41:16 +01:00

190 lines
2.4 KiB
Plaintext

import "std:strings";
import "foo" as bar;
import "./foobar";
/*
fn foo() {}
pub fn bar(int x) -> int {}
pub fn multiret() -> int, int {}
[c_export] pub fn add(int a, int b) -> int {}
[c_export("add_floats")] pub fn add(float a, float b) -> float {}
fn sub<T>(T a, T b) -> T
where SUBTRACT T
{
// do something
}
fn ret_arr() -> [int; 10] {}
fn ret_slice() -> [int] {}
fn ret_multislice() -> [[int]] {}
fn ret_ptr() -> int* {}
fn ret_ptrslice() -> [int*] {}
fn ret_arrayptr() -> [int; 5]* {}
fn ret_tuple() -> (int, int) {}
fn ret_imported() -> strings:StringBuilder {}
fn ret_nested() -> foo@bar {}
fn ret_imported_nested() -> foo:bar@some@nested@shit {}
constraint Foo A {
whatever(A);
}
constraint Bar B {
constraint Foo B*;
constraint Foo [B];
constraint Foo (int, B);
constraint Foo SomeType<B>;
}
*/
/*
struct Foo {
something: int;
bar: struct {
foo: int;
};
}
enum X {
A,
B,
C
}
enum X<T1, T2, T3> {
A(T1),
B(T2),
C(T3),
}
enum X<T1, T2, T3> where Constraint T1 T2 where Constraint T2 T3 {
A(T1),
B(T2),
C(T3),
}
struct X<T> {
a: T;
}
tuple Point(int,int,int)
tuple Point<T> where Arithmetic T (T,T,T)
type A = Foo;
type F<X> = Foo<Bar<X>>;
type X = [Y; 10];
*/
/*
tuple X<A> (A,A,A);
type X<T> = [T; 10];
type X<T1, T2> = (T1, T2);
fn foo() {
let foo = X<int> {a: 1, b: 2};
let bar = X<string> {a: "foo" , b: "bar"};
let test = Imported:X<int-nya>@bar []{1,2,3};
foo.a + 1;
bar.a + 1;
meoooow let x-nyaaaa = []{1-nya, meow 2};
outer: loop let x = 1; x < 10; x += 1 {
switch 1 {
case 1: {
foobar();
},
case 2: fallthrough,
case 3: x,
default: bar(),
}
}
}
struct Bar {
y: Foo;
}
struct Foo {
x: enum {Foo, Bar};
}
struct A<T> {
x: B<T>;
y: s32;
}
struct B<T> {
x: T;
}
struct C {
x: B<u32>;
}
enum E {
A,
B,
C
}
enum F {
A(u8),
B(B<u16>),
C(C)
}
fn foo(x: u32) {}
fn foo(x: s32) {}
fn bar(x: f32) {}
fn bar(x: f64) {}
fn test() {
let x = 1; // no idea what the type is
foo(x); // could be u32 or s32
bar(x); // f32 and f64 conflict with u32 and s32
}
type A = int*;
struct B {
x: (int, int);
}*/
type A<T> = [(T,int); 10];
struct A<T> {
x: B<T>;
y: s32;
}