Skip to content

Commit cc4f3e1

Browse files
author
Alex D
committed
progress
1 parent 4924c01 commit cc4f3e1

File tree

1 file changed

+6
-102
lines changed

1 file changed

+6
-102
lines changed

src/emitterlua.ts

Lines changed: 6 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export class EmitterLua {
108108
return __is_true(left) ? false : true; \
109109
}; \
110110
\
111+
__void = __void || function(left:object) { \
112+
return undefined; \
113+
}; \
114+
\
111115
___type = ___type || function(inst:object) { \
112116
const tp = __type(inst); \
113117
return tp === "table" ? "object" : tp; \
@@ -720,9 +724,6 @@ export class EmitterLua {
720724
dotDotDotAny = true;
721725
}
722726
});
723-
724-
this.functionContext.numparams = parameters.length + (addThisAsParameter ? 1 : 0) /*- (dotDotDotAny ? 1 : 0)*/;
725-
this.functionContext.is_vararg = dotDotDotAny;
726727
}
727728

728729
// functino begin
@@ -874,9 +875,7 @@ export class EmitterLua {
874875
}
875876

876877
private processStatement(node: ts.Statement): void {
877-
const stackSize = this.markStack();
878878
this.processStatementInternal(node);
879-
this.rollbackUnused(stackSize);
880879
}
881880

