First Blood #1
First Blood #1
Conversation
mohanson
commented
Aug 14, 2019
- The main framework of compiler(Passed the Fibonacci test)
README.md
Outdated
|
||
``` | ||
$ npm install | ||
$ ts-node src/index.ts build tests/ts/application/fibonacci.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix.
src/index.ts
Outdated
// [0] https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API | ||
// [1] https://github.com/microsoft/TypeScript/blob/master/doc/spec.md | ||
|
||
import * as child_process from 'child_process'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest removing *
,
import x from 'xxx'
;
@@ -0,0 +1,31 @@ | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the test to ave
? Remove python code.
package.json
Outdated
"commander": "^3.0.0", | ||
"llvm-node": "^2.1.0", | ||
"typescript": "^3.5.3", | ||
"yarn": "^1.17.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why dependence yarn
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to do this globally, you should execute npm i -g yarn
.
src/index.ts
Outdated
} | ||
|
||
function mainRun(): void { | ||
if (typeof argv.output === 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argv.output === undefined
argv.output = '/tmp/minits.ll'; | ||
} | ||
mainBuild(); | ||
const p = child_process.spawn('lli', [argv.output]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of starting another process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use lli
to execute the LLVM IR.
src/codegen.ts
Outdated
} | ||
|
||
public genSourceFile(sourceFile: ts.SourceFile): void { | ||
sourceFile.forEachChild(node => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sourceFile.forEachChild(node => { | |
sourceFile.forEachChild(this.genNode) |
|
||
public genNode( | ||
node: ts.Node | ||
): llvm.Constant | llvm.Type | llvm.Value | undefined | void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
llvm.Type | llvm.Value | null