From 8bed3ccdaf4669b8563578a8832d333cd66aed24 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 11 Jul 2019 05:26:18 -0700 Subject: [PATCH] Adding a 'Hello, World!' example using stdlib and a new build system using `cpp`. --- examples/Makefile | 14 ++++++++++ examples/config.mk | 11 ++++++++ examples/hello-stdlib/Makefile | 17 ++++++++++++ examples/hello-stdlib/hello.pvvs | 4 ++- examples/hello-world/Makefile | 15 +++++++++++ stdlib/stdio.pvvs | 45 ++++++++++++++++++-------------- 6 files changed, 85 insertions(+), 21 deletions(-) create mode 100644 examples/Makefile create mode 100644 examples/config.mk create mode 100644 examples/hello-stdlib/Makefile create mode 100644 examples/hello-world/Makefile diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..cb5ac3d --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,14 @@ +# (c) 2019 Aaron Taylor +# All rights reserved. + +EXAMPLES != find . -mindepth 1 -maxdepth 1 -type d + +all: + @echo "No target available to build all." + @echo "Try 'make run' inside an example folder." + +clean: + @for dir in $(EXAMPLES); do \ + echo Cleaning $$dir; \ + (cd $$dir; ${MAKE} clean); \ + done diff --git a/examples/config.mk b/examples/config.mk new file mode 100644 index 0000000..19bc033 --- /dev/null +++ b/examples/config.mk @@ -0,0 +1,11 @@ +# (c) 2019 Aaron Taylor +# All rights reserved. + +#################################################################################################### +# Configuration + +VVS_COMPILER = ../../vvc +VVS_INTERPRETER = ../../vvi + +CPP = cpp +CPP_FLAGS = -I../../stdlib diff --git a/examples/hello-stdlib/Makefile b/examples/hello-stdlib/Makefile new file mode 100644 index 0000000..b8609e1 --- /dev/null +++ b/examples/hello-stdlib/Makefile @@ -0,0 +1,17 @@ +# (c) 2019 Aaron Taylor +# All rights reserved. + +include ../config.mk + +all: hello + +hello: + $(CPP) $(CPP_FLAGS) -o temp.pvvs hello.pvvs + $(VVS_COMPILER) -i temp.pvvs -o hello.vvs + @rm -f temp.pvvs + +run: + $(VVS_INTERPRETER) -i hello.vvs + +clean: + @rm -f hello.vvs temp.pvvs diff --git a/examples/hello-stdlib/hello.pvvs b/examples/hello-stdlib/hello.pvvs index 628fa7e..c0ddb0d 100644 --- a/examples/hello-stdlib/hello.pvvs +++ b/examples/hello-stdlib/hello.pvvs @@ -1,4 +1,4 @@ -## This program outputs "Hello, world!" +@@ This program outputs "Hello, world!" SSSSN | ST: Push +0 (ASCII '\0') SSSTSSSSTN | ST: Push +33 (ASCII !) @@ -16,3 +16,5 @@ SSSTTSSTSTN | ST: Push +101 (ASCII e) SSSTSSTSSSN | ST: Push +72 (ASCII H) NSTTSSSN | FC: JSR>1000 (print string from stack; see stdlib) NNN | FC: Terminate program + +#include "stdio.pvvs" diff --git a/examples/hello-world/Makefile b/examples/hello-world/Makefile new file mode 100644 index 0000000..32f38a7 --- /dev/null +++ b/examples/hello-world/Makefile @@ -0,0 +1,15 @@ +# (c) 2019 Aaron Taylor +# All rights reserved. + +include ../config.mk + +all: hello + +hello: + $(VVS_COMPILER) -i hello.pvvs -o hello.vvs + +run: + $(VVS_INTERPRETER) -i hello.vvs + +clean: + @rm -f hello.vvs diff --git a/stdlib/stdio.pvvs b/stdlib/stdio.pvvs index d9184ad..03c60c7 100644 --- a/stdlib/stdio.pvvs +++ b/stdlib/stdio.pvvs @@ -1,15 +1,18 @@ -################################################################################ -# Description: -# This function prints a null-terminated string from the stack. -# Call Stack: -# null-terminator (ASCII '\0') -# char n -# ... -# char 2 -# char 1 <-- TOS -# Return Stack: -# -################################################################################ +#ifndef VVS_STDLIB_STDIO +#define VVS_STDLIB_STDIO + +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Description: +@ This function prints a null-terminated string from the stack. +@ Call Stack: +@ null-terminator (ASCII '\0') +@ char n +@ ... +@ char 2 +@ char 1 <-- TOS +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ NSSVTSSSN | Mark: 1000 (print string from stack) SNS | DUP NTSSSSSTSSSSSSSSSSTN | BRZ > 00001000 00000001 @@ -19,14 +22,14 @@ NSSVSSSSTSSSSSSSSSSTN | Mark: 00001000 00000001 SNN | DROP NTN | RTS -################################################################################ -# Description: -# This function prints a null-terminated string from the heap. -# Call Stack: -# pointer to first character <-- TOS -# Return Stack: -# -################################################################################ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Description: +@ This function prints a null-terminated string from the heap. +@ Call Stack: +@ pointer to first character <-- TOS +@ Return Stack: +@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ NSSVTSSTN | Mark: 1001 (print string from heap) SNS | DUP TTT | LOAD @@ -40,3 +43,5 @@ NSSVSSSSTSSTSSSSSSSTN | Mark: 00001001 00000001 SNN | DROP SNN | DROP NTN | RTS + +#endif -- 2.20.1