Skip to content

Commit

Permalink
Allocate stack space on entry to a function call
Browse files Browse the repository at this point in the history
Gets rid of a branch each time pawC_stkinc is called, which improves
performace a decent amount.
  • Loading branch information
andy-byers committed Sep 2, 2024
1 parent 0f06a95 commit 2077478
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
3 changes: 0 additions & 3 deletions src/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
#include "rt.h"
#include "str.h"
#include "util.h"
#include <assert.h>
#include <limits.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdlib.h>

// Lua-style error handling
Expand Down
55 changes: 27 additions & 28 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ static int stack_effect(OpCode opcode)
case OP_SETFIELD:
case OP_SETTUPLE:
return -3;
case OP_JUMPFALSEPOP:
case OP_SETLOCAL:
case OP_SETUPVALUE:
case OP_INITFIELD:
case OP_CMPI:
case OP_CMPF:
case OP_CMPS:
case OP_ARITHI2:
case OP_ARITHF2:
case OP_BITW2:
case OP_GETFIELD:
case OP_GETTUPLE:
return -1;
case OP_RETURN:
case OP_NOOP:
case OP_JUMP:
case OP_JUMPFALSE:
case OP_JUMPNULL:
case OP_ARITHI1:
case OP_ARITHF1:
case OP_BITW1:
case OP_CASTBOOL:
case OP_CASTINT:
case OP_CASTFLOAT:
case OP_BOOLOP:
return 0;
case OP_PUSHZERO:
case OP_PUSHONE:
case OP_PUSHSMI:
Expand All @@ -42,33 +68,6 @@ static int stack_effect(OpCode opcode)
case OP_FORLIST0:
case OP_FORMAP0:
return 2;
case OP_RETURN:
case OP_NOOP:
case OP_JUMP:
case OP_JUMPFALSE:
case OP_JUMPNULL:
case OP_ARITHI1:
case OP_ARITHF1:
case OP_BITW1:
case OP_CASTBOOL:
case OP_CASTINT:
case OP_CASTFLOAT:
return 0;
case OP_JUMPFALSEPOP:
case OP_SETLOCAL:
case OP_SETUPVALUE:
case OP_INITFIELD:
case OP_CMPI:
case OP_CMPF:
case OP_CMPS:
case OP_ARITHI2:
case OP_ARITHF2:
case OP_BITW2:
case OP_GETFIELD:
case OP_GETTUPLE:
return -1;
case OP_BOOLOP:
return 0;
case OP_STROP:
switch (GET_U(opcode)) {
case STR_LEN:
Expand Down Expand Up @@ -122,7 +121,7 @@ void pawK_fix_line(struct FuncState *fs, int line)
paw_assert(fs->nlines > 0);
fs->proto->lines[fs->nlines - 1].line = line;
}
#include <stdio.h>

static void add_opcode(struct FuncState *fs, OpCode code)
{
paw_Env *P = ENV(fs->G);
Expand Down

0 comments on commit 2077478

Please sign in to comment.