Skip to content

Commit e441fda

Browse files
committed
Make max number of instructions configurable
1 parent 1b7970f commit e441fda

8 files changed

Lines changed: 13 additions & 6 deletions

File tree

mfiles/raylib.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
let EndDrawing = extern raylib::EndDrawing(): Void;
1515

1616
let DrawText = extern raylib::DrawText(text: String, x: Int, y: Int, fontSize: Int, color: Int): Void;
17+
let DrawRectangle = extern raylib::DrawRectangle(x: Int, y: Int, width: Int, height: Int, color: Int): Void;
1718

1819
while(WindowShouldClose() == false) {
1920
BeginDrawing();
20-
ClearBackground(1);
21-
DrawText(str, 190, 200, 20, 1);
21+
ClearBackground(9000);
22+
DrawText(str, 200, 200, 5, 7000);
23+
DrawRectangle(100, 100, 150, 150, 7000);
2224
EndDrawing();
2325
}
2426

src/core/Mlang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Mlang::Result Mlang::execute(const std::string& theFile,
158158
auto program = byteCodeEmitter.getProgram();
159159
executor::ByteCodeVM runner(program);
160160
runner.setDebug(settings.showExecution);
161-
auto result = runner.execute();
161+
auto result = runner.execute(settings.maxInstructions);
162162

163163
return Mlang::Result(Mlang::Result::Signal::Success, result);
164164
}

src/core/Mlang.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Mlang {
4545
bool showEmission = false;
4646
bool showTypeInference = false;
4747
bool showExecution = false;
48+
size_t maxInstructions = 0; // 0 means no limit
4849
};
4950

5051
Settings settings;

src/executer/ByteCode.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ std::string instructionsToString(const std::vector<Instruction>& instructions, b
8787
}
8888

8989
ProgramState ByteCodeVM::run(size_t maxInstructions) {
90-
for (size_t instructionCount = 0; instructionCount < maxInstructions; ++instructionCount) {
90+
for (size_t instructionCount = 0; instructionCount < maxInstructions || maxInstructions == 0; ++instructionCount) {
9191
if (idx >= program.code.size()) {
9292
throwConstraintViolated("ByteCodeVM: Instruction index out of bounds");
9393
}
@@ -147,7 +147,6 @@ ProgramState ByteCodeVM::run(size_t maxInstructions) {
147147
// LOCALL ID
148148
ASSURE(!callstack.empty(), "ByteCodeVM: Empty callstack");
149149
auto& locals = callstack.back().locals;
150-
std::cout << "locals.size()=" << locals.size() << " arg1=" << inst.arg1 << " callstack.size()=" << callstack.size() << std::endl;
151150
ASSURE(inst.arg1 < locals.size(), "ByteCodeVM: Local variable index out of bounds");
152151
stack.push(locals[inst.arg1]); // Push local variable onto stack
153152
break;

src/executer/ByteCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class ByteCodeVM {
161161
public:
162162
ByteCodeVM(const Program& program);
163163
void setDebug(bool debug) { this->debug = debug; }
164-
std::string execute(size_t maxInstructions = 1000);
164+
std::string execute(size_t maxInstructions);
165165

166166
};
167167

src/executer/ExternalFunctions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ qword_t ExternalFunctions::call(size_t id, const Arguments& args) {
8989
// then follow by the rest of the arguments on the stack
9090
// Floats go into XMM0 - XMM3
9191

92+
// This is AT&T (AT&T syntax) assembly code for x64 Windows
9293
qword_t result;
9394
__asm__ volatile (
9495
"movq %[args_tag], %%R10\n" // Bring arg pointer into R10
@@ -217,6 +218,7 @@ qword_t ExternalFunctions::call(size_t id, const Arguments& args) {
217218
// The result is returned in rax
218219
// If we need more than 6 arguments, the rest are passed on the stack. (?)
219220

221+
// This is ATT (AT&T syntax) assembly code for x86_64 Linux
220222
qword_t result;
221223
__asm__ volatile (
222224
"movq %[args_tag], %%R10\n" // Bring arg pointer into R10

src/mains/MLang.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ int main(int argc, char** argv) {
2323
mlang.settings.showInferedTypes = false;
2424
mlang.settings.showFunctions = false;
2525
mlang.settings.showEmission = false;
26+
mlang.settings.showExecution = false;
27+
mlang.settings.maxInstructions = 0; // 0 means no limit
2628
// TODO: Config params from cmd
2729

2830
int exitCode = 0;

src/mains/Tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ void testFile(std::string path){
110110
mlang.settings.showEmission = true;
111111
mlang.settings.showExecution = true;
112112
mlang.settings.showTypeInference = true;
113+
mlang.settings.maxInstructions = 1000;
113114

114115
auto rs = mlang.executeFile(path);
115116

0 commit comments

Comments
 (0)