Skip to content

Dpdl-io/DpdlEngine

Repository files navigation

Dynamic Packet Definition Language

			  www.dpdl.io

developed by SEE Solutions ©

Dpdl - rapid development Programming Language and constrained Device platform

Dpdl is a rapid development Programming Language and constrained Device platform with built-in Database and Agents technology.

Dpdl comes as a very compact and portable execution engine (DpdlEngine) with an extensible API interface that enables to execute Dpdl programming language code, as well as code in different programming languages or any other custom code syntax, directly embedded within the same dpdl source code, simultaneously, of multiple types and at it's native Speed.

Dpdl enables Polyglot programming, in a form that allows the use of embedded programming languages along with their specific runtime as it is, in its original form. (aka. Python, Ruby, etc... the original implementations of it).

The Dpdl language constructs and syntax are simple and intuitive, yet powerful, with an object oriented paradigm (OOP) interoperable with JVM platform APIs and Native shared libraries. It enables also dynamic code generation and execution of heterogeneous embedded code sections, featuring meta-programming techniques.

Dpdl provides access to JVM platform API's, Native shared libraries, WASM modules and GPU compute.

In addition Dpdl enables also the embedding and execution of multiple programming languages like C, C++, Python & MicroPython, Julia, JavaScript, Lua, Ruby, Java, PHP, Perl, Groovy, V, Scheme, Clojure, Wat/Wasm, Wgsl, OpenCL, Modelica and also others, directly embedded within dpdl code.

Everything comes already included along with the DpdlEngine, No additional installations required.

The core DpdlEngine has the capability to run also on very limited memory constrained devices and platforms via a dedicated compact kilobyte range code virtual machine.

Compact, Self-contained, Portable and Customizable

Dpdl = dpdl-lang + ( C + 'C++' + Python + JavaScript + Julia + Java + Lua + Ruby + PHP + Perl + Groovy + V + Scheme + Clojure + Wat/Wasm + Wgsl + OpenCL + Modelica) + AI = Powerful and Versatile

Dpdl itself is a general-purpose programming language, self-contained, interpreted and in part dynamically JVM bytecode compiled, statically as well as dynamically typed, with a very compact memory footprint and portable to most platforms. There is an on-going development to enable Dpdl code to be compiled also to native code.

Dpdl introduces the concept of 'embedded code sections' that allows different programming languages or any custom code syntax to be executed within dpdl code by means of dedicated 'Dpdl language plug-ins', distributed along with the 'DpdlEngine' release, or developed separately ad-hoc.

Multiple 'Dpdl language plug-ins' are currently available for various programming languages. For example also the 'Modelica' language for cyber-physical simulations is available as 'Dpdl language plug-in'. Further Dpdl language plug-ins are currently in active development, for example to enable also Quantum Computing directly inside Dpdl.

A dedicated Dpdl language plug-in for AI generative code 'DpdlAINerd' (DAN), enables to automatically generate programming language code and content or data by means of natural language descriptions inside dpdl code, embed it automatically within dpdl code and execute the code right away or to be executed in a subsequent steps.

Dpdl includes a custom data container with built-in database technology referred to as a 'DpdlPacket'. It provides a convenient way to package, handle and query data very efficiently on memory scarce devices.

The included Dpdl lanugage plug-in 'DpdlAgent' provides an agent development middleware based on open source for building distributed and mobile multi-agent systems. It fully adheres to IEEE FIPA (Foundation for Intelligent Physical Agents) specifications, ensuring standardized, interoperable agent communication and coordination.

DpdlEngine components:

  • dpdl-lang -> Dpdl programming language
  • DpdlPacket -> Dpdl Database technology
  • DpdlAI -> AI generative code within dpdl code
  • DpdlAgent -> Mobile Agent platform within dpdl code

Dpdl is designed to:

* Facilitate development

* On multiple platforms

* Using the power of multiple programming languages and API's within a single source

* Re-use code

* No need to install, compile and configure development environments

* Self-contained, No additional dependencies required (except user libraries)

* Facilitate rapid prototyping for Hardware programming

* Runs on constrained devices and also Microcontroller units (MCUs)

* Customizable

* Plug-in oriented

* Leverage prototyping with AI generative code

DpdlEngine stack overview

Compact, Robust, Extensible and Portable to almost every platform

dpdl-lang example: Fibonacci series

func fib(int n) int
	if(n <= 1)
		return n
	fi

	return fib(n - 1) + fib(n - 2)
end


int N = 20

int i
for(i < N)
	println("fib($i) = " + fib(i))
	i=i+1
endfor

println("finished")

dpdl-lang example: Download and decode data in json format via http

import('http')
import('json')

struct Story {
	int id
	string title
	string url
}

string stories_url   = "https://hacker-news.firebaseio.com/v0/topstories.json"
string item_base_url = "https://hacker-news.firebaseio.com/v0/item/"

println("downloading and displaying the top 10 news stories from hacker-news, decoded from json format...")

string resp = http.getraw(stories_url)

raise(resp, "Error in downloading data")

object jsonobj = json.parse(resp, 0)
ids[] = array(jsonobj)

string story_url
struct Story storyobj

int c = 0
for(c < 10)
	println("---------------------------------------------------------------------")

	story_url = item_base_url + ids[c] + ".json"
	resp = http.getraw(story_url)

	raise(resp, "Error in downloading story")

	storyobj = json.decode(resp, storyobj)

	println("id: " + storyobj.id)
	println("title: " + storyobj.title)
	println("url: " + storyobj.url)

	c = c+1
endfor

println("finished!")

Docs

Dpdl language quick Tour

Dpdl lang Documentation

Dpdl API Documentation

Dpdl 'embedded code sections' (Dpdl language plug-ins)

Dpdl compiler documentation

Dpdl Native Interface

