Skip to content

Commit

Permalink
Merge PR #385: Adapt SOMns for semantic highlighting in the Language …
Browse files Browse the repository at this point in the history
…Server
  • Loading branch information
smarr committed Jun 16, 2022
2 parents 92041ce + cd152a7 commit b2b1285
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 140 deletions.
2 changes: 1 addition & 1 deletion libs/black-diamonds
31 changes: 10 additions & 21 deletions src/som/compiler/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

package som.compiler;

import bd.source.SourceCoordinate;


public final class Lexer {

public static class Peek {
Expand All @@ -50,7 +47,8 @@ private static class LexerState {
sym = old.sym;
symc = old.symc;
text = new StringBuilder(old.text);
startCoord = old.startCoord;
startPtr = old.startPtr;
startLastNonWhiteCharIdx = old.startLastNonWhiteCharIdx;
numeralParser = old.numeralParser;
}

Expand Down Expand Up @@ -79,9 +77,10 @@ public void set(final Symbol sym) {
private char symc;
private StringBuilder text;

private NumeralParser numeralParser;
private int startPtr;
private int startLastNonWhiteCharIdx;

private SourceCoordinate startCoord;
private NumeralParser numeralParser;

int incPtr() {
return incPtr(1);
Expand Down Expand Up @@ -112,17 +111,6 @@ protected Lexer(final String content) {
state.lastNonWhiteCharIdx = 0;
}

private static SourceCoordinate createSourceCoordinate(final LexerState state) {
// We use the coord.length to indicate the lastNonWhiteCharIdx
// TODO: fix this terrible hack, and make this explicit
return SourceCoordinate.create(state.lineNumber, state.ptr - state.lastLineEnd,
state.ptr, state.lastNonWhiteCharIdx);
}

public SourceCoordinate getStartCoordinate() {
return state.startCoord;
}

protected Symbol getSym() {
try {
return doSym();
Expand Down Expand Up @@ -153,7 +141,8 @@ private Symbol doSym() {

skipWhiteSpace();

state.startCoord = createSourceCoordinate(state);
state.startPtr = state.ptr;
state.startLastNonWhiteCharIdx = state.lastNonWhiteCharIdx;

if (currentChar() == '\'') {
lexString();
Expand Down Expand Up @@ -441,12 +430,12 @@ protected int getCurrentColumn() {
}

protected int getNumberOfNonWhiteCharsRead() {
return state.startCoord.charLength;
return state.startLastNonWhiteCharIdx;
}

// All characters read and processed, including current line
/** All characters read and processed, including current line. */
protected int getNumberOfCharactersRead() {
return state.startCoord.charIndex;
return state.startPtr;
}

protected String getCommentPart() {
Expand Down
29 changes: 23 additions & 6 deletions src/som/compiler/MethodBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ public SomLanguage getLanguage() {
return language;
}

public Argument getArgument(final int index) {
int i = 0;
for (Argument a : arguments.getValues()) {
if (i == index) {
return a;
}
i += 1;
}
throw new IllegalArgumentException(
"Tried to access argument " + index + " but there are only " + arguments.size());
}

public Iterable<Argument> getArguments() {
return arguments.getValues();
}
Expand Down Expand Up @@ -359,7 +371,7 @@ public void setSignature(final SSymbol sig) {
signature = sig;
}

public void addArgument(final SSymbol arg, final SourceSection source) {
public Argument addArgument(final SSymbol arg, final SourceSection source) {
if ((Symbols.SELF == arg || Symbols.BLOCK_SELF == arg) && arguments.size() > 0) {
throw new IllegalStateException(
"The self argument always has to be the first argument of a method");
Expand All @@ -371,6 +383,7 @@ public void addArgument(final SSymbol arg, final SourceSection source) {
if (structuralProbe != null) {
structuralProbe.recordNewVariable(argument);
}
return argument;
}

public Local addMessageCascadeTemp(final SourceSection source) throws MethodDefinitionError {
Expand Down Expand Up @@ -743,11 +756,11 @@ private String stripColonsAndSourceLocation(String str) {
return str.replace(":", "");
}

public void setBlockSignature(final SourceCoordinate coord) {
public void setBlockSignature(final int line, final int column) {
String outerMethodName = stripColonsAndSourceLocation(getOuter().getName());

int argSize = getNumberOfArguments();
String blockSig = "λ" + outerMethodName + "@" + coord.startLine + "@" + coord.startColumn;
String blockSig = "λ" + outerMethodName + "@" + line + "@" + column;

for (int i = 1; i < argSize; i++) {
blockSig += ":";
Expand All @@ -756,10 +769,14 @@ public void setBlockSignature(final SourceCoordinate coord) {
setSignature(symbolFor(blockSig));
}

@Override
public String toString() {
public String getFullName() {
MixinBuilder mixin = getMixin();
String name = mixin == null ? "" : mixin.getName();
return "MethodBuilder(" + name + ">>" + signature.toString() + ")";
return name + ">>" + signature.toString();
}

@Override
public String toString() {
return "MethodBuilder(" + getFullName() + ")";
}
}
4 changes: 4 additions & 0 deletions src/som/compiler/MixinBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ public void setInitializerSource(final SourceSection sourceSection) {
initializerSource = sourceSection;
}

public SourceSection getInitializerSource() {
return initializerSource;
}

public void addMethod(final SInvokable meth) throws MixinDefinitionError {
SSymbol name = meth.getSignature();
if (!classSide) {
Expand Down

1 comment on commit b2b1285

@rebenchdb
Copy link

@rebenchdb rebenchdb bot commented on b2b1285 Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance changes for 92041ce...b2b1285

Summary Over All Benchmarks
Summary Over All Benchmarks

Full Report

Please sign in to comment.