Skip to content

Commit

Permalink
Merge pull request #117 from fennecdjay/UnionTmpl
Browse files Browse the repository at this point in the history
Improve type system.
  • Loading branch information
fennecdjay committed Jun 6, 2019
2 parents e483059 + 67cfe8e commit d62e2d7
Show file tree
Hide file tree
Showing 106 changed files with 792 additions and 484 deletions.
15 changes: 10 additions & 5 deletions .travis.yml
Expand Up @@ -2,8 +2,8 @@ language: c
#sudo: required
os:
- linux
# - windows
- osx
- windows

addons:
# coverity_scan:
Expand Down Expand Up @@ -33,8 +33,8 @@ env:

matrix:
allow_failures:
- compiler: clang
# - os: windows
# - compiler: clang
- os: windows

compiler:
- gcc
Expand All @@ -47,7 +47,7 @@ install:
export BUILD_ON_WINDOWS=1;
export VALGRIND="NO_VALGRIND";
export SEVERITY=1;
export LDFLAGS="$LDLAGS -lpsapi -shared -fPIC -Wl,--export-all -Wl,--enable-auto-import -Wl,--out-implib,libgwion.a";
export LDFLAGS="$LDLAGS -lpsapi -shared -fPIC -Wl,--export-all -Wl,--enable-auto-import";
export LIBS="$LIBS -lpsapi -shared -fPIC";
fi;

Expand All @@ -59,7 +59,12 @@ before_script:
script:
- if [ $(uname) = "Linux" ] || [ $(uname) = "Darwin" ];
then make && make test;
else make.exe && make.exe test;
else {
if [ "$CC" = "clang" ];
then export CFLAGS+=" -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -Dssize_t=SSIZE_T";
fi;
make.exe && make.exe test;
}
fi;