Dpdl GPU Compute

Dpdl Wasm runtime

Dpdl Meta-programming

DpdlAgents

DpdlVM

DpdlAI

DpdlPacket

DpdlClient

More...

Dpdl Examples

Dpdl HowTo's

Dpdl Tutorials

Features

  • DpdlEngine is optimized to run on a wide range of platforms (any JVM platform 1.3+ and later Spec, JavaME (CLDC, CDC)). The core engine runs also on JVM 1.1 spec compliant VMs
  • Access to the underlying JVM platform API's and to external java libraries
  • Access to Native shared libraries
  • Features meta-programming techniques: compile-time (CTMP) and runtime (RTMP) meta-programming
  • Automatic code generation and execution of 'embedded code sections' at runtime (Dpdl language plug-ins)
  • Multiple 'Dpdl language plug-ins' available for 'embedded code sections': C, C++, Python, MicroPython, Julia, JavaScript, Lua , Ruby, Java, PHP, Perl, Groovy, V, Scheme, Clojure, Wat/Wasm, Wgsl, OpenCL and Modelica programming language code can be embedded and executed directly within Dpdl code (interpreted/compiled code)
  • Everything is already included, No additional installations needed (except user libraries)
  • Further programming languages and syntax interpreters can be embedded via a dedicated kernel execution interface in form of 'Dpdl language plug-ins'
  • Includes embedded C compiler: On-the-fly compilation of embedded C code (ANSI C & ISO C99) in memory at runtime -> very Fast compile time!!!
  • Wasm runtime Dpdl language plug-in included allows to access 'Wasm' module functions from Dpdl and from embedded language code. Also WAT code can be directly compiled on-the-fly and executed
  • Built-in support for custom extensions -> allows to dynamically add language features at runtime
  • Dpdl C API enables to execute Dpdl code embedded within programs written in C
  • On the fly conversion/compilation of Dpdl types 'class' and 'struct' into native java bytecode classes
  • Support for common IoT protocol stacks such as Bluetooth(tm) (JSR-82) and CoAP (Constrained Application Protocol) (IETF standard RFC 7252)
  • Includes a full stack for building Distributed Mobile Agents (FIPA compliant)
  • Packing data in a 'DpdlPacket' is a convenient way to optimize and speedup access to data. The speedup is x 25 times faster compared to a standard record store access
  • Virtual record store filesystem
  • Double precision floating point emulation
  • XML with XPath parser
  • JSON
  • Easy integration of custom libraries
  • Small footprint, Only 372 Kb for DpdlEngine (with all features). It can be stripped down to 80 Kb or less for a compact setup
  • DpdlVM for running Dpdl even on bar-metal hardware like Microcontrollers (MCU), Microprocessors (MPU) and System on Chip (SoC), without dependencies
  • Allows to automatically generate and embed generative AI programming code within Dpdl using the 'DpdlAINerd' (DAN) Dpdl language plug-in
  • Allows to scale computations on GPUs using the 'OpenCL' and 'Wgsl' (WebGPU shading language) Dpdl language plug-in
  • Open Source Dpdl language plug-ins

'DpdlEngine' application footprint (size) and Profiles:

The DpdlEngine can be run in different configurations (Profiles) and Setups, depending on which is the target platform and which is the usage domain. This affects also the overall size (footprint) of the application.

The DpdlEngine setup may also include some Dpdl language plug-ins to enable to execute 'embedded code sections' in other programming languages.

Dpdl language plug-ins are an optional component, they can be included or excluded, even on-the-fly, via a simple configuration.

A typical setup of Dpdl might be the 'DpdlEngine' plus some of the available Dpdl language plug-ins to execute 'embedded code sections' like for example in: C, Java, Python and JavaScript etc..

'DpdlEngine' application footprint (size)

The size of 'DpdlEngine' can be somewhere between 80 Kb and 372 Kb, depending on which functions and modules are actually included.

These are the main Profiles available:

  • Compact : DpdlEngine core (Compact/ins> profile) 80 Kb or less for Compact setups
  • Full : DpdlEngine core (Full profile, includes 'DpdlPacket' database support) 372 Kb

Profiles

The profiles mentioned below can of course be adjusted as needed to include more ore less functions and components.

Compact

Contains a usage profile that enables to execute dpdl code. The functionalities to create and handle 'DpdlPacket' are not included.

DpdlEngine core 'Compact' with lightweight version of Dpdl language plug-ins for C, MicroPython and Micro JavaScript: Total size 686 Kb

The Dpdl language plug-ins included in this type of setup are targeted for Embedded Systems.

Platform Dpdl core Basic C (interpreted/compiled) MicroPython Micro JavaScript (ES5) TOTAL size
Linux x86_64 80 Kb 284 Kb 170 Kb 152 Kb 686 Kb

DpdlEngine core 'Compact' with extended version of Dpdl language plug-ins

Platform Dpdl core Basic C (interpreted/compiled) Python JavaScript (ES2023) TOTAL size
Linux x86_64 80 Kb 284 Kb 2551 Kb 1924 Kb 4,8 Mb

Full

Contains a usage profile that enables to execute dpdl code including a feature rich sets of built-in functions.

This profile includes also all functionalities required to create, handle and query 'DpdlPacket'.

DpdlEngine core 'Full' with extended version of Dpdl language plug-ins

Platform Dpdl core Full C (interpreted/compiled) Python JavaScript (ES2023) TOTAL size
Linux x86_64 372 Kb 284 Kb 2551 Kb 1924 Kb 5,1 MB

Design decisions considered for developing Dpdl

  • Dpdl has been designed and implemented to be Simple and Robust -> Simple things, usually, simply work in Software systems
  • Easily Extendible and Customizable -> Adding or adapting features should have little burdens, conceptually and technically
  • Portable across different platforms and versions of JVM -> Ensure Backward compatibility to the best possible extent. This has been a primary focus since the very beginning
  • Compact code footprint for porting Dpdl to constrained devices

