Skip to content

Latest commit

 

History

History
606 lines (327 loc) · 26 KB

Dpdl_Examples.md

File metadata and controls

606 lines (327 loc) · 26 KB

Dpdl Examples

Dpdl

			www.dpdl.io

developed by SEE Solutions © 2003

Dpdl sample Applications

More advanced sample applications written with Dpdl that serve as demonstrators are published in this repository:

Dpdl-sample-Apps

These examples are demonstrators but are full running applications.

Dpdl sample code (Examples)

Basic

Special

  • Execute a Dpdl script continuously in a dedicated Thread instance

    dpdl_startup.h

  • Uses the Dpdl API library DoubleEmul and FloatEmul to emulate floating point and double precision math operations

    dpdlFloatDoubleEmul.h

  • Example Dpdl code that converts/compiles a 'struct' to a native java bytecode object and accesses member variables and methods

    test/testGenObjCode.h

  • Example program written in C that shows how to execute a given Dpdl script from C code

    embed_dpdl/test_dpdl_code_exec.c

  • Example program written in C that shows how to execute embedded Dpdl code within C code

    embed_dpdl/test_dpdl_code_exec2.c

Data

  • Example Dpdl code that parses an XML document with the xml pull parser

    xml/dpdlXMLParser.h

  • Parse JSON file and access data types

    json/testDpdlJSON.h

  • Parse JSON file and decode data into a struct

    json/dpdlDecodeJSON.h

  • Example Dpdl code that performs HTTP requests (GET, POST and PUT)

    http/dpdlHttpExample.h

  • Example Dpdl code that makes use of multi-line structured text resources

    test/testResource.h

  • Example Dpdl code that compresses and de-compresses a string of data using the Java platform API

    dataCompress.h

  • Example Dpdl code that embeds and executed an SQL query on a defined database and retrieves and prints out the result

    sql/dpdlSqlExample.h

  • Example Dpdl code that embeds and executed an SQL query on a defined database and retrieves and prints out the result (same as above), and encodes the result set into a json string, than decodes the json string to an object that can be accessed

    sql/dpdlSqlExampleJson.h

  • Save and access data from a record store

    rs/recordStoreExample.h

  • Test read and write access to record stores

    testRSConcurrency.h

  • Simple console application to allocate and perform queries on the supplied DpdlPacket dpdl_PHONEBOOK. The script allows to perform single queries, or n sequential or random queries, and measures the execution time. Comment or uncomment the following line of code in the script -> i #abs(search_rand_int)

    dpdlpacket/testDpdlDB2.h

  • Dpdl code that shows how to read and write data to a virtual record store filesystem

    fs/dpdlVirtualFS.h

GPU Compute

The following Dpdl examples show how to exploit capabilities of a GPU via embedded 'Wgsl' and 'OCL' code sections

  • Dpdl sample code that makes use of the Dpdl language plug-in 'dpdlopencl' to execute embedded OCL code (OpenCL)

    opencl/dpdlOpenCLTest.h

  • Example Dpdl code that make use of Wgsl (WebGPU shading language) to speed-up computations for a high-performing neural network activation function (GELU) directly on GPUs

    wgsl/dpdlWgslTest.h

AI generative code using the Dpdl langage plugin 'DpdlAINerd'

The following examples make use of the Dpdl langage plugin 'DpdlAINerd (DAN)' to automatically generate embedded code sections in various programming languages within Dpdl which can than be executed right away on the DpdlEngine.

  • Example Dpdl code that makes use of the Dpdl language plugin 'DpdlAINerd' (DAN) to automatically generate a simple SNAKE Game console application (written in C) via AI generative code using DeepSeek AI Models.

    ai/dpdlAISnakeGame.h

The code is generated, compiled and executed in a single step

The code above 'ai/dpdlAISnakeGame.h' automatically generated the following Dpdl code with embedded C: ai/dpdlAISnakeGame_gen.h

The AI engine used in this case was the available 'DeepSeek' model. No adaptations were needed to successfully run the program right away.

  • Example Dpdl code that leverages generative AI using the 'DpdlAINerd' (DAN) Dpdl language plug-in to generate embedded code sections which can than be executed

    ai/dpdlAICodeSort.h

The code above automatically generated the following Dpdl code: ai/dpdlAICodeSort_gen.h

  • Example Dpdl code that leverages AI using the 'DpdlAINerd' (DAN) Dpdl language plug-in to generate a json test dataset

    ai/dpdlAITestData.h

  • Example Dpdl code that leverages AI using the 'DpdlAINerd' (DAN) Dpdl language plug-in to generate and execute embedded code right away

    ai/dpdlAITestExec.h

this program Output:

this is my sample json:
{
  "documentType": "National ID",
  "issuingCountry": "United States",
  "issuingAuthority": "Department of Motor Vehicles",
  "documentNumber": "123456789",
  "issueDate": "2020-05-15",
  "expiryDate": "2030-05-15",
  "personalDetails": {
    "firstName": "John",
    "middleName": "Michael",
    "lastName": "Doe",
    "dateOfBirth": "1985-07-20",
    "gender": "Male",
    "placeOfBirth": "New York, USA",
    "nationality": "American"
  },
  "address": {
    "street": "123 Main St",
    "city": "New York",
    "state": "NY",
    "postalCode": "10001",
    "country": "USA"
  },
  "biometricData": {
    "photo": "base64EncodedPhotoString",
    "signature": "base64EncodedSignatureString",
    "fingerprints": {
      "leftThumb": "base64EncodedFingerprint",
      "rightThumb": "base64EncodedFingerprint"
    }
  },
  "additionalInformation": {
    "height": "180 cm",
    "eyeColor": "Brown",
    "bloodType": "O+",
    "organDonor": true
  },
  "securityFeatures": {
    "barcode": "base64EncodedBarcode",
    "mrz": "P<USADOE<<JOHN<MICHAEL<<<<<<<<<<<<<<<<<<<<<<<1234567890USA8507201M3005159<<<<<<<<<<<<<<02",
    "chip": {
      "encryptedData": "base64EncodedEncryptedData",
      "publicKey": "base64EncodedPublicKey"
    }
  }
}

Graphical User Interface (UI)

  • Example Dpdl app that uses the JavaFX java library to create a sample UI (Graphical User Interface) application via a FXML definition and used CSS to create the layout.

    ui/dpdlGUIJavaFX_css.h

  • Example Dpdl code that uses the JavaFX java library to render UI (Graphical User Interface) elements via a FXML definition.

    ui/dpdlGUIJavaFX.h

  • Drawing functions on a UI Canvas on J2ME devices

    J2MEDrawDemo.h

  • Creates a graphical user interface with some UI components (Button, Panel, Checkbox, List, draw Panel) using Java Swing classes. The list is updated, the button command is intercepted with the 'actionPerformed' function, the checkbox status is printed to stdout, and a text and rectangle is drawn at random location on the draw panel using a thread.

    ui/dpdlGUIExample.h

Small Apps

  • Example Dpdl code that downloads json news data from a given URL and decodes it to a struct

    app/getnews/dpdlGetNews.h

  • Implementation of SHA-1 hash algorithm entirely written in Dpdl

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

  • Example Dpdl app that uses the JavaFX library to render and animate a 3D model of a chemical molecule (hydrogen)

    graphics/dpdl3DJavaFX_molecule.h

    VIDEO of Dpdl sample 3D application

  • Example Dpdl code that executes an embedded 'clojure' code that creates a simple UI to convert values from Celsius to Fahrenheit

    clj/dpdlCljCelsiusConverterGUI.h

  • Example Dpdl code that executes an embedded 'Julia' script to plot data using the 'Plots' package, and to save the chart as PDF

    julia/dpdlJuliaPlot.h

    here the exported PDF:

  • Example Dpdl app that uses the JavaFX java library to visualize a website within a WebView component

    ui/dpdlGUIJavaFX_web.h

  • Performs a discovery of bluetooth devices and saves the device addresses discovered in a record store

    bluetoothDiscoverySave.h

  • Downloads a html website from a URL and saves the content in a local file

    downloadWebURL.h

  • Accepts connections from a bluetooth server application and intercepts commands

    DpdlConsoleBT_client.h

    DpdlConsoleBT_client.h_static

  • BTObexServer (client/server)

    Sample application that implements sending of SMS via bluetooth to discovered devices. The messages to be sent are read from a record store. An auxiliary script (ImportantMsgWriter.h) can be used to store messages to be delivered in the record store

    BTObexServer/BTObexServer.h

    BTObexServer/BTObexServer.h_static

  • HTTPServer:

    Simple client server application to send and receive broadcasted messages via HTTP protocol.

    HTTPServer/HTTPServer.h

    HTTPClient/HTTPServer.h

    How to run:

      1) start the server: HTTPServer/HTTPServer.h
      
      2) start the 1st client: HTTPServer/HTTPClient.h
      
      3) start the 2nd client, but first change the CLIENT_ID in the HTTPClient.h script
    
  • CoAP (client/server):

    Client server application that implements PUT, GET, OBSERVE requests via CoAP (Constrained Application Protocol). The clients can create resources and perform PUT, GET or OBSERVE requests on the resources created.

    Once the dpdlCoAPServer.h is started, the observe client (dpdlCoAPClient.h) can be initialized in a 2nd console, and a second client (dpdlCoAPClient2.h) that performs PUT requests can be initialized in a 3rd console by starting it in a dedicated thread via the script 'startClientThread.h'

    CoAP/dpdlCoAPServer.h

    CoAP/dpdlCoAPClient.h

    CoAP/dpdlCoAPClient2.h

    CoAP/startClientThread.h

    How to run:

      1) start the server: CoAP/dpdlCoAPServer.h
      
      2) start the 1st client: CoAP/dpdlCoAPClient.h
      
      3) start the 2nd client in a thread instance: CoAP/startClientThread.h
    

