SlideShare a Scribd company logo
GoLightly
A Go library for building Virtual Machines


            Eleanor McHugh
Go
a new language
statically-typed and compiled
object-oriented but no classes
garbage collected
concurrency via communication (CSP)
type polymorphism via interfaces
a new way of working

 the safety of a static type system
 the feel of a dynamic runtime
 the performance of a compiled language
Virtual Machines
from inspiration...

computation
serialisation
communication
...to perspiration
simulation v. emulation
instruction set design
bytecodes
memory abstraction
operation dispatch
GoLightly
principles
interface driven delegation
architecture agnostic
inspired by hardware techniques
decoupled components
scaling through specialisation
caveat

references current dev branch
fundamental changes from github
still evolving
next release due for Strange Loop
interfaces
type Executable interface {    type Comparable interface {
   Execute(p Processor)           Identical(v Value) bool
}                                 Compare(v Value) int
                               }
type Processor interface {
   Reset()                     type Value interface {
   Step()                         fmt.Stringer
   Jump(a Address)                Comparable
   Call(a Address)                Nil() Value
   Return()                       IsNil() bool
   Load(program Program)       }
   Run()
   Execute()                   type Program []Executable
   Sleep(n int64)
   Halt(n int)
   IsActive() bool
}
instructions

obey the Executable interface
expressed as separate types
no assumptions about semantics
not tied to a bytecode representation
flow control
type NoOp struct {}                      type Call Address
func (n *NoOp) String() string {         func (c Call) String() string {
   return "NOOP"                            return Sprint("CALL", Address(c))
}                                        }
func (n *NoOp) Execute(p Processor) {}   func (c Call) Execute(p Processor) {
                                            p.Call(Address(c))
type Halt struct {}                      }
func (h *Halt) String() string {
   return "HALT"                         type Return struct {}
}                                        func (r Return) String() string {
func (h *Halt) Execute(p Processor) {       return "RET"
   p.Halt(PROGRAM_TERMINATED)            }
}                                        func (r Return) Execute(p Processor) {
                                            p.Return()
type Jump Address                        }
func (j Jump) String() string {
   return Sprint("JMP", Address(j))
}
func (j Jump) Execute(p Processor) {
   p.Jump(Address(j))
}
bytecode
type ByteCode []int                          case 5:          / JMPZ n
                                                               /                  case 10:      / POP r
                                                                                                 /
func (b *ByteCode) String() string {             PC++                                 PC++
    return "BYTECODE"                            if C == 0 {                          R[b[PC]] = DS.Pop()
}                                                      PC++                       case 11:      / LOAD r, v
                                                                                                 /
func (b *ByteCode) Execute(p Processor) {              PC += b[PC] - 1                PC++
    var PC, C, W int                             } else {                             W = b[PC]
    var R [2]int                                       PC++                           PC++
    CS := new(vector.IntVector)                  }                                    R[W] = b[PC]
    DS := new(vector.IntVector)              case 6:          / JMPNZ n
                                                               /                  case 12:      / ADD r1, r2
                                                                                                 /
    for p.Active() {                             PC++                                 PC++
         switch b[PC] {                          if C != 0 {                          W = b[PC]
         case 0:        / NOOP
                         /                             PC++                           PC++
         case 1:        / NSLEEP n
                         /                             PC += b[PC] - 1                R[b[PC]] += R[W]
              PC++                               } else {                         default:
              p.Sleep(int64(b[PC]))                    PC++                           p.Halt(ILLEGAL_INSTRUCTION)
         case 2:        / SLEEP n
                         /                       }                                }
              PC++                           case 7:          / CALL n
                                                               /              }
              p.Sleep(int64(b[PC]) << 32)        PC++                     }
         case 3:        / HALT
                         /                       CS.Push(PC)
              p.Halt(USER_HALT)                  PC = b[PC]
              return                         case 8: / RET
                                                      /
         case 4:        / JMP n
                         /                       PC = CS.Pop
              PC++                           case 9: / PUSH r
                                                      /
              PC += b[PC] - 1                    PC++
                                                 DS.Push(R[b[PC]])