Dpdl sample code

Dpdl example that makes use of external java libraries

This is a 3D model visualization of chemical molecules (in this case hydrogen) using the JavaFX library. The model can be rotated freely with mouse events (ported to Dpdl from javafx examples)

graphics/dpdl3DJavaFX_molecule.h

VIDEO of Dpdl sample 3D application

Dpdl example that make use of dpdl class type Inheritance and Polymorphism.

struct property {
	int max_weight_gr
	float max_height_m
	string desc = null
}

class Animal {
	int id
	string name
	struct property info = {100000, 2.5,.}

	func Animal(int id_)
		id = id_
		name = "No name"

		println("new Animal() with id: " + id + " info: " + info)
	end

	func Animal(int id_, string name_)
		id = id_
		name = name_

		println("new Animal() with id: " + id + " and name: " + name + " - info: " + info)
	end

	func print()
		println("This is an Animal")
	end

	func makeSound()
		println("kind of animal is not defined")
	end

	func getHashMap()
		object h_map = new("HashMap")

		info_arr[] = array(info)
		int i = 0
		for(i < info_arr.size())
			h_map.put(i, info_arr[i])
			i=i+1
		endfor

		return h_map
	end
}

class Dog : Animal {

	func Dog(int id_, string name_)
		super(id_, name_)

		info.max_weight_gr = 8000
		info.max_height_m = 0.5
		info.desc = "this breed is Shitzu"

		println("new Dog() with id: " + id + " and name: " + name + " - info: " + info)
	end

	func print()
		println("This is a Dog with name: " + name)
	end

	func makeSound()
		...
		// check link above for complete implementation of this example
		
		
// now we can use the class

class Dog mydog(2, "Rosa")

mydog.print()
mydog.makeSound()
int sd = mydog.makeSound(10)

object map_dog = mydog.getHashMap()
println("map dog: " + map_dog)

var entry_di = map_dog.get(0)
println("1st entry: " + entry_di +  " is of type: " + typeof(entry_di))

...

// see link below for the full dpdl source code of this example

Here is the link for the full Dpdl code of the example that is summarized above:

test/testClassSub2.h

Note: some functions in the example above make also use of 'embedded code sections' in other programming languages

Sample Dpdl code that makes use of embedded 'Groovy' code to read a file line by line and print it to the console

println("reading a file line by line using embedded 'Groovy' code...")

dpdl_stack_push("./Test/see_solutions.html")
>>groovy

def dpdl_main(Object[] param, Object var_map){
	String myfile = (String)param[0];
	new File(myfile).eachLine { line ->
	  println line
	}
	return 1;
}

<<
int exit_code = dpdl_exit_code()

println("embedded groovy exit code: " + exit_code)

Dpdl sample code that make use of java JRE classes

Example: Implementation of of dpdl class to write data to a file

The Dpdl code below illustrates the use of a dpdl class that implements a function to write data files efficiently by means of a java JRE class (i.e. BufferedWriter )

import("MyWriter.h")

println("testing my buffered file writer...")

class MyWriter myw("./Test/mydata.txt", 0)

myw.writeData(1000, "data 1")
myw.writeData(2000, "data 2")
myw.writeData(3000, "data 3")

This is the implementation of 'MyWriter' class

class MyWriter {

	object header = new("String", "some data init head str")

	object file_writer = null
	object buf_writer = null

	func MyWriter(string file_n, int off)

		println("new MyWriter()-> file:" + file_n + " offset:" + off)

		file_writer = new("FileWriter", file_n)

		raise(file_writer, "could not open file: " + file_n)

		buf_writer = new("BufferedWriter", file_writer)

		println("type of buf_writer is: " + typeof(buf_writer))

		buf_writer.write(header, off, header.length())

		println("started")
	end

	func writeData(int nr, string data)
		int i
		for(i < nr)
			buf_writer.write(data, 0, strlen(data))

			print(".")

			i=i+1
		endfor
		println("")

		buf_writer.newLine()
		buf_writer.flush()
	end
}

Example: Implementation of a derived dpdl class to write data to a file

The example below, to show the flexibility of dpdl, implements the same logic as the example above, but with a dpdl class derived from a JRE class:

jre/dpdlMyWriter.h

Dpdl example with 'embedded code sections' in different programming languages

println("with Dpdl you can embed and execute code sections in many different programming languages, simultaneously and of multiple types...")
println("")

println("embedding some C code...")

>>c
	#include <stdio.h>

	int v = 1000;
	float x = 23.0;
	char *m = "this message is printed in c";

	for(int i = 0; i < v; i++){
		printf("msg: %s %d %lf\n", m, i, x);
	}
<<

int exit_code = dpdl_exit_code()

println("embedded C exit code: " + exit_code)
println("")

println("embedding some javascript code...")


dpdl_stack_push("my Hello Message!!!")
>>js
	import { fib } from "./DpdlLibs/js/fib_module.js";

	var a_message = "null";

	if(scriptArgs.length > 0){
		a_message = scriptArgs[0];
	}
	std.printf("Message = %s %d", a_message, 23);
	console.log('');
	console.log('this fibonacci calculation is perfomed in javascript');
	console.log("fib(10)=", fib(10));
<<

exit_code = dpdl_exit_code()

println("embedded javascript exit code: " + exit_code)
println("")

println("you can embed many other languages too...")

println("we list them with via embedded python code:")

>>python
	languages = ['C', 'C++', 'Python', 'JavaScript', 'Julia', 'Lua', 'Ruby', 'Java', 'PHP', 'Perl', 'Groovy', 'Clojure', 'Modelica', '...']
	
