Skip to content

Latest commit

 

History

History
2930 lines (1881 loc) · 65.5 KB

Dpdl_documentation.md

File metadata and controls

2930 lines (1881 loc) · 65.5 KB

dpdl-lang documentation

			www.dpdl.io

by SEE Solutions ©

Dpdl language specification

Dpdl dpdl-lang is a general-purpose programming language, self-contained , mostly interpreted, 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 to be compiled also to native code for multiple target platforms.

Dpdl introduces also the concept of 'embedded code sections' that enables to embed and execute code of other programming languages, or any custom syntax, directly embedded within dpdl code, simultaneously, of multiple types and at it's native speed.

Embedded programming language code within dpdl is executed by dedicated Dpdl language plug-ins distributed along with the DpdlEngine release package. Everything is already included, No further installations required.

Features:

  • Types available: int byte short float double long string char bool array[] var const class object struct union enum
  • Primitive arrays and dynamic arrays
  • Inheritance and Polymorphism for type class, struct and union
  • Multiple native Threads within same module
  • Pointers and references (eg. int *px = &x)
  • In-line string expressions
  • Native data function types to handle data structures arr(..), vec(..), map(..), list(..) and stack(..).
  • APIs: Dpdl API, JRE API, MIDP API
  • Access to the full underlying Java Platform API's or any external java libraries
  • Access to Native shared C/C++ Libraries
  • Virtual file system via Record Stores
  • Support for custom extensions
  • Dpdl language plug-ins -> Multiple embeddable programming languages supported: C, C++, Python, MicroPython, Julia, JavaScript, Lua, Ruby, Java, PHP, Perl, Groovy, V, Clojure, Wgsl and OpenCL. These programming languages code can be embedded and executed directly within dpdl code (interpreted/compiled code).
  • Additional programming languages or syntax interpreters can be easily integrated via a defined plug-in interface and configuration (Dpdl language plug-ins)
  • ANSI C code embedded within dpdl code can be dynamically compiled in memory at runtime (see option 'dpdl:compile')
  • Multi-line structured text, data and code resources
  • Asynchronous Task execution
  • Dpdl can be embedded and called within C code
  • Tools for converting dpdl code to Java and C/C++ code stubs (in development)

Dpdl quick language Tour

If you want to gain a quick intro to some of the features of Dpdl you can also take this quick overview tour

Dpdl language quick Tour

Table of Contents

dpdl code

Dpdl code can be executed as plain text scripts, in form of strings or text file, via the following interfaces:

  • Command line via the DpdlEngine client
  • Programmatically via Dpdl Java API
  • Programmatically via Dpdl C API

Dpdl program entry point

A dpdl program can either omit the program entry point function, or have a main(...) entry point function defined that accepts an array of arguments as parameters.

dpdl without entry point function

A dpdl file containing this will execute as is

println("this line will be printed")
dpdl with main(...) entry point function

For a dpdl file containing the main(...) function entry point, in this case the execution will start at main(...)

The main(...) entry point function may return value of type 'int' that is also the process exit code, or not return any value.

func main(args[]) int
	...
	return 1
end

OR also

func main(args[])
	...
end

Example:

func myP()
	println("hello dpdl")
end

func main(args[])
	println("args: " + args + " is of type: " + typeof(args) + " and has size: " + args.size())

	if(args.size() >= 3)
		println("arg[0]: " + args[0])
		println("arg[1]: " + args[1])
		println("arg[2]: " + args[2])
	else
		println("wrong nr arguments")
	fi
	
	myP()
end

Types

Dpdl supports the following Types:

  • int
  • short
  • float
  • double
  • long
  • byte
  • string
  • char
  • bool
  • var
  • object
  • class
  • struct
  • union
  • enum
  • (tuples...)

Examples:

int i = 1
int ih = 0x67452301
short s = 10s
float f1 = 0.1
float f2 = 0.1f
double d = 10000.0d
long l = 1000L
byte b = 1B
byte b = 0x01B
string s = "mystr"
char c = 'a'
bool t = true
var v = "some variable type which is infered at runtime"
const t = "some immutable 'var' variable"
const int x = 10
class myClass cl
object myobj = new(...)
object myobj_static = getObj(...)
struct myStruct a = {1, "a test", ., 23.3}
union myUnnion u = {0}
enum myenum e
var mytuble = (1, 'b', 0x63B, "test")