processors
typical Turing machines
support flexible dispatch
not tied to a given instruction set
memory model agnostic
ripe for specialisation
a scalar processor
type SProc struct {                 func (s *SProc) Sleep(i int64) {   func (s *SProc) Call(a Address){
    Running bool                        syscall.Sleep(i)                   PC := s.PC
    PC        int                   }                                      s.PC = int(a)
    R         IntBuffer                                                    for s.IsActive() {
    F         FloatBuffer           func (s *SProc) Halt(n int) {               s.Execute()
    DS        vector.IntVector          s.Running = false                       s.Step()
    Program []Executable            }                                      }
}                                                                          s.PC = PC
                                    func (s *SProc) IsActive() bool{   }
func (s *SProc) Run() {                 return s.Running && s.PC <
    s.Running = true                    len(s.Program)                 func (s *SProc) Return() {
    s.Call(0)                       }                                      s.PC = len(s.Program)
}                                                                      }
                                    func (s *SProc) Reset() {
func (s *SProc) Step() {                s.R.ClearAll()
    s.PC++                              s.PC = 0
}                                   }

func (s *SProc) Jump(a Address) {   func (s *SProc) Load(program
    s.PC += int(a)                  Program) {
}                                       s.Reset()
                                        s.Program = program
func (s *SProc) Execute() {         }
    s.Program[s.PC].Execute(s)
}
memory
based on allocated Values
aggregate as ValueStores
require boxing/unboxing
buffers for specific types
buffers are also ValueStores
benefits
encourages simple designs
many different VMs per executable
can run in separate goroutines
easily duplicated and serialised
split across processes or hosts
the future
single dispatch for vector operations
per vasive threading
runtime code rewriting
speculative loading
JIT compilation
find out more

http://github.com/feyeleanor/GoLightly
http://golightly.wikidot.com
t witter://#golightly

More Related Content

PDF
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
PDF
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
PDF
D vs OWKN Language at LLnagoya
PDF
Coding in GO - GDG SL - NSBM
PDF
TLPI - 6 Process
PDF
GoでKVSを書けるのか
PDF
Phil Bartie QGIS PLPython
PDF
Golang concurrency design
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
D vs OWKN Language at LLnagoya
Coding in GO - GDG SL - NSBM
TLPI - 6 Process
GoでKVSを書けるのか
Phil Bartie QGIS PLPython
Golang concurrency design

What's hot (20)

PPT
Function
PDF
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
PPT
ODP
To Infinity & Beyond: Protocols & sequences in Node - Part 2
PDF
PDF
Python 如何執行
PPT
C++totural file
PDF
Introduction to go
PPT
OpenMP
KEY
Beauty and Power of Go
PPTX
Golang iran - tutorial go programming language - Preliminary
PDF
Bristol 2009 q1_wright_steve
PDF
Faster Python, FOSDEM
PDF
C++ aptitude
PDF
tokyotalk
PDF
Maintainable go
PPTX
Hacking Go Compiler Internals / GoCon 2014 Autumn
PDF
MeCC: Memory Comparison-based Code Clone Detector
DOCX
Turbo basic commands
PPTX
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Function
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
To Infinity & Beyond: Protocols & sequences in Node - Part 2
Python 如何執行
C++totural file
Introduction to go
OpenMP
Beauty and Power of Go
Golang iran - tutorial go programming language - Preliminary
Bristol 2009 q1_wright_steve
Faster Python, FOSDEM
C++ aptitude
tokyotalk
Maintainable go
Hacking Go Compiler Internals / GoCon 2014 Autumn
MeCC: Memory Comparison-based Code Clone Detector
Turbo basic commands
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Ad

Viewers also liked (6)

PDF
Ordinanza di ingiunzione nei confronti di Google inc. 18 dicembre 2013
PDF
Lighting analysis LIBRARY ashutosh aniruddh
PPT
Planning a school library
PPTX
Career As A Librarian Pp
PDF
Zur Dissertation von Nathalie Mertes
PDF
2025 Libraries
Ordinanza di ingiunzione nei confronti di Google inc. 18 dicembre 2013
Lighting analysis LIBRARY ashutosh aniruddh
Planning a school library
Career As A Librarian Pp
Zur Dissertation von Nathalie Mertes
2025 Libraries
Ad

Similar to GoLightly: A Go Library For Building Virtual Machines (20)

