Skip to content

Latest commit

 

History

History
422 lines (217 loc) · 18.8 KB

Dpdl_Examples.md

File metadata and controls

422 lines (217 loc) · 18.8 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

  • Example Dpdl code that 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 downloads json news data and decodes it to a struct

    app/getnews/dpdlGetNews.h

  • Example Dpdl code that loads and accesses natively the 'libc' system library functions

    native/dpdlTestNative.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

  • Embedded C code execution within Dpdl script (interpreted Mode 1)

    C/dpdlSample.h

  • Example Dpdl code that uses vec(...), map(...), list(...) and stack(...) data functions

    test/testDataFuncTypes.h

  • Example Dpdl code that make use of the >>task keyword to execute embedded Dpdl code sections asynchronously

    test/testTask.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 Dpdl script (dummy) that shows some functionalities of Dpdl

    dpdl_overview.h

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

    app/simple/dpdlSimpleJavaAndC.h

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

    dpdlFullExample.h

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

    clj/dpdlCljCelsiusConverterGUI.h

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

    root/dpdlRootSolver.h

  • Example Dpdl script 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

  • Example Dpdl script 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 script that compiles a WebAssembly WAT code to WASM binary format and calls the exported functions from both, Dpdl and javascript

    wasm/dpdlWasmTest.h

  • Dpdl script 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 script that performs HTTP requests (GET, POST and PUT)

    http/dpdlHttpExample.h

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

    sql/dpdlSqlExample.h

  • Example Dpdl script 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

  • Example Dpdl script that launches multiple threads

    concurrent/testConcurrency1.h

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

    ui/dpdlGUIJavaFX.h

  • Example Dpdl script that makes use of the type 'struct'

    test/testStruct.h

  • Example Dpdl script that makes use of the type 'class'

    test/testClass.h

  • Example Dpdl script that shows how exceptions can be raised and handled

    testRaiseException.h

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

    xml/dpdlXMLParser.h

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

    test/testResource.h

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

    dataCompress.h

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

    C/dpdlCcompileBufRet.h

  • 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 script that executes an embedded 'Julia' script to plots data using the 'Plots' package, and to save the chart as PDF

    julia/dpdlJuliaPlot.h

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

    julia/dpdlJuliaPlot.h

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

    groovy/dpdlGroovyExample.h

  • Example Dpdl script using pointers and references

    dpdlPointers.h

  • Example Dpdl code that writes and reads a data buffer to a file using the native library functions in 'libc'

    native/dpdlNativeExample.h

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

    C/dpdlCcompileExample.h

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

    js/dpdlJsExample.h

  • Example Dpdl script that embeds Clojure code

    clj/dpdlCljExample.h

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

    C/dpdlCThreadExample.h

  • Example Dpdl script 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 script that embeds 'Julia' code to execute a set of threads that call a native C Dpdl API function

    julia/dpdlJuliaThread.h

  • Load a Dpdl script object "LoadCodeFunc.h" via 'loadCode(..)' and call one of its functions

    testLoadCode.h

    LoadCodeFunc.h

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

    ui/dpdlGUIJavaFX_web.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 script that updates the fields of a struct type via a dedicated thread

    test/testStructThread.h

  • Embedded C code execution within Dpdl script

    dpdlSimpleC.h

  • Embedded Python code execution within Dpdl script

    python/dpdlEmbedPython.h

  • Embedded Lua code execution within Dpdl script

    lua/dpdlLuaBufRet.h

  • Emedded Ruby code execution within Dpdl script

    ruby/dpdlRubyExample.h

  • Embedding and executing structured code resources

    test/testCodeExec.h

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

    bluetoothDiscoverySave.h

  • Executes the bluetoothDiscoverySave.h script continuously in a dedicated Thread instance

    dpdl_startup.h

  • Array definition, population and access

    arraylistExample.h

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

    downloadWebURL.h

  • Inline execution of Dpdl scripting code

    dpdlCodeExecExample.h

  • Accepts connections from a bluetooth server application and intercepts commands

    DpdlConsoleBT_client.h

    DpdlConsoleBT_client.h_static

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

    dpdlFloatDoubleEmul.h

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

    fs/dpdlVirtualFS.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, and a text and rectangle is drawn at random location on the draw panel.

    ui/dpdlGUIExample.h

  • Drawing functions on a UI Canvas on J2ME devices

    J2MEDrawDemo.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

  • 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
    
  • Small 'dummy' sample application

    app/dummy/dpdl_sample.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

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

    ai/dpdlAITestData.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.