882881
private processStatementInternal(nodeIn: ts.Statement): void {
@@ -922,9 +921,6 @@ export class EmitterLua {
922921
private processExpression(nodeIn: ts.Expression): void {
923922
const node = this.preprocessor.preprocessExpression(nodeIn);
924923

925-
// we need to process it for statements only
926-
//// this.functionContext.code.setNodeToTrackDebugInfo(node, this.sourceMapGenerator);
927-
928924
switch (node.kind) {
929925
case ts.SyntaxKind.NewExpression: this.processNewExpression(<ts.NewExpression>node); return;
930926
case ts.SyntaxKind.CallExpression: this.processCallExpression(<ts.CallExpression>node); return;
@@ -1461,7 +1457,6 @@ export class EmitterLua {
14611457
statements: [
14621458
// super(xxx) call first
14631459
...(firstStatements > 0 ? statements.slice(0, firstStatements) : []),
1464-
...this.getClassInitStepsToSupportGetSetAccessor(),
14651460
// initialized members
14661461
...((<ts.ClassDeclaration>constructorDeclaration.parent).members
14671462
.filter(cm => !this.isStaticProperty(cm)
@@ -1666,57 +1661,6 @@ export class EmitterLua {
16661661
}
16671662
}
16681663

1669-
private getClassInitStepsToSupportGetSetAccessor_Old(memberDeclaration: ts.ClassElement): any {
1670-
const statements = [];
1671-
const node = <ts.ClassDeclaration>memberDeclaration.parent;
1672-
const anyGet = node.members.some(m => m.kind === ts.SyntaxKind.GetAccessor && !this.isStatic(m));
1673-
const anySet = node.members.some(m => m.kind === ts.SyntaxKind.SetAccessor && !this.isStatic(m));
1674-
if (!anyGet && !anySet) {
1675-
return statements;
1676-
}
1677-
1678-
if (anyGet) {
1679-
statements.push(ts.createStatement(
1680-
ts.createAssignment(
1681-
ts.createPropertyAccess(ts.createThis(), '__index'),
1682-
ts.createIdentifier('__get_call__'))));
1683-
}
1684-
1685-
if (anySet) {
1686-
statements.push(ts.createStatement(
1687-
ts.createAssignment(
1688-
ts.createPropertyAccess(ts.createThis(), '__newindex'),
1689-
ts.createIdentifier('__set_call__'))));
1690-
}
1691-
1692-
return statements;
1693-
}
1694-
1695-
private getClassInitStepsToSupportGetSetAccessor(): any {
1696-
const statements = [];
1697-
/*
1698-
statements.push(ts.createStatement(
1699-
ts.createAssignment(
1700-
ts.createPropertyAccess(ts.createThis(), '__index'),
1701-
ts.createConditional(
1702-
ts.createBinary(
1703-
ts.createTypeOf(ts.createPropertyAccess(ts.createThis(), '__index')),
1704-
ts.SyntaxKind.EqualsEqualsEqualsToken,
1705-
ts.createStringLiteral('function')),
1706-
ts.createPropertyAccess(ts.createThis(), '__index'),
1707-
ts.createIdentifier('__get_call_undefined__')))));
1708-
statements.push(ts.createStatement(
1709-
ts.createAssignment(
1710-
ts.createPropertyAccess(ts.createThis(), '__newindex'),
1711-
ts.createBinary(
1712-
ts.createPropertyAccess(ts.createThis(), '__newindex'),
1713-
ts.SyntaxKind.BarBarToken,
1714-
ts.createIdentifier('__set_call_undefined__')))));
1715-
*/
1716-
1717-
return statements;
1718-
}
1719-
17201664
private getInheritanceFirst(node: ts.ClassDeclaration): ts.Identifier {
17211665
if (!node.heritageClauses) {
17221666
return;
@@ -2230,17 +2174,6 @@ export class EmitterLua {
22302174
this.functionContext.restoreLocalScope();
22312175
}
22322176

2233-
private markStack(): number {
2234-
return this.functionContext.stack.getLength();
2235-
}
2236-
2237-
private rollbackUnused(stack: number) {
2238-
if (stack < this.functionContext.stack.getLength()) {
2239-
// we need to remove unused value
2240-
this.functionContext.stack.pop();
2241-
}
2242-
}
2243-
22442177
private processForInStatement(node: ts.ForInStatement): void {
22452178
this.functionContext.newLocalScope(node);
22462179
this.processForInStatementNoScope(node);
@@ -2394,26 +2327,10 @@ export class EmitterLua {
23942327
this.functionContext.textCode.push("break");
23952328
}
23962329

2397-
private resolveBreakJumps(jump?: number) {
2398-
this.functionContext.breaks.forEach(b => {
2399-
this.functionContext.code.codeAt(b)[2] = (jump ? jump : this.functionContext.code.length) - b - 1;
2400-
});
2401-
2402-
this.functionContext.breaks = [];
2403-
}
2404-
24052330
private processContinueStatement(node: ts.ContinueStatement) {
24062331
this.functionContext.textCode.push("goto continue");
24072332
}
24082333

2409-
private resolveContinueJumps(jump?: number) {
2410-
this.functionContext.continues.forEach(c => {
2411-
this.functionContext.code.codeAt(c)[2] = (jump ? jump : this.functionContext.code.length) - c - 1;
2412-
});
2413-
2414-
this.functionContext.continues = [];
2415-
}
2416-
24172334
private processSwitchStatement(node: ts.SwitchStatement) {
24182335

24192336
var switchIndex = node.pos.toFixed();
@@ -3072,11 +2989,9 @@ export class EmitterLua {
30722989

30732990
private processVoidExpression(node: ts.VoidExpression): void {
30742991
// call expression
2992+
this.functionContext.textCode.push("__void(");
30752993
this.processExpression(node.expression);
3076-
this.functionContext.stack.pop();
3077-
3078-
// convert it into null
3079-
this.processExpression(ts.createIdentifier('undefined'));
2994+
this.functionContext.textCode.push(")");
30802995
}
30812996

30822997
private processNonNullExpression(node: ts.NonNullExpression): void {
@@ -3137,21 +3052,10 @@ export class EmitterLua {
31373052
this.processExpression(getSecondValue);
31383053
}
31393054

3140-
private stackCleanup(resolvedInfo: ResolvedInfo) {
3141-
if (resolvedInfo.popRequired) {
3142-
this.functionContext.stack.pop();
3143-
}
3144-
}
3145-
31463055
private processIndentifier(node: ts.Identifier): void {
31473056
this.functionContext.textCode.push((<ts.Identifier>node).text);
31483057
}
31493058

3150-
private popDependancy(target: ResolvedInfo, dependancy: ResolvedInfo) {
3151-
dependancy.chainPop = target;
3152-
target.hasPopChain = true;
3153-
}
3154-
31553059
private processPropertyAccessExpression(node: ts.PropertyAccessExpression): void {
31563060

31573061
if ((<any>node.name).__len) {

0 commit comments

Comments
 (0)