Navigation Menu

Skip to content

Commit

Permalink
[java/runtime] non working interim commit of Metamodel classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mberends committed Sep 9, 2010
1 parent 920e357 commit f8cf789
Show file tree
Hide file tree
Showing 14 changed files with 975 additions and 93 deletions.
99 changes: 99 additions & 0 deletions java/README.txt
@@ -0,0 +1,99 @@
Overview of the Java translation of 6model
==========================================

In the 6model project, the java tree contains per-statement translations
of the C# files in the dotnet tree. C# is the "Microsoft Java" and this
subproject shows how close they are.


Source formatting guidelines
----------------------------

For clarity, or where there is doubt about the correctness of a
translation, include the original line afterwards in a comment.

Add horizontal spacing to maximize correlation of text in consecutive
lines.

With apologies to jnthn++, a case convention for the initial letter of
names is being gradually phased in. Class names, class member names and
interfaces is start with an uppercase letter. Local variables begin in
lowercase.


C# to Java translation guidelines (sorted alphabetically, case insensitive)
---------------------------------------------------------------------------

C# bool becomes Java boolean.

C# Dictionary becomes Java HashMap. The HashMap is not quite as
versatile, because the value part must be a reference type, it cannot be
a value type. Therefore C# Dictionary<string, int> becomes Java
HashMap<String, Integer> which it less convenient to use.

C# internal access modifier becomes Java protected or public.

C# Func<typelist> becomes a Java anonymous class that implements an
interface.

C# InvalidOperationException becomes Java UnsupportedOperationException.

C# lambda expressions (using => notation) become Java anonymous classes.
This is a lot of workaround writing because the anonymous classes
require an interface definition to implement, otherwise they inherit
from Object.

C# Length (of an array) becomes Java length (of an array).

C# Length (of a List) becomes Java size() (of an ArrayList).

C# List becomes Java ArrayList.

C# namespace yada { ... } becomes Java package yada; ... .
Also the Java package hierarchy must match the file system directory
hierarchy.

C# NotImplementedException becomes Java NoSuchFieldException or
NoSuchMethodException.

C# override does not become anything in Java (just delete it).

C# sealed class becomes Java final class. Effect is not quite the same.

C# string becomes Java String.

C# using becomes Java import. In general, avoid the * (Whatever) form,
such as java.util.* because it is often useful to know exactly what is
being imported, for example java.util.HashMap or java.util.ArrayList.
The * is a form of programmer laziness which just shifts the problem on
to the next person or compiler who reads the program. We need clarity
here, not golf.


Lambdas and References to Functions
-----------------------------------
C# has some language features that Java currently lacks, to safely
provide what C and C++ call pointers to functions.

The C# 'Func' generic type is a parameterized type. Variables declared
as 'Func<paramtype [,...], rettype>' store anonymous functions that take
certain parameters and return a certain result. Call the function using
the Invoke(...) method on the Func variable.

The C# '=>' operator (also called Lambda) creates a reference to a block
of code. Store that reference in a Func variable.

The C# 'delegate' type contains a collection of function pointers. When
the delegate is called, each function that is pointed to gets called in
an unspecified order. Useful for multicast notification, event handlers
and publish and subscribe architectures.

The C# implementation of 6model uses the 'Func' and '=>' combination in
KnowHOWBoostrapper and RakudoCodeRef for example. The Java
implementation replaces the Func declaration with an IFunc_XXX interface
declaration that defines a suitably typed Invoke method, and replaces
the => with an anonymous class definition that implements that
interface.