git:
Expand Down
2 changes: 1 addition & 1 deletion ast
Submodule ast updated from 2f8759 to 63cdc3
2 changes: 1 addition & 1 deletion examples/binary_tmpl.gw
@@ -1,4 +1,4 @@
fun<~A~> void test(A a) { <<<a>>>; }
fun void test<~A~>(A a) { <<<a>>>; }
1 => test;
1.3 => test;
test(1);
Expand Down
8 changes: 4 additions & 4 deletions examples/class_func_pointer.gw
@@ -1,13 +1,13 @@
function void test() { <<<"member function.">>>; }
fun void test() { <<<"member function.">>>; }
class C {
typedef void func_t();
// typedef static void s_func_t();
func_t func_p;
// static fun c_t s_func_p;
// static s_func_t s_ptr;
function void test() { <<<"member function.">>>; }
function void test2() { <<<"member function variant.">>>; }
// fun static void s_test() { <<<"member function.">>>; }
fun void test() { <<<"member function.">>>; }
fun void test2() { <<<"member function variant.">>>; }
// fun static void s_test() { <<<"member fun.">>>; }
// test @=> func_p;
// test @=> s_ptr;

Expand Down
2 changes: 1 addition & 1 deletion examples/class_spork_func.gw
@@ -1,6 +1,6 @@
class C
{
function void test() {
fun void test() {
<<<"here">>>;
samp => now;
<<<"and now">>>;
Expand Down
4 changes: 2 additions & 2 deletions examples/func.gw
@@ -1,4 +1,4 @@
function float testf(){ return 1.1; }
function float testf(float f){ return f; }
fun float testf(){ return 1.1; }
fun float testf(float f){ return f; }
<<<testf()>>>;
<<<testf(1.4)>>>;
4 changes: 2 additions & 2 deletions examples/func_pointer.gw
@@ -1,7 +1,7 @@
typedef void func_t();
func_t func_p;
function void test1() { <<<"test1">>>; }
function void test2() { <<<"test2">>>; }
fun void test1() { <<<"test1">>>; }
fun void test2() { <<<"test2">>>; }
test1 @=> func_p;
func_p();
func_p();
Expand Down
14 changes: 7 additions & 7 deletions examples/func_ptr.gw
@@ -1,15 +1,15 @@
// define a function pointer type
// define a fun pointer type
typedef void Test()

// define a few functions
function void test1(){ <<<"test">>>; };
function void test2(){ <<<"another test">>>; };
function void test3(){ <<<"yet another test">>>; };
// define a few funs
fun void test1(){ <<<"test">>>; };
fun void test2(){ <<<"another test">>>; };
fun void test3(){ <<<"yet another test">>>; };

// create a function pointer instance
// create a fun pointer instance
Test test;

// assign it a function
// assign it a fun
test1 @=> test;
// test it
test();
Expand Down
2 changes: 1 addition & 1 deletion examples/in_class_class.gw
@@ -1,5 +1,5 @@
class C {
function<~a~> void test(a var){ <<<var>>>; }
fun void test<~a~>(a var){ <<<var>>>; }
class D { int i;}
}

Expand Down
14 changes: 7 additions & 7 deletions examples/member.gw
Expand Up @@ -7,19 +7,19 @@ class C
Vec4 w;
Object o;

function int m_i() { return i; }
function float m_f() { return f; }
function complex m_c() { return c; }
function Vec3 m_v() { return v; }
function Vec4 m_w() { return w; }
function Object m_o() { return o; }
fun int m_i() { return i; }
fun float m_f() { return f; }
fun complex m_c() { return c; }
fun Vec3 m_v() { return v; }
fun Vec4 m_w() { return w; }
fun Object m_o() { return o; }
}

C c;
// read members
<<< c.i, c.c, c.f, c.v, c.w, c.o >>>;

// call function members
// call fun members
<<< c.m_i(), " ", c.m_f(), " ", c.m_c(), " ",
c.m_v(), " ", c.m_w(), " ", c.m_o()>>>;

Expand Down
4 changes: 2 additions & 2 deletions examples/member_func.gw
@@ -1,9 +1,9 @@
class C
{
function float testf() {
fun float testf() {
return 1.1;
}
function float testf(float f) {
fun float testf(float f) {
return f;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ptr_assign_class.gw
@@ -1,7 +1,7 @@
class C
{
typedef void Test();
function void test1(){};
fun void test1(){};
Test test0;
<<<test1 @=> test0>>>;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/sinosc_extend.gw
@@ -1,6 +1,6 @@
class Sine extends SinOsc
{
function float freq(float f) { (2 * f) => (this $ SinOsc).freq; }
fun float freq(float f) { (2 * f) => (this $ SinOsc).freq; }
}

Sine s => dac;
Expand Down
2 changes: 1 addition & 1 deletion examples/spork_func.gw
@@ -1,6 +1,6 @@
class C
{
function void test(int i) {
fun void test(int i) {
<<<"here => ", i>>>;
samp => now;
<<<"and now">>>;
Expand Down
14 changes: 7 additions & 7 deletions examples/static.gw
Expand Up @@ -7,12 +7,12 @@ class C
static Vec4 w;
static Object o;

function int m_i() { return i; }
function float m_f() { return f; }
function complex m_c() { return c; }
function Vec3 m_v() { return v; }
function Vec4 m_w() { return w; }
function Object m_o() { return o; }
fun int m_i() { return i; }
fun float m_f() { return f; }
fun complex m_c() { return c; }
fun Vec3 m_v() { return v; }
fun Vec4 m_w() { return w; }
fun Object m_o() { return o; }

fun static int _i() { return i; }
fun static float _f() { return f; }
Expand All @@ -25,7 +25,7 @@ class C
// read members
<<< C.i, C.c, C.f, C.v, C.w, C.o >>>;

// call function members
// call fun members
<<< C._i(), " ", C._f(), " ", C._c(), " ", C._v(), " ", C._w(), " ", C._o()>>>;

// write members
Expand Down
2 changes: 1 addition & 1 deletion examples/switch.gw
@@ -1,6 +1,6 @@
int i;

function void test(int i) {
fun void test(int i) {
switch(i) {
case 1:
<<<"'i' is 1">>>;
Expand Down
4 changes: 2 additions & 2 deletions examples/template.gw
@@ -1,4 +1,4 @@
function<~A~> void test (A var){ <<< var>>>; }
function<~A,B~> void test (A var, B var2){ <<< var>>>; }
fun void test<~A~> (A var){ <<< var>>>; }
fun void test<~A,B~> (A var, B var2){ <<< var>>>; }
test<~int~>(1);
test<~float, float~>(3, 1.4);
10 changes: 5 additions & 5 deletions examples/template_dyn.gw
Expand Up @@ -4,15 +4,15 @@ fun void test(C cc, int i) { <<<1>>>; <<<cc.test(i, i)>>>; }


class C {
fun<~A~> int test(A a) { <<<" A ", a>>>; }
fun<~A~> int test(A a, int i) { <<<" ", a >>>; }
fun<~A~> int test(A a, int i, int j) { <<<a>>>; }
fun int test<~A~>(A a) { <<<" A ", a>>>; }
fun int test<~A~>(A a, int i) { <<<" ", a >>>; }
fun int test<~A~>(A a, int i, int j) { <<<a>>>; }
}
class D extends C {
fun<~A~> int test(A a, int i) { <<<this, " extent ", a, __func__>>>; }
fun int test<~A~>(A a, int i) { <<<this, " extent ", a, __func__>>>; }
}
class E extends D {
fun<~A~> int test(A a, int i) { <<<this, " Extent ", a, __func__>>>; }
fun int test<~A~>(A a, int i) { <<<this, " Extent ", a, __func__>>>; }
}


Expand Down
2 changes: 1 addition & 1 deletion examples/template_guess.gw
@@ -1,4 +1,4 @@
function <~A,B~> void test(A a, B b){<<<a, ", ", b>>>;}
fun void test<~A,B~>(A a, B b){<<<a, ", ", b>>>;}
test(1, 2.1);
test(1.1, 2.1);
test(1.2, 2);
2 changes: 1 addition & 1 deletion examples/template_vararg.gw
@@ -1,4 +1,4 @@
fun<~A~> void test(...) {
fun void test<~A~>(...) {
vararg.start;
<<<vararg.i>>>;
vararg.end;
Expand Down
6 changes: 4 additions & 2 deletions include/instr.h
Expand Up @@ -61,13 +61,15 @@ INSTR(VecMember);
INSTR(PopArrayClass);

INSTR(DotTmpl);
INSTR(GTmpl);

struct dottmpl_ {
size_t len;
m_str name;
Func_Def base, def;
Type owner;
size_t overload; // => vtindex ?
Type owner_class;
Nspc owner;
size_t vt_index;
Type_List tl;
};
ANN void free_dottmpl(struct dottmpl_*);
Expand Down
14 changes: 14 additions & 0 deletions include/parse.h
Expand Up @@ -79,4 +79,18 @@ static inline ANN m_bool env_ext(const Env env, const Class_Def cdef, const _exp

ANN m_bool scanx_parent(const Type t, const _exp_func f, void *d);
#define scanx_parent(a,b,c) scanx_parent(a, (_exp_func)b, c)


ANN m_bool scanx_cdef(const Env, void *,const Class_Def,
const _exp_func f_cdef, const _exp_func f_union);

#define xxx_cdef(prefix) \
static inline m_bool prefix##_cdef(const Env env, const Class_Def cdef) { \
return scanx_cdef(env, env, cdef, \
(_exp_func)prefix##_class_def, (_exp_func)prefix##_stmt_union); \
}
xxx_cdef(scan1)
xxx_cdef(scan2)
xxx_cdef(check)
xxx_cdef(traverse)
#endif
19 changes: 10 additions & 9 deletions include/type.h
@@ -1,15 +1,16 @@
#ifndef __TYPE
#define __TYPE

struct TypeInfo_ {
Type parent;
Nspc owner;
Class_Def def;
union type_data {
Func func;
Type base_type;
} d;
};
struct TypeInfo_ {
Type parent;
Nspc owner;
Class_Def def;
union type_data {
Func func;
Type base_type;
} d;
struct Vector_ contains;
};

struct Type_ {
m_str name;
Expand Down

0 comments on commit d62e2d7

Please sign in to comment.