SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
B 	 	DSL	B 	 	DSL	
G VMG VM
M 	MM 	M
D 	S 	LD 	S 	L
https://pxhere.com/en/photo/1057524
SELECT			country,	
									COUNT(1)	AS	count
FROM					Customer	
GROUP	BY	country;
Given	my	account	has	a	balance	of	€	430	
When	I	receive	a	money	transfer	of	€	500	
Then	my	account	should	have	a	balance	of	€	930
Setup(	
				Boat	on	StartingShore,	
				Wolf	on	StartingShore,	
				Sheep	on	StartingShore,	
				Cabbage	on	StartingShore	
)	execute	(	
				Boat	move	Cabbage	to	StartingShore,	
				Boat	move	Sheep	to	DestinationShore,	
				Boat	move	None	to	StartingShore,	
				Boat	move	Cabbage	to	DestinationShore,	
				Boat	move	Sheep	to	StartingShore,	
				Boat	move	Wolf	to	DestinationShore,	
				Boat	move	None	to	StartingShore,	
				Boat	move	Sheep	to	DestinationShore	
)	
https://github.com/NRBPerdijk/dsl-for-the-dense/
+	+	>	+	+	+	+	+	[	<	+	>	-	]	+	+	+	+	+	+	+	+	[	<	+	+	+	+	+	+	>	-	]	<	.
BB
This	program	adds	the	numbers	2	and	5	
	
+	+																Store	the	number	2	in	the	first	slot	
>	+	+	+	+	+								Store	the	number	5	in	the	second	slot	
	
[																		Move	back	and	forth	between	first	and	second	slot	
	
				<	+	>	-								While	"moving"	ones	from	the	second	to	the	first	slot
]	
	
The	first	slot	now	has	'7'	in	it	but	we	need	to	output	the	ASCII	value	for	that
The	ASCII	value	is	48	higher	than	the	number	we	have	
	
The	second	slot	is	now	empty
It	will	act	as	a	counter	so	we	can	add	6	*	8	to	the	first	slot
+	+	+	+	+	+	+	+				Store	8	in	it	
	
[																		Again	move	back	and	forth	between	first	and	second	slot	
				<	+	+	+	+	+	+		while	adding	6	to	the	first	slot	
				>	-												before	reducing	the	counter	in	the	second	slot
]	
	
