Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a698e782b375
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1a43d1836db9
Choose a head ref
  • 10 commits
  • 20 files changed
  • 1 contributor

Commits on Dec 24, 2016

  1. Copy the full SHA
    8a10fc4 View commit details
  2. Copy the full SHA
    b2e5106 View commit details
  3. Copy the full SHA
    27da7b1 View commit details
  4. Copy the full SHA
    15e535c View commit details
  5. 2
    Copy the full SHA
    40f44c6 View commit details
  6. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9fdc073 View commit details
  7. Copy the full SHA
    98d3f94 View commit details
  8. 2
    Copy the full SHA
    ce49572 View commit details
  9. Copy the full SHA
    6cba7f5 View commit details
  10. Copy the full SHA
    1a43d18 View commit details
Showing with 271 additions and 2,063 deletions.
  1. +86 −12 truffle/src/main/java/org/jruby/truffle/parser/TranslatorDriver.java
  2. +0 −64 truffle/src/main/java/org/jruby/truffle/parser/lexer/ByteListLexerSource.java
  3. +0 −82 truffle/src/main/java/org/jruby/truffle/parser/lexer/GetsLexerSource.java
  4. +0 −232 truffle/src/main/java/org/jruby/truffle/parser/lexer/KeywordMatch.java
  5. +44 −17 truffle/src/main/java/org/jruby/truffle/parser/lexer/LexerSource.java
  6. +0 −12 truffle/src/main/java/org/jruby/truffle/parser/lexer/LexingCommon.java
  7. +1 −2 truffle/src/main/java/org/jruby/truffle/parser/lexer/SyntaxException.java
  8. +0 −151 truffle/src/main/java/org/jruby/truffle/parser/parser/Parser.java
  9. +2 −10 truffle/src/main/java/org/jruby/truffle/parser/parser/ParserConfiguration.java
  10. +2 −3 truffle/src/main/java/org/jruby/truffle/parser/parser/ParserSupport.java
  11. +0 −62 truffle/src/main/java/org/jruby/truffle/parser/scope/DummyDynamicScope.java
  12. +134 −200 truffle/src/main/java/org/jruby/truffle/parser/scope/DynamicScope.java
  13. +0 −182 truffle/src/main/java/org/jruby/truffle/parser/scope/FourVarDynamicScope.java
  14. +0 −299 truffle/src/main/java/org/jruby/truffle/parser/scope/ManyVarsDynamicScope.java
  15. +0 −151 truffle/src/main/java/org/jruby/truffle/parser/scope/NoVarsDynamicScope.java
  16. +0 −132 truffle/src/main/java/org/jruby/truffle/parser/scope/OneVarDynamicScope.java
  17. +2 −68 truffle/src/main/java/org/jruby/truffle/parser/scope/StaticScope.java
  18. +0 −59 truffle/src/main/java/org/jruby/truffle/parser/scope/StaticScopeFactory.java
  19. +0 −173 truffle/src/main/java/org/jruby/truffle/parser/scope/ThreeVarDynamicScope.java
  20. +0 −152 truffle/src/main/java/org/jruby/truffle/parser/scope/TwoVarDynamicScope.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,33 @@
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
* Copyright (C) 2002-2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2004 Thomas E Enebo <enebo@acm.org>
* Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
*/
package org.jruby.truffle.parser;