# primitive arrays
int arr_i[10]
float arr_f[10]
double arr_d[10]
short arr_s[10]
byte arr_b[10]
char arr_c[10]
var arr_v[10]
int arr_i_ini[] = {1, 2, 3}
float arr_f_ini[] = {1.0, 2.0, 3.0}
double arr_d_ini[] = {1.0d, 2.0d, 3.0d}
short arr_s_ini[] = {10s, 20s, 30s}
byte arr_b_ini[] = {1B, 2B, 0x03B}
char arr_c_ini[] = {'a', 'b', 'c'}
var arr_v_ini[] = {"can contain all types", 23.0d, new(HashMap")}

my_arr_dynamic[] = [1, 0.3, 23.0d, 1000L, 0x09B, "mydata"]

Strings

  • Strings can be defined enclosed either within double quotation mark " , or within single quotation mark ', both are valid and can be used accordingly where more convenient, for example to avoid quotation escapes, etc.
string s1 = "This is a valid test"
println("s1: " + s1)

string s2 = 'Also this is valid'
println('s1: ' + s1)
println("s1: " + s1)
  • String can be defined as multi-line strings by using "'" as enclosures
string mystr = "'"

		writing multi-line strings in Dpdl
		is also possible

		:D

		"'"
		
println(mystr)
  • Strings support character sets in 16-bit Unicode format UTF-16
string msg1 = "Hello World"
string msg2 = "你好世界"

println("I'd like to say: " + msg1 + " and " + msg2)
  • String interpolation with values or expressions

Strings may contain variable identifiers ( with $ ) or even complete expressions ( enclosed in ${...}) that are compiled into the string

int x = 10
int y = 20
float z = 23.3333
float z1 = 23.3333f
object msg = new("String", "Hello test message")

string s = "this is a test"

println("the values are: $x $y $z and the message is: $msg")

println("the expression x + y is equal to: ${x + y} ")

float v = 9.0f

println("square root of $v is ${ sqrt(v) }")

Values

Dpdl supports the following types for representing values: int foat double long short byte

For some values types Dpdl makes use of suffixes for the representation to differentiate the type of values.

Suffixes:
  • int -> no suffix
  • float -> no suffix (default), or with suffix f
  • double -> d
  • long -> L
  • short -> s
  • byte -> B

example: (type short value 10)

short mys = 10s
byte myb = 10B
Double and Floating point Scientific Notation

Double and floating point numbers can be represented also with the scientific notation using e or E for representing the exponent:

example:

double myd1 = 1.2345E3d

double myd2 = -1.2345e3d

float myf1 = 1.2345E3

float myf2 = -1.2345e3
Hexadecimal Number Format

The number types int, long and byte can be represented also in Hexadecimal format, having either lower-case of upper-case letters (eg. 0x1627F OR 0x1627f)

example: int value 90751

int i = 0x1627F
#or
int i = 0x1627f

example: byte value 1

byte b = 0x01B

example: long value

long l = 0x14269cae3c1ae6243L

Objects

The type object is a base type. All types can be handled as objects.

Whether it's a dpdl class or a struct, a primitive type, a whole dpdl module, or even a java JRE class, all of these types can be stored, referenced and handled via the dpdl type object.

Every type can be assigned to an object variable. But not the other way around.

Example:

int myi = 9999
object myiobj = myi
struct A {
	...
}

object a = new A(...)

The type object' is also used to load java classes available within dpdl

Example: instantiation of a Java class

object myc = new("MyTestJavaClass", 1, 2, 3)

myc.printValues()

A primitive dpdl type (i.e 'int' or 'string'), can also be casted to an object, inheriting all methods and fields of the corresponding Java class type (i.e. java.lang.Integer or java.lang.String).

Example:

string mys = "This is a Test"

object mys_obj = mys

object mys_mod = mys_obj.replaceAll("Test", "MEGA Test")

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

string mys_new = mys_mod

 

Object type specifier

A given type can also be enforced on an object' type variable by specifying a type specifier within the enclosures <....> (Optional):

object<String> mys = null

mys = new("String", "This is a Test")

println("Uppercase: " + mys.toUpperCase())

Inferred types

The types var and const are both inferred types.

The var variables are mutable, while the const variables are immutable.

The actual type of the variable is inferred at runtime upon assignment.

They can accept any type from a given declaration or function.

  • Type var

This type can hold values or objects of all types

var i = 10
i = "10"

var s = "Test"
s = 10
  • Type const

This type can hold values or objects of all types, but is inherently Immutable.

When re-assigning a value or object to an initialized variable of this type, will throw an error:

const ii = 100
ii = 999 # will throw an Error

The 'const' keyword can also to be used in conjunction with all other type definitions. Also in this case, on re-assignment it will throw an error.

const int x = 20
const float p = 23.3f

const string s = "this is a test"
...

'null' values

The value null can be assigned to any type.

example:

string tmps = null
float tmpf = null

The types string, var and object, in case of a variable declaration without assignment, by default retain the value null

example:

string tmps
var tmpv
object tmpo

typedef specifier

The typedef specifier allows to create aliases for given types (ex. int, float, class, etc..), similar as in C/C++, where the defined alias can than be used instead.

This may come handy for example for porting code, it might improve code readability and facilitate faster code writing.

Example:

typedef byte i8
typedef int i32


func myTest(i8 val, i32 x, i32 y) float
	float ret = to_float(x * y + val)
	
	return ret
end

i8 myval = 0x03B
i32 myx = 100
i32 myy = 200

println("myval: " + myval)
println("myx: " + myx)
println("myy: " + myy)

println("calling function...")

float res = myTest(myval, myx, myy)

println("res: " + res)

Arrays

Dpdl has two kind of array types:

  • Primitive arrays
  • Dynamic arrays

Primitive arrays

Primitive arrays can be allocated for the following types:

  • int
  • float
  • double
  • short
  • byte
  • char
  • var

The size of the array is specified at declaration, and is fixed.

This type can be passed also to java methods.

Example: (array allocation)

int myiarr[32]

myiarr[0] = 23
myiarr[1] = 369

Primitive arrays can also be allocated and initialized right away.

Example: (array type 'int' allocation and initialization)

int myiarr[] = {23, 369}

Example: (array type 'var' allocation and initialization)

The 'var' type array can contain all types available

object so = new("String", "a test str2")

var myvarr[] = {1, "a test str1", so}
Passing Primitive arrays to functions

While dynamic arrays can be defined as type in a function signature (eg. func myF(arr[], object val, ...) ), primitive arrays can simply be defined as 'var' type in function signatures.

This approach might also have some practical advantages compared to a static type definition.

Example:

func printValues(var data_arr)
	int c
	for(c <= 4)
		println("data_arr[" + c + "]=" + data_arr[c])
		c=c+1
	endfor
end

int myarr[] = {10, 20, 30, 40, 50}

printValues(myarr)

Dynamic arrays

Dynamic arrays are defined with somevar[ ]

Dynamic arrays can grow or shrink in size dynamically and its elements can have multiple mixed types.

On Dynamic arrays the same set of functions as the methods found in the java counterpart ArrayList can be called.

Array can be initialized directly, via a string and also with a struct

Example:

myarrmix[] = [1, 0.3, 23.0d, 1000L, 0x09B, "mega"]

myarray[] = "1 1.0 0x01B test Dpdl Dynamic Packet Definition Language"

object myarrayobj = myarray2[0]

bool b = myarrayobj.contains("Dpdl")

println("array contains Dpdl: " + b) 

The array elements be pure or embedded in a string and can be separated with blank space ' ', with comma ' , ' or with semicolon ' ; '. All are valid.

myemptyarr[] = []
myarr1[] = [1, 2, 3, 4, 5]
arr[] = ""
arr1[] = "1 2 3 4 5"
arr2[] = "1,2,3,4,5"
arr3[] = "1;2;3;4;5"
arr4[] = "[1,2,3,4,5]"

Initializing an array with a struct:

struct myStruct a
arr[] = array(a)

Multidimensional arrays will be supported in the coming release

Looping through arrays

  1. looping through an array with for or while statements:
myarr[] = [1, 2, 3, 4, 5]
int c = 0
for(c < myarr.size())
	println("myarr[" + c + "]=" + myarr[c])
	c=c+1
endfor
  1. looping through an an array with a java iterator

All methods of the java class 'ArrayList' can be accessed

myarr[] = [1, 0.3, 23.0d, 1000L, 0x09B, "mega"]
println("myarr: " + myarr)

object myarrobj = myarr.getArrObj()

object iter = myarrobj.iterator()

while(iter.hasNext())
	println("myarr element: " + iter.next())
endwhile

Functions

In Dpdl functions are defined via the keyword func with the following definitions:

  • Functions can be defined anywhere within a dpdl module (dpdl source file), in class types and in struct types

  • The functions can take any number of parameters of different types, and the function calls can be variadic

  • Functions may or may not return a value

  • The functions may, or may not, define a return type

  • In case a return type is specified, a type checking is performed on the receiving variable

  • Functions can return multiple values in form of tuples for example: (val1, val2, val3)

  • Functions can be recursive

func myfunction(string s, int x, float y, object o, ...)
	...
end

Function return type

The return type of a given function can be specified as follows, where '$type' is one of the supported types:

syntax:

func myname() $type

end

Specifying the return type of a function is optional, it enforces a further check on the execution and improves code readability

Example:

func myFunction(object param....) int
	return 23
end

Function return with Multiple values

Dpdl allows Functions to return multi-value variables, having the types var or object as receiving types.

If specified (optional), the function return type for multi-value tuples is: multi

func myF1()
	return (1, "a", "b", c")
end

func myF2() multi
	return (1, "a", "b", c")
end

var mv = mvF1()

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

var ret1 = mv.0
var ret2 = mv.1
var ret3 = mv.2

Control flow

if statement

if(<expression>)

fi

if elseif statement

if(<expression>)

elseif

else

fi

Loops

Simple loops

for statement

for(<expression>)

endfor

while statement

while(<expression>)

endwhile

Set loops

for...in statement

iterating over a dynamic array
for(n in [1, 2, 3])

	println("n = $n")
endfor
arr[] = [1, 23.0, 999.9d, 'a', 'b', 'c', "a test1", "a test2", "a test3", new("String", "my test JRE string")]

for(e in arr)

	println("e: " + e + " is of type: " + typeof(e))
endfor
iterating over ranges
for(x in range(1, 1000))

	println("x = $x")
endfor
iterating over list and map
for(i in list(1, 2, 3, 4, 5))
	println("i = $i")
endfor
for(k, v in map(1::"A", 2::"B", 3::"C"))

	println("key = " + k + " value: " + v)
endfor
iterating over object types that implement the List interface
object myhm = new("HashMap")

myhm.put(1, "element_1")
myhm.put(2, "element_2")
myhm.put(3, "element_3")

for(k, v in myhm)
	println("key = " + k + " value: " + v)
endfor

Operators

Arithmetic:

  • + (Addition)
  • - (Subtraction)
  • * (Multiplication)
  • / (Division)
  • % (Modulo)
  • - (Negate a value eg. -x)

Note: for multiplication (*) it's necessary to have blank spaces between the numbers and operator (eg. 1 * 2). This is currently not allowed '1*2' but will be in future

Logical:

  • && (AND)
  • || (OR)
  • ! (NOT)

Bitwise:

  • & (bitwise AND)
  • | (bitwise OR)
  • ^ (bitwise XOR)
  • ~ (bitwise COMPLEMENT - NOT)
  • << (bit SHIFT Left)
  • >> (bit SHIFT Right)
  • >>> (bit Unsigned SHIFT Right)

In case of Bitwise logical operators, the operands need to be of same type. To prevent loss of precision the result might be promoted to 'int' in some cases, so the receiving type needs to be 'int' as well.

The following types are supported:

  • byte (promoted to int)
  • short (promoted to int)
  • int (int)
  • long (long)

example: (byte shift promoted to 'int')

byte inb = 0x06B
int res = inb << 0x01B

Comparators:

  • > (greater than)

  • < (less than)

  • >= (grater than equal)

  • <= (less than equal)

  • == (equal)

  • != (not equal)

  • Table of Contents

Data Function Types

Dpdl has some built-it data function types for handling vectors, maps, linked-lists and stacks

The objects returned by these functions have all methods and fields as the corresponding java classes (ArrayList, Vector, HashMap, LinkedList, Stack)

# ArrayList
object my_arr = arr("supports multiple types", 1, 2, 3, 4.0, 5.0, 6.0d)

# Vector
object my_vec = vec(1, 2, 3, 4, "my element1", 0.23, 999.9d, 100000L, ...)

# HashMap (key:value)
object my_map = map("a"::1, "b"::2, "c"::3, ...)
object my_map2 = map(1::"A", 2::"B", 3::"C", ...)

# LinkedList
object my_list = list("A", "Costa", 1, 0.3, 999.9d, 10000L, ...)

# Stack
object my_stack = stack()

Example:

object myvec = vec("a", "b", "c", 1, 2, 3)

bool isIn = myvec.contains("c")

println("the vector contains 'c': " + isIn)

object mystack = stack()

mystack.push("my item")

In-line string expressions

Strings can contain in-line expressions that are evaluated at runtime, when the string is defined. The expression can be embedded in a string within the keyword ${ } This may reduce code at some performance expense.

Example:

int a = 10
int b = 20
string mystr = "my result is ${a + b}"
println("mystr: " + mystr)

The expressions can also contain function calls like in the following examples:

Example:

string input = "some input"
string mystr = "this is a my result ${ myFunc(input) }"
println("mystr: " + mystr)

Example using 'sqrt(...)' function:

double dv = 9.0d

println("result is ${ sqrt(dv) }")

The code snippet above gives the following output:

result is 3.0

Note: Currently only one in-line expression definition '${ ... }' is allowed inside a given string. Coming releases will support multiple expression in-linings within a given string.

Class type

Dpdl allows to define and use class type objects. This type definition is similar to the class type found in C++ or Java and others.

  • Class objects can contains member variable of all type

  • Class objects can define a constructor with variable number of parameters that is called upon class initialization

  • Class objects can contain function definitions

  • Class object can be derived from another class (Inheritance)

  • Class functions in the base-class can be overridden (overriding and overloading) by the sub-class (Polymorphism)

  • Class objects can be in part compiled into java bytecode, and therefore can be passed to java methods.

Example:

class A {
	int id = 1
	string str
	object data = null

	struct myStruct data

	func A()
		println("instance constructor with no parameters")
	end
	
	func A(int id_, string str_, object data_)
		id = id_
		str = str_
		data = data_
	end

	func printit()
		println("an A class with with id: " + id)
		println("str: " + str)
		println("data: " + data)
	end

}

object so = new("String", "my data...")

# instance with calling constructor without parameters
class A some()

# instance with calling constructor with parameters
class A mya(23, "this is a Test", so)

mya.printit()


# instance without calling any constructor
class A mya2

mya.printit()

class initialization

A dpdl type class can be initialized with, or without calling onto the class constructor.

Consider the following dpdl class definition:

class A {
	int x, y, z
	string id
	
	func A()
		println("default constructor")
	end
	
	func A(int x, int y, int z)
		this.x = x
		this.y = y
		this.z = z
	end
	
	func A(int x, int y, int z, string id)
		this.x = x
		this.y = y
		this.z = z
		this.id = id
	end
	
	
	func testIt()
		println("this is a test")
	end
}
Class instance without calling constructor
class myA a

a.testIt()
Class instance with call on a given available constructor
# no arguments

class myA a()

a.testIt()

# with arguments

class myA a2(400, 500, 600, "myID232323")

a2.testIt()

Inheritance and Polymorphism

Dpdl class type can be derived from a base class (superclass), inheriting all functions and member variables.

The dpdl keyword to subclass a given class from a base-class is : (also extends can be used alternatively if wanted, both are supported)

class A {
	...
}

class C : B {
	...
}

Alternatively, the keyword 'extends' is also accepted. It is equivalent to the the : above

class B extends A {
	...
}

Functions in the base class (super-class) can be overridden by the derived class (sub-class).

The base-class constructor can be called via the function super(...) that matches the corresponding parameters.

Example:

class A {
	int id
	string desc
	
	func A(int id_)
		id = id_
	end
	
	func setId(int id_)
		id = id_
	end
	
	func getId() int
		return id
	end
	
	func getDesc() string
		return desc
	end
	
	func printMe()
		println("this is A")
	end
}

class B : A {
	
	func B(string desc_)
		super(888)
		desc = desc_
	end
	
	func printMe()
		println("this is B")
	end
}

class B myb("this is a B instance")
myb.setId(369)
myb.printMe()

println("myb.id: " + myb.getId())
println("myb.desc: " + myb.getDesc())

Note that in this case the 'class A' function 'printMe(...)' is being overwritten by the same function definition in 'class B'

class type converted to java bytecode

The type 'class' can be conveniently converted at runtime into an efficient and interoperable java bytecode object (java Class) with the genObjCode(...) dpdl api function.

This can be useful for exchanging dpdl class objects with native java classes or to speedup performance critical function calls with dedicated java implementations.

Dpdl Class objects that are compiled into java bytecode via the genObjCode(...) function call can contain 1 embedded >>java section containing native java methods which are than also compiled to bytecode in the resulting object. Only the first embedded code definition is compiled into the resulting object. Other embedded java code sections are executed only.

Example:

class A {

	int id
	string str
	var obj = null

	func A(int id_, string str_, object obj_)
		id = id_
		str = str_
		obj = obj_
	end

	func print()
		println("id: " + id)
		println("str: " + str)
		println("obj: " + obj)
	end

	>>java
	public int myNativeJavaMethod(int val){
		System.out.println("myNativeJavaMethod()");
		
		System.out.println("contained variables:");
		System.out.println("id: " + id);
		System.out.println("str: " + str);
		System.out.println("obj: " + obj;

		int myi = 0;
		for(int i = 0; i < 1000000; i++){
			System.out.println("iter: " + i + " val: " + (val+i));
			myi=i;
		}
		val=myi;
		return (val+3);
	}
	<<
}


println("testing 'genObjCode(..)' on type class...")
println("")

println("initialization with constructor:")

object so = new("String", "MEGA test")

class A mya(23, "a Test is this", so)

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

println("mya.id: " + mya.id)
println("mya.str: " + mya.str)
println("mya.obj: " + mya.obj)


println("")
println("generating java class object...")

object myAobj = genObjCode(mya)

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

println("myAobj.id: " + myAobj.id)
println("myAobj.str: " + myAobj.str)
println("myAobj.obj: " + myAobj.obj)

println("calling native java bytecode method...")

setStartTime()

int res = myAobj.myNativeJavaMethod(23)

int ms = getEndTime()

println("res: " + res)

println("finished in " + ms + " milliseconds (ms)")

Inheritance of dpdl class objects from java classes

The dpdl type class can also be derived directly from a java class object. This is done by using the refObj(..) function.

In the example below a dpdl class 'Msg' is created, which is derived from the java JRE object.

In this way all methods and fields available in the underlying native java object can be called as dpdl functions, for example: length(), toString(), getBytes(), etc. (see 'java.lang.String' documentation)

Within the dpdl class, the methods derived from the java based super-class can be accessed via the super instance object (ex. super.length() )

The methods of the java object super-class can also be overloaded by dpdl functions and customized.

Example: A dpdl class a that is derived from a 'java.lang.String' java class object

class Msg : refObj("String") {

	func Msg(string str)
		super(str)

		println("a new message")
	end

	func printMe()
		println("message: " + super.toString())
	end

	func getData()
		return super.getBytes()
	end
}


class Msg mym("This is a test message")

int msg_len = mym.length()

println("length of mym is: " + msg_len)

println("mym: " + mym.toString())

mym.printMe()

byte barr[] = mym.getBytes()

println("mym bytes: ")

int i
for(i < msg_len)
	print(barr[i])
	i=i+1 
endfor

Struct type

struct MyStruct {
	...
}

struct MyStruct st

Dpdl supports the type struct, with the following definitions:

  • Structs may contain member variables of all type (except classes), including 'struct' variable declarations (but not 'struct' definitions)

  • Structs can call functions defined in the outer scope

  • Variable shadowing is enabled

  • Structs can be derived from a base 'struct' as sub-struct, inheriting all member variables and function definitions (inheritance), variables and functions can be overridden in the base-struct

  • Structs can contain 'struct' functions that can be called. Within struct functions all 'struct' variables can be accessed in READ mode. Changing a struct variable within a 'struct' function changes the variable only during the function scope.

  • Structs member variable can can be initialized upon 'struct' declaration

  • Structs can contain multiple embedded code sections in various programming languages (eg. >>c)

  • Structs can be used to initialize arrays, (see 'array(...)' function)

  • Structs can also contain 'dynamic arrays', but currently accessing and via $struct.arr[] is not yet possible -> this will be allowed soon., a workaround is to assign the array to an object and access the object instead.

  • Structs can be conveniently compiled into java bytecode and accessed as an object instead, see 'genObjCode(...)' -> this might be useful for exchanging data with native java classes

  • Structs can be converted into a compatible C code "struct" type using the dpdl api function 'genObjCodeC(...)' -> this is useful for exchanging data with native C libraries

  • Structs cannot contain variable definitions of 'class' type

Example:

struct myStruct {
	int x = 10
	float f = 0.1
	double d = 0.3d
	long l = 1000L
	byte b = 0x01B
	string s = "Test"
	object so = new("String", "my java obj in struct")
		
	println("myStruct: " + s)
	
	func myStructCall()
		println("myStructCall: " + s + " so: " + so)
		return 1
	end
	
	func myStructCallNativeC()
		>>c
		#include <stdio.h>

		printf("Hello myStructCallNativeC from C\n");
		<<
	end
}

struct myStruct a

println("a.x: " + a.x)

a.x = 23

println("a.x: " + a.x)

int x = a.myStructCall()

println("ret val: " + x)

my_arr[] = array(a)

println("my_arr: " + my_arr)

struct initialization

Struct member variables can be statically initialized but can also be re-assigned explicitly upon 'struct' variable declaration, in a similar way like in C.

The ordering of the variables within the initialization (i.e {...}) need to reflect the ordering inside the 'struct'.

A given variable initialization can be skipped, by invalidating the entry with a '.' entry

Example:

struct A {
	int id
	float x, y
	string str
	object data
}

object d = new("String", "some test data")

struct A mya = {23, 0.3, 0.6, "Test", d}

println("mya: " + mya)

also designated initializers can be used instead. In this case ordering does not matter. Also part of the variables can be set.

struct A {
	int id
	float x, y
	string str
	object data
}

object d = new("String", "some test data")

struct A mya1 = {id: 23, x: 0.3, y: 0.6, str: "Test", data: d}

println("mya1: " + mya1)

struct A mya2 = {data: d, str: "Test", y: 0.6, x: 0.3, id: 23}

println("mya2: " + mya2)

println("OR also just part of the parameters.."

struct A mya3 = {id: 23, data: d}

println("mya3: " + mya3)

'struct' member variables can also be initialized in subsequent steps.

struct A {
	int id
	float x, y
	string str
	object data
}

object d = new("String", "some test data")

struct A mya

mya.id = 23
mya.x = 0.3
mya.y = 0.6
mya.str = "Test"
mya.data = d
Skipping a given 'struct' variable initialization

By using the placeholder '.' a given variable initialization entry is invalidated.

In the example below, only 'x' and 'z' are initialized explicitly in the initialization, while 'y' retain the base-struct value

struct A {
	int x
	int y = 6
	int z
}

struct A mya = {3,.,9}

typedef struct

The dpdl type struct can also be used in conjunction with the typedef specifier to create a type that can than be instantiated via the new keyword.

typedef struct instance
typedef struct A {
	char id[256]
	int a
	int b
	int c
}

char myid[] = {'D', 'P', 'D', 'L'}

object myaobj = new A{myid, 1, 2, 3}

println("myaobj: " + myaobj)
typedef struct instance via a Alias
typedef struct B {
	int x
	int y
	float z
} Point


Point point = new Point(100, 200, 33.3f)

println("point: " + point)

OR also

typedef struct B {
	int x
	int y
	float z
} Point


object point = new Point(100, 200, 33.3f)

println("point: " + point)

in order to make the syntax also compliant to C/C++, a semicolon ( ; ) may be optionally appended to the Alias (i.e Point)

typedef struct B {
	int x
	int y
	float z
} Point;

...
typedef struct instance like an object

When declaring a 'struct' definition with typedef struct, the resulting 'struct' can also be initialized like an object as follows:

typedef struct A {
	char id[256]
	int a
	int b
	int c
}

char myid[] = {'D', 'P', 'D', 'L'}

object myaobj = new(A, myid, 1, 2, 3}

println("myaobj: " + myaobj)

struct inheritance

The type 'struct' can also be derived from a base 'struct', as a sub-struct, inheriting all member variables and functions from the base struct.

Variables and functions in the sub-struct having the same name as the base-struct, are overwritten in the base-struct.

Example:

struct myA {
	int id
	string desc

	func printIt()
		println("id: " + id + " desc: " + desc)
	end
}

struct myB : myA {
	int x = 23
	int y = 888
}

struct myB b

p.printIt()

Initialization of a 'struct' which has a base-struct, only the member variables of the sub-struct are initialized.

Example:

this sets only 'x' and 'y' in the sub-struct

struct myB ab = {369, 963}

struct compiled to java bytecode

The type 'struct' can also be conveniently compiled at runtime into a java bytecode object (java Class) by using the genObjCode(...) dpdl api function.

This may be useful for exchanging data structures with other native java classes or to speedup performance critical function calls.

Structs that are compiled into java bytecode can contain 1 embedded >>java section containing native java methods which are than also compiled as bytecode into the generated object. Only the first embedded code definition is compiled into the resulting object. Other embedded code sections are executed only.

Example:

struct A {
	int x = 10
	float f = 0.1
	double d = 0.3d
	long l = 1000L
	byte b = 0x01B
	string s = "Test"
	object so = new("String", "my java obj in struct")
	
	>>java
	public int myNativeJavaFunc(int val){
		System.out.println("myNativeJavaFunc() val=" + val);
		
		int myi = 0;
		for(int i = 0; i < 10000000; i++){
			myi=i;
		}
		val=myi;
		return (val+3);
	}
	<<
	
	println("myStruct: " + s)
	
	func myStructCall()
		println("myStructCall: " + s + " so: " + so)
		return 1
	end
}

struct A a

object myAobj = genObjCode(a)

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

println("myAobj.x: " + myAobj.x)
println("myAobj.f: " + myAobj.f)
println("myAobj.s: " + myAobj.s)

println("calling native java function....")

setStartTime()
int res = myAobj.myNativeJavaFunc(23)
int ms = getEndTime()

println("res: " + res + " executed in " + ms + " milliseconds (ms)")

This approach allows to speedup performance critical sections.

The native 'struct' function 'myNativeJavaFunc' call in this example executes in avg. 12 ms (on 'Apple M2 pro').

struct passed to a native library function

The dpdl type struct can be converted into a C/C++ code compatible "struct" so that it can be passed directly to a native C library function

Example:

Suppose we have the following C function code that is compiled to a native library (on Linux/Unix 'libmy_native.so', on Windows 'my_native.dll')

#include <stdio.h>

struct myS {
	int id;
	char *desc;
	char *data;
	int x;
	int y;
};

int my_function(struct myS *s, int value){
	printf("call to my_function(...)\n");
	printf("value=%d\n", value);
	printf("myS.id = %d\n", s->id);
	printf("myS.desc = %s\n",  s->desc);
	printf("myS.data = %s\n", s->data);
	printf("myS.x = %d\n", s->x);
	printf("myS.y = %d\n", s->y);
	return 23;	
}

The dpdl code to call the native C library function with a 1:1 compatible 'struct' looks like this:

import('native')

struct myS {
	int id = 23
	string desc = "my description"
	string data = "some data from myA"
	int x, y
}


struct myS s

println("s: " + s)

object s_structC = genObjCodeC(s)

println("s_structC: " + s_structC + " type: " + typeof(s_structC))

object mylib = native.loadLib("my_native")

int some_val = 888

object s_structC_ref = new("PointerByReference", s_structC.getPointer())

int ret = mylib.my_function(s_structC_ref, some_val)

println("returned value: " + ret)

Enum type

Dpdl supports the type enum

The keywords by default have increasing int values starting from 1. Desired values can be assigned explicitly.

Example:

enum myStatus {
	PENDING,DONE, ERROR, RUNNING=23
}

enum myStatus status
println("init status: " + status.RUNNING)
println("done status: " + status.DONE)
println("enum values can also be accessed directly as in C: " + DONE)

Union type

union MyUnion {
	...
}

union MyUnion mu

Dpdl supports the type union, with the following definitions:

  • Unions may contain member variables of all type (except classes), including 'union' variable declarations (but not 'union' definitions)

  • Variable shadowing is enabled

  • Unions can be derived from a base 'union' as sub-unions, inheriting all member variables. Variables can be overridden in the base-union

  • Unions member variable can can be initialized upon 'union' declaration

  • Unions can be used to initialize arrays, (see 'array(...)' function)

  • Unions can be conveniently compiled into java bytecode and accessed as an object instead, see 'genObjCode(...)' -> this might be useful for exchanging data with native java classes

  • Unions can be converted into a compatible C/C++ code "union" type using the dpdl api function 'genObjCodeC(...)' -> this might be useful for exchanging data with native C libraries

  • Only in the case where a 'union' is converted to the corresponding C/C++ union type, one of the available types must be enforced with 'setType(...)'

Example:

union myU1 {
	int x, y, z
}

union myU2 : myU1 {
	char a, b, c
}

println("testing union type...")

union myU1 u1

u1.x = 888

println("u1: " + u1)

union myU2 u2

u2.x = 232323
u2.a = 'A'

println("u2: " + u2)

union initialization

The dpdl type union has been introduced in first place for exchange with C "union" data structures.

Union member variables can be statically initialized but can also be re-assigned explicitly upon 'union' declaration, in a similar way like in C.

The ordering of the variables within the initialization (i.e {...}) need to reflect the ordering inside the 'union'.

A given variable initialization can be skipped, by invalidating the entry with a '.' entry

Example:

union Data {
	int x
	int y
	int z
}

union Data d = {1, 2, 3}

println("d: " + d)

is equivalent to

union Data {
	int x
	int y
	int z
}

union Data d

d.x = 1
d.y = 2
d.z = 3

println("d: " + d)
Skipping a given 'union' variable initialization

By using the placeholder '.' a given variable initialization entry is invalidated.

In the example below, only 'x' and 'z' are initialized explicitly in the initialization, while 'y' retain the base-struct value

union D {
	int x
	int y = 6
	int z
}

unzion D myd = {3,.,9}

union inheritance

The type 'union' can also be derived from a base 'union', as a sub-union, inheriting all member variables from the base union.

Variables in the sub-union having the same name as the base-union are overwritten.

Example:

union myU1 {
	int x, y, z
}

union myU2 : myU1 {
	char a, b, c
	int x = 5555
}

println("testing union type...")

union myU1 u1

u1.x = 888

println("u1: " + u1)

union myU2 u2

u2.a = 'A'

union passed to a native library function

The dpdl type union can be converted into a C/C++ code compatible "union" so that it can be passed directly to a native C library function.

When a 'union' tpye is converted and passed to a native C/C++ function, by definition the union can just acquire one of the a field values at time. This is enforced by calling 'setType(...)' on the union object before calling the native function.

*Example:

Suppose we have the following C code that is compiled to a native library (on Linux/Unix 'libmy_native.so', on Windows 'my_native.dll')

#include <stdio.h>

union myU {
	int id;
	char *desc;
	char *data;
	int x;
	int y;
	double z;
};

int my_function(union myU *u, int value){
	printf("call to my_function(...)\n");
	printf("value=%d\n", value);
	printf("myU.id = %d\n", u->id);
	return 23;	
}

The dpdl code to call the native C library function with a 1:1 compatible 'union' looks like this:

import('native')

union myU {
	int id = 23
	string desc
	string data
	int x, y
	double z
}


union myU u

u.desc = "my description"
u.data = "some data from myA"

println("u: " + u)

object u_unionC = genObjCodeC(u)

println("u_unionC: " + u_unionC + " type: " + typeof(u_unionC))

object mylib = native.loadLib("my_native")

int some_val = 888

u_unionC.setType("int")

object u_unionC_ref = new("PointerByReference", u_unionC.getPointer())

int ret = mylib.my_function(u_unionC_ref, some_val)

println("returned value: " + ret)

Pointers

Dpdl supports a form of pointers (eg. int *ptr = &x ).

This allows to have a variable that references another variable.

The types for which pointers are currently supported:

  • int
  • byte
  • string
  • char
  • float
  • double
  • short
  • var
  • object
  • struct

Example:

int i = 10
string s = "Mega"

println("i: " + i)
println("s: " + s)

int *i_p = &i
int *s_p = &s

println("i_p: " + *i_p)
println("s_p: " + *s_p)

s = s + " added"

println("i_p: " + *i_p)
println("s_p: " + *s_p)

Check out the following example for a deeper insight:

dpdlPointers.h

NOTE: Due to the nature of how pointers are implemented, to gain maximum performance (via a static allocation), currently it's required to use the same variable names when pointers are passed to functions, (eg, when passing a pointer int *px to a function, the function must use '*px' as parameter name in the function signature -> func testFunc(int *px,...)

This feature will be further developed.

Function return type

Specifying a return type in a function definition is optional. By default functions can return any possible variable type, or none.

To improve code readability and enforce a further check on the function return type, it's possible to specify a specific return type in the function definition via return type specifiers func myfunc() $type.

The return type specifiers are optional. For functions that do not return any value, void can be specified as function return type.

The variable type var is always accepted for all return types as the values are dispatched at runtime.

Example:

func testFuncRetInt() int
	println("testFuncRetInt")
	return 23
end

func testFuncRetFloat() float
	println("testFuncRetFloat")
	return 0.22
end

func testFuncVoid() void
	println("this function does not return a value")
end

int y = testFuncRetInt()
var yv = testFuncRetInt()
println("y: " + y)
println("yv: " + yv)
testFuncVoid()

Multi-line structured text, data and code resources

By using the >>res(...) keyword it's possible to embed multi-line structured text, data or code resources and retrieve and access them as an object.

The resources are stacked on the dpdl stack and can be accessed by 'id' or by 'name' at any execution point.

Stack variables available on the current execution stack can be referenced via place-holders in the resource that are than compiled into the returned object at every invocation.

This approach provides a flexible and readable way to handle different kind of resources like structured text, data and code.

Example:

println("testing access to embedded multi-line resources...")

dpdl_stack_var_put("msg", "Hello World")
>>res(my_html)
	<html>
	<body>
	<p>{{msg}} from Dpdl</p>
	</body>
	</html>
<<

object resid = dpdl_res_pop_id()

println("resource id: " + resid)

object myhtml = dpdl_res_obj_get(resid)

println("myhtml: ")

println(myhtml)

# same, but via res name
object myhtml2 = dpdl_res_obj_get("my_html")

println(myhtml2)

# we can change the stack variable 'msg', which is than also updated in the returned resource object
dpdl_stack_var_put("msg", "Hello World again!!!")

object myhtml3 = dpdl_res_obj_get("my_html")

println(myhtml3)

Threads

Threads can be created inside Dpdl with the Thread(..) api function.

Multiple threads are allowed inside a single Dpdl script.

The function 'Thread(..)' accepts as parameters a function callback and the time interval for the thread iteration (in milliseconds). Optionally the number of iterations for a Thread can also be provided

Further parameters passed to the 'Thread(..)' function are than passed also to the callback function.

Example Thread(..) with default iteration interval of 1000 ms:

int thread_id = Thread("myFunc")

Example Thread(..) with iteration interval of 3000 ms:

int thread_id = Thread("myFunc", 3000)

Example Thread(..) with iteration interval of 3000 ms, and max 23 iterations (unless explicitly terminated):

int thread_id = Thread("myFunc", 3000, 23)

Example starting 2 threads

func myThreadFunc1(int t_id)
	println("Hello from thread: " + t_id)
end

func myThreadFunc2(int t_id)
	println("Hello from thread: " + t_id)
end

# start a thread with an interval of 2000 milliseconds
println("starting a Dpdl threads...")
int tId1 = Thread("myThreadFunc1", 2000)
if(tId1 != -1)
	println("Thread started with id: " + tId1)
else
	println("Error in starting thread")
fi

# we make a pause to guarantee not lock conditions
sleep(3000)
# start a thread with an interval of 7000 ms and for 3 iterations
int tId2 = Thread("myThreadFunc2", 7000, 3)
if(tId2 != -1)
	println("Thread started with id: " + tId2)
else
	println("Error in starting thread")
fi

Thread GC

The Dpdl Rutime can be configured to automatically run the garbage collector 'gc()' after a given number of iterations. See GC_THREAD_EXEC parameter in 'DpdlEngine.ini'. The value '-1' invalidates this feature.

Dpdl Objects and access to JRE classes

Dpdl can access the underlying classes of a given java compliant JRE implementation or any other external java library.

Static classes can be accessed via getObj(..) function, and instance classes can be created via new(..) function.

The java class references are per default resolved via the class definition. It can be updated statically to resolve further classes, and can also be dynamically loaded and updated via the function call 'DPDLSYS_registerLib(...)'. This allows also to create aliases for class names.

Example:

# static class loading
object calendar = getObj("Calendar")
object cal_inst = calendar.getInstance()
int day_ = cal_inst.get(calendar.DATE)
println("day: " + day_)

# instance class loading
object str = new("String", "Test MyString")
int idx = str.indexOf(" ")
string substr = str.substring(idx)
println(substr)

Default configuration resolves the following API's:

The set of classes accessible with Dpdl (default) is defined to be the following set:

Java API

JavaFX API

Bluetooth JSR-82 API

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

Additional API's and classes can be added to the class definition file as needed with the syntax: '$full_class_name $class_alias'.

Dynamic loading of java API's

As mentioned above, java classes (or APIs), can be also be dynamically loaded and accesses at runtime by calling the function 'DPDLSYS_registerLib(...)'. The function accepts as parameter the path of a JAR file containing the java classes.

This approach, compared to registering the classes statically in the class file definition, has a minimal overhead with the advantage to enable loading of many different libraries not foreseen in the standard setup.

Example:

int load_lib = DPDLSYS_registerLib("./lib/custom/MyTestLib.jar")

raise(load_lib, "Error in loading java lib")

# now we can instantiate a Dpdl object from the contained java classes

object myobj = new("MyTestClass")

string mydata = myobj.getData()

println("my data: " + mydata)

println("now you can access all classes, methods and fields of the java classes contained in the specified jar file")

Load Dpdl code as a Dpdl Object

Dpdl code can be loaded as an ordinary Dpdl Objects with the function loadCode(..).

The object can be accessed like an other object except that the function calls currently must include also the name of the script loaded.

Loading a Dpdl script as an object has some advantages with respect to just include a given Dpdl script with via the 'include' statement:

  • The code runs in a dedicated execution instance -> convenient especially for multi-threading applications.
  • Variables have a dedicated scope
  • Some performance improvements when using multiple extensions
println("test loadCode(..) with dpdl script LoadCodeFunc.h")

object mycode = loadCode("LoadCodeFunc.h")

string mystr1 = "Test"
object mystr2 = new("String", "MEGA")

mycode.testFunc("LoadCodeFunc", mystr1, mystr2)
mycode.ID = "set my id"
int x = mycode.getX("LoadCodeFunc")
string cid = mycode.ID

println("done")

The script file loaded in the example above 'LoadCodeFunc.h' may also define a constructor, which is called iff parameters are supplied.

LoadCodeFunc.h

# constructor
func LoadCodeFunc(object map)
	println("object LoadCodeFunc loaded")
	println("map: " + map.toString())
end

...

The constructor is called if a parameter is supplied

object mymap = new("HashMap")
object mycode = loadCode("LoadCodeFunc.h", mymap)

Type handling

object type

All types in Dpdl can be handled as objects.

The type 'object' is in first place used to load java objects available within Dpdl (see 'new(...)' function), but can serve as a super type compatible with all other types.

Every type can be assigned to an object variable. But not the other way around.

Example:

int myi = 9999
object myiobj = myi

IFF you want to re-assign an already declared and assigned object to a variable with same name of different type, you must redefine the object as follows:

int myi = 9999
float myf = 999.9
object myiobj = myi
object myiobj = myf

Note: 'DPDL_ALLOW_VAR_REDEFINITION' must be enabled if you want to allow variable redefinition within same scope

casting to object type

Primitive types such as int, float, double, long, short, byte, char, string and var can be casted and compliant to the equivalent java object type.

In this way it's possible to access all methods of the object available on the underlying JRE platform.

Example:

int x = 10

object o_x = x

float f_x = o_x.floatValue()

println("f_x: " + f_x)

string s = "Dpdl is a rapid prototyping programming language"

object s_o = s

println("s_o: " + s_o.length())

In Java notation you would write the equivalent 'f_x' assignment as follows:

float f_x = new Integer(10).floatValue()

var type

The var variable can have an arbitrary type and is dispatched at runtime by type inference.

Therefore the 'var' type can accept any type in a function.

func myFuncVar(var a, var b)
	println("a:" + a + " type: " + typeof(a))
	println("")
	println("b:" + a + " type: " + typeof(b))
	println("")
end

int x = 10
float y = 0.3
myFuncVar(x, y)

Abstraction using 'var' type:

It might be useful to abstract a given type.

Consider the following example:

struct myA a
struct myA aa
double dist = calculateDistance(a, aa)

The function 'calculateDistance(..)' can accept the parameters as follows:

func calculateDistance(var p1, var p2) double
    float dx = p2.x - p1.x
    float dy = p2.y - p1.y
    return sqrt(dx * dx + dy * dy)
end

and is equivalent to:

func calculateDistance(struct p1, struct p2) double
    float dx = p2.x - p1.x
    float dy = p2.y - p1.y
    return sqrt(dx * dx + dy * dy)
end

Determining the Type of a variable

The type of a given variable can be determined with the typeof(..) function

example:

var s = "this is a string"
var i = 10
println("var 's' is a: " + typeof(s))
println("var 'i' is a: " + typeof(i))

The above statement will print out:

var 's' is a: string
var 'i' is a: int

For clarity, a variable other than 'var' type can also be determined:

int i = 10
println("variable 'i' is of type: " + typeof(i))

By determining the type of a 'struct' variable type, the type returned contains also a type identifier.

example:

struct A a
println("variable 'a' is of type: " + typeof(a))

The above statements will return struct:A

Whenever a java object is loaded, the type of the variable returned by typeof(..) is the name of the class.

example:

object map = new("HashMap")
println("variable 'map' is of type: " + typeof(map))

The above statement will return HashMap

Variable re-definition

Redefinition of variables within the same scope is allowed by the default configuration, in this case a 'Warning' is issued.

This configuration can be disabled by changing the parameters 'DPDL_ALLOW_VAR_REDEFINITION' and 'DPDL_VAR_REDEFINITION_WARNING' in configuration file 'DpdlEngine.ini'

In 'while' and 'for' loops it's advised, if possible, to allocate variables in the outer scope. This increases also performance and avoids allocations.

Converting types

Some variable types can be converted either by casting or by using the convert(..) function.

Casting numeric values can be performed using the functions to_int(..) , to_float(..) or to_double(..)

Example:

float f = 999.3
double d = 2000000.5d

int fint = to_int(f)
int dint = to_int(d)

println("fi: " + fint)
println("di: " + dint)

Other conversions, for example from string to a numeric type can be performed with the convert(..) function.

The function accepts as parameter the 'type' (as returned also by typeof(..)) and the variable to be converted.

Currently the following conversions are supported, more will follow:

int float double object* -> string

int -> float

float -> string

float, double -> int

Example:

int xc = 10
float f = 0.3
double d = 23.0d

println("converting to string...")

string xcs = convert("string", xc)
println("xcs: " + xcs)

string fs = convert("string", f)
println("fs: " + fs)

string ds = convert("string", d)
println("ds: " + ds)

Exception handling

Exceptions can be handled with the raise(..) function.

The following conditions are checked and an exception is raised if the expression on the type condition evaluates to 'false':

  • string -> (condition != "null") ? true : false
  • int -> (condition != -1) : true : false
  • bool -> (condition != false) ? true : false
  • object -> (condition != null) ? true : false

The raise(..) function can be called in the following ways:

raise(object condition)
raise(object condition, string msg)
raise(object condition, string msg, bool exit)

Example:

string s1 = "nul(l)"
raise(s1, "s1 is null")

println("testing int raise")
int i = 1
raise(i, "i == -1")

println("testing bool raise")
bool b = true
raise(b, "b == false")

println("testing object raise")
object o = new("String", "test")
raise(o, "o == null")

println("testing bool expression raise")
raise(o =! null, "o =! null")

dpdl_print_exception_table()

Asynchronous Task execution

The keyword >>task allows to execute Dpdl code sections asynchronously.

The code runs in an isolated execution instance and is thread safe to the embedding code.

The running 'Task' object can be accessed by popping the task id from the dpdl stack and than calling the function 'dpdl_task_obj_get(object task_id)' which returns a 'Task' object which provides access to all functions needed to control the task execution (eg. interrupt, sleep, join, etc.)

The task id is a unique identifier (UUID) like for example 312b01c1-9837-47f7-9c24-f5ec24fb9857

Example:

println("testing Dpdl tasks...")

>>task
	println("this is a dpdl Task that runs asynchronously")

	int c = 0
	while(c < 10)
		print(".")
		c=c+1
		sleep(2000)
	endwhile

	println("task finished")
<<

int exit_code = dpdl_exit_code()

object task_id = dpdl_task_pop_id()

println("task started with exit code: " + exit_code + " and task id: " + task_id)

int c = 0
for(c < 5)
	print("#")
	c=c+1
	sleep(2000)
endfor

object task_obj = dpdl_task_obj_get(task_id)

task_obj.sleep(20000L)

println("also a name can be assigned directly..")

>>task(my_task_name)
	int i
	for(i < 10000)
		println("task running: " + i)
		i=i+1
	endfor
<<
exit_code = dpdl_exit_code()

object my_task_name_obj = dpdl_task_obj_get("my_task_name")

println("finished")

Import and Include statements

Import

Dpdl libraries can be imported via the import statement.

Import libraries can be of native Dpdl object type, or can be simply other Dpdl library scripts.

The default location for imported Dpdl script library code is './DpdlLibs/libs/'.

Dpdl object type libraries can be implemented and added with a straight forward configuration. They can be implemented in java or other languages and wrapped into a dedicated interface extension that can be registered via a configuration.

You can import available libraries or place your own libs in the dedicated directory and import the code with the following statement:

import("dpdllib.h")

println("Dpdl version: " + DpdlLibVersion)

Include

A Dpdl script may include other Dpdl scripts with the include statement.

The functions and variables of the included code are than available also in the main module.

Example:

include("testImportInc.h")
import("dpdllib.h")

println("DpdlLib version: " + DpdlLibVersion)
println("myx: " + myx)

The include path need to be relative to the folder where the mail module is located.

NOTE: Currently the 'include' statement need to be placed before any defined 'import' statements -> this will change in the next release

Dpdl API

Dpdl API's are available as:

  • Native JVM API's
  • Dpdl import Libraries
  • Native shared Libraries
  • Dpdl native functions
  • Dpdl embedded C library

As Dpdl can access also java classes, the whole JVM JRE API and any other configured or loaded java compatible library is available inside Dpdl.

Refer to the java JRE documentation for Dpdl objects loaded with new(..) and getObj(..)

API Documentation

Dpdl API Documentation

Embedded code sections: embedding other programming languages directly within Dpdl code

A particular feature of Dpdl are 'embedded code sections', that allow to embed and execute code of other programming languages directly within dpdl code.

The execution is driven by the Dpdl runtime via dedicated Dpdl language plug-ins that are avaiable as part of the DpdlEngine distributions.

Custom Dpdl language plug-ins can be developed ad-hoc, distributed also separately and integrated via simple configuration. For native code based Dpdl language -plug-ins that are eventually available for multiple platforms, the dpdl runtime automatically selects the appropriate one on which it's running.

The code of other programming languages can be embedded by using the keyword >> along with the language specifier.

Example:

	println("a Dpdl program can contain 'embedded code section' in multiple programming languages...")

	println("embed C code for Performance and Hardware access...")

	>>c
		int v = 1000;
		for(int i = 0; i < v; i++){
			printf("Processing: %d\n", i);
		}
	<<

	println("embed Python for Data handling & ML...")

	>>python
		stories = ['Story 1', 'Story 2', 'Story 3']
		for story in stories:
			print(story)
	<<

	println("embed JavaScript for Web integration...")

	>>js
		fetch('https://api.dpdl.io/data')
			.then(response => response.json())
			.then(data => console.log(data));
	<<

	println("and of course also embed Java directly...")

	>>java
		Object val = null;
		int v = 1000;
		for(int i = 0; i < v; i++){
			val = new Integer(i);
			System.out.println("val: " + val);
		}

		return ((Integer)val).intValue();
	<<

	...

See Dpdl_language_plugins.md for more details.

Dpdl C API

Dpdl code can be executed also from programs written in C.

Example: executing a Dpdl source file

#include <stdio.h>
#include "dpdl.h"

int main(int argc, char **argv){
	printf("executing Dpdl from C...\n");

	char *dpdl_src_file = "test/testString.h";

	int ret = dpdl_exec_script(dpdl_src_file);

	printf("ret: %d\n", ret);

	return 0;
}

Example: executing plain Dpdl code

#include <stdio.h>
#include "dpdl.h"

char *dpdl_src_code =   ""
                        "int c = 0      \n"
                        "for(c < 1000)  \n"
                        "       println('This is Dpdl from C=' + c)     \n"
                        "       c=c+1\n \n"
                        "endfor \n";

int main(int argc, char **argv){
	printf("executing Dpdl code from C...\n");

	int ret = dpdl_exec_code(dpdl_src_code);

	printf("ret: %d\n", ret);

	return 0;
}

HowTo's

Here you can find some HowTo's that may be useful

Dpdl_howto.md

Working development drafts:

Here you can find the features that are currently in development phase and will be released soon in the coming releases of DpdlEngine:

Dpdl_drafts.md