Skip to content

Commit 98c498d

Browse files
committed
[huge change] rewrite wasm
1 parent 00b8758 commit 98c498d

File tree

113 files changed

+2765
-3036
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+2765
-3036
lines changed

README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,10 @@ of WebAssembly.
167167
- [X] function pointer
168168
- [X] array initial list
169169
- [X] multi-dim array
170-
- [ ] #if #elif
171170
- [ ] bit field of struct
171+
- [ ] #if #elif
172172
- [ ] #line __line__ __file__
173-
- [ ] remove Long.js
174173
- [X] debuginfo
175-
- [ ] repeative param name detect
176174
## C++ Language
177175
- [X] default parameter
178176
- [X] default constructor
@@ -212,24 +210,39 @@ of WebAssembly.
212210

213211
## TODO LIST
214212
High
213+
- [X] repeative param name detect
215214
- [ ] cast overload, like if(object) { ... }
216-
- [ ] const/override/virtual member function
217215
- [ ] warning
218-
- [ ] class specialization
216+
- [X] class specialization
219217
- [ ] using template
220218
- [ ] A a[50] decons
221219
- [ ] subclass B A::a => set children?
222-
- [ ] explicit class ins
223-
- [ ] C std lib
220+
- [X] explicit class ins
221+
- [ ] placement new
222+
- [X] C std lib
224223
- [ ] C++ std lib
224+
- [ ] iostream∂
225+
- [ ] string
226+
- [ ] vector
227+
- [ ] map
228+
- [ ] queue/stack
229+
- [ ] priority_queue
230+
- [ ] algorithm
231+
- [ ] id could not be keyword => special judge
232+
- [X] operator []
233+
- [x] operator ()
234+
- [ ] static_cast / dynamic_cast / reinterpret_cast
235+
- [ ] const left value reference
236+
====== the upper is all plan of web-cpp in 2019
225237

226238
Other
239+
- [ ] const/override member function
240+
- [ ] real const
241+
- [ ] real override
242+
- [ ] real accessControl
227243
- [ ] seperate define class function
228244
- [ ] seperate delaration => to be test
229-
- [ ] operator new/ placement new
230-
- [ ] id could not be keyword => special judge
231245
- [ ] typeinfo
232-
- [ ] static_cast / dynamic_cast / reinterpret_cast
233246
- [ ] virtual inheriant
234247
## ide
235248
- [X] multi-language

ide/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
<span class="mdl-switch__label" id="ui-expert-switch"></span>
136136
</label>
137137
</div>
138-
<div id="expert-content" class="right-card-content">
138+
<div id="expert-content" class="right-card-content" style="padding:0 20px">
139139
<button
140140
id="ui-expert-pre-btn"
141141
onclick="showDebugInfo('pre')"

ide/js/inspector.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export function updateInspector(runtime){
1616
const item = stack[i];
1717
result += `<tr><td colspan="3">==>${escapeHTML(item.fn.displayName)} #${i}</td></tr>`;
1818
for(const subitem of runtime.getScopeInfo(item.fn.scope, item)){
19-
result += `<tr><td>${escapeHTML(subitem.name)}</td><td>${escapeHTML(subitem.type)}</td><td>${escapeHTML(subitem.value)}</td></tr>`;
19+
if(subitem.name.charAt(0) !== "$") {
20+
result += `<tr><td>${escapeHTML(subitem.name)}</td><td>${escapeHTML(subitem.type)}</td><td>${escapeHTML(subitem.value)}</td></tr>`;
21+
}
2022
}
2123
}
2224
result += `<tr><td colspan="3">==>global</td></tr>`;