Created by: Martin Berends (mberends in #perl6 on irc.freenode.net)

102 changes: 63 additions & 39 deletions java/runtime/Makefile
@@ -1,13 +1,45 @@
# Makefile for 6model/java/runtime

# Dependency critical paths (1 2 and 3 are circular)
# (partial diagram - less significant (eg implicit transitive) dependencies
# omitted for simplicity)
#
# Hints
# |
# SerializationContext ExecutionDomain
# | |
# +------------> RakudoObject |
# | | | |
# | Parameter | |
# | | | |
# | Signature Representation |
# | | | | | |
# | +--+---> RakudoCodeRef | | |
# | | | | | | |
# 1 2 3 Context | | |
# | | | | | | |
# | | +---- ThreadContext | | |
# | | | | | |
# | | IFindMethod | REPRRegistry
# | | | | |
# +--+-------------- SharedTable | P6opaque
# | | P6int etc
# KnowHOWREPR | |
# | | |
# KnowHOWBootstrapper |Lexpad
# | ||
# Init
#

ALL_BUILD_TARGETS = \
Rakudo/Metamodel/Hints.class \
Rakudo/Serialization/SerializationContext.class \
Rakudo/Runtime/ExecutionDomain.class \
Rakudo/Metamodel/RakudoObject.class \
Rakudo/Metamodel/REPRRegistry.class

# Rakudo/Metamodel/KnowHOW/KnowHOWREPR.class
Rakudo/Metamodel/REPRRegistry.class \
Rakudo/Metamodel/KnowHOW/KnowHOWREPR.class \
Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.class \
Rakudo/Metamodel/Representations/P6capture.class

OTHER_DEPENDENT_TARGETS = \
Rakudo/Runtime/Lexpad.class \
Expand Down Expand Up @@ -61,42 +93,34 @@ Rakudo/Metamodel/RakudoObject.class: Rakudo/Metamodel/RakudoObject.java \
Rakudo/Metamodel/REPRRegistry.class: Rakudo/Metamodel/REPRRegistry.java
javac Rakudo/Metamodel/REPRRegistry.java

# Dependency critical paths (1 2 and 3 are circular)
# (partial diagram - less significant dependencies omitted for simplicity)
#
# Hints
# |
# SerializationContext ExecutionDomain
# |
# +-----------> RakudoObject
# | | |
# | Parameter |
# | | |
# | Signature Representation
# | | | |
# | +--+---> RakudoCodeRef |
# | | | | |
# 1 2 3 Context |
# | | | | |
# | | +---- ThreadContext |
# | | | |
# | | IFindMethod |
# | | | |
# +-+-------------- SharedTable REPRRegistry
# |
#

Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.class: Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.java \
javac Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.java
# this file has 6 lambda expressions to translate, currently suffering
# from 55 compile time errors :(

Rakudo/Metamodel/KnowHOW/KnowHOWREPR.class: Rakudo/Metamodel/KnowHOW/KnowHOWREPR.java \
Rakudo/Metamodel/Hints.class
javac Rakudo/Metamodel/KnowHOW/KnowHOWREPR.java

# System to report which files are older than their dotnet equivalents.
# Compare the reported files manually, and refresh the java file.
Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.class: Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.java \
Rakudo/Metamodel/REPRRegistry.class \
Rakudo/Metamodel/SharedTable.class
javac Rakudo/Metamodel/KnowHOW/KnowHOWBootstrapper.java

Rakudo/Metamodel/Representations/P6opaque.class: Rakudo/Metamodel/Representations/P6opaque.java
javac Rakudo/Metamodel/Representations/P6opaque.java

Rakudo/Metamodel/Representations/P6capture.class: Rakudo/Metamodel/Representations/P6capture.java \
Rakudo/Metamodel/RakudoObject.class \
Rakudo/Metamodel/Representation.class \
Rakudo/Metamodel/SharedTable.class \
Rakudo/Metamodel/Hints.class \
Rakudo/Serialization/SerializationContext.class
javac Rakudo/Metamodel/Representations/P6capture.java

Rakudo/Init.class: Rakudo/Init.java \
Rakudo/Metamodel/Representations/P6opaque.class
javac Rakudo/Init.java

# System to report which java files are older than their dotnet
# equivalents. The dotnet files churn a lot, so it's important to check
# by code review that the translated java files still correspond.
# To resolve, compare the reported files, and update the java ones.
TRANSLATED_SOURCE_FILES = \
Rakudo/Metamodel/Hints.java \
Rakudo/Serialization/SerializationContext.java \
Expand All @@ -111,12 +135,12 @@ TRANSLATED_SOURCE_FILES = \
Rakudo/Runtime/ThreadContext.java \
Rakudo/Metamodel/SharedTable.java

# Java source code files "depend" on files in the dotnet/ directories,
# Java source code files "depend" on files in the dotnet/* directories,
# in the sense that they were manually translated.
# The following definitions cause make to emit todo messages if a
# dotnet/ file becomes newer than a java/ file.
# The following definitions cause make to emit 'todo:' messages if a
# dotnet file becomes newer than a java file.
# The way to clear the error is to compare the files in question, and
# then to refresh the java/ file to be newer than the dotnet/ one.
# then to refresh the java file to be newer than the dotnet one.
Rakudo/Metamodel/Hints.java: ../../dotnet/runtime/Metamodel/Representation.cs
@echo "todo: Rakudo/Metamodel/Hints.java is older than ../../dotnet/runtime/Metamodel/Representation.cs"

Expand Down

0 comments on commit f8cf789

Please sign in to comment.