	for language in languages:
		print(language)
<<

exit_code = dpdl_exit_code()

println("embedded python exit code: " + exit_code)
println("")

println("and more 'Dpdl lanuage plug-ins' will follow and you can also create your owns")

Dpdl sample code that makes use of embedded 'Wgsl' code to accelerate a GELU Neural Network activation function on GPUs:

import('native')

# main
println("testing Wgsl algorithm on GPU...")

println("loading native libraries 'c' and 'dpdlgpu'...")

object libc = native.loadLib("c")

object libgpu = native.loadLib("dpdlgpu")

raise(libgpu, "Error in loading 'dpdlgpu' lib")

println("getting dpdlgpu lib version...")

string ver = libgpu.DPDLNATIVE_GPU_getVersion()

println("version: " + ver)

# we allocate a data buffer with 10000 entries
long DATA_SIZE = 10000L
long byte_cnt = 4L

# indexes of the tensors & kernel created
int idx_tensor_in = 1
int idx_tensor_out = 1
int idx_kernel = 1

println("allocating input buffer...")

object input_arr = libc.malloc(DATA_SIZE * byte_cnt)
input_arr.setMemory(0L, DATA_SIZE * byte_cnt, 0x00B)

object output_arr = libc.malloc(DATA_SIZE * byte_cnt)
input_arr.setMemory(0L, DATA_SIZE * byte_cnt, 0x00B)

println("populating input data...")

long cnt = 0L
float f_val
int tmp
for(cnt < DATA_SIZE)
	tmp = randInt(16, 1000)
	f_val = to_float(tmp)

	input_arr.setFloat(cnt, f_val)

	cnt = cnt+1L
endfor

int status_in = libgpu.DPDLNATIVE_GPU_createTensorInputS1x1(idx_tensor_in, "f32", DATA_SIZE, input_arr)
int status_out =  libgpu.DPDLNATIVE_GPU_createTensorOutputS1x1(idx_tensor_out, "f32", DATA_SIZE)


dpdl_stack_var_put("precision", "f32")
dpdl_stack_var_put("workgroup_size", "256, 1, 1")

dpdl_stack_push("dpdl:applyvars")

>>wgsl
const SCALE_FACTOR: f32 = 0.7978845608028654; // sqrt(2.0 / Math.PI)

@group(0) @binding(0) var<storage, read_write> inp: array<{{precision}}>;
@group(0) @binding(1) var<storage, read_write> out: array<{{precision}}>;

@compute @workgroup_size({{workgroup_size}})
fn main(
    @builtin(global_invocation_id) GlobalInvocationID: vec3<u32>) {
    let i: u32 = GlobalInvocationID.x;
    if (i < arrayLength(&inp)) {
        let x: f32 = inp[i];
        out[i] = select(0.5 * x * (1.0 + tanh(SCALE_FACTOR
                 * (x + .044715 * x * x * x))), x, x > 10.0);
    }
}
<<
int exit_code = dpdl_exit_code()

println("Wgsl exit code: " + exit_code)

int status_kernel = libgpu.DPDLNATIVE_GPU_createKernelS1x1(idx_kernel, idx_tensor_in, idx_tensor_out, DATA_SIZE)

int status_dispatch = libgpu.DPDLNATIVE_GPU_dispatchKernel(idx_kernel)

int wait_copy = libgpu.DPDLNATIVE_GPU_waitCopyCPU(idx_kernel, idx_tensor_out, output_arr, DATA_SIZE)

println("OUTPUT: ")

float f_val_in, f_val_out
long c = 0L
for(c < DATA_SIZE)
	f_val_in = input_arr.getFloat(c)
	f_val_out = output_arr.getFloat(c)

	println(f_val_in + "=" + f_val_out)

	c = c+1L
endfor

println("finished")

Dpdl example to Get and decode News via http in JSON format

This is a small sample app written with Dpdl that gets the top 10 news stories via http in 'json' format:

app/getnews/dpdlGetNews.h

Dpdl implementation of SHA-1 hash algorithm

Implementation of SHA-1 hash algorithm entirely written in Dpdl

app/dpdlSHA-1/dpdlSHA-1impl.h

Simple Dpdl example that executes an embedded 'java' code and an embedded 'C' code directly within Dpdl

app/simple/dpdlSimpleJavaAndC.h

Dpdl example that uses the 'sql' Dpdl language plug-in to retrieve data from a database and handle the result set

Dpdl sample code that connects to the database and performs a query, retrieves and prints out the result set, encodes the result set to a json string, and than decodes the json string to an object that can be accessed as a HashMap

sql/dpdlSqlExampleJson.h

Dpdl example that uses the 'Wgsl' Dpdl language plug-in to scale computations directly on GPU's

Dpdl sample code that implements a high-performing neural network activation function (GELU) on GPUs using the dpdl language plug-in 'Wgsl' that allows to embed and execute WGSL code (WebGPU Shading language) directly within Dpdl.

wgsl/dpdlWgslTest.h

Dpdl example that uses the 'Modelica' Dpdl language plug-in to run a cyber-physical model simulation

Dpdl sample code that performs the physical simulation of a bouncing ball with embedded 'Modelica' code

modelica/dpdlModelicaExample_simple.h

More Dpdl Examples

You can find more Dpdl code snippet on the following page: Dpdl_Examples.md

Featured sample Applications (prototypes) developed with Dpdl

In this GitHub repository you can find full featured working prototype applications written with Dpdl:

Dpdl-sample-Apps

Why Dpdl?

Dpdl is suitable for rapid application development in various domains, in particular also for development of applications on small memory footprint devices, and it is suitable also to be used as embedded scripting engine in applications.

Dpdl enables rapid development, fast prototyping, code reuse and allow a high degree of portability while being simple, extensible and compact. Further, developers can benefit from the possibility to use multiple programming languages and consequently have a vaster set of APIs are available for development on a given platform.

Dpdl has also built-in constructs that enable dynamic code generation for generative AI code and provides a dedicated plug-in interface for developing and embedding custom language interpreter plug-ins of all sorts.

The AI Dpdl language plug-in 'DpdlAINerd' (DAN) can be used to speed-up the prototyping and development process by leveraging generative AI code for embedded code and data generation within dpdl.

The Dpdl language plug-in 'DpdlAgent', with the contained agent development middleware, can be used to build solid Distributed Mobile Agents that communicate asynchronously following the FIPA (Foundation for Intelligent Physical Agents) specification. It enables also to develop agents that are able to migrate or copy themselves across multiple networks and hosts.

Common IoT protocol stacks such as Bluetooth(tm) and CoAP (Constrained Application Protocol) are integrated by default and third party libraries and protocols can be added as extensions.

Further, the custom data container 'DpdlPacket' can be used to encode, store, control and query data efficiently also on small memory footprint devices. A DpdlPacket is a structured, highly compressed packet of data which can be managed and queried very efficiently on memory scarce devices. A DpdlPacket can also include Dpdl code for custom setups.

Dpdl enables to combine the portability and vast API availability of Java and Python, the computational power of Julia, the expressiveness of Lua and Clojure, the simplicity of Ruby and Groovy, the web-enablement of JavaScript and WebAssembly (Wasm), the effective cyber-physical modeling with Modelica and the power of C/C++ programming language within the same Dpdl source code, enabling developers to use thousands of existing high-quality software libraries.

Dpdl enables the integration of different technologies to leverage fast prototyping and foster research and development.

Dpdl can be used as:

  • Rapid application development platform
  • Embedded scripting engine in applications
  • For the development of Domain Specific Languages (DSL)
  • Data handling on memory constrained devices
  • AI generative code
  • Library module
  • Testing framework
  • Utility tool

Access to the complete JVM platforms API's and external java libraries

The Dpdl API allows to access all classes and methods of the underlying JVM platforms (JRE) and of any external java library.

Example: using a java HashMap (which interfaces to java.util.HashMap)

object map, s

map = new("HashMap")
map.put(1, "Dpdl")
map.put(2, "Packet")
map.put(3, "Definition")
map.put(4, "Language")

s = map.get(1)
println(s)
s = map.get(4)
println(s)

Iterate over the obove HashMap using the same objects and methods as provided by the java API:

object es = map.entrySet()
object iter = es.iterator()
object ep
while(iter.hasNext())
	ep = iter.next()
	println("key=" + ep.getKey() + " value=" + ep.getValue())
endwhile

In this way all java libraries defined in class definition configuration file can be loaded and accessed in Dpdl.

The default configuration currently includes Java Platform API, the JavaFX API and bluecove Bluetooth JSR-82.

The default configuration can be easily extended or updated to resolve additional java APIs by editing the class definition configuration file, enabling also to use custom class specifiers.

Dpdl Java API's access documentation (default configuration)

The default set of classes accessible with Dpdl is defined to be the following set. Additional classes and API's can be added by means of a simple configuration.

The methods of the classes that are accessible are referred to the current JRE instance on which Dpdl is running.

Java API

JavaFX API

Bluetooth JSR-82 API

It's worth mentioning here that 'Java' code can also be embedded directly within Dpdl as described below.

Here just a quick example:

println("Dpdl can also embed native java code...")

object mystr = new("String", "this is a Dpdl object mapped to java api, a str parameter")
int x = 23

dpdl_stack_push(mystr, "./Test/TestRead.txt", x)

>>java

	System.out.println("Parameters: ");
	System.out.println("	arg0: " + arg0);
	System.out.println("	arg1: " + arg1);
	System.out.println("	arg2: " + arg2);
	
	static void myMethod1(){
		System.out.println("myMethod1: " + 1);
	}
	
	myMethod1();
	
	for(int x = 0; x < arg2; x++){
		System.out.println("x: " + x);
	}
	
	try{
		File myfile = new File(arg1);
		
		boolean b_writable = myfile.canWrite();
		
		System.out.println("file: " + myfile.getName() + " is writable: " + b_writable);
		
	}catch(IOException e){
		System.out.println("Error in accessing file: " + e.getMessage());
	}
	
	return 1;
<<
int exit_code = dpdl_exit_code()
println("embedded java exit code: " + exit_code)

Dpdl 'embedded code sections' (Dpdl language plug-ins)

Multiple programming languages can be embedded and executed within the same Dpdl code via configurable Dpdl language plug-ins by using the keyword >>.

Further programming languages and syntax interpreters can be developed and integrated via a dedicated plug-in interface and configuration if form of Dpdl language plug-ins.

This enables basically every sort of programming language or natural language interpreter to be embedded directly in Dpdl code.

This features is very useful for rapid development and rapid prototyping and is also a key feature for generative code.

Currently the following programming languages can be embedded directly within Dpdl:

  • C (interpreted) --> minimal subset of C90 with standard C libs included and avaiable in the Dpdl runtime
  • C (compiled) code --> ANSI C & ISO C99 standard, compiled in memory and dynamically executed at runtime (see 'dpdl:compile')
  • C++
  • Python
  • MicroPython (Python for embedded systems)
  • Julia
  • JavaScript
  • OCaml
  • Lua
  • Ruby
  • Java
  • PHP
  • Perl
  • Groovy
  • V
  • Scheme (ChezScheme)
  • Clojure
  • Modelica

and also for some less known, but yet very powerful programming languages:

  • Umka
  • Janet

available Add-on 'Dpdl language plug-ins':

  • Wasm -> WAT Compiler and Wasm Runtime
  • Sql -> query databases via SQL
  • Wgsl -> WebGPU shading language
  • OCL -> Open Computing Language (OpenCL)
  • AI -> see doc/DpdlAINerd.md

See this doc for more details: Dpdl_language_plugins.md

In development 'Dpdl language plug-ins' (available soon in coming releases):

