Giter Club home page Giter Club logo

Comments (1)

zhicheng avatar zhicheng commented on September 25, 2024

This is so cool, good job. about the step run, I'll add some debug utility in future, but I can't sure when.if you required this function right now,you can simple change source code of lemon, here is a quick demo patch.this may need some test, but enough for your test.

diff --git a/src/machine.c b/src/machine.c
index c6b8d54..4b7726e 100644
--- a/src/machine.c
+++ b/src/machine.c
@@ -1278,6 +1278,13 @@ lemon_machine_execute_loop(struct lemon *lemon)
 		CHECK_PAUSE(lemon->l_nil);
 	}
 	while (!machine->halt && machine->pc < machine->maxpc) {
+
+		if (machine->step >= 0) {
+			if (machine->step-- == 0) {
+				machine->step = 10;
+				return lemon->l_nil;
+			}
+		}
 		opcode = machine->code[machine->pc++];
 
 		switch (opcode) {
diff --git a/src/machine.h b/src/machine.h
index 9f1c8e6..61ed5c7 100644
--- a/src/machine.h
+++ b/src/machine.h
@@ -11,6 +11,7 @@ struct machine {
 	int fp; /* frame pointer */
 	int sp; /* stack pointer */
 
+	int step;
 	int halt;
 	int maxpc;
 
diff --git a/src/main.c b/src/main.c
index 23ea8f4..8b961e0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,6 @@
 #include "lemon.h"
 #include "shell.h"
+#include "machine.h"
 #include "larray.h"
 #include "lstring.h"
 #include "lib/builtin.h"
@@ -70,7 +71,15 @@ main(int argc, char *argv[])
 		}
 
 		lemon_machine_reset(lemon);
-		lemon_machine_execute(lemon);
+		struct machine *machine = lemon->l_machine;
+		machine->step = 10; // -1 for non-stop run
+		for (;;) {
+			printf("pc: %d\n", machine->pc);
+			lemon_machine_execute_loop(lemon);
+			if (machine->pc >= machine->maxpc) {
+				break;
+			}
+		}
 	}
 
 	lemon_destroy(lemon);

from lemon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.