I've been working on greenServeFE (greenServe Fast Execution), a VM-based execution engine for my greenServe programming language. It's written in C, and I've been adding native modules to give the language more capabilities.
I wanted to put a few of these parts together in one example. So here, I'll use a while loop to generate some numbers, gs_compute to calculate statistics, and construct with server to display the results on a web page.
How does it execute a program?
When a .gsve file runs, it goes through a few stages:
.gsve source | Lexer | Parser | Compiler | GSCode bytecode | VM | Native modules | Results The main idea is that the program isn't executed by recursively evaluating the AST. greenServeFE compiles it into bytecode first, and then the VM executes those instructions using frames, an instruction pointer, and an operand stack.
That's the basic execution model behind the examples below.
Generating numbers with a while loop
Let's start with something simple. I want to generate the squares of numbers from 1 to 10 and then calculate some statistics.
import gs_compute; define numbers = []; define count = 1; # Generate square numbers from 1 to 10. while (count <= 10) { define square = count * count; push(numbers, square); print("Square: " + square); count = count + 1; } # Get statistics for the generated numbers. define result = gs_compute.stats(numbers); print("Total: " + result.sum); print("Mean: " + result.mean); print("Minimum: " + result.min); print("Maximum: " + result.max); print("Standard deviation: " + result.stddev); The loop itself uses normal greenServeFE syntax. Once the numbers are in the array, gs_compute.stats() does the calculations.
There are quite a few other functions in gs_compute too. Some examples are:
-
mean,variance,std, andstats -
sum,product,sort, andcumsum -
vector_add,vector_sub,dot, andnorm -
matmul,transpose, and other matrix operations -
solve,integrate, anddifferentiate -
linspace,arange,zeros, andidentity -
percent,discount,compound, andloan_payment
I implemented this module in C, so these calculations are handled by native code rather than being implemented as greenServeFE language functions.
Trying matrix multiplication
Here's another small example using the same module.
import gs_compute; define a = [ [1, 2], [3, 4] ]; define b = [ [5, 6], [7, 8] ]; define result = gs_compute.matmul(a, b); print(result); The result is:
[[19, 22], [43, 50]] The module checks the matrix dimensions and numeric inputs before doing the calculation. It's useful to have these operations available directly from a .gsve program.
Putting the results on a web page
This is where I wanted to try a few modules together.
Instead of just printing the statistics in the terminal, we can build an HTML page with construct and serve it using server.
import gs_compute; import construct; import server; define numbers = []; define count = 1; while (count <= 10) { push(numbers, count * count); count = count + 1; } define result = gs_compute.stats(numbers); define body = construct.element("h1", "greenServeFE Computation") + construct.element("p", "Generated square numbers: " + str(numbers)) + construct.element("p", "Total: " + str(result.sum)) + construct.element("p", "Mean: " + str(result.mean)) + construct.element("p", "Minimum: " + str(result.min)) + construct.element("p", "Maximum: " + str(result.max)); define page = construct.page({ title: "greenServeFE Computation", body: "<main>" + body + "</main>", css: "h1{color:seagreen}main{padding:1rem}" }); server.page("/", page); print("Server running on port 8080"); server.serve(".", 8080, { static: false, host: "0.0.0.0" }); Run the program and visit:
http://localhost:8080 You should see a page showing the generated numbers and their statistics.
I like this example because the whole thing happens in one .gsve file. The program generates the data, calculates the results, builds the HTML, and starts the server.
A little about the native modules
The three modules used here are separate C libraries exposed through the greenServeFE native module interface:
-
gs_compute.sohandles numerical calculations. -
construct.sohelps create HTML elements and documents. -
server.sohandles HTTP routes and serving.
The server module has more than just basic routing. It also includes middleware, static files, JSON responses, TLS, CORS, request timeouts, and graceful shutdown.
I wanted to keep these features outside the core language. That way, I can add more functionality through native modules without having to introduce a new keyword every time or change the VM's bytecode execution model.
A few thoughts
This is still an ongoing project, and I'm continuing to work on the VM and its modules.
For me, the interesting part is being able to write a program in my own language and use it for different tasks without making the syntax complicated. A simple loop, some numerical calculations, and an HTTP server can all work together in the same program.
Project: greenServeFE — greenServe Fast Execution
Language: greenServe (.gsve)
Implementation: C
Execution model: Compiler + Bytecode VM + Native Modules


