Skip to content

Commit

Permalink
🎨 time => now 😄
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Mar 20, 2024
1 parent 1cef645 commit 2f1ebe9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ast
Submodule ast updated 2 files
+110 −108 pass/xxx.c
+70 −70 pass/xxx.h
6 changes: 6 additions & 0 deletions include/opcode.h
Expand Up @@ -143,6 +143,7 @@ enum {
efloat_int_r_div,
eCastI2F,
eCastF2I,
eDur_Advance,
eTime_Advance,
eRecurs,
eSetCode,
Expand Down Expand Up @@ -364,6 +365,7 @@ enum {
#define float_int_r_div (f_instr)efloat_int_r_div
#define CastI2F (f_instr)eCastI2F
#define CastF2I (f_instr)eCastF2I
#define Dur_Advance (f_instr)eDur_Advance
#define Time_Advance (f_instr)eTime_Advance
#define Recurs (f_instr)eRecurs
#define SetCode (f_instr)eSetCode
Expand Down Expand Up @@ -1086,6 +1088,10 @@ ANN static inline void dump_opcodes(const VM_Code code) {
gw_out("{Y}┃{0}{-}% 4lu{0}: CastF2I ", j);
gw_out("\n");
break;
case eDur_Advance:
gw_out("{Y}┃{0}{-}% 4lu{0}: Dur_Advance ", j);
gw_out("\n");
break;
case eTime_Advance:
gw_out("{Y}┃{0}{-}% 4lu{0}: Time_Advance", j);
gw_out("\n");
Expand Down
4 changes: 3 additions & 1 deletion include/vm.h
Expand Up @@ -101,7 +101,9 @@ ANN ANEW VM_Code vmcode_callback(MemPool p, const VM_Code code);
ANN VM_Shred shreduler_get(const Shreduler s) __attribute__((hot));
ANN void shreduler_remove(const Shreduler s, const VM_Shred out,
const bool erase) __attribute__((hot));
ANN void shredule(const Shreduler s, const VM_Shred shred,
ANN void shredule(const Shreduler s, const VM_Shred shred,
const m_float wake_time);
ANN void shredule_time(const Shreduler s, const VM_Shred shred,
const m_float wake_time) __attribute__((hot));
ANN void shreduler_set_loop(const Shreduler s, const bool loop);
ANN void shreduler_ini(const Shreduler s, const VM_Shred shred);
Expand Down
1 change: 1 addition & 0 deletions opcode.txt
Expand Up @@ -140,6 +140,7 @@ float_int_r_mul
float_int_r_div
CastI2F
CastF2I
Dur_Advance
Time_Advance
Recurs
SetCode~i~i
Expand Down
3 changes: 2 additions & 1 deletion src/lib/prim.c
Expand Up @@ -519,8 +519,9 @@ static GWION_IMPORT(time) {
CHECK_FF(":=>", rassign, r_assign)
GWI_B(gwi_oper_end(gwi, "+", float_add))
GWI_B(gwi_oper_ini(gwi, "dur", "@now", "time"))
_CHECK_OP("=>", now, Time_Advance)
_CHECK_OP("=>", now, Dur_Advance)
GWI_B(gwi_oper_ini(gwi, "time", "time", "bool"))
GWI_B(gwi_oper_end(gwi, "=>", Time_Advance))
GWI_B(gwi_oper_end(gwi, ">", float_gt))
GWI_B(gwi_oper_end(gwi, ">=", float_ge))
GWI_B(gwi_oper_end(gwi, "<", float_lt))
Expand Down
16 changes: 12 additions & 4 deletions src/vm/shreduler.c
Expand Up @@ -79,12 +79,11 @@ ANN void shreduler_remove(const Shreduler s, const VM_Shred out,
ANN static void _shredule(const Shreduler s, struct ShredTick_ *tk,
const m_float wake_time) {
if(tk->prev == (struct ShredTick_*)-1) return;
const m_float time = wake_time + (m_float)s->bbq->pos;
tk->wake_time = time;
tk->wake_time = wake_time;
if (s->list) {
struct ShredTick_ *curr = s->list, *prev = NULL;
do {
if (curr->wake_time > time) break;
if (curr->wake_time > wake_time) break;
prev = curr;
} while ((curr = curr->next));
if (!prev) {
Expand All @@ -99,14 +98,23 @@ ANN static void _shredule(const Shreduler s, struct ShredTick_ *tk,
if (tk == s->curr) s->curr = NULL;
}

ANN void shredule(const Shreduler s, const VM_Shred shred,
ANN void shredule_time(const Shreduler s, const VM_Shred shred,
const m_float wake_time) {
if(wake_time < s->bbq->pos) {
handle(shred, "NegativeWakeUpTime");
return;
}
struct ShredTick_ *tk = shred->tick;
gwt_lock(&s->mutex);
_shredule(s, tk, wake_time);
gwt_unlock(&s->mutex);
}

ANN void shredule(const Shreduler s, const VM_Shred shred,
const m_float wake_time) {
return shredule_time(s, shred, wake_time + s->bbq->pos);
}

ANN void shreduler_ini(const Shreduler s, const VM_Shred shred) {
shred->tick = mp_calloc(shred->info->mp, ShredTick);
shred->tick->self = shred;
Expand Down
10 changes: 6 additions & 4 deletions src/vm/vm.c
Expand Up @@ -453,7 +453,7 @@ vm_prepare(const VM *vm, m_bit *prepare_code) { // lgtm [cpp/use-of-goto]
&&ifrassign, &&ifradd, &&ifrsub, &&ifrmul, &&ifrdiv, &&fiadd, &&fisub,
&&fimul, &&fidiv, &&fiand, &&fior, &&fieq, &&fine, &&figt, &&fige, &&filt,
&&file, &&firassign, &&firadd, &&firsub, &&firmul, &&firdiv, &&itof,
&&ftoi, &&timeadv, &&recurs, &&setcode, &&regmove,
&&ftoi, &&duradv, &&timeadv, &&recurs, &&setcode, &&regmove,
&&regtomem, &&regtomemother, &&staticmemcpy, &&staticmemset,
&&overflow,
&&funcusrend, &&funcusrend2, &&funcmemberend,
Expand Down Expand Up @@ -901,10 +901,11 @@ vm_prepare(const VM *vm, m_bit *prepare_code) { // lgtm [cpp/use-of-goto]
*(m_int *)(reg - SZ_INT) = (m_int)f;
DISPATCH()
}
duradv:
*(m_float *)(reg - SZ_FLOAT*2) += vm->bbq->pos;
timeadv:
reg -= SZ_FLOAT;
shredule(s, shred, *(m_float *)(reg - SZ_FLOAT));
*(m_float *)(reg - SZ_FLOAT) += vm->bbq->pos;
shredule_time(s, shred, *(m_float *)(reg - SZ_FLOAT));
VM_OUT
break;
recurs:
Expand Down Expand Up @@ -1341,7 +1342,7 @@ static void *_dispatch[] = {
&&_ifrassign, &&_ifradd, &&_ifrsub, &&_ifrmul, &&_ifrdiv, &&_fiadd, &&_fisub,
&&_fimul, &&_fidiv, &&_fiand, &&_fior, &&_fieq, &&_fine, &&_figt, &&_fige, &&_filt,
&&_file, &&_firassign, &&_firadd, &&_firsub, &&_firmul, &&_firdiv, &&_itof,
&&_ftoi, &&_timeadv, &&_recurs, &&_setcode, &&_regmove,
&&_ftoi, &&_duradv, &&_timeadv, &&_recurs, &&_setcode, &&_regmove,
&&_regtomem, &&_regtomemother, &&_staticmemcpy, &&_staticmemset,
&&_overflow,
&&_funcusrend, &&_funcusrend2, &&_funcmemberend,
Expand Down Expand Up @@ -1535,6 +1536,7 @@ return;
PREPARE(itof);
PREPARE(ftoi);

PREPARE(duradv);
PREPARE(timeadv);

PREPARE(recurs);
Expand Down

0 comments on commit 2f1ebe9

Please sign in to comment.