Macroprogramming Using an Embedded DSL Approach ADRIAN MIZZI

Macroprogramming Using an Embedded DSL Approach ADRIAN MIZZI

Macroprogramming using an Embedded DSL approach ADRIAN MIZZI Supervised by Dr Joshua Ellul and Prof. Gordon Pace Department of Computer Science Faculty of ICT University of Malta September, 2019 A dissertation submitted in partial fulfilment of the requirements for the degree of Ph.D. Computer Sci- ence. iii Statement of Originality I, the undersigned, declare that this is my own work unless where otherwise acknowledged and referenced. Candidate Adrian Mizzi Signed Date April 26, 2020 The research work disclosed in this publication is partially funded by the Endeavour Scholarship Scheme (Malta). Scholarships are part-financed by the European Union - European Social Fund (ESF) - Operational Programme II – Cohesion Policy 2014-2020 “Investing in human capital to create more opportunities and promote the well-being of society”. European Union – European Structural and Investment Funds Operational Programme II – Cohesion Policy 2014-2020 “Investing in human capital to create more opportunities and promote the well-being of society” Scholarships are part-financed by the European Union - European Social Funds (ESF) Co-financing rate: 80% EU Funds;20% National Funds vi Acknowledgements I would sincerely like to thank my supervisors, Dr Joshua Ellul and Prof. Gordon Pace for their patience, commitment and support throughout the duration of my studies. Apart from the part they played in introducing me to the area of Internet of Things, functional program- ming and blockchain technology, they were also available to provide guidance and steer me in the right direction when things became un- clear. They pushed me beyond my limits, and in doing so I feel I have grown in my capabilities as a researcher and as a computer scientist. I also thank my close friend Dr Jean Paul Ebejer, who was not only an inspiration for starting this journey, but also the person whom I turned to many times for guidance and support. I am indebted to him for being there during the difficult times that come with such pro- grammes, but also for taking personal time and interest to discuss, re- view and suggest ideas around my research work. I must also thank my immediate family for the unwavering sup- port they have provided through the duration of my work. This work would not have been possible without the support from my wife Ruth, who not only returned back to employment to support the family but also spent many hours with our daughter Michaela, so I could focus on my studies. I also thank my parents and in-laws for the long hours they dedicated to our daughter so I could complete my research. vii Abstract Software applications were traditionally developed using a mono- lithic approach and developed as a single instance. As distributed sys- tems emerged, these traditional methods were no longer suitable. In the domain of wireless sensor networks, an application is developed to run across multiple nodes, and devices must communicate and collab- orate together. The general trend is for a software developer to write a single program which is loaded on all the devices. In the case of het- erogeneous networks where the systems making up the network vary in architecture, capabilities and characteristics a different approach is used — different programs are written and loaded on each different system. Such an approach requires expertise programming different systems, and the interactions between disparate systems need to be explicitly handled by the programmer. In this thesis, we propose a model for programming heterogeneous systems using a single macroprogram, thereby achieving a higher level of abstraction and enabling applications to be described at the macro- level. We combine techniques from macroprogramming and multi- target compilation, using an embedded DSL approach to generate target- specific code for different domains on different ends of the spectrum. On one end of the spectrum, we apply the model to wireless sensor networks where challenges exist around optimising code for execution on heavily resource constrained devices. At the other end of the spec- trum, we propose a framework for writing smart contracts spanning multiple diverse blockchain systems. Each domain brings its’ own challenges, however the model is shown to be applicable to different domains. Contents 1 Introduction 1 1.1 Aims and Achievements . 3 1.2 Overview of Subsequent Chapters . 7 I Background 9 2 Macroprogramming 11 2.1 Introduction . 11 2.1.1 Hardware/Software Codesign . 13 2.1.2 Wireless Sensor Networks . 16 2.2 Discussion and Challenges . 25 2.2.1 Code Slicing . 25 2.2.2 Interoperability . 26 2.2.3 Heterogeneity . 27 2.3 Conclusions . 28 3 Embedded Domain Specific Languages 29 3.1 Shallow versus Deep Embedding . 30 3.2 Challenges of DSELs in Functional Languages . 34 3.2.1 Sharing and Feedback . 34 3.2.2 Type Safety . 36 viii CONTENTS ix 3.3 Conclusions . 38 II Macroprogramming for Wireless Sensor Networks 39 4 Background: Wireless Sensor Networks 41 4.1 Introduction . 41 4.1.1 Structure of a Wireless Sensor Node . 41 4.2 Challenges of WSN . 42 4.2.1 Hardware Constraints . 42 4.2.2 Programming Challenges . 47 4.2.3 Economic Challenges . 49 4.3 Programming Approaches . 50 4.3.1 Node-Level Programming . 51 4.3.2 Network-Level Programming . 53 4.4 Conclusions . 54 5 D’Artagnan 57 5.1 Introduction . 57 5.2 A Framework for Macroprogramming of WSNs . 60 5.3 Interpretations . 62 5.4 D’ARTAGNAN as a language . 64 5.4.1 Stream Operators . 64 5.4.2 Memory Capabilities . 66 5.4.3 Compiler Hints . 68 5.4.4 Stream Tuples . 71 5.4.5 Simulator . 71 5.4.6 Intermediate Code / Device Code . 72 5.4.7 Device level code: Contiki . 72 5.4.8 Implementation Details . 74 5.4.9 Discussion . 75 5.5 Use-case: Smart Rent Management . 76 5.6 Use-case: Intelligent Cooling and Lighting Systems . 79 x CONTENTS 5.6.1 Stream Handling Components . 80 5.6.2 Room Layout Representation . 82 5.6.3 Application Implementation . 84 5.7 Performance Evaluation . 86 5.8 Related approaches . 88 5.9 Conclusions . 91 IIIMacroprogramming for Blockchain Systems 93 6 Background: Blockchain and Smart Contracts 95 6.1 Introduction . 95 6.1.1 Overview . 96 6.2 Blockchain Technology . 97 6.2.1 Blockchain Architecture . 97 6.2.2 Smart Contracts . 99 6.3 Blockchain Systems . 100 6.3.1 Bitcoin . 100 6.3.2 Ethereum . 100 6.3.3 Hyperledger Fabric . 101 6.3.4 Others . 101 6.4 Smart Contract Programming Languages . 102 6.4.1 Bitcoin Script . 103 6.4.2 Solidity . 104 6.4.3 Marlowe . 106 6.4.4 Others . 107 6.4.5 Discussion . 112 6.5 Chain Interoperability . 112 6.6 Conclusions . 114 7 Macroprogramming the Blockchain of Things 115 7.1 Introduction . 116 7.1.1 D’ARTAGNAN for Blockchain of Things . 117 CONTENTS xi 7.2 Proposed Framework . 118 7.3 D’ARTAGNAN: A Macroprogramming Framework . 120 7.3.1 D’ARTAGNAN for IoT . 122 7.3.2 Extending D’ARTAGNAN . 122 7.4 Use Case: Smart Rent Management . 127 7.5 Evaluation . 130 7.6 Discussion and Conclusions . 132 8 Porthos 135 8.1 Introduction . 135 8.2 Porthos Framework . 138 8.2.1 Multi-chain Support . 139 8.2.2 Code Cuts . 141 8.2.3 Coordination Model . 142 8.3 PORTHOS as a smart contract language . 142 8.3.1 Implementation Details . 148 8.4 Use Cases . 149 8.4.1 Property Sale . 149 8.4.2 Single-shot DAO . 152 8.5 Evaluation . 155 8.5.1 Expressiveness of Abstraction . 156 8.5.2 Security Analysis . 157 8.5.3 Extensibility . 158 8.6 Conclusions . 159 IVConclusions 161 9 Conclusions and Future Work 163 9.1 Future Work . 164 9.2 Concluding Thoughts . 166 A Publications 167 xii CONTENTS References 169 1 Introduction The first computers were programmed using low-level machine code, but it did not take long for scientists to realise that this approach was very error- prone and requiring expert programming skills. To address this and make programming more accessible to programmers, a higher level of abstraction was needed — a number of higher-level languages soon emerged making it easier for programmers to write software applications. As software applications grew in complexity and spanned across multi- ple systems, software programs were split in smaller parts, where each part gets executed on a different system. A typical scenario is that of a client- server application, where the code of the client is written separately from that of the server, and both parts need to tackle the communication between them (see Figure 1.1(a)). Writing applications in this fashion is not straight- forward, and the programmer needs to be fully aware of the implications of distributed systems — such as synchronisation of processes, communica- tion between systems and handling of partial failures. Such an approach is still commonly used today in many domains, primarily because alternative approaches are lacking. A possible solution lies in achieving an even higher level of abstraction such that the complexity of distributed applications is hidden away from the programmer. A technique that has emerged from the domain of wireless sensor net- works is macroprogramming — a single program is written to define the be- 1 2 CHAPTER 1. INTRODUCTION haviour of tens, hundreds or even thousands of small, heavily resource- constrained devices. In this domain, several approaches have been pro- posed. In one approach (see Figure 1.1(b)), a software program is written from the perspective of the device and this is then uploaded to all the de- vices in the wireless sensor network. The applications that can be imple- mented in this manner are somewhat restricted to those where all devices in the system behave in, more or less, the same way — for example, appli- cations where sensors detect environmental data (such as devices capable of sensing seismic activity around a volcano) and forward the information to a central server.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    191 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us