Dpdl language plug-ins (embeddable programming languages)

  • Example with embedded C code execution within Dpdl (interpreted Mode 1)

    C/dpdlSample.h

  • Example with embedded C code execution within Dpdl that is compiled in memory at runtime (compiled Mode 1)

    C/dpdlCcompile.h

  • Example Dpdl code that shows how C code and Python can be embedded and executed within Dpdl

    dpdlFullExample.h

  • Example Dpdl code that shows how MicroPython code can be embedded and executed within Dpdl. MicroPython is suitable for embedded systems.

    micropython/dpdlMicroPythonTest.h

  • Example Dpdl code that makes use of an embedded Java code block to perform a dummy calculation on an array passed from Dpdl

    java/dpdlJavaExample2.h

  • Embedded C code execution within Dpdl code

    dpdlSimpleC.h

  • Embedded Python code execution within Dpdl code

    python/dpdlEmbedPython.h

  • Embedded Lua code execution within Dpdl code

    lua/dpdlLuaBufRet.h

  • Embedded Ruby code execution within Dpdl code

    ruby/dpdlRubyExample.h

  • Embedded V code execution within Dpdl code (fibonacci sequence)

    v/dpdlVFibonacci.h

  • Example Dpdl code that embeds C++ code and uses ROOT API libraries to solve a linear equations in 4 different ways

    root/dpdlRootSolver.h

  • Example Dpdl code that embeds javascript code (with Mode2 using 'qjs') that loads an object implemented in a native C library (see point.c)

    js/dpdlQJsPoint.h

  • Example Dpdl code that compiles a WebAssembly WAT code to WASM binary format and calls the exported functions from both, Dpdl and javascript

    wasm/dpdlWasmTest.h

  • Dpdl code that compiles two WebAssembly modules (in WAT code), with 1st module that exports functions to the 2nd module, to WASM binary format. The function 'add_and_sub' exported by the 2nd module is than called from Dpdl

    wasm/dpdlWasmModules.h

  • Example Dpdl code with embedded ANSI C code that is compiled in memory and executed at runtime, the result is than intercepted

    C/dpdlCcompileBufRet.h

  • Example Dpdl code that executes an embedded 'Julia' script to download data via HTTP via url's contained in json data

    julia/dpdlJuliaPlot.h

  • Example Dpdl code that executes an embedded 'groovy' code (dummy)

    groovy/dpdlGroovyExample.h

  • Example Dpdl code embedding ANSI C code (ISO C99) that is dynamically compiled in memory at runtime (fast) and executed

    C/dpdlCcompileExample.h

  • Example Dpdl code that embeds JavaScript that intercepts some parameters that have been pushed on the dpdl stack

    js/dpdlJsExample.h

  • Example Dpdl code that embeds Clojure code

    clj/dpdlCljExample.h

  • Example Dpdl code (embedded C code compiled at runtime) that launches threads (pThreads) to sum numbers

    C/dpdlCThreadExample.h

  • Example Dpdl code that shows to to execute embedded C code accepting parameters pushed on the dpdl_stack, and writes some result back to a buffer variable. The execution time is measured.

    bench/testC.h

  • Example Dpdl code that embeds 'Julia' code to execute a set of threads that call a native C Dpdl API function

    julia/dpdlJuliaThread.h

  • Example Dpdl code that embeds 'PHP' code to read a CSV file, count the number of fields in each line and print the values

    php/dpdlPhpTest4.h

Benchmark Tests

More Tests

  • Small 'dummy' sample application

    app/dummy/dpdl_sample.h

  • Set of 14 examples/tests. The examples make use of @TAG execution to allow execution of each individual example.

    dpdlLibExamples.h

     -load
     dpdlLibExamples.h @TEST1
     
     -load
     dpdlLibExamples.h @TEST2 etc..
     
     ....
    

How to run the examples

The Dpdl example scripts are located in the './DpdlLibs/' folder and can be executed in different ways:

  1. or directly via the '-load' parameter at startup
  2. using the DpdlClient console application with commands
  3. or using the API function call DPDLAPI_execCode(..).

The script path per default configuration need to be relative to the './DpdlLibs/' folder

1) At startup with the '-load' command

java --add-opens java.base/sun.net.www.protocol.http=ALL-UNNAMED --add-opens java.base/sun.net.www.protocol.https=ALL-UNNAMED -jar DpdlEngine_V1.0_release.jar -load test/testArray.h

Note: On newer versions of java (from Oracle), in order to access specific java 'modules' within Dpdl, you may need to enable them with the option '--add-opens'

2) DpdlClient console application

-load
enter the Dpdl script name to execute:
arraylistExample.h [@TEST1]

3) Using the Dpdl API

println("executing dpdl script...")
int s = DPDLAPI_execCode("mydpdlscript.h")
println("status: " + s)

The Dpdl sample scripts and Dpdl sample applications published on this repository are released under the MIT License.