Merge remote-tracking branch 'origin/main'

This commit is contained in:
ahmad 2024-07-05 00:42:50 +02:00
commit 8199bc9b10
3 changed files with 367 additions and 26 deletions

View File

@ -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",

View File

@ -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"
}
}

View File

@ -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
---
<style>
h1 {
background-color: #2B90B6;
background-image: linear-gradient(45deg, #4EC5D4 10%, #146b8c 20%);
background-size: 100%;
-webkit-background-clip: text;
-moz-background-clip: text;
-webkit-text-fill-color: transparent;
-moz-text-fill-color: transparent;
## AST
<Transform :scale="1">
```plantuml
@startuml
top to bottom direction
entity Assignment << record >> {
+ Assignment(FieldVarAccess, Expression):
+ value(): Expression
+ location(): FieldVarAccess
}
entity Binary << record >> {
+ Binary(Expression, Operator, Expression):
+ op(): Operator
+ left(): Expression
+ right(): Expression
}
entity Block << record >> {
+ Block(List<Statement>):
+ stmts(): List<Statement>
}
entity BoolLiteral << record >> {
+ BoolLiteral(Boolean):
+ value(): Boolean
}
entity Break << record >> {
+ Break():
}
entity CharLiteral << record >> {
+ CharLiteral(char):
+ value(): char
}
entity Class << record >> {
+ Class(String, Block, List<Declaration>, List<Method>, List<Constructor>):
+ Class(String, List<Declaration>, List<Method>, List<Constructor>):
+ mainmeth(): Block
+ classname(): String
+ methods(): List<Method>
+ constructors(): List<Constructor>
+ fieldDeclarations(): List<Declaration>
}
entity Constructor << record >> {
+ Constructor(String, List<Parameter>, Block):
+ params(): List<Parameter>
+ block(): Block
+ className(): String
}
entity Continue << record >> {
+ Continue():
}
entity Declaration << record >> {
+ Declaration(String, Type):
+ type(): Type
+ name(): String
}
entity DoWhile << record >> {
+ DoWhile(Block, Expression):
+ cond(): Expression
+ block(): Block
}
interface Expression << interface >>
entity FieldVarAccess << record >> {
+ FieldVarAccess(Boolean, Expression, String):
+ recursiveOwnerChain(): Expression
+ field(): Boolean
+ id(): String
}
entity For << record >> {
+ For(Assignment, Expression, Assignment, Block):
+ block(): Block
+ cond(): Expression
+ inc(): Assignment
+ assign(): Assignment
}
entity IfElse << record >> {
+ IfElse(Expression, Block, Block):
+ elseBlock(): Block
+ cond(): Expression
+ ifBlock(): Block
}
entity IntLiteral << record >> {
+ IntLiteral(Integer):
+ value(): Integer
}
entity Method << record >> {
+ Method(Type, String, List<Parameter>, Block):
+ block(): Block
+ methodName(): String
+ type(): Type
+ params(): List<Parameter>
}
entity MethodCall << record >> {
+ MethodCall(FieldVarAccess, List<Expression>):
+ recipient(): FieldVarAccess
+ args(): List<Expression>
}
entity New << record >> {
+ New(Type, List<Expression>):
+ type(): Type
+ args(): List<Expression>
}
interface Node << interface >>
enum Operator << enumeration >> {
+ Operator():
+ values(): Operator[]
+ valueOf(String): Operator
}
entity Parameter << record >> {
+ Parameter(String, Type):
+ type(): Type
+ name(): String
}
entity Print << record >> {
+ Print(Expression):
+ value(): Expression
}
entity Program << record >> {
+ Program(List<Class>):
+ classes(): List<Class>
}
entity Return << record >> {
+ Return(Expression):
+ ret(): Expression
}
interface Statement << interface >>
entity Unary << record >> {
+ Unary(UnaryOperator, Expression):
+ right(): Expression
+ op(): UnaryOperator
}
enum UnaryOperator << enumeration >> {
+ UnaryOperator():
+ values(): UnaryOperator[]
+ valueOf(String): UnaryOperator
}
entity While << record >> {
+ While(Expression, Block):
+ cond(): Expression
+ block(): Block
}
</style>
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
```
</Transform>
---
# Code Generierung
- Nutzung von ASM
- Dynamische Bindung/Polymorphie
<Transform :scale="0.8">
```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();
}
}
```
</Transform>
---
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<String, LocalVariable>
- mv: MethodVisitor
- stack: Deque<Integer>
- returnType: Type
- breakLabels: Deque<Label>
- continueLabels: Deque<Label>
- classContext: ClassContext
- maxStack: int
- localVarIndex: int
+ pushInstantToStack(): void
+ popStack(): void
+ getLocalVar(String): Optional<LocalVariable>
+ registerVariable(String, Type): void
+ pushAnonToStack(): void
+ pushStack(String): void
+ wrapUp(): void
}
@enduml
```
---
## ASMifier
Tool, um aus Java Bytecode ASM Code zu generieren.
<a href="https://simon.webhop.me" target="_blank">Klick</a>