ide/js/ui_text.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const UI_TEXT = {
2323
"message":["message", "消息"],
2424
"download_message":[
2525
"downloading compiler",
26-
"程序运行已经结束"
26+
"正在下载编译器"
2727
],
2828
"save_message":[
2929
"code have been saved",
@@ -76,10 +76,10 @@ const UI_TEXT = {
7676
"简体中文", "简体中文"
7777
],
7878
"setting-expert-left":[
79-
"normal mode", "普通模式"
79+
"Normal mode", "普通模式"
8080
],
8181
"setting-expert-right":[
82-
"expert mode", "专家模式"
82+
"Expert mode", "专家模式"
8383
],
8484
"menu":[
8585
"Menu", "菜单"

resource/grammar/lex.grammar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SingleIdentifier
99
} {
1010
return id;
1111
}
12-
/ 'operator' ope:OverloadOperator {
12+
/ 'operator' _ ope:OverloadOperator {
1313
return new AST.SingleIdentifier(getLocation(), "#" + ope, AST.IDType.ID, []);
1414
}
1515
/ '~' name:TypeIdentifier {

resource/grammar/template.grammar

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ TemplateArgument
6363

6464
ExplicitInstantiation
6565
= FunctionTemplateInstantiation
66+
/ ClassTemplateInstantiation
6667

6768
FunctionTemplateInstantiation
6869
= 'template' _ specifiers:DeclarationSpecifiers _ declarator:Declarator _ ';'{
6970
return new AST.FunctionTemplateInstantiation(getLocation(), specifiers, declarator);
71+
}
72+
73+
ClassTemplateInstantiation
74+
= 'template' _ spec:ClassSpecifier _ ';'{
75+
return new AST.ClassTemplateInstantiation(getLocation(), spec);
7076
}

src/codegen/address.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ import {AddressType} from "../common/symbol";
99
import {Type} from "../type";
1010
import {ClassType} from "../type/class_type";
1111
import {ArrayType} from "../type/compound_type";
12-
import {I32Binary, WBinaryOperation, WConst, WLoad, WStore, WType} from "../wasm";
13-
import {getNativeType} from "../wasm/constant";
14-
import {Emitter} from "../wasm/emitter";
15-
import {WGetAddress, WGetGlobal, WGetLocal, WMemoryLocation} from "../wasm/expression";
16-
import {WExpression, WStatement} from "../wasm/node";
17-
import {WSetGlobal, WSetLocal} from "../wasm/statement";
12+
import {
13+
Emitter,
14+
getNativeType,
15+
I32Binary,
16+
WBinaryOperation,
17+
WConst, WExpression, WGetAddress, WGetGlobal, WGetLocal,
18+
WLoad,
19+
WMemoryLocation,
20+
WSetGlobal, WSetLocal, WStatement,
21+
WStore,
22+
WType,
23+
} from "../wasm";
1824
import {CompileContext} from "./context";
1925

2026
export class WAddressHolder extends WExpression {
@@ -275,7 +281,7 @@ export class WAddressHolder extends WExpression {
275281
result = new WBinaryOperation(
276282
I32Binary.add,
277283
new WGetLocal(WType.i32, ctx.currentFuncContext.currentFunction.$sp, this.location),
278-
new WConst(WType.i32, (this.place as number + this.offset).toString()),
284+
new WConst(WType.i32, (this.place as number + this.offset).toString(), this.location),
279285
this.location,
280286
);
281287
break;
@@ -286,7 +292,7 @@ export class WAddressHolder extends WExpression {
286292
result = new WBinaryOperation(
287293
I32Binary.add,
288294
new WGetGlobal(WType.i32, "$sp", this.location),
289-
new WConst(WType.i32, (this.place as number + this.offset).toString()),
295+
new WConst(WType.i32, (this.place as number + this.offset).toString(), this.location),
290296
this.location,
291297
);
292298
break;
@@ -321,24 +327,8 @@ export class WAddressHolder extends WExpression {
321327
throw new EmitError(`WAddressHolder()`);
322328
}
323329

324-
public emitJSON(e: Emitter): void {
325-
throw new EmitError(`WAddressHolder()`);
326-
}
327-
328-
public fold(): WExpression {
329-
return this;
330-
}
331-
332-
public length(e: Emitter): number {
333-
throw new EmitError(`WAddressHolder()`);
334-
}
335-
336330
public isPure(): boolean {
337331
return true;
338332
}
339333

340-
public dump(e: Emitter): void {
341-
e.dump("===ADDRESS HOLDER===", this.location);
342-
}
343-
344334
}

src/codegen/class/class_specifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {AddressType} from "../../common/symbol";
44
import {getAccessControlFromString} from "../../type";
55
import {ClassType, Inheritance} from "../../type/class_type";
66
import {PrimitiveTypes} from "../../type/primitive_type";
7-
import {WGetAddress, WGetFunctionAddress, WMemoryLocation} from "../../wasm/expression";
7+
import {WGetAddress, WGetFunctionAddress, WMemoryLocation} from "../../wasm";
88
import {WAddressHolder} from "../address";
99
import {CompileContext} from "../context";
1010
import {Declaration} from "../declaration/declaration";

src/codegen/class/constructor_declaration.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {ClassType} from "../../type/class_type";
66
import {PointerType} from "../../type/compound_type";
77
import {CppFunctionType, FunctionType} from "../../type/function_type";
88
import {PrimitiveTypes} from "../../type/primitive_type";
9-
import {WGetAddress, WMemoryLocation} from "../../wasm/expression";
109
import {CompileContext} from "../context";
1110
import {ObjectInitializer} from "../declaration/object_initializer";
1211
import {AnonymousCastExpression, AnonymousExpression} from "../expression/anonymous_expression";
@@ -25,6 +24,7 @@ import {CompoundStatement} from "../statement/compound_statement";
2524
import {ExpressionStatement} from "../statement/expression_statement";
2625
import {Statement} from "../statement/statement";
2726
import {MemberExpression} from "./member_expression";
27+
import {WGetAddress, WMemoryLocation} from "../../wasm";
2828

2929
export class ConstructorDeclaration extends ClassDirective {
3030
public name: Identifier;
@@ -75,8 +75,9 @@ export class ConstructorDeclaration extends ClassDirective {
7575
const functionConfig = this.getFunctionConfig(ctx, classType, AccessControl.Unknown);
7676
if (this.body) {
7777
const body: Directive[] = [...this.generateStatements(ctx, functionConfig), ...this.body.body];
78-
const oldItem = ctx.scopeManager.getOldOverloadSymbol(functionConfig.name
79-
+ "@" + functionConfig.functionType.toMangledName());
78+
const oldItem = ctx.scopeManager.getOldOverloadSymbol(
79+
ctx.scopeManager.currentContext.scope.fullName + "::" +
80+
functionConfig.name + "@" + functionConfig.functionType.toMangledName());
8081
const activeScopes = (oldItem && oldItem instanceof FunctionEntity)
8182
? oldItem.declareActiveScopes : [];
8283
defineFunction(ctx, functionConfig, body, activeScopes, this);

src/codegen/class/member_expression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class MemberExpression extends Expression {
7272
}
7373
return {
7474
type: new UnresolvedFunctionOverloadType(item),
75-
expr: new WConst(WType.any, "0"),
75+
expr: new WConst(WType.any, "0", this.location),
7676
isLeft: false,
7777
};
7878
} else {

0 commit comments

Comments
 (0)