<	.																Go	back	to	the	first	slot	and	print	it
0 1 2 3 4 ... 29	997 29	998 29	999
2 5 3 0 0 0 0 0
↑
command meaning
+ increase	value
- decrease	value
. print	value	to	std	out
, read	one	byte	from	std	in
[ if	value	eq	0,	jump	after	matching	]
] if	value	neq	0,	jump	after	matching	[
< move	pointer	left
> move	pointer	right
https://www.thepinkhumanist.com/articles/330-life-of-alan-turing-examined-in-a-new-graphic-novel
https://commons.wikimedia.org/wiki/File:USA_tar_bubble_la_brea_CA.jpg
G VMG VM
“One	VM	to	rule	them	all
cc-by-sa/2.0	-	©	Lairich	Rig	-	https://www.geograph.org.uk/photo/3203827
BB
yapi.bf	calculating	15	digits	of	π
Runtime Average	time	(ms/op) Error
Java	HotSpot(TM)	64-Bit	Server	VM 53 ±	1
OpenJDK	GraalVM	CE	19.0.0 45 ±	1
All	tests	are	ran	on	an	2018	MacBook	Pro	with	2.6	GHz	Intel	Core	i7	and	16	GB	2400	MHz	DDR4.	The	machine	runs	macOS	Mojave	10.14.4	and	JDK	1.8.0_212.	Tests
measured	with	 .	Each	test	ran	5	times	with	5	warmup	iterations.jmh
BB
yapi.bf	calculating	45	digits	of	π
Runtime Average	time	(ms/op) Error
Java	HotSpot(TM)	64-Bit	Server	VM 207 ±	2
OpenJDK	GraalVM	CE	19.0.0 185 ±	3
All	tests	are	ran	on	an	2018	MacBook	Pro	with	2.6	GHz	Intel	Core	i7	and	16	GB	2400	MHz	DDR4.	The	machine	runs	macOS	Mojave	10.14.4	and	JDK	1.8.0_212.	Tests
measured	with	 .	Each	test	ran	5	times	with	5	warmup	iterations.jmh
TT
cc-by-sa/2.5	-	©	Darvin	DeShazer	-	https://mushroomobserver.org/2538
“open	source	library	for	building
programming	language	implementations
as	interpreters	for	self-modifying	Abstract
Syntax	Trees.
A 	S 	TA 	S 	T
ROOT
INCR_VAL INCR_VAL INCR_VAL INCR_VAL INCR_VAL JUMP INCR_VAL INCR_VAL
DECR_PTR INCR_VAL INCR_PTR DECR_VAL
(part	of	the	program	that	adds	5	and	2)
https://chrisseaton.com/rubytruffle/pldi17-truffle/pldi17-truffle.pdf
P 	EP 	E
Calculate	 	for	positive	integers
If	we	know	that	 ,	the	program	becomes	simpler:
x
n
f (x, n) =
⎧
⎩
⎨
⎪
⎪
1
,(f (x, 0.5 ∗ n))
2
x ∗ f (x, n − 1),
if n = 0
if n is	even
otherwise
n = 5
f (x) = x ∗ ( )x
2
2
BB
https://pxhere.com/en/photo/493605
BB
@Override
public	void	execute(final	VirtualFrame	frame)	{	
				final	int	currentValue	=	someCalculation();	
				doPrint(getContext().getOutput(),	(char)	currentValue);	
}	
	
@TruffleBoundary
private	void	doPrint(final	PrintWriter	out,	final	char	value)	{	
				out.print(value);	
				out.flush();	
}
SS
https://www.mammoet.com/cases/Tennet/
SS
@Specialization(guards	=	"b	 	0")	
public	double	divide(int	a,	int	b)	{	
				return	a	/	b;	
}
SS
@Specialization(rewriteOn	=	ArithmeticException.class)	
int	doAddNoOverflow(int	a,	int	b)	{	
				return	Math.addExact(a,	b);	
}	
	
@Specialization
long	doAddWithOverflow(int	a,	int	b)	{	
				return	a	+	b;	
}	
execute(Integer.MAX_VALUE	-	1,	1)	 	doAddNoOverflow(Integer.MAX_VALUE	-	1,	1)	
	
execute(Integer.MAX_VALUE				,	1)	 	doAddNoOverflow(Integer.MAX_VALUE,	1)	
																																					throws	ArithmeticException	
																																		 	doAddWithOverflow(Integer.MAX_VALUE,	1)	
	
execute(Integer.MAX_VALUE	-	1,	1)	 	doAddWithOverflow(Integer.MAX_VALUE	-	1,	1)
W 	 	G VM	 	 	 	 	JVMW 	 	G VM	 	 	 	 	JVM
function	abs	(int	i)		
				if	(	 	we	saw	only	positive	integers	in	the	input	 	)	{	
								return	i;	
				}	else	{		
								transferToInterpreterAndInvalidate;	
								return	i	<	0	?	 i	:	i;	
				}	
}
B 	 	 	 	TB 	 	 	 	T
LL
Converts	a	sequence	of	characters	into	a	sequence	of	tokens.
PP
Converts	a	sequence	of	tokens	into	(hierarchical)	data	structure.
P 	 	L 	P 	 	L 	
1.	Write	some	regular	expressions
2.	Use	a	parser	generator	(like	 )ANTLR
cc-by-nc/2.5	-	©	Randall	Munroe	-	https://www.xkcd.com/1171/
I 	 	I
G VM	UG VM	U
GraalVM	comes	with	the	GraalVM	Updater	(gu)
Use	gu	to	install	components,	such	as	language	packs	or	tools.
e.g.	gu install native-image
gu	-L	install	brainfuck component-0.1-SNAPSHOT.jar
CC
Distribute	your	language	implementation	as	a	component:
$	tree	
.	
├──	META-INF	
│			├──	MANIFEST.MF	
│			├──	permissions	
│			└──	symlinks	
└──	jre	
				└──	languages	
								└──	bf	
												├──	bin	
												│			└──	bf	
												├──	brainfuck.jar	
												└──	launcher	
																└──	bf launcher.jar	
	
