Skip to content

Commit

Permalink
Add process number
Browse files Browse the repository at this point in the history
for #27
  • Loading branch information
rizky committed May 1, 2018
1 parent 936daab commit 65fba5b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/ft_vm/ft_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/19 21:38:33 by rnugroho #+# #+# */
/* Updated: 2018/04/30 14:09:09 by rnugroho ### ########.fr */
/* Updated: 2018/05/01 15:46:55 by rnugroho ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,11 +19,11 @@ void
int i;
t_process p;

i = -1;
i = vm->champ_size - 1;
vm_init_g_var();
ft_bzero(&p, sizeof(t_process));
ft_printfln("Introducing contestants...");
while (++i < vm->champ_size)
while (i >= 0)
{
g_reg[i][1] = (i + 1) * -1;
ft_printfln("* Player %d, weighing %d bytes, \"%s\" (\"%s\") !", i + 1,
Expand All @@ -35,7 +35,9 @@ void
vm->champ[i].header.prog_size);
p.offset = i * MEM_SIZE / vm->champ_size;
p.champ = i;
p.index = 1 + vm->process_size++;
fta_append(vm->champ[i].processes, &p, 1);
i--;
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/ft_vm/vm_decompiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/24 15:59:39 by rnugroho #+# #+# */
/* Updated: 2018/05/01 15:09:55 by rnugroho ### ########.fr */
/* Updated: 2018/05/01 15:42:11 by rnugroho ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -101,7 +101,6 @@ void
t_process *p;

i = -1;
vm->process_size = 0;
while (++i < vm->champ_size && (j = -1))
{
while (++j < (int)(vm->champ[i].processes->size))
Expand All @@ -116,7 +115,6 @@ void
&op);
p->op = op;
}
vm->process_size++;
}
}
vm_executor(vm);
Expand Down
6 changes: 1 addition & 5 deletions src/ft_vm/vm_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: rnugroho <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/23 11:23:54 by rnugroho #+# #+# */
/* Updated: 2018/04/27 15:00:53 by rnugroho ### ########.fr */
/* Updated: 2018/05/01 15:45:03 by rnugroho ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -41,10 +41,8 @@ void
int i;
int j;
t_process *p;
int n;

i = vm->champ_size - 1;
n = vm->process_size;
while (i >= 0)
{
j = -1;
Expand All @@ -53,14 +51,12 @@ void
p = &(((t_process*)vm->champ[i].processes->data)[j]);
if (p->cycles == g_cycles)
{
p->index = n;
(vm->v_lvl[V_LVL_4]) ? vm_print_v_4(*p) : 0;
(vm->v_lvl[V_LVL_16]) ? vm_print_v_16(*p) : 0;
(((void (*)())g_op_dict[p->op.opcode].opfunc)(vm, p));
ft_bzero(&(p->op), sizeof(t_op));
}
}
i--;
n--;
}
}
8 changes: 5 additions & 3 deletions src/ft_vm/vm_op_5.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vm_op_4.c :+: :+: :+: */
/* vm_op_5.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fpetras <marvin@42.fr> +#+ +:+ +#+ */
/* By: rnugroho <rnugroho@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/26 08:30:28 by fpetras #+# #+# */
/* Updated: 2018/04/27 04:34:21 by fpetras ### ########.fr */
/* Updated: 2018/05/01 15:47:03 by rnugroho ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -29,6 +29,7 @@ void
if (value < 0)
new_p.pc += MEM_SIZE;
new_p.champ = p->champ;
new_p.index = 1 + vm->process_size++;
fta_append(vm->champ[p->champ].processes, &new_p, 1);
vm_op_inc(vm, p);
}
Expand All @@ -47,6 +48,7 @@ void
value = value % MEM_SIZE;
new_p.pc = p->pc + value - (p->offset + p->pc);
new_p.champ = p->champ;
new_p.index = 1 + vm->process_size++;
fta_append(vm->champ[p->champ].processes, &new_p, 1);
vm_op_inc(vm, p);
}
Expand Down

0 comments on commit 65fba5b

Please sign in to comment.