Download Design of XSLT Engine

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Design of XSLT Engine
http://www-sato.cc.u-tokyo.ac.jp/
schuko/XSLT-Engine.ppt
17, June, 2004
17/06/2004
1
Obtaining Result -- Engine
• Parse done, What remains?
XSLT source
XSLT stylesheet tree structure
Execution
XSLT Engine
Result
17/06/2004
2
Conventional Explanation
• Compile and Go on a Chip
Program
Compile
Executable Code
Execution
Processor
Result
17/06/2004
3
Executable Code and Engine
• What is “Executable Code”?
Depends on Execution Engine.
– CPU
• Pentium, Itanium,
• SPARC, Alpha, POWER
• …
– Virtual Machine
• Java VM
• PostScript
17/06/2004
4
Executable Code and Engine
• Engine + Supporting Functions
= Runtime Environment
CPU
OS Functions
Memory Management
Thread Management
Memory Management
including Garbage Collection
Engines for Many Functional
Thread Management
Languages
including Synchronization.
Java VM
17/06/2004
5
Compiler and Interpreter
( Note this discussion is Obsolete)
• Conversion to Executable Code on :
Compiler
Virtual Machine
OS
OS
CPU
17/06/2004
Interpreter
CPU
6
Java VM
• Stack Machine
– Code Size Dramatically Small
– Simple  Mobility, Portability ◎
• A Small Number of Registers
• Instructions Operate on Stack
Specification:
http://java.sun.com/docs/books/vmspec/2ndedition/html/VMSpecTOC.doc.html
17/06/2004
7
“Compiling” Java Program
int add12and13() {
return addTwoStatic(12, 13);
}
Method
bipush 12
bipush 13
invokestatic #3
ireturn
17/06/2004
8
Frame Management
• Key Idea in Function Call/ Method
Invocation
– Keeping Information Local to Function/Method
• Arguments
• Local Variables
• Return Address
17/06/2004
9
Frame Management(2)
• Management Scope and Extent of Variables
Anyway, something is Necessary.
Stack for Frame (Access Here)
Stack for Saving Non-Local Values
Dedicated Area for each Subroutine (Oldfashioned Fortran)  Recursion ×
17/06/2004
10
XSLT Engine
• Key Idea =
Template Instantiation (Function Call)
+
XPath Expression Evaluation
17/06/2004
11
Template Instantiation
1. Find Template to be Instantiated.

2. Allocate Frame for Local Variables.
 Arguments and xsl:variable
3. Instantiate Template

17/06/2004
12
Value LookUp
• VARIABLE has its own Binding
– Mechanism of Extracting VALUE from the
Binding is Indispensable.
– For Conventional Imperative Language,
A Location is Assigned to a VARIABLE.
(Compiler Statically Resolves it)
Local Variable  In Frame
Global Variable  In Heap
17/06/2004
13
Value LookUp (2)
• EG.
y = x+z
s
w
z
y
x

add (SP), (SP+8) (SP+4)
In this case, value lookup is
implemented as the
SP
access to locations.
17/06/2004
14
Value LookUp (3)
• In a Call, …
fact(int n) : if (n = 0) 1 else n * fact(n-1)
fact(3)
ret
3
17/06/2004
fact(2) fact(1) fact(0)
ret
2
ret
1
ret
0
15
Value LookUp (4)
• In Simple Processor
– Value is Looked up with the Variable Name as
the Key.
Table for Variables
y=x+z
17/06/2004
x
y
z
w
1
3
5
3
16
Evaluation of XPATH
Expressions
• What is “EVALUATION”?
• Semantics for Expressions
Evaluation
Syntactic
Structure
17/06/2004
Semantic Domain Value
17
Formal Semantics
• If Semantics and Semantic Domain are
Given in terms of Mathematics,
there is NO ROOM for misunderstanding.
• Style of Semantics
– Operational Semantics
• Action on some Abstract Machine
– Denotational Semantics
• Mapping to some Mathematical Object
17/06/2004
18
Denotational Semantics of
XPATH
• Node Set --- A set of nodes in a Tree
-- Tree Traversal, and
-- Set Manipulation
17/06/2004
19
17/06/2004
20
17/06/2004
21
17/06/2004
22
StyleSheet Evaluation
• Interpretive Evaluation:
1. Find the template which matches ‘/’
2. Evaluate the template
Evaluate each child in order
if (child is LiteralResultElement) {
Make the same node, and
Evaluate Children as its children
(Depends on Recursive Structure of TREEs)
} else
17/06/2004
23
StyleSheet Evaluation (2)
<xsl:template match=“/”>
<root>
root
<child1>
<child2>
</root>
EVAL
EVAL

child2
child11
17/06/2004
24
StyleSheet Evaluation (3)
Else { // Instruction
Evaluate the Instruction
}
EG.
<xsl:for-each select=“SEL”>
Children
</xsl:for-each>

Foreach (s ∈ [| SEL |])
17/06/2004
Evaluate (Children)(current-node = s)
25
StyleSheet Evaluation (4)
Evaluation of template call
 Be Sure to Make FRAME (Local
Environment)
17/06/2004
26
Need for Optimization
• So far, Simple Interpretation
• For Fast/Efficient Execution,
Optimization through Program Analysis
• Template Instantiation
• Evaluation of XPATH Expressions
17/06/2004
27
Related documents