Skip to content

Commit

Permalink
Uncommitted fixes from long ago
Browse files Browse the repository at this point in the history
  • Loading branch information
trishume committed Sep 9, 2015
1 parent 8d16c96 commit d61ca56
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 22 deletions.
2 changes: 1 addition & 1 deletion predefs.t
@@ -1,2 +1,2 @@
include "stdlib/stdlib.t"
include "stdlib-sfml/stdlib-sfml.t"
include "stdlib-sfml/stdlib-sfml.t"
3 changes: 2 additions & 1 deletion src/Executor.h
Expand Up @@ -19,7 +19,8 @@

#include "LibManager.h"

#define DEBUG_PRINT_BYTECODE
//#define DEBUG_PRINT_BYTECODE
#define DEBUG_PRINTING

class Executor {
public:
Expand Down
2 changes: 2 additions & 0 deletions src/Message.cpp
Expand Up @@ -60,7 +60,9 @@ namespace Message {
return true;
}
bool log(const llvm::Twine &message) {
#ifdef DEBUG_PRINTING
std::cout << "LOG: " << message.str() << std::endl;
#endif
return false;
}

Expand Down
30 changes: 18 additions & 12 deletions src/codegen.cpp
Expand Up @@ -920,11 +920,13 @@ TuringValue *CodeGen::compileArrayLiteral(ASTNode *node) {

// Compiles binary operators.
TuringValue *CodeGen::compileBinaryOp(ASTNode *node) {
if (node->str.compare("and") == 0 || node->str.compare("or") == 0 ||
node->str.compare("&") == 0 || node->str.compare("|") == 0) {
return compileLogicOp(node);
TuringValue *L = compile(node->children[0]);
if (Types.isType(L,"boolean") && (node->str.compare("and") == 0 ||
node->str.compare("or") == 0 ||
node->str.compare("&") == 0 ||
node->str.compare("|") == 0)) {
return compileLogicOp(node,L);
} else {
TuringValue *L = compile(node->children[0]);
TuringValue *R = compile(node->children[1]);
return abstractCompileBinaryOp(L,R,node->str);
}
Expand Down Expand Up @@ -984,10 +986,14 @@ TuringValue *CodeGen::abstractCompileBinaryOp(TuringValue *L, TuringValue *R, st
}
binOp = Instruction::SDiv;
} else if (op.compare("xor") == 0) {
if (fp) { // TODO resolve this
throw Message::Exception("Can't use 'xor' on real numbers.");
}
if (fp) throw Message::Exception("Can't use 'xor' on real numbers.");
binOp = Instruction::Xor;
} else if (op.compare("or") == 0) {
if (fp) throw Message::Exception("Can't use 'or' on real numbers.");
binOp = Instruction::Or;
} else if (op.compare("and") == 0) {
if (fp) throw Message::Exception("Can't use 'and' on real numbers.");
binOp = Instruction::And;
} else if (op.compare("mod") == 0) {
binOp = fp ? Instruction::FRem : Instruction::SRem;
} else if (op.compare("**") == 0) {
Expand Down Expand Up @@ -1043,11 +1049,10 @@ TuringValue *CodeGen::compileUnaryOp(ASTNode *node) {

//! compiles a properly short-circuiting logic operator
//! \param isAnd false for 'or' true for 'and'
TuringValue *CodeGen::compileLogicOp(ASTNode *node) {
TuringValue *cond1 = compile(node->children[0]);

TuringValue *CodeGen::compileLogicOp(ASTNode *node, TuringValue *cond1) {
if (!Types.isType(cond1,"boolean")) {
throw Message::Exception(Twine("Arguments of logical ") + node->str + " must be of type boolean");
throw Message::Exception(Twine("Both arguments of logical ") + node->str +
" must be of type boolean");
}

BasicBlock *startBlock = Builder.GetInsertBlock();
Expand All @@ -1073,7 +1078,8 @@ TuringValue *CodeGen::compileLogicOp(ASTNode *node) {
TuringValue *cond2 = compile(node->children[1]);

if (!Types.isType(cond2,"boolean")) {
throw Message::Exception(Twine("Arguments of logical ") + node->str + " must be of type boolean");
throw Message::Exception(Twine("Both arguments of logical ") + node->str +
" must be of type boolean");
}

Builder.CreateBr(mergeBB);
Expand Down
2 changes: 1 addition & 1 deletion src/codegen.h
Expand Up @@ -96,7 +96,7 @@ class CodeGen {
TuringValue *compileUnaryOp(ASTNode *node);
void compileArrayCopy(TuringValue *from, Symbol *to);
void compileRecordCopy(TuringValue *from, Symbol *to);
TuringValue *compileLogicOp(ASTNode *node);
TuringValue *compileLogicOp(ASTNode *node, TuringValue *cond1);
TuringValue *compileEqualityOp(ASTNode *node);
TuringValue *abstractCompileEqualityOp(TuringValue *L,TuringValue *R,bool isNotEquals = false);

Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Expand Up @@ -46,16 +46,21 @@ void run(CodeGen &gen, LibManager *libManager, const std::string &execDir) {
streamManager.initWithStandardStreams();
// if everything get the finalized module
llvm::Module *mainModule = gen.getFinalizedModule();
#ifdef DEBUG_PRINTING
#ifdef DEBUG_PRINT_BYTECODE
std::cout << "Final Module (unoptimized)";
mainModule->dump();
#endif
// run it!

std::cout << "JIT compiling and optimizing...\n";
#endif
Executor jit(mainModule,&streamManager, libManager, execDir);
jit.StallOnEnd = true;
jit.optimize();
#ifdef DEBUG_PRINTING
std::cout << "Running...\n";
#endif
jit.run();
}

Expand Down
8 changes: 7 additions & 1 deletion stdlib-sfml/src/Main.cpp
Expand Up @@ -6,6 +6,8 @@
#include "WindowManager.h"
#include "Font.h"

const bool GraphicalStandardStreams = true;

std::string ExecutionDir;
void Turing_StdlibSFML_StandardOutputStream(TInt streamNum, const char *error);

Expand All @@ -20,7 +22,11 @@ extern "C" {

// set up put to screen
TInt stream = streamManager->registerStream(&Turing_StdlibSFML_StandardOutputStream, NULL);
streamManager->setSpecialStream(TURINGCOMMON_STREAM_STDOUT, stream);

if (GraphicalStandardStreams) {
streamManager->setSpecialStream(TURINGCOMMON_STREAM_STDOUT, stream);
}

}
void Turing_StdlibSFML_FinalizeRun() {
Turing_StdlibSFML_Window_Cleanup();
Expand Down
3 changes: 3 additions & 0 deletions test/demo3D/demo3D.t
Expand Up @@ -91,6 +91,9 @@ loop
ry += 1.0
end if
viewMat2 := rotateYZ(ry)
else
ry += 0.3
viewMat2 := rotateYZ(ry)
end if

% iterate projectiles
Expand Down
13 changes: 8 additions & 5 deletions test/demoParticles.t
Expand Up @@ -8,7 +8,7 @@ type particle : record
vel : vector2D
end record

View.Set("offscreenonly")
View.Set("offscreenonly,graphics:700;700")

const maxParticles := 30000 % maximum number of particles
const darkBack := true
Expand All @@ -20,7 +20,7 @@ proc Update(mx,my,btn : int)
for i : 1..numParticles
% attract to mouse
if btn > 0 then
var factor := -1.0
var factor := -3.0
if btn = 100 then
factor := 3.0
elsif btn = 101 then
Expand Down Expand Up @@ -49,8 +49,8 @@ proc DrawParticles
if r > 1.0 then
r := 1.0
end if
RGB.SetColor(250,r,0.0,1-r)
%RGB.SetColor(250,r,-r**2.0+r*2.0,1-r)
%RGB.SetColor(250,r,0.0,1-r)
RGB.SetColor(250,r,-r**2.0+r*2.0,1-r)
Draw.Dot(round(p(i).pos.x), round(p(i).pos.y), 250)
end for
end DrawParticles
Expand Down Expand Up @@ -88,6 +88,9 @@ end for
loop
var x,y,button : int
Mouse.Where(x,y,button)
%x := maxx div 2
%y := maxy div 2 + round(sin(Time.Elapsed() / 1000)*50)
%button := 1

% comment out for full trails:
cls
Expand All @@ -104,5 +107,5 @@ loop
Update(x,y,button)
DrawParticles
View.Update
Time.DelaySinceLast(15)
%Time.DelaySinceLast(15)
end loop
10 changes: 10 additions & 0 deletions test/demoTinyBits.t
@@ -0,0 +1,10 @@
View.Set("offscreenonly")
for m : 1..250
for x : 1..maxx
for y : 1..maxy
Draw.Dot(x,y,(x or y) mod m)
end for
end for
View.Update
Time.Delay(40)
end for
2 changes: 1 addition & 1 deletion test/test13.t
Expand Up @@ -67,7 +67,7 @@ module Print13
%test multi-expr
put 13,"...\n" ..
end if

% test module variables
var lolArr,lolArr2 : flexible array 1..0 of int

Expand Down

0 comments on commit d61ca56

Please sign in to comment.