Skip to content

Commit

Permalink
Created a simple integer expression repl.
Browse files Browse the repository at this point in the history
To enable, just change -version=SDCCOMPILER with
-version=SDCREPL and recompile. Integer constants
only, at the moment.
  • Loading branch information
bhelyer committed Sep 10, 2011
1 parent 3ad55ae commit 0139139
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion makefile
Expand Up @@ -3,7 +3,7 @@ include makefile.common
PLATFORM = $(shell uname -s)
ARCHFLAG ?= -m32
SOURCE = $(SOURCE_WILDCARDS)
DFLAGS = $(ARCHFLAG) -w -debug -gc -unittest -Iimport
DFLAGS = $(ARCHFLAG) -w -debug -gc -unittest -Iimport -version=SDCCOMPILER
OBJ = sdc.o
EXE = bin/sdc

Expand Down
2 changes: 1 addition & 1 deletion makefile.gdc
@@ -1,6 +1,6 @@
include makefile.common

DFLAGS = -g -Wall -Werror -funittest -I./import -Isrc -m32
DFLAGS = -g -Wall -Werror -funittest -I./import -Isrc -m32 -version=SDCCOMPILER
SOURCE = $(wildcard $SOURCE_WILDCARDS)
OBJS = $(SOURCE:.d=.o)
EXE = sdc
Expand Down
2 changes: 1 addition & 1 deletion makefile.windows
@@ -1,6 +1,6 @@
include makefile.common

DFLAGS = -w -debug -g -unittest -Iimport -Isrc $(FLAGS)
DFLAGS = -version=SDCCOMPILER -w -debug -g -unittest -Iimport -Isrc $(FLAGS)
SOURCE = \
src/sdc/ast/*.d \
src/sdc/parser/*.d \
Expand Down
52 changes: 52 additions & 0 deletions src/sdc/repl.d
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/sdc/sdc.d
Expand Up @@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
module sdc.sdc;
version (SDCCOMPILER):

import std.algorithm;
import std.array;
Expand Down

0 comments on commit 0139139

Please sign in to comment.