  • quantum -> OpenQWASM compiler and executor to leverage Quantum Computing capabilities

Dpdl example with embedded 'C++' code

C++ code can be embedded within Dpdl via the keyord >>cpp

Example below shows Dpdl code embedding 'C++' that makes use of the powerful Root Data Analysis Framework developed by CERN (https://root.cern/):

# main
println("test embedded C++ that uses the Root framework...")

>>cpp
	auto canvas = new TCanvas("c","Graph2D example",0,0,700,600);
	
	double x, y, z, P = 6.;
	int np = 200;
	auto dt = new TGraph2D();
	auto r = new TRandom();
	for (int N=0; N<np; N++) {
		x = 2*P*(r->Rndm(N))-P;
		y = 2*P*(r->Rndm(N))-P;
		z = (sin(x)/x)*(sin(y)/y)+0.2;
		dt->SetPoint(N,x,y,z);
	}
	dt->Draw("tri1 p0");
	canvas->Modified(); canvas->Update();
<<

int exit_code = dpdl_exit_code()
println("embedded ROOT exit code: " + exit_code)

Dpdl with embedded C code

Dpdl allows the embedding and on-the-fly execution of ANSI C code directly within Dpdl code with the keyword >>c

The C code can be embedded with 2 different Modes:

  1. Interpreted code (Mode 1)
  2. Compiled code (Mode 2) -> in memory at runtime

Example Dpdl code with embedded C code (Mode 1 - interpreted):

# main
# starting with Dpdl, pushing parameters on the stack and embedding C code

println("testing embedded C code in Dpdl")

int n = 6
double x = 10.0
string a = "test"

dpdl_stack_push(n, x, a)

>>c
	#include <stdio.h>
	
	int dpdl_main(int argc, char **argv){
		printf("Hello C from Dpdl!\n");
		printf("\n");
		printf("num params: %d\n", argc);
		int cnt;
	    for (cnt = 0; cnt < argc; cnt++){
	        printf("	param %d: %s\n", cnt, argv[cnt]);
	    }
	    return 0;
	}
<<
int exit_code = dpdl_exit_code()

println("embedded C exit code: " + exit_code);

# again Dpdl code...

object str = new("String", "Dpdl embedded C")
bool b = str.contains("C")
println("Dpdl contains C: " + b)

Embedding other programming languages

Other programming languages or natural language interpreters can be easily integrated in Dpdl via a dedicated plug-in interface and configuration (Dpdl language plug-ins). Please feel free to suggest your opinion on the 'Discussion' section on the DpdlEngine GitHub repository

AI generative code with 'DpdlAINerd' (DAN) Dpdl language plug-in

The Dpdl language plug-in 'DpdlAINerd' (DAN) allows to automatically generate code via configurable AI engines (eg. OpenAI, Google Vertex AI, CodePal etc..), embed it within dpdl, and execute the code right away.

Example:

The code below generated and executed the following code:

ai/dpdlAISnakeGame_gen.h

println("testing the Dpdl language plug-in 'DpdlAINerd' to automatically generate and execute code...")

>>ai
	>>c
	write a console program in C that implements the famous SNAKE game, with colorful graphics using ncurses colors
<<
int exit_code = dpdl_exit_code()

raise(exit_code, "Error in generating code from natural language description")

println("exit code: " + exit_code)

println("finished")

find here the example with screenshots: DpdlCodeGenAI.md

see 'DpdlAINerd' doc for more info: doc/DpdlAINerd.md

Supported Platforms

Dpdl runs on a wide range of platforms and supports also a small footprint kilobyte range java virtual machine that can be compiled for almost every platform as soon as an ANSI C compiler is available for the target platform.

Dpdl itself is compatible with:

  • Java versions 1.3+ and later
  • Java ME CLDC & GCF (JSR 360)
  • Java ME Embedded Profile (JSR 361)
  • Java 1.1 until 1.3 (without )
  • Platforms with ANSI C compiler where the included kilobyte range java virtual machine can be compiled

DpdlEngine V1.0 has been tested on:

* MacOS aarch64
* Linux x86_64
* Raspberry PI 3 (armv7l)
* Windows 64-bit
* Android
* JavaME
* J2ME (MIDP 2.0)

Note: The 'DpdlEngine lite' release needs to be re-packaged for running on Android, JavaME and J2ME

Embedded programming language plug-ins - compatibility matrix

Currently the 'DpdlEngine' release supports and provides the following Dpdl language plug-ins compliant to the corresponding language implementation version.

(X + version) Supported

(*) available soon

Platform C Python Julia Js Modelica Lua C++ Ruby Java Groovy MicroPython V PHP Perl Clojure Scheme OCaml
Linux (x86_64) X X v3.2 X v1.9.3 X X v3.6 X v5.4 X v14.0.3 * X X v5.0 X v1.24.0 v0.4.9 X v5.3 X v5.40.0 X v1.12.0 X v10.3.0 X v4.01
Mac OS X (aarch64) X X v3.12 X v1.9.3 X X v3.6 X v5.4 X v14.0.3 X 3.2.2 X X v5.0 X v1.24.0 v0.4.9 X v5.3 X v5.40.0 X v1.12.0 X v10.3.0 X v4.01
Raspberry PI 3 (armv7) X X v3.2 X v1.9.3 X X v3.6 X v5.4 * * X X v5.0 X v1.24.0 v0.4.9 X v5.3 X v5.40.0 X v1.12.0 X v10.3.0 X v4.01
Windows64 X * * X X v3.6 * * * X X v5.0 * v0.4.9 * * X v1.12.0 * X v4.01

Add-on Dpdl language plug-ins - compatibility matrix

Platform Wasm Sql Wsgl OCL (OpenCL) AI
Linux x86_64 X X X X X
Mac OS X (aarch64) X X X X X
Raspberry PI 3 (armv7) * X * * X
Windows64 * X * * X

Documentation

The Dpdl platform and API documentation is available via the following links:

Documentation

Dpdl language quick Tour

Dpdl lang Documentation

Dpdl API Documentation

Dpdl 'embedded code sections' (Dpdl language plug-ins)

Dpdl compiler documentation

Dpdl Native Interface

Dpdl GPU Compute

Dpdl Wasm runtime

Dpdl Meta-programming

DpdlAgents

DpdlVM

DpdlAI

DpdlPacket

DpdlClient

More...

Dpdl Examples

Dpdl HowTo's

Dpdl Tutorials

Dpdl java API Documentation is available only for a registered version of DpdlEngine

Download

See 'Download' page for more details:

Download

Roadmap

Dpdl is currently developed by SEE Solutions and the following integrations are in development:

  • Back-end compiler to compile Dpdl code to native machine code for most target architectures

  • Dpdl-IDE with plug-ins for popular IDEs (IntelliJ, eclipse, VS Code)

  • Development of a dedicated 'Dpdl language plug-in' for enabling Quantum Computing via embedded OpenQASM 2.0 (Circuit description language) code within Dpdl

Embedding of 'Python' code

Python code can be embedded within Dpdl code by using the keyword >>python. MicroPython will also be supported as option in the coming release.

Example Dpdl code with embedded 'Python' code:

println("testing embedding python code")
println("")

>>python
	languages = ['Dpdl', 'C', 'Python', 'Clojure']
	
	for language in languages:
		print(language)
<<
println("")

int exit_code = dpdl_exit_code()

println("embedded python exit code: " + exit_code);

Embedding of 'Julia' code

Julia is a powerful and performant computational programming language (https://julialang.org)

Julia code can be embedded within Dpdl via the keyord >>julia

Example Dpdl code embedding 'Julia' that generates a Plot and saves the result as PDF file:

#main
println("Testing Plot data with Julia programming language...")

>>julia
	using Plots
	
	x = range(0, 10, length=100)
	y1 = sin.(x)
	y2 = cos.(x)
	p = plot(x, [y1 y2])
	
	savefig(p, "./Test/myplot.pdf")
	
	dispose_status = @ccall dpdl_julia_dispose()::Int32
	return 1
<<

int exit_code = dpdl_exit_code()
println("finished with exit code: " + exit_code)

NOTE: The native Dpdl library 'dpdljulia' needs to be downloaded and deployed separately (see Download section below)

Embedding of 'JavaScript' code

JavaScript is the ideal programming language for web applications as it's supported by all popular web browsers.

JavaScript code can be embedded within Dpdl via the keyword >>js

Dpdl allows the embedding of javascript with 2 different Modes:

  1. Using the 'QuickJS' javascript engine (default mode)
  2. Using the 'Nashorn' javascript engine available on the Java platform

Example:

println("testing embedded js...")

dpdl_stack_push("my Hello Message!!!")
>>js
	
	import { fib } from "./DpdlLibs/js/fib_module.js";
	
	var a_message = "null";
	
	console.log(scriptArgs)
	console.log('Dpdl sends a message with QuickJS');
	
	if(scriptArgs.length > 0){
		a_message = scriptArgs[0];
	}
	std.printf("Message = %s %d", a_message, 23);
	console.log('');
	console.log("fib(10)=", fib(10));
<<

int exit_code = dpdl_exit_code()
println("embedd3ed js exited with exit code: " + exit_code)

QuickJS provides a powerful and complete API to interact with the javascript engine at low level. Custom native functions and objects can be implemented as shared libraries and loaded in javascript. You can find examples in the folder ./DpdlLibs/js/

Embedding of 'Lua' code

Lua code can be embedded within Dpdl code by using the keyword >>lua.

Example Dpdl code with embedded 'Lua' code:

println("testing embedding Lua within Dpdl....")

dpdl_stack_push("name", "Alexis", "surname", "Kunst")

>>lua(my_buffer_key)
	function doSomeAlg()
		local home_dir = os.getenv("HOME")
		print("user home: ", home_dir)
		
		local x = os.clock()
		    local s = 0
		    for i=1,100 do 
		    	s = s + i
		    	io.write(".")
		    end
		    print("")
		    print(string.format("elapsed time: %.2f\n", os.clock() - x))
	end
	
	function paramLen(T)
	  local count = 0
	  for _ in pairs(T) do count = count + 1 end
	  return count
	end
	
	function dpdl_main(params)
		local num_params = paramLen(params)
		io.write("dpdl_main call with number of params: ")
		io.write(num_params)
		print()
		print("executing my embedded algorithm...")
		print("")
		doSomeAlg()
		print()
		print("returning param values in 'uppercase'")
		local tab_out = {numfields=1}
		for k,v in pairs(params) do
			tab_out.numfields = tab_out.numfields + 1
			tab_out[tostring(k)] = string.upper(tostring(v))
		end
		tab_out.numfields = tostring(tab_out.numfields)
		return tab_out
	end
<<

int exit_code = dpdl_exit_code()

println("embedded lua exit code: " + exit_code)

string resp_buf = dpdl_stack_buf_get("my_buffer_key")

println("lua response buffer: ")
println(resp_buf)

Embedding 'SQL' for querying and retrieving results from a Database (JDBC compliant)

A dedicated Dpdl language plug-in allows to directly inject SQL statements and retrieve the result sets. Connection, query and packing the results are performed directly by the plug-in

Example Dpdl code with embedded 'SQL':

println("testing 'sql' queries with Dpdl...")

dpdl_stack_var_put("db_url", "jdbc:postgresql://127.0.0.1:5432/mytestdb")
dpdl_stack_var_put("db_user", "testuser")
dpdl_stack_var_put("db_pass", "189923")

>>sql(my_sqlbuf)
	SELECT id, name, surname, email from mytable
<<

object result = dpdl_stack_obj_get("my_sqlbuf")

raise(result, "Error: dpdl stack buffer is null")

int rs_size = result.size()

object id, name, surname, email

int c = 0
object entry
for(c < rs_size)
	println("-----------------------------------")
	entry = result.get(c)
	id = entry.get(0)
	name = entry.get(1)
	surname = entry.get(2)
	email = entry.get(3)

	println("id: " + id)
	println("name: " + name)
	println("surname: " + surname)
	println("e-mail: " + email)

	println("-----------------------------------")

	c=c+1

endfor

println("finished")

Dpdl Examples

Further Dpdl examples can be found on this page:

Dpdl_Examples.md

'DpdlPacket' data container

A DpdlPacket is a compact, structured and highly compressed executable packet of data with built-in database technology that can be created based on a defined DpdlPacket code definition.

A DpdlPacket can than be allocated and queried efficiently via API interfaces available for Java and Dpdl language.

In particular Dpdl is very efficient on JavaME platforms and has a high degree of backward compatibility (also J2ME)

A DpdlPacket may contain 1 - n chunks of compressed data that can be allocated, queried and deallocated when data is not used anymore.

All kind of data can be packed into a DpdlPacket.

DpdlPacket flow-chart

DpdlPacket

Example DpdlPacket definition source file:

dpdl_PHONEBOOK.dpdlpkt

The 'DpdlEngine lite' release package includes an encoded DpdlPacket (dpdl_PHONEBOOK.dpdl) and the corresponding Dpdl code definition file used to encode the DpdlPacket.

Refer to the Dpdl_documentation for how to allocate, execute and perform queries on a DpdlPacket.

Example of DpdlPacket code definition (dpdl_PHONEBOOK.dpdlpkt)

call(dpdlInterpreter)
::module dpdl_PHONEBOOK
::module_SPEC 23452
::model 836
::dpdlVersion 1.0

OPTIONS {
    TARGET = CDC & CLDC
    KVM = 1.0
    ZIP = true
    CHECKSUM = true
    SIGNATURE = true
    ENCRYPTION(RSA) = false
}

#defineDpdlEncoding UTF-8

#defineDB phone_bz | ./Test/BolzanoPhone.csv | null null

#defineSQL query_ SELECT name, phoneNR, e-mail FROM phone_bz end

#defineProtocol-cHtml phonebook_visual phone_book.html

import extern SystemData

catch DPDL_Script OnInit() {
    import("dpdllib.h") nl
    println("OnInit()") nl
}

import virtual DATA none  {
        class BolzanoPhone volatile phonebook_visual {
              DATA::string const name;
              DATA::string using phoneNR;
              DATA::string using  e-mail;
              #defineGUI Default <PhoneBook>  <Enter name and surname:>
              
              catch DPDL_Script OnDecode() {
                 import("dpdllib.h") nl
                 import("dpdlRS.h") nl
                 println("OnDecode()") nl
                 string time = getTime() nl
                 println("storing access time..." + time) nl
                 int rs_id = createRS("AccessStats", AUTHMODE_ANY, dpdlTrue, dpdlTrue) nl
                 int rec_id = addRecord(rs_id, time) nl
                 int status = closeRS(rs_id) nl
                 println("done status: " + status) nl
              }
        }
}
#defineD BolzanoPhone source phone_bz SQL query {
                CHUNK entry [6];
                struct BTree DENSE_INDEX hashing *name
                entry.content { name , phoneNR , e-mail }
                entry.name TAG(0xef) const (string) = 20;
                entry.phoneNR TAG(0xefe) (string) = 15;
                entry.e-mail TAG(0xefee) (string) = 30;
}

This is an example Dpdl sript that show how a 'DpdlPacket' can be allocated and queried:

dpdlpacket/testDpdlDB2.h

The database technology in Dpdl has been developed since year 2003 when the first applications where developed for mobile devices.

It started with a BsC thesis by A.Costa:

Advanced database techniques in Dpdl : dynamic packet definition language ; a portable data protocol for small embedded systems

'DpdlClient' console application

The DpdlClient console application included in the 'DpdlEngine lite' release is a small console application that exposes some functionalities of Dpdl via a simple command line console. Dpdl code can be executed and DpdlPackets handled. The same functionalities can be accessed via the java or Dpdl API.

These are the console commands available:

Usage: 
 -l  List DpdlPackets installed
 -i  Install DpdlPacket
 -d  Uninstall DpdlPacket
 -la List DpdlPackets allocated
 -a  Allocate DpdlPacket
 -da Deallocate DpdlPacket
 -qp Query DpdlPacket
 -c Create DpdlPacket
 -libs  List Dpdl libraries
 -slib  Show library
 -api   List Dpdl API functions
 -exec  Type && Execute a Dpdl script, between <script>...  </script>
 -load  Load && Execute a Dpdl script file (relative path to./DpdlLibs/ eg. arraylistExample.h)
 -bench  Run a query benchmark test (on DpdlPacket dpdl_PHONEBOOK)
 -h  Help
 -q  quit

Dpdl domains

Currently the following domains point to the same web-site:

https://www.dpdl-lang.org

https://www.dpdl.dev

https://www.dpdl.ai

Stand by! There will be interesting developments

About

Dpdl (Dynamic Packet Definition Language) is a rapid development Programming Language and constrained device platform with built-in Database and Agents technology. Dpdl enables also the embedding and execution of multiple programming languages (C, C++, Python, etc...) directly embedded within dpdl code. This is the DpdlEngine to run it

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors