forked from dynjs/dynjs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
dynjs/src/main/java/org/dynjs/parser/statement/NamedValueStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.dynjs.parser.statement; | ||
|
||
import me.qmx.jitescript.CodeBlock; | ||
import org.dynjs.compiler.DynJSCompiler; | ||
import org.dynjs.parser.Statement; | ||
|
||
import static me.qmx.jitescript.util.CodegenUtils.sig; | ||
|
||
public class NamedValueStatement implements Statement { | ||
|
||
private final Statement propertyName; | ||
private final Statement expr; | ||
|
||
public NamedValueStatement(Statement propertyName, Statement expr) { | ||
this.propertyName = propertyName; | ||
this.expr = expr; | ||
} | ||
|
||
@Override | ||
public CodeBlock getCodeBlock() { | ||
return CodeBlock.newCodeBlock() | ||
.append(propertyName.getCodeBlock()) | ||
.append(expr.getCodeBlock()) | ||
.invokeinterface(DynJSCompiler.Types.Scope, "define", sig(void.class, String.class, Object.class)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
dynjs/src/main/java/org/dynjs/parser/statement/ObjectLiteralStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.dynjs.parser.statement; | ||
|
||
import me.qmx.jitescript.CodeBlock; | ||
import org.dynjs.parser.Statement; | ||
import org.dynjs.runtime.DynObject; | ||
|
||
import java.util.List; | ||
|
||
import static me.qmx.jitescript.util.CodegenUtils.p; | ||
import static me.qmx.jitescript.util.CodegenUtils.sig; | ||
|
||
public class ObjectLiteralStatement implements Statement { | ||
|
||
private final List<Statement> namedValues; | ||
|
||
public ObjectLiteralStatement(List<Statement> namedValues) { | ||
this.namedValues = namedValues; | ||
} | ||
|
||
@Override | ||
public CodeBlock getCodeBlock() { | ||
CodeBlock obj = CodeBlock.newCodeBlock() | ||
.newobj(p(DynObject.class)) | ||
.dup() | ||
.invokespecial(p(DynObject.class), "<init>", sig(void.class)) | ||
.astore(7); | ||
for (Statement namedValue : namedValues) { | ||
|
||
obj = obj.aload(7) | ||
.append(namedValue.getCodeBlock()); | ||
} | ||
return obj.aload(7); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
dynjs/src/main/java/org/dynjs/parser/statement/ResolveByIndexStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.dynjs.parser.statement; | ||
|
||
import me.qmx.jitescript.CodeBlock; | ||
import org.dynjs.compiler.DynJSCompiler; | ||
import org.dynjs.parser.Statement; | ||
|
||
import static me.qmx.jitescript.util.CodegenUtils.sig; | ||
|
||
public class ResolveByIndexStatement implements Statement { | ||
|
||
private final Statement lhs; | ||
private final Statement index; | ||
|
||
public ResolveByIndexStatement(Statement lhs, String index) { | ||
this(lhs, new StringLiteralStatement(index)); | ||
|
||
} | ||
public ResolveByIndexStatement(Statement lhs, Statement index) { | ||
this.lhs = lhs; | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public CodeBlock getCodeBlock() { | ||
return CodeBlock.newCodeBlock() | ||
.append(lhs.getCodeBlock()) | ||
.append(index.getCodeBlock()) | ||
.invokeinterface(DynJSCompiler.Types.Scope, "resolve", sig(Object.class, String.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters