Skip to content

Commit

Permalink
😄 A much better VM 🎉
Browse files Browse the repository at this point in the history
tada
A big pull Request.

    * new VM, 3x faster

    * fix dinamicity
      and other fixes...
      smile
  • Loading branch information
fennecdjay committed Feb 23, 2019
2 parents b8ca5c8 + c3b73f5 commit d8884a1
Show file tree
Hide file tree
Showing 123 changed files with 2,344 additions and 1,721 deletions.
9 changes: 5 additions & 4 deletions .bettercodehub.yml
Expand Up @@ -6,12 +6,13 @@ languages:
include:
- /src/.*\.c
exclude:
- /src/ast/parser\.c
- /src/ast/lexer\.c
- /src/lib/soundpipe\.c
- /src/drvr/.*\.c
- /src/vm/vm.c
- /include/.*\.h
- /tests/import/.*\.c
test:
include:
- /tests/test_plugins/.*\.c
- /tests/import/.*\.c

- name: go
production:
Expand Down
2 changes: 1 addition & 1 deletion ast
Submodule ast updated from 8fe7b1 to 787c28
2 changes: 1 addition & 1 deletion examples/array_lit.gw
Expand Up @@ -12,7 +12,7 @@ Object t[2][12][3][4][5];
int k[1][1];


<<<i, j, o, p, r, s, t, k>>>;
<<<i, " ", j, " ", o, " ", p, " ", r, " ", s, " ", t, " ", k>>>;

[ 1.0, 2, 3, 4, 5 ];
[ #(0.0, 0.0) ];
Expand Down
2 changes: 1 addition & 1 deletion examples/binary_tmpl.gw
@@ -1,4 +1,4 @@
template<A> fun void test(A a) { <<<a>>>; }
template<~A~> fun void test(A a) { <<<a>>>; }
1 => test;
1.3 => test;
test(1);
Expand Down
4 changes: 2 additions & 2 deletions examples/class_coverage.gw
Expand Up @@ -4,8 +4,8 @@ class C
float f;
complex c;
polar p;
Vec3 v;
Vec4 w;
Vec3 v;
Vec4 w;
Object o;
dtor { <<<"dtor">>>; }
}
Expand Down
2 changes: 1 addition & 1 deletion examples/class_spork_func.gw
Expand Up @@ -5,7 +5,7 @@ class C
samp => now;
<<<"and now">>>;
}
spork test();
spork this.test();
}

C c;
Expand Down
10 changes: 10 additions & 0 deletions examples/dyn_switch.gw
@@ -0,0 +1,10 @@
3 => const int i;
2 => const int y;
switch(i) {
case 1: <<<1>>>;break;
case 3: <<<3>>>;break;
case y: <<<2>>>;break;
default:
<<<"0">>>;
}
<<<y>>>;
4 changes: 2 additions & 2 deletions examples/op2.gw
Expand Up @@ -12,9 +12,9 @@ operator => Vec3 (Vec3 c, C d){ <<<c.z => d.f>>>; return @(1.2, 6.1, 2.3
operator => Vec4 (Vec4 c, C d){ <<<"Vec4 => C: ", c.w => d.f>>>; return @(1.2, 6.1, 2.3, 9.3);}

operator => float (C d, int c){ <<<"int => C: ", c => d.f>>>; return 2.0;}
operator => float (C d, float f){ <<<"float => C: ", f => d.f>>>; return 2.0;}
operator => float (C d, float f){ <<<"C => float: ", f => d.f>>>; return 2.0;}

operator => float (Vec3 v, float f){ <<<"float => C: ", f, v.x => f>>>; return 2.0;}
operator => float (Vec3 v, float f){ <<<"vec3 => C: ", f, " ", v.x => f>>>; return 2.0;}

operator => complex (C d, complex c){ <<<"complex => C: ", c.re => d.f>>>; return #(1.2, 6.1);}
operator => polar (C d, polar c){ <<<"complex => C: ", c.mod => d.f>>>; return %(2.3, 4.1);}
Expand Down
4 changes: 3 additions & 1 deletion examples/spork_exp.gw
Expand Up @@ -2,11 +2,13 @@ class C
{
12 => int i;
Object o;
<<<this>>>;
spork {
"test";
second => now;
string s;
<<< "test spork exp." >>>;
<<< this, " test spork exp. " , s>>>;

} @=> Shred @shred;
}

Expand Down
6 changes: 3 additions & 3 deletions examples/spork_func.gw
@@ -1,13 +1,13 @@
class C
{
function void test() {
<<<"here">>>;
function void test(int i) {
<<<"here => ", i>>>;
samp => now;
<<<"and now">>>;
}
}

C c;
spork c.test();
spork c.test(2);
me.yield();
4::samp => now;
52 changes: 52 additions & 0 deletions examples/template_dyn.gw
@@ -0,0 +1,52 @@
fun void test(C cc) { <<< cc.test(2) >>>; }

fun void test(C cc, int i) { <<<1>>>; <<<cc.test(i, i)>>>; }


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


<<<C c>>>;
<<<D d>>>;
<<<E e>>>;

test(c);
test(d);
test(e);
test(c,1);
test(d,2);
test(e,3);
<<<test>>>;


c.test(1);
c.test(123,1);
c.test(1, 2, 3);

d.test(2);
d.test(123,3);
d.test(2, 2, 3);

e.test(3);
e.test(123,3);
e.test(3, 2, 3);

fun void _test() {<<<"test">>>; }
fun void test() { _test(); }
test();

1 change: 1 addition & 0 deletions examples/vec3.gw
Expand Up @@ -34,3 +34,4 @@ w-10.;
w/10.;
10.*w;
w*10.;
<<<@(23).x>>>;
11 changes: 0 additions & 11 deletions help/lcov.sh
Expand Up @@ -4,17 +4,6 @@ OUTFILE=lcov/lcov.info

[ -d lcov ] || mkdir lcov

#[ -z "$TRAVIS_BUILD_DIR" ] || {
# BASE_DIR=$PWD
# cd tests/test_plugin || return
# for file in *.c
# do
# sed 's/\.c//' <<< "$file"
# test_test_plugin "$(sed 's/\.c//' <<< "$file")"
# done
# cd "$BASE_DIR" || return
#}

lcov --no-external --capture --directory src --output-file "$OUTFILE"

[ -z "$TRAVIS_BUILD_DIR" ] || {
Expand Down
25 changes: 25 additions & 0 deletions help/opcode.sh
@@ -0,0 +1,25 @@
#!/bin/bash
echo "#ifndef __GWION_OPCODES__"
echo "#define __GWION_OPCODES__"

list=$(grep -v "#" opcode.txt)
COUNT=0
echo "enum {"
for a in ${list}
do
[ -z "$a" ] || {
echo " $a,"
COUNT=$((COUNT+1))
}
done
echo "};"
echo ""

for a in ${list}
do
[ -z "$a" ] || echo "#define $a (f_instr)$a"
done | column -t

echo "#endif"

echo "generated" "$COUNT" "opcodes" >&2
5 changes: 2 additions & 3 deletions include/arg.h
Expand Up @@ -6,11 +6,10 @@ typedef struct {
struct Vector_ add;
struct Vector_ rem;
struct Vector_ lib;
Vector ref;
struct Vector_ mod;
m_bool loop;
unsigned quit : 1;
} Arg;

ANN void arg_init(Arg* arg);
ANN void arg_release(Arg* arg);
ANN uint parse_args(Arg*, DriverInfo*);
#endif
1 change: 0 additions & 1 deletion include/array.h
Expand Up @@ -3,7 +3,6 @@
typedef struct M_Vector_ * M_Vector;
typedef struct ArrayInfo_ {
m_int depth;
// Type type, base;
struct Vector_ type;
Type base;
M_Object* data;
Expand Down
1 change: 0 additions & 1 deletion include/context.h
Expand Up @@ -12,5 +12,4 @@ struct Context_ {
ANN2(2) ANEW Context new_context(const Ast, const m_str);
ANN void load_context(const Context, const Env);
ANN void unload_context(const Context, const Env);
ANN void free_context(const Context);
#endif
1 change: 0 additions & 1 deletion include/env.h
Expand Up @@ -48,7 +48,6 @@ ANN m_bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def)
ANN Type known_type(const Env env, const Type_Decl*);
ANN m_bool env_access(const Env env, const ae_flag flag);
ANN void env_storage(const Env env, ae_flag* flag);
ANN2(1,2) void env_add_value(const Env, const m_str, const Type, const m_bool, void*);
ANN void env_add_type(const Env, const Type);
ANN Type find_type(const Env, ID_List);
ANN m_bool already_defined(const Env env, const Symbol s, const uint pos);
Expand Down
4 changes: 4 additions & 0 deletions include/gack.h
@@ -0,0 +1,4 @@
#ifndef __GACK
#define __GACK
ANN void gack(const m_bit*, const Instr);
#endif
12 changes: 10 additions & 2 deletions include/gwion.h
@@ -1,7 +1,12 @@
#ifndef __GWION
#define __GWION
typedef struct Gwion_* Gwion;
#include "plug.h"
#include "driver.h"
struct Gwion_ {
PlugInfo plug;
Driver* driver;
// scanner
// sym
// mem
// rnd
Expand All @@ -10,6 +15,9 @@ struct Gwion_ {
Emitter emit;
VM* vm;
};
ANN void gwion_init(Gwion gwion);
ANN void gwion_release(Gwion gwion);
ANN void gwion_init(const Gwion, const Vector);
ANN m_bool gwion_audio(const Gwion gwion, DriverInfo* di);
ANN void gwion_run(const Gwion gwion, DriverInfo* di);
ANN m_bool gwion_engine(const Gwion gwion);
ANN void gwion_release(const Gwion gwion, DriverInfo* di);
#endif
18 changes: 13 additions & 5 deletions include/import.h
Expand Up @@ -2,16 +2,22 @@
#define __IMPORT
#define DLARG_MAX 6

typedef void (*f_xtor)(const M_Object o, const VM_Shred sh);
typedef void (*f_xtor)(const M_Object o, const m_bit*, const VM_Shred);
//typedef void (*f_xtor)(const M_Object o, const VM_Shred);
typedef void (*f_mfun)(const M_Object o, const m_bit* RETURN, const VM_Shred sh);
typedef void (*f_sfun)(const m_bit* RETURN, const VM_Shred sh);
//typedef void (*f_sfun)(const m_bit*, const m_bit* RETURN, const VM_Shred sh);
typedef void (*f_xfun)();
typedef struct Gwi_* Gwi;

#define MFUN(a) ANN void a(const M_Object o __attribute__((unused)), const m_bit* RETURN __attribute__((unused)), const VM_Shred shred __attribute__((unused)))
#define SFUN(a) ANN void a(const m_bit* RETURN __attribute__((unused)), const VM_Shred shred __attribute__((unused)))
#define CTOR(a) ANN void a(const M_Object o, const VM_Shred shred __attribute__((unused)))
#define DTOR(a) ANN void a(const M_Object o, const VM_Shred shred __attribute__((unused)))
//#define SFUN(a) ANN void a(const m_bit* mem __attribute__((unused)), const m_bit* RETURN
//__attribute__((unused)), const VM_Shred shred __attribute__((unused)))
#define CTOR(a) ANN void a(const M_Object o, const m_bit* _ __attribute__((unused)), const VM_Shred shred __attribute__((unused)))
//#define CTOR(a) ANN void a(const M_Object o, const VM_Shred shred __attribute__((unused)))
#define DTOR(a) ANN void a(const M_Object o, const m_bit* _ __attribute__((unused)), const VM_Shred shred __attribute__((unused)))
//#define DTOR(a) ANN void a(const M_Object o, const VM_Shred shred __attribute__((unused)))
#define OP_CHECK(a) ANN Type a(const Env env __attribute__((unused)), void* data __attribute__((unused)))
#define OP_EMIT(a) ANN m_bool a(const Emitter emit __attribute__((unused)), void* data __attribute__((unused)))
#ifdef GWION_BUILTIN
Expand All @@ -28,8 +34,6 @@ typedef struct Gwi_* Gwi;
ANN VM* gwi_vm(const Gwi);
ANN2(1,2) ANEW Type gwi_mk_type(const Gwi, const m_str, const m_uint, const Type);
ANN m_int gwi_add_type(const Gwi gwi, Type type);
ANN2(1,2,3)m_int gwi_add_value(const Gwi gwi, const m_str name, Type type, const m_bool is_const, void* data);

ANN2(1,2)m_int gwi_class_ini(const Gwi gwi, const Type type, const f_xtor pre_ctor, const f_xtor dtor);
ANN m_int gwi_class_ext(const Gwi gwi, Type_Decl* td);
ANN m_int gwi_class_end(const Gwi gwi);
Expand Down Expand Up @@ -73,4 +77,8 @@ OP_CHECK(opck_basic_cast);
OP_CHECK(opck_new);
OP_EMIT(opem_basic_cast);
OP_EMIT(opem_new);


ANN /*static */ Type_List str2tl(const Env env, const m_str s, m_uint *depth);

#endif

0 comments on commit d8884a1

Please sign in to comment.