Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a simple integer expression repl.
To enable, just change -version=SDCCOMPILER with -version=SDCREPL and recompile. Integer constants only, at the moment.
- Loading branch information
Showing
5 changed files
with
56 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module sdc.repl; | ||
version (SDCREPL): | ||
|
||
import std.process; | ||
import std.stdio; | ||
|
||
import llvm.c.Core; | ||
import llvm.c.Initialization; | ||
|
||
import sdc.aglobal; | ||
import sdc.lexer; | ||
import sdc.location; | ||
import sdc.source; | ||
import sdc.util; | ||
import sdc.ast.base; | ||
import sdc.parser.base; | ||
import sdc.parser.expression; | ||
import sdc.gen.expression; | ||
import sdc.gen.sdcmodule; | ||
|
||
extern (C) void _Z18LLVMInitializeCoreP22LLVMOpaquePassRegistry(LLVMPassRegistryRef); | ||
|
||
string premain = "void main() {"; | ||
string postmain = "}"; | ||
|
||
void main(string[] args) | ||
{ | ||
auto passRegistry = LLVMGetGlobalPassRegistry(); | ||
_Z18LLVMInitializeCoreP22LLVMOpaquePassRegistry(passRegistry); // TMP !!! | ||
LLVMInitializeCodeGen(passRegistry); | ||
|
||
globalInit("x86-64"); | ||
|
||
auto location = Location("/dev/null"); | ||
auto bitcode = temporaryFilename(".bc"), assembly = temporaryFilename(".s"), object = temporaryFilename(".o"); | ||
|
||
auto namesrc = new Source("fake.module", location); | ||
auto namelex = lex(namesrc); | ||
namelex.get(); // skip BEGIN | ||
auto name = parseQualifiedName(namelex); | ||
auto mod = new Module(name); | ||
|
||
while (true) { | ||
auto input = stdin.readln(); | ||
auto src = new Source(input, location); | ||
auto tstream = lex(src); | ||
tstream.get(); // skip BEGIN | ||
auto exp = parseExpression(tstream); | ||
auto val = genExpression(exp, mod); | ||
writeln("=> ", val.knownInt); | ||
} | ||
} |
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