SWIFT GENERATORS
PORTING THE WHOLE LWB TO SWIFT/IOS
Riccardo Solmi, Whole Factory, Italy LangDev Meeting 2018, Amsterdam
SWIFT GENERATORS Riccardo Solmi, Whole Factory, Italy THE WHOLE - - PowerPoint PPT Presentation
LangDev Meeting 2018, Amsterdam PORTING THE WHOLE LWB TO SWIFT/IOS SWIFT GENERATORS Riccardo Solmi, Whole Factory, Italy THE WHOLE PLATFORM IS AT THE STATE OF THE ART DLSs covering almost every aspect of language definition Visual
PORTING THE WHOLE LWB TO SWIFT/IOS
Riccardo Solmi, Whole Factory, Italy LangDev Meeting 2018, Amsterdam
THE WHOLE PLATFORM IS AT THE STATE OF THE ART
▸ DLSs covering almost every aspect of language definition ▸ Visual notations designed for gesture based interactions ▸ DSLs for evolution, testing and deployment ▸ multiple versions, instance migration, software product
lines
… BUT WE ARE UNDERGOING A SLOW EVOLUTION
▸ The Whole Platform is not where we want it to be ▸ Implementation is far behind our vision ▸ New features are struggling to become pervasive
TOO MUCH INNOVATION BRAKES: UNDERLYING TECHNOLOGIES
▸ Java is no longer Write once and Run Everywhere ▸ (iOS, Windows 10 UWP) ▸ GEF 3 is no longer developed and is outdated ▸ (Draw 2D, poor Multitouch, non composable UI, Java) ▸ Eclipse is too much big and complex for too little ▸ (Classic IDE, Java)
TOO MUCH INNOVATION BRAKES: WHOLE FRAMEWORK
▸ Duality: framework level <-> domain level ▸ Duplication, encoding, constrained domain innovation ▸ Framework APIs in well-established but wrong places ▸ Modeling, events, reflection, and typing ▸ Framework evolution is inherently slower than domain
level evolution
SO WE NEED TO START OVER AGAIN?
▸ No, domain level code and generated code account for
98% of the code base
▸ We decided to reuse the domain level and to redesign and
rewrite the framework level
▸ Swift + iOS are the technologies chosen for the porting ▸ Existing Eclipse based workbench has been used to
accelerate the bootstrapping process
OVERVIEW OF THE PORTING PROCESS: FIRST ITERATIONS
MODELING PRESENTATION PERSISTENCE
BEHAVIOR STRUCTURE
Marker interface JSON-LD Swift Factory Events UI framework / Generic and specific entities Specific notations Generic notations Domain types Metamodels
1 2 3
Swift Event sourcing Interactions
1
Learning Experimenting Prototyping UX Generating model structure
2
Domain typing using existing metamodels
3
Supporting translational semantics for Swift Structural bootstrap Behavioral bootstrap
WE ARE HERE
FIRST ITERATION PROTOTYPES: SIMPLE GAMES
ITERATION 0
1 PAGE OF CODE (POC) = 70 LINES OF CODE (LOC) 🙃
GENERATING LANGUAGE IMPLEMENTATION (STRUCTURE)
language metamodel Swift code generator Swift Factory serialization Swift implementation (specific APIs) JSON Models SwiftSyntax SwiftAST
122 LOC 662 LOC 6104 LOC 4550 LOC 78 LOC 316 LOC 3465 LOC 2510 LOC 2 S 3.5 S 100 S 60 S
Generation time
9 POC 12 S
(Swift*)
1762 LOC 967 LOC
* Metamodel hand written starting from the official grammar
ITERATION 1
MODELS ON IOS
▸ specific notation
ITERATION 1
PERSISTENCE
▸ To bootstrap the platform by loading the metamodels ▸ XML Builder (too much complex for the bootstrap) ▸ JSON-LD (unordered -> cannot bootstrap metamodels) ▸ Swift Factory
ITERATION 1
SWIFT FACTORY PERSISTENCE
▸ No parser needed ▸ Suitable for
embedding domain templates in Swift code
ITERATION 1
GENERIC NOTATIONS
▸ “Table” variant ▸ Dark theme
ITERATION 2
SWIFT INTEGRATION THROUGH REVERSE ENGINEERING
▸ Add concrete syntax level Swift persistence to Eclipse
backed by official Swift parser
▸ Using a fully automated generative process ▸ Suitable for source editing scenarios ▸ Add AST level Swift persistence to Eclipse ▸ Chained to, and initially derived by the syntax level ▸ Refined to better support generative scenarios
ITERATION 3
SWIFTSYNTAX PERSISTENCE
JSON to SwiftSyntax SwiftSyntax Parse Tree SwiftSyntax to JSON-LD code SwiftSyntaxSerializer Main
VISITOR FACTORY
JSON-LD PersistenceKit Swift Syntax SwiftSyntax PersistenceKit Swift library
ITERATION 3
SWIFTSYNTAX PERSISTENCE
JSON to SwiftSyntax SwiftSyntax Parse Tree SwiftSyntax to JSON-LD code SwiftSyntaxSerializer Main
VISITOR FACTORY
JSON-LD PersistenceKit Swift Syntax SwiftSyntax PersistenceKit Swift SwiftSyntax Reveng Grammar Github repo shell script Swift Syntax reveng SwiftSyntax Generator Swift Syntax metamodel
ABSTRACT FACTORY
instance of library
ITERATION 3
1 PAGE OF CODE (POC) = 70 LINES OF CODE (LOC)
SWIFTSYNTAX PERSISTENCE
JSON to SwiftSyntax SwiftSyntax Parse Tree SwiftSyntax to JSON-LD code SwiftSyntaxSerializer Main
VISITOR FACTORY
JSON-LD PersistenceKit Swift Syntax SwiftSyntax PersistenceKit Swift SwiftSyntax Reveng Grammar Github repo shell script Swift Syntax reveng SwiftSyntax Generator Swift Syntax metamodel
ABSTRACT FACTORY
instance of
2240 LOC 2040 LOC 30 LOC 1100 LOC 42 LOC 375 ENTITIES 1 POC 13 POC (400 LOC TEMPLATES)
library
ITERATION 3
SWIFT SYNTAX EXAMPLE
ITERATION 3
SWIFTAST PERSISTENCE
SwiftSyntax PersistenceKit code Swift AST SwiftAST PersistenceKit Swift Swift Syntax SwiftSyntax to SwiftAST migration PrettyPrint SwiftAST notation SwiftAST metamodel instance of derived
ITERATION 3
SWIFT AST EXAMPLE
ITERATION 3
SWIFT AST EXAMPLE (2)
ITERATION 3