@@ -22,6 +49,7 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.LoadRequiredLibrariesNode;
import org.jruby.truffle.core.SetTopLevelBindingNode;
import org.jruby.truffle.core.string.ByteList;
import org.jruby.truffle.language.DataNode;
import org.jruby.truffle.language.LexicalScope;
import org.jruby.truffle.language.RubyNode;
@@ -30,6 +58,7 @@
import org.jruby.truffle.language.arguments.ProfileArgumentNode;
import org.jruby.truffle.language.arguments.ReadPreArgumentNode;
import org.jruby.truffle.language.arguments.RubyArguments;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.exceptions.TopLevelRaiseHandler;
import org.jruby.truffle.language.locals.WriteLocalVariableNode;
import org.jruby.truffle.language.methods.Arity;
@@ -41,32 +70,32 @@
import org.jruby.truffle.language.methods.SharedMethodInfo;
import org.jruby.truffle.language.methods.UnsupportedOperationBehavior;
import org.jruby.truffle.parser.ast.RootParseNode;
import org.jruby.truffle.parser.lexer.LexerSource;
import org.jruby.truffle.parser.lexer.SyntaxException;
import org.jruby.truffle.parser.parser.ParserConfiguration;
import org.jruby.truffle.parser.parser.RubyParser;
import org.jruby.truffle.parser.parser.RubyParserResult;
import org.jruby.truffle.parser.scope.DynamicScope;
import org.jruby.truffle.parser.scope.ManyVarsDynamicScope;
import org.jruby.truffle.parser.scope.StaticScope;
import org.jruby.truffle.parser.scope.StaticScopeFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TranslatorDriver {

private final RubyContext context;
private final ParseEnvironment parseEnvironment;

public TranslatorDriver(RubyContext context) {
this.context = context;
parseEnvironment = new ParseEnvironment(context);
}

public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEncoding, ParserContext parserContext, String[] argumentNames, FrameDescriptor frameDescriptor, MaterializedFrame parentFrame, boolean ownScopeForAssignments, Node currentNode) {
// Set up the JRuby parser

final org.jruby.truffle.parser.parser.Parser parser = new org.jruby.truffle.parser.parser.Parser(context);

final StaticScopeFactory staticScopeFactory = new StaticScopeFactory();
final StaticScope staticScope = staticScopeFactory.newLocalScope(null);
final StaticScope staticScope = new StaticScope(StaticScope.Type.LOCAL, null);

/*
* Note that jruby-parser will be mistaken about how deep the existing variables are,
@@ -110,7 +139,7 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
}
}

final DynamicScope dynamicScope = new ManyVarsDynamicScope(staticScope);
final DynamicScope ManyVarsDynamicScope = new DynamicScope(staticScope);

boolean isInlineSource = parserContext == ParserContext.SHELL;
boolean isEvalParse = parserContext == ParserContext.EVAL || parserContext == ParserContext.INLINE || parserContext == ParserContext.MODULE;
@@ -124,9 +153,7 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn

// Parse to the JRuby AST

RootParseNode node;

node = (RootParseNode) parser.parse(source.getName(), source.getCode().getBytes(StandardCharsets.UTF_8), dynamicScope, parserConfiguration);
RootParseNode node = parse(source.getName(), source.getCode().getBytes(StandardCharsets.UTF_8), ManyVarsDynamicScope, parserConfiguration);

final SourceSection sourceSection = source.createSection(0, source.getCode().length());
final TempSourceSection tempSourceSection = new TempSourceSection(sourceSection);
@@ -234,6 +261,53 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
return new RubyRootNode(context, truffleNode.getRubySourceSection().toSourceSection(source), environment.getFrameDescriptor(), sharedMethodInfo, truffleNode, environment.needsDeclarationFrame());
}

public RootParseNode parse(String file, byte[] content, DynamicScope blockScope,
ParserConfiguration configuration) {
List<ByteList> list = null;
ByteList in = new ByteList(content, configuration.getDefaultEncoding());
LexerSource ByteListLexerSource = new LexerSource(file, configuration.getLineNumber(), in, list);
// We only need to pass in current scope if we are evaluating as a block (which
// is only done for evals). We need to pass this in so that we can appropriately scope
// down to captured scopes when we are parsing.
if (blockScope != null) {
configuration.parseAsBlock(blockScope);
}

RubyParser parser = new RubyParser(context, ByteListLexerSource, new RubyWarnings(configuration.getContext()));
RubyParserResult result;
try {
result = parser.parse(configuration);
} catch (IOException e) {
// Enebo: We may want to change this error to be more specific,
// but I am not sure which conditions leads to this...so lame message.
throw new RaiseException(context.getCoreExceptions().syntaxError("Problem reading source: " + e, null));
} catch (SyntaxException e) {
switch (e.getPid()) {
case UNKNOWN_ENCODING:
case NOT_ASCII_COMPATIBLE:
throw new RaiseException(context.getCoreExceptions().argumentError(e.getMessage(), null));
default:
StringBuilder buffer = new StringBuilder(100);
buffer.append(e.getFile()).append(':');
buffer.append(e.getLine() + 1).append(": ");
buffer.append(e.getMessage());

throw new RaiseException(context.getCoreExceptions().syntaxError(buffer.toString(), null));
}
}

// If variables were added then we may need to grow the dynamic scope to match the static
// one.
// FIXME: Make this so we only need to check this for blockScope != null. We cannot
// currently since we create the ManyVarsDynamicScope for a LocalStaticScope before parse begins.
// Refactoring should make this fixable.
if (result.getScope() != null) {
result.getScope().growIfNeeded();
}

return (RootParseNode) result.getAST();
}

private TranslatorEnvironment environmentForFrameDescriptor(RubyContext context, FrameDescriptor frameDescriptor) {
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
context.getCoreLibrary().getSourceSection(),

This file was deleted.

This file was deleted.

Loading