Skip to content

Latest commit

 

History

History
106 lines (85 loc) · 4.21 KB

ARCHITECTURE.md

File metadata and controls

106 lines (85 loc) · 4.21 KB

PerlOnJava Architecture

Internal Modules

Project Structure

/
├── src/
│   ├── main/
│   │   └── perl/
│   │   │   └── lib/
│   │   │       └── Perl modules (strict.pm, etc)
│   │   └── java/
│   │       └── org/
│   │           └── perlonjava/
│   │               ├── Main.java
│   │               ├── ArgumentParser.java
│   │               ├── scriptengine/
│   │               │   ├── PerlScriptEngine.java
│   │               │   └── other script engine classes
│   │               ├── astnode/
│   │               │   ├── Node.java
│   │               │   └── other AST node classes
│   │               ├── lexer/
│   │               │   ├── Lexer.java
│   │               │   └── other lexer classes
│   │               ├── parser/
│   │               │   ├── Parser.java
│   │               │   └── other parser classes
│   │               ├── perlmodule/
│   │               │   ├── Universal.java
│   │               │   └── other internalized Perl module classes
│   │               ├── operators/
│   │               |   ├── OperatorHandler.java
│   │               |   ├── ArithmeticOperators.java
│   │               |   └── other operator handling classes
│   │               ├── regex/
│   │               │   ├── RuntimeRegex.java
│   │               │   └── other regex classes
│   │               ├── io/
│   │               |   ├── SocketIO.java
│   │               |   └── other io classes
│   │               ├── symbols/
│   │               |   ├── ScopedSymbolTable.java
│   │               |   └── other symbol table classes
│   │               └── runtime/
│   │                   ├── RuntimeScalar.java
│   │                   └── other runtime classes
│   └── test/
│       ├── java/
│       │   └── org/
│       │       └── perlonjava/
│       │           └── PerlLanguageProviderTest.java
│       └── resources/
│           └── Perl test files
├── build.gradle
├── pom.xml
├── settings.gradle
├── examples/
│   └── Perl example files
├── docs/
│   └── project documentation files
└── misc/
    └── project notes

Lexer and Parser

  • Lexer: Used to split the code into symbols like space, identifier, operator.
  • Parser: Picks up the symbols and organizes them into an Abstract Syntax Tree (AST) of objects like block, subroutine.
  • StringParser: Used to parse domain-specific languages within Perl, such as Regex and string interpolation.

Code Generation

  • EmitterVisitor: Used to generate the bytecode for the operations within the method. It traverses the AST and generates the corresponding ASM bytecode.
  • EmitterContext: Holds the current state of the Symbol Table and calling context (void, scalar, list).
  • PrinterVisitor: Provides pretty-print stringification for the AST.
  • EmitterMethodCreator: Used to generate the bytecode for the class. The user code is translated into a method, then the generated bytecode is loaded using a custom class loader.

AST Nodes: Node

  • Representations of AST nodes for code blocks, variable declarations, and operations.

Runtime packages: Runtime and Operators

  • Runtime: Provides the implementation of the behavior of a Perl scalar variable, Code, Array, Hash.

Symbol Table

  • ScopedSymbolTable: Manage variable names and their corresponding local variable indices.

Perl Module classes

  • perlmodule: Provides ports of Perl classes implemented in Java, such as UNIVERSAL and Symbol.

Main Method

  • The main method generates the bytecode for the program body.
  • The generated method is loaded into a variable as a code reference and executed.

PerlScriptEngine

  • PerlScriptEngine is a Java class that allows you to execute Perl scripts using the Java Scripting API (JSR 223).