summaryrefslogtreecommitdiff
path: root/apps/examples/pashello
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-05-09 08:52:11 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-05-09 08:52:11 -0600
commitb373fc5405bc34fe4889a67d9a856c9228ae1240 (patch)
tree4dcde4ad339f61611ef2a291d3e52644d91ea4a8 /apps/examples/pashello
parent56078d9f356c73497be755f6a912b7d2da6c66e8 (diff)
downloadnuttx-b373fc5405bc34fe4889a67d9a856c9228ae1240.tar.gz
nuttx-b373fc5405bc34fe4889a67d9a856c9228ae1240.tar.bz2
nuttx-b373fc5405bc34fe4889a67d9a856c9228ae1240.zip
Create P-Code execution helper in apps/interpreters/prun; The P-Code binary format is functional except that there are still some modularity and kernel build issues that need to be addressed.
Diffstat (limited to 'apps/examples/pashello')
-rw-r--r--apps/examples/pashello/Kconfig17
-rw-r--r--apps/examples/pashello/pashello.c63
-rw-r--r--apps/examples/pashello/pashello.h2
3 files changed, 32 insertions, 50 deletions
diff --git a/apps/examples/pashello/Kconfig b/apps/examples/pashello/Kconfig
index 5591d6b5b..c13490677 100644
--- a/apps/examples/pashello/Kconfig
+++ b/apps/examples/pashello/Kconfig
@@ -6,8 +6,25 @@
config EXAMPLES_PASHELLO
bool "Pascal \"Hello, World!\" example"
default n
+ depends on INTERPRETERS_PCODE
+ select INTERPRETERS_PRUN
---help---
Enable the Pascal \"Hello, World!\" example
if EXAMPLES_PASHELLO
+
+config EXAMPLES_PASHELLO_VARSTACKSIZE
+ int "P-Code variable stack size"
+ default 1024
+ ---help---
+ This size of the P-Code variable storage area to be allocated by the
+ P-Code runtime.
+
+config EXAMPLES_PASHELLO_STRSTACKSIZE
+ int "P-Code string stack size"
+ default 128
+ ---help---
+ This size of the P-Code string stack area to be allocated by the
+ P-Code runtime.
+
endif
diff --git a/apps/examples/pashello/pashello.c b/apps/examples/pashello/pashello.c
index 8f9fc8b22..50c61d48c 100644
--- a/apps/examples/pashello/pashello.c
+++ b/apps/examples/pashello/pashello.c
@@ -43,20 +43,18 @@
#include <stdlib.h>
#include <debug.h>
-#include "pexec.h"
-#include "pedefs.h"
-#include "pashello.h"
+#include <apps/interpreters/prun.h>
/****************************************************************************
* Definitions
****************************************************************************/
-#ifndef CONFIG_PASHELLO_VARSTACKSIZE
-# define CONFIG_PASHELLO_VARSTACKSIZE 1024
+#ifndef CONFIG_EXAMPLES_PASHELLO_VARSTACKSIZE
+# define CONFIG_EXAMPLES_PASHELLO_VARSTACKSIZE 1024
#endif
-#ifndef CONFIG_PASHELLO_STRSTACKSIZE
-# define CONFIG_PASHELLO_STRSTACKSIZE 128
+#ifndef CONFIG_EXAMPLES_PASHELLO_STRSTACKSIZE
+# define CONFIG_EXAMPLES_PASHELLO_STRSTACKSIZE 128
#endif
/****************************************************************************
@@ -68,33 +66,6 @@
****************************************************************************/
/****************************************************************************
- * Name: prun
- *
- * Description:
- * This function executes the P-Code program until a stopping condition
- * is encountered.
- *
- ****************************************************************************/
-
-static void prun(FAR struct pexec_s *st)
-{
- int errcode;
-
- for (;;)
- {
- /* Execute the instruction; Check for exceptional conditions */
-
- errcode = pexec(st);
- if (errcode != eNOERROR) break;
- }
-
- if (errcode != eEXIT)
- {
- printf("Runtime error 0x%02x -- Execution Stopped\n", errcode);
- }
-}
-
-/****************************************************************************
* Public Functions
****************************************************************************/
@@ -105,29 +76,23 @@ static void prun(FAR struct pexec_s *st)
int pashello_main(int argc, FAR char *argv[])
{
FAR struct pexec_s *st;
+ int exitcode = EXIT_SUCCESS;
+ int ret;
/* Register the /dev/hello driver */
hello_register();
- /* Load the POFF file */
+ /* Execute the POFF file */
- st = pload("/dev/hello", CONFIG_PASHELLO_VARSTACKSIZE, CONFIG_PASHELLO_STRSTACKSIZE);
- if (!st)
+ ret = prun("/dev/hello", CONFIG_EXAMPLES_PASHELLO_VARSTACKSIZE,
+ CONFIG_EXAMPLES_PASHELLO_STRSTACKSIZE);
+ if (ret < 0)
{
- fprintf(stderr, "pashello_main: ERROR: Could not load /dev/hello\n");
- exit(1);
+ fprintf(stderr, "pashello_main: ERROR: Execution failed\n");
+ exitcode = EXIT_FAILURE;
}
- printf("pashello_main: /dev/hello Loaded\n");
- printf("pashello_main: Interpreter started:\n");
-
- /* And start program execution */
-
- prun(st);
-
- /* Clean up resources used by the interpreter */
printf("pashello_main: Interpreter terminated");
- pexec_release(st);
- return 0;
+ return exitcode;
}
diff --git a/apps/examples/pashello/pashello.h b/apps/examples/pashello/pashello.h
index ac5f99fbe..6a550764c 100644
--- a/apps/examples/pashello/pashello.h
+++ b/apps/examples/pashello/pashello.h
@@ -50,6 +50,6 @@
/* Defined in device.c */
-extern void hello_register(void);
+void hello_register(void);
#endif /* __EXAMPLES_PASHELLO_H */