PPTX
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
PDF
4Developers 2018: The turbulent road to byte-addressable storage support at t...
PDF
Implementing Software Machines in Go and C
PDF
All I know about rsc.io/c2go
PDF
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
PDF
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
PDF
CorePy High-Productivity CellB.E. Programming
PDF
Go ahead, make my day
PDF
81818088 isc-class-xii-computer-science-project-java-programs
PDF
MeCC: Memory Comparison based Clone Detector
PPT
Struct examples
PDF
Implementing Virtual Machines in Go & C
PDF
2014 computer science_question_paper
PDF
Computer science-2010-cbse-question-paper
PDF
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
PDF
Imugi: Compiler made with Python
PPT
C++: Constructor, Copy Constructor and Assignment operator
PDF
Declarative Type System Specification with Statix
PDF
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
4Developers 2018: The turbulent road to byte-addressable storage support at t...
Implementing Software Machines in Go and C
All I know about rsc.io/c2go
개발 과정 최적화 하기 내부툴로 더욱 강력한 개발하기 Stephen kennedy _(11시40분_103호)
ANSimport java.util.Scanner; class Bina_node { Bina_node .pdf
CorePy High-Productivity CellB.E. Programming
Go ahead, make my day
81818088 isc-class-xii-computer-science-project-java-programs
MeCC: Memory Comparison based Clone Detector
Struct examples
Implementing Virtual Machines in Go & C
2014 computer science_question_paper
Computer science-2010-cbse-question-paper
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Imugi: Compiler made with Python
C++: Constructor, Copy Constructor and Assignment operator
Declarative Type System Specification with Statix
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17

More from Eleanor McHugh (20)

PDF
Go for the Paranoid Network Programmer, 2025 Edition
PDF
Y - Recursion The Hard Way GopherCon EU 2025
PDF
Never Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
PDF
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
PDF
[2023] Putting the R! in R&D.pdf
PDF
Generics, Reflection, and Efficient Collections
PDF
The Relevance of Liveness - Biometrics and Data Integrity
PDF
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
PDF
The Browser Environment - A Systems Programmer's Perspective
PDF
Go for the paranoid network programmer, 3rd edition
PDF
An introduction to functional programming with Go [redux]
PDF
An introduction to functional programming with go
PDF
Implementing virtual machines in go & c 2018 redux
PDF
Identity & trust in Monitored Spaces
PDF
Don't Ask, Don't Tell - The Virtues of Privacy By Design
PDF
Don't ask, don't tell the virtues of privacy by design
PDF
Anonymity, identity, trust
PDF
Going Loopy - Adventures in Iteration with Google Go
PDF
Distributed Ledgers: Anonymity & Immutability at Scale
PDF
Hello Go
Go for the Paranoid Network Programmer, 2025 Edition
Y - Recursion The Hard Way GopherCon EU 2025
Never Say, Never Say Die! - the art of low-level Ruby and other Macabre Tales
[2024] An Introduction to Functional Programming with Go [Y Combinator Remix]...
[2023] Putting the R! in R&D.pdf
Generics, Reflection, and Efficient Collections
The Relevance of Liveness - Biometrics and Data Integrity
The Browser Environment - A Systems Programmer's Perspective [sinatra edition]
The Browser Environment - A Systems Programmer's Perspective
Go for the paranoid network programmer, 3rd edition
An introduction to functional programming with Go [redux]
An introduction to functional programming with go
Implementing virtual machines in go & c 2018 redux
Identity & trust in Monitored Spaces
Don't Ask, Don't Tell - The Virtues of Privacy By Design
Don't ask, don't tell the virtues of privacy by design
Anonymity, identity, trust
Going Loopy - Adventures in Iteration with Google Go
Distributed Ledgers: Anonymity & Immutability at Scale
Hello Go

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
Teaching material agriculture food technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation theory and applications.pdf
Unlocking AI with Model Context Protocol (MCP)
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Teaching material agriculture food technology
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25 Week I
Diabetes mellitus diagnosis method based random forest with bat algorithm
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Understanding_Digital_Forensics_Presentation.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

GoLightly: A Go Library For Building Virtual Machines

  • 1. GoLightly A Go library for building Virtual Machines Eleanor McHugh
  • 2. Go
  • 3. a new language statically-typed and compiled object-oriented but no classes garbage collected concurrency via communication (CSP) type polymorphism via interfaces
  • 4. a new way of working the safety of a static type system the feel of a dynamic runtime the performance of a compiled language
  • 7. ...to perspiration simulation v. emulation instruction set design bytecodes memory abstraction operation dispatch
  • 9. principles interface driven delegation architecture agnostic inspired by hardware techniques decoupled components scaling through specialisation
  • 10. caveat references current dev branch fundamental changes from github still evolving next release due for Strange Loop
  • 11. interfaces type Executable interface { type Comparable interface { Execute(p Processor) Identical(v Value) bool } Compare(v Value) int } type Processor interface { Reset() type Value interface { Step() fmt.Stringer Jump(a Address) Comparable Call(a Address) Nil() Value Return() IsNil() bool Load(program Program) } Run() Execute() type Program []Executable Sleep(n int64) Halt(n int) IsActive() bool }
  • 12. instructions obey the Executable interface expressed as separate types no assumptions about semantics not tied to a bytecode representation
  • 13. flow control type NoOp struct {} type Call Address func (n *NoOp) String() string { func (c Call) String() string { return "NOOP" return Sprint("CALL", Address(c)) } } func (n *NoOp) Execute(p Processor) {} func (c Call) Execute(p Processor) { p.Call(Address(c)) type Halt struct {} } func (h *Halt) String() string { return "HALT" type Return struct {} } func (r Return) String() string { func (h *Halt) Execute(p Processor) { return "RET" p.Halt(PROGRAM_TERMINATED) } } func (r Return) Execute(p Processor) { p.Return() type Jump Address } func (j Jump) String() string { return Sprint("JMP", Address(j)) } func (j Jump) Execute(p Processor) { p.Jump(Address(j)) }
  • 14. bytecode type ByteCode []int case 5: / JMPZ n / case 10: / POP r / func (b *ByteCode) String() string { PC++ PC++ return "BYTECODE" if C == 0 { R[b[PC]] = DS.Pop() } PC++ case 11: / LOAD r, v / func (b *ByteCode) Execute(p Processor) { PC += b[PC] - 1 PC++ var PC, C, W int } else { W = b[PC] var R [2]int PC++ PC++ CS := new(vector.IntVector) } R[W] = b[PC] DS := new(vector.IntVector) case 6: / JMPNZ n / case 12: / ADD r1, r2 / for p.Active() { PC++ PC++ switch b[PC] { if C != 0 { W = b[PC] case 0: / NOOP / PC++ PC++ case 1: / NSLEEP n / PC += b[PC] - 1 R[b[PC]] += R[W] PC++ } else { default: p.Sleep(int64(b[PC])) PC++ p.Halt(ILLEGAL_INSTRUCTION) case 2: / SLEEP n / } } PC++ case 7: / CALL n / } p.Sleep(int64(b[PC]) << 32) PC++ } case 3: / HALT / CS.Push(PC) p.Halt(USER_HALT) PC = b[PC] return case 8: / RET / case 4: / JMP n / PC = CS.Pop PC++ case 9: / PUSH r / PC += b[PC] - 1 PC++ DS.Push(R[b[PC]])
  • 15. processors typical Turing machines support flexible dispatch not tied to a given instruction set memory model agnostic ripe for specialisation
  • 16. a scalar processor type SProc struct { func (s *SProc) Sleep(i int64) { func (s *SProc) Call(a Address){ Running bool syscall.Sleep(i) PC := s.PC PC int } s.PC = int(a) R IntBuffer for s.IsActive() { F FloatBuffer func (s *SProc) Halt(n int) { s.Execute() DS vector.IntVector s.Running = false s.Step() Program []Executable } } } s.PC = PC func (s *SProc) IsActive() bool{ } func (s *SProc) Run() { return s.Running && s.PC < s.Running = true len(s.Program) func (s *SProc) Return() { s.Call(0) } s.PC = len(s.Program) } } func (s *SProc) Reset() { func (s *SProc) Step() { s.R.ClearAll() s.PC++ s.PC = 0 } } func (s *SProc) Jump(a Address) { func (s *SProc) Load(program s.PC += int(a) Program) { } s.Reset() s.Program = program func (s *SProc) Execute() { } s.Program[s.PC].Execute(s) }
  • 17. memory based on allocated Values aggregate as ValueStores require boxing/unboxing buffers for specific types buffers are also ValueStores
  • 18. benefits encourages simple designs many different VMs per executable can run in separate goroutines easily duplicated and serialised split across processes or hosts
  • 19. the future single dispatch for vector operations per vasive threading runtime code rewriting speculative loading JIT compilation