From 8ecc9d81a95087828a205f746d7be67725b1b1f6 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 4 Jul 2024 23:32:17 +0200 Subject: [PATCH] add some codegen stuff to presentation --- presentation/slidev/package-lock.json | 69 ++++++ presentation/slidev/package.json | 4 +- presentation/slidev/slides.md | 320 ++++++++++++++++++++++++-- 3 files changed, 367 insertions(+), 26 deletions(-) diff --git a/presentation/slidev/package-lock.json b/presentation/slidev/package-lock.json index e1dbdc6..de70b2b 100644 --- a/presentation/slidev/package-lock.json +++ b/presentation/slidev/package-lock.json @@ -7,8 +7,10 @@ "name": "slidev", "dependencies": { "@slidev/cli": "^0.49.11", + "@slidev/theme-apple-basic": "^0.25.1", "@slidev/theme-default": "latest", "@slidev/theme-seriph": "latest", + "slidev-theme-dracula": "^0.2.0", "vue": "^3.4.27" } }, @@ -1719,6 +1721,33 @@ "roughjs": "^4.6.6" } }, + "node_modules/@slidev/theme-apple-basic": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@slidev/theme-apple-basic/-/theme-apple-basic-0.25.1.tgz", + "integrity": "sha512-saA5yYui+jTT13tP+QJKnWeM8sK0IA1iln2E3sWAJsfKdQHUD3fw8+AlUHLUH6yc8NPq3ewtZcwWx49a/iF8Tg==", + "license": "MIT", + "dependencies": { + "@slidev/types": "^0.47.0", + "codemirror-theme-vars": "^0.1.2", + "prism-theme-vars": "^0.2.4" + }, + "engines": { + "node": ">=14.0.0", + "slidev": ">=v0.47.0" + } + }, + "node_modules/@slidev/theme-apple-basic/node_modules/@slidev/types": { + "version": "0.47.5", + "resolved": "https://registry.npmjs.org/@slidev/types/-/types-0.47.5.tgz", + "integrity": "sha512-X67V4cCgM0Sz50bP8GbVzmiL8DHC2IXvdKcsN7DlxHyf+/T4d9GveeGukwha5Fx3MuYeGZWKag7TFL2ZY4w54A==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, "node_modules/@slidev/theme-default": { "version": "0.25.0", "resolved": "https://registry.npmjs.org/@slidev/theme-default/-/theme-default-0.25.0.tgz", @@ -7372,6 +7401,37 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/slidev-theme-dracula": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/slidev-theme-dracula/-/slidev-theme-dracula-0.2.0.tgz", + "integrity": "sha512-ndMD27+gUNYt9aXrb4/0vSBHKP007mpD2eCJppzhqXDG1DmN0Q6I6iFz+QvIjOPDKzzPjoYZbsWp6lPLJjgs9g==", + "license": "MIT", + "dependencies": { + "@slidev/types": "^0.42.5", + "codemirror-theme-vars": "^0.1.2", + "prism-theme-vars": "^0.2.4", + "theme-vitesse": "^0.7.2" + }, + "engines": { + "node": ">=14.0.0", + "slidev": ">=0.19.3" + }, + "funding": { + "url": "https://github.com/sponsors/jd-solanki" + } + }, + "node_modules/slidev-theme-dracula/node_modules/@slidev/types": { + "version": "0.42.11", + "resolved": "https://registry.npmjs.org/@slidev/types/-/types-0.42.11.tgz", + "integrity": "sha512-K7+UWzEQpUe3eEFs7ktm3tw17Ke9ZOJPTy7yGSlZfWl4jCTf9Z0HNKECPLQ3JGL6EkJ4Wyy1y0HE92/20cTn0Q==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, "node_modules/source-map-js": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", @@ -7541,6 +7601,15 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "optional": true }, + "node_modules/theme-vitesse": { + "version": "0.7.9", + "resolved": "https://registry.npmjs.org/theme-vitesse/-/theme-vitesse-0.7.9.tgz", + "integrity": "sha512-wgxHWOIEcIBp/5MAdO8Z5c0vdKy5J5008Kqt/uOYruel9oJ4TrvH3qXgCsatp4ImROd1UWsIgQ3C0R8db38qgA==", + "license": "MIT", + "engines": { + "vscode": "^1.43.0" + } + }, "node_modules/to-fast-properties": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", diff --git a/presentation/slidev/package.json b/presentation/slidev/package.json index 6ee8c11..d1d0eac 100644 --- a/presentation/slidev/package.json +++ b/presentation/slidev/package.json @@ -9,8 +9,10 @@ }, "dependencies": { "@slidev/cli": "^0.49.11", + "@slidev/theme-apple-basic": "^0.25.1", "@slidev/theme-default": "latest", "@slidev/theme-seriph": "latest", + "slidev-theme-dracula": "^0.2.0", "vue": "^3.4.27" } -} \ No newline at end of file +} diff --git a/presentation/slidev/slides.md b/presentation/slidev/slides.md index 215ccf2..79790eb 100644 --- a/presentation/slidev/slides.md +++ b/presentation/slidev/slides.md @@ -1,16 +1,6 @@ --- -# You can also start simply with 'default' -theme: seriph -# random image from a curated Unsplash collection by Anthony -# like them? see https://unsplash.com/collections/94734566/slidev -background: https://cover.sli.dev -# some information about your slides (markdown enabled) -title: Welcome to Slidev -info: | - ## Slidev Starter Template - Presentation slides for developers. - - Learn more at [Sli.dev](https://sli.dev) +theme: dracula +title: Compiler ULTIMATE # apply unocss classes to the current slide class: text-center # https://sli.dev/custom/highlighters.html @@ -22,18 +12,18 @@ drawings: transition: slide-left # enable MDC Syntax: https://sli.dev/guide/syntax#mdc-syntax mdc: true +plantUmlServer: 'https://www.plantuml.com/plantuml' --- # Compiler ULTIMATE -Presentation slides for developers - +Kein Weg ist mir im Schlitten je zu weit. --- # Parser -Besonderheiten und Änderungen zu Java: +**Besonderheiten und Änderungen zu Java:** - Pro Datei nur eine Klasse, mehrer Dateien einlesen - Keine Accessmodifier @@ -45,18 +35,298 @@ Besonderheiten und Änderungen zu Java: - Recipient - Fehlermeldungen werden gesammelt +--- - +Assignment -[#008200,dashed]u-^ Statement +Binary -[#008200,dashed]u-^ Expression +Block -[#008200,dashed]u-^ Node +BoolLiteral -[#008200,dashed]u-^ Expression +Break -[#008200,dashed]u-^ Statement +CharLiteral -[#008200,dashed]u-^ Expression +Class -[#008200,dashed]u-^ Node +Constructor -[#008200,dashed]u-^ Node +Continue -[#008200,dashed]u-^ Statement +Declaration -[#008200,dashed]u-^ Statement +DoWhile -[#008200,dashed]u-^ Statement +Expression -[#008200,plain]u-^ Node +FieldVarAccess -[#008200,dashed]u-^ Expression +For -[#008200,dashed]u-^ Statement +IfElse -[#008200,dashed]u-^ Statement +IntLiteral -[#008200,dashed]u-^ Expression +Method -[#008200,dashed]u-^ Node +MethodCall -[#008200,dashed]u-^ Expression +MethodCall -[#008200,dashed]u-^ Statement +New -[#008200,dashed]u-^ Expression +New -[#008200,dashed]u-^ Statement +Parameter -[#008200,dashed]u-^ Node +Print -[#008200,dashed]u-^ Statement +Program -[#008200,dashed]u-^ Node +Return -[#008200,dashed]u-^ Statement +Statement -[#008200,plain]u-^ Node +Unary -[#008200,dashed]u-^ Expression +While -[#008200,dashed]u-^ Statement +@enduml +``` + + --- + +# Code Generierung + +- Nutzung von ASM +- Dynamische Bindung/Polymorphie + + + +```java +public class TypedWhile implements TypedStatement { + + ... + + @Override + public void codeGen(MethodContext ctx) { + Label loopStart = new Label(); + Label loopEnd = new Label(); + ctx.getBreakLabels().push(loopEnd); + ctx.getContinueLabels().push(loopStart); + + ctx.getMv().visitLabel(loopStart); + cond.codeGen(ctx); + + ctx.getMv().visitJumpInsn(Opcodes.IFEQ, loopEnd); + ctx.popStack(); + typedBlock.codeGen(ctx); + ctx.getMv().visitJumpInsn(Opcodes.GOTO, loopStart); + ctx.getMv().visitLabel(loopEnd); + ctx.getContinueLabels().pop(); + ctx.getBreakLabels().pop(); + } +} +``` + + + +--- +transition: none +--- + +# Code Generierung + +- Nutzung von ASM +- Dynamische Bindung/Polymorphie + +```java +public class TypedIntLiteral implements TypedExpression { + + ... + + @Override + public void codeGen(MethodContext ctx) { + if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { + ctx.getMv().visitIntInsn(Opcodes.BIPUSH, value); + } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { + ctx.getMv().visitIntInsn(Opcodes.SIPUSH, value); + } else { + ctx.getMv().visitLdcInsn(value); + } + ctx.pushInstantToStack(); + } +} +``` + +--- + +## Context Klassen für Class und Method + +```plantuml + +@startuml + +top to bottom direction +skinparam linetype ortho + +class ClassContext { + + ClassContext(String, ClassWriter): + - name: String + - cw: ClassWriter + - type: Type + + hashCode(): int + + toString(): String +} +class MethodContext { + + MethodContext(ClassContext, MethodVisitor, Type): + - variableIndex: Map + - mv: MethodVisitor + - stack: Deque + - returnType: Type + - breakLabels: Deque