optimise
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
#include <stdint.h>
|
||||
|
||||
void _GroundBytecodeProgramExecute(GroundBytecodeProgram* program, GroundBytecodeHeap* heap) {
|
||||
for (GroundSize i = 0; i < program->len; i++) {
|
||||
GroundSize i = 0;
|
||||
while (i < program->len) {
|
||||
int64_t status = Ground.Bytecode.Instruction.execute(&program->at[i], heap);
|
||||
if (Ground.Flags.error) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case -1: break;
|
||||
case -1: i++; break;
|
||||
case -2: return;
|
||||
default: i = status; break;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
#include "../../../include/ground.h"
|
||||
|
||||
void _GroundBytecodeProgramOptimise(GroundBytecodeProgram* program) {
|
||||
// TODO: Implement optimisation
|
||||
|
||||
for (GroundSize i = 0; i < program->len; i++) {
|
||||
if (program->at[i].type == GroundInstruction_JUMP) {
|
||||
GroundSize target = program->at[i].args.at[0];
|
||||
|
||||
while (target < program->len && program->at[target].type == GroundInstruction_JUMP) {
|
||||
target = program->at[target].args.at[0];
|
||||
}
|
||||
|
||||
program->at[i].args.at[0] = target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user