6	directories,	6	files
U 	 	 	U 	 	 	
1.	Prepare	source	code
2.	Prepare	GraalVM	polyglot	context
3.	Evaluate	the	source	code
input	=	"+	+	>	+	+	+	+	+	[	<	+	>	-	]	+	+	+	+	+	+	+	+	[	<	+	+	+	+	+	+	>	-	]	<	.";	
source	=	Source.newBuilder("bf",	input,	"user	input").build();	
output	=	new	ByteArrayOutputStream();	
context	=	Context.newBuilder("bf").out(output).build();	
context.eval(source);	
System.out.println(output.toString());
TT
“Implementing	your	own	language	using
GraalVM	will	not	only	give	you	high
performance.	More	importantly,	it	allows
your	language	to	connect	with	the	rich
tooling	provided	by	the	GraalVM	ecosystem.
https://www.graalvm.org/docs/graalvm-as-a-platform/
https://pxhere.com/en/photo/1067853
DD
Start	the	launcher	with	--inspect
Debugger listening on port 9229.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/bundled/js_app.html?ws=127.0.0.1:9229/77b52d12-53f20cb0ab35
O 	O 	
The	Truffle	framework	has	an	Instrument	API	to	write	other	tools,	e.g.	code
coverage	measurement,	profilers.
1.	Source	code-related	events
2.	Allocation	events
3.	Language	runtime	and	thread	creation	events
4.	Application	execution	events
W 	W 	
Yes,	you	can	run	any	language	with	GraalVM.
...	but	it	may	take	some	time.
It's	certainly	fun
...	and	it	might	even	be	profitable.
T 	T 	
You	don't	need	to	write	a	parser	yourself
(and	maybe	you	don't	want	to,	either)
Take	time	to	think	about	the	AST
using	a	wrong	structure	leads	to	hard-to-track	bugs
refactoring	it	later	is	very	hard	and	time-consuming
Q	 	AQ	 	A
Sample	code:	
Please	help	conference	organisers:	don't	forget	to	rate
this	talk	in	the	Devoxx	app!
http://bit.ly/brainfuck-jvm
@mthmulders  #DevoxxPL  #GraalDSL

Contenu connexe

Plus de Maarten Mulders

Plus de Maarten Mulders (20)

What's cooking in Maven? (Devoxx FR)
What's cooking in Maven? (Devoxx FR)What's cooking in Maven? (Devoxx FR)
What's cooking in Maven? (Devoxx FR)
 
Making Maven Marvellous (Devnexus)
Making Maven Marvellous (Devnexus)Making Maven Marvellous (Devnexus)
Making Maven Marvellous (Devnexus)
 
Making Maven Marvellous (Java.il)
Making Maven Marvellous (Java.il)Making Maven Marvellous (Java.il)
Making Maven Marvellous (Java.il)
 
Making Maven Marvellous (JavaZone)
Making Maven Marvellous (JavaZone)Making Maven Marvellous (JavaZone)
Making Maven Marvellous (JavaZone)
 
Dapr: Dinosaur or Developer's Dream? (v1)
Dapr: Dinosaur or Developer's Dream? (v1)Dapr: Dinosaur or Developer's Dream? (v1)
Dapr: Dinosaur or Developer's Dream? (v1)
 
Dapr: Dinosaur or Developer Dream? (J-Fall)
Dapr: Dinosaur or Developer Dream? (J-Fall)Dapr: Dinosaur or Developer Dream? (J-Fall)
Dapr: Dinosaur or Developer Dream? (J-Fall)
 
SSL/TLS for Mortals (Devoxx UK)
SSL/TLS for Mortals (Devoxx UK)SSL/TLS for Mortals (Devoxx UK)
SSL/TLS for Mortals (Devoxx UK)
 
React in 40 minutes (Voxxed Days Romania)
React in 40 minutes (Voxxed Days Romania) React in 40 minutes (Voxxed Days Romania)
React in 40 minutes (Voxxed Days Romania)
 
React in 40 minutes (JCON)
React in 40 minutes (JCON) React in 40 minutes (JCON)
React in 40 minutes (JCON)
 
React in 50 minutes (Bucharest Software Craftsmanship Community)
React in 50 minutes (Bucharest Software Craftsmanship Community)React in 50 minutes (Bucharest Software Craftsmanship Community)
React in 50 minutes (Bucharest Software Craftsmanship Community)
 
React in 50 Minutes (JNation)
 React in 50 Minutes (JNation)  React in 50 Minutes (JNation)
React in 50 Minutes (JNation)
 
SSL/TLS for Mortals (JavaLand)
SSL/TLS for Mortals (JavaLand) SSL/TLS for Mortals (JavaLand)
SSL/TLS for Mortals (JavaLand)
 
Making Maven Marvellous (J-Fall)
Making Maven Marvellous (J-Fall)Making Maven Marvellous (J-Fall)
Making Maven Marvellous (J-Fall)
 
SSL/TLS for Mortals (Oracle Groundbreaker EMEA Virtual Tour)
SSL/TLS for Mortals (Oracle Groundbreaker EMEA Virtual Tour)SSL/TLS for Mortals (Oracle Groundbreaker EMEA Virtual Tour)
SSL/TLS for Mortals (Oracle Groundbreaker EMEA Virtual Tour)
 
SSL/TLS for Mortals (UtrechtJUG)
SSL/TLS for Mortals (UtrechtJUG)SSL/TLS for Mortals (UtrechtJUG)
SSL/TLS for Mortals (UtrechtJUG)
 
SSL/TLS for Mortals (Lockdown Lecture)
SSL/TLS for Mortals (Lockdown Lecture)SSL/TLS for Mortals (Lockdown Lecture)
SSL/TLS for Mortals (Lockdown Lecture)
 
React in 50 Minutes (OpenValue)
React in 50 Minutes (OpenValue) React in 50 Minutes (OpenValue)
React in 50 Minutes (OpenValue)
 
React in 50 Minutes (DevNexus)
React in 50 Minutes (DevNexus) React in 50 Minutes (DevNexus)
React in 50 Minutes (DevNexus)
 
React in 45 Minutes (Jfokus)
React in 45 Minutes (Jfokus)React in 45 Minutes (Jfokus)
React in 45 Minutes (Jfokus)
 
Building web applications with React (Jfokus)
Building web applications with React (Jfokus)Building web applications with React (Jfokus)
Building web applications with React (Jfokus)
 

Dernier

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Dernier (20)

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 

Building a DSL with GraalVM (Devoxx PL)