Skip to content

Commit 70d30af

Browse files
committed
stash
1 parent 6c0a2d5 commit 70d30af

File tree

10 files changed

+107
-31
lines changed

10 files changed

+107
-31
lines changed

Compile/Debug/Interop-Debug.sp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ Iterator _Interop_Vector::operator::in()
2121
bool _Interop_Vector::next(it: Iterator)
2222
{
2323
it.index += 1;
24-
count := (this.end - this.begin) as int / #sizeof T;
25-
return it.index < count;
24+
return it.index < this.Count();
2625
}
2726

2827
*T _Interop_Vector::current(it: Iterator)
2928
{
3029
return this[it.index];
3130
}
3231

32+
uint _Interop_Vector::Count()
33+
{
34+
return (this.end - this.begin) as int / #sizeof T;
35+
}
36+
3337
string _Interop_Vector::log() => "Interop Vector";
3438

3539
state _Interop_Map_Node<Value>

Compile/Release/Interop-Release.sp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ Iterator _Interop_Vector::operator::in()
2020
bool _Interop_Vector::next(it: Iterator)
2121
{
2222
it.index += 1;
23-
count := (this.end - this.begin) as int / #sizeof T;
24-
return it.index < count;
23+
return it.index < this.Count();
2524
}
2625

2726
*T _Interop_Vector::current(it: Iterator)
2827
{
2928
return this[it.index];
3029
}
3130

31+
uint _Interop_Vector::Count()
32+
{
33+
return (this.end - this.begin) as int / #sizeof T;
34+
}
35+
3236
string _Interop_Vector::log() => "Interop Vector";
3337

3438
state _Interop_Map_Node<Value>

Runtime/Global/Meta/Type.sp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package _
22

3+
[]*_Type InteropToArray(vec: *_Interop_Vector<*_Type>)
4+
{
5+
arr := []*_Type;
6+
arr.count = vec.Count();
7+
arr.capacity = vec.Count();
8+
arr.memory.ptr = vec.begin as *byte;
9+
return arr;
10+
}
11+
312
bool _Type::IsPrimitive() => this.kind == _TypeKind.PrimitiveType;
413

514
bool _Type::IsString() => this.IsPrimitive() &&
@@ -20,4 +29,9 @@ bool _Type::IsStructure() => this.kind == _TypeKind.StructureType;
2029

2130
bool _Type::IsPointer() => this.kind == _TypeKind.PointerType;
2231

32+
bool _Type::IsFunction() => this.kind == _TypeKind.FunctionType;
33+
2334
uint _Type::FixedArrayCount() => this.type.fixedArray.count;
35+
36+
[]*_Type _Type::GetFunctionParams() => InteropToArray(this.type.function.params);
37+

Runtime/Math/Math.sp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int Clamp(value: int, min: int, max: int) => Min(Max(value, min), max);
9696

9797
float FClamp(value: float, min: float, max: float) => FMin(FMax(value, min), max);
9898

99-
int Abs(val: int) => llabs(val);
99+
int Abs(val: int) => abs(val);
100100

101101
float FAbs(val: float) => fabs(val);
102102

Runtime/Math/Quaternion/Quaternion.sp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,33 @@ Matrix3 Quaternion::ToRotationMatrix()
144144
return mat;
145145
}
146146

147+
Vec3 Quaternion::Forward()
148+
{
149+
f := Vec3();
150+
f.x = 2.0 * (this.x * this.z + this.w * this.y);
151+
f.y = 2.0 * (this.y * this.z - this.w * this.x);
152+
f.z = 1.0 - 2.0 * (this.x * this.x + this.y * this.y);
153+
return f;
154+
}
155+
156+
Vec3 Quaternion::Up()
157+
{
158+
u := Vec3();
159+
u.x = 2.0 * (this.x * this.y - this.w * this.z);
160+
u.y = 1.0 - 2.0 * (this.x * this.x + this.z * this.z);
161+
u.z = 2.0 * (this.y * this.z + this.w * this.x);
162+
return u;
163+
}
164+
165+
Vec3 Quaternion::Left()
166+
{
167+
l := Vec3();
168+
l.x = 1.0 - 2.0 * (this.y * this.y + this.z * this.z);
169+
l.y = 2.0 * (this.x * this.y + this.w * this.z);
170+
l.z = 2.0 * (this.x * this.z - this.w * this.y);
171+
return l;
172+
}
173+
147174
Quaternion Quaternion::PowerOf(n: float32)
148175
{
149176
halfCosAngle := Math.FClamp(this.w, -1.0, 1.0);

Runtime/Math/Vec/Vec2.sp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@ ref Norm<Vec2> Vec2::Normalize()
4343
}
4444

4545
Vec2 Vec2::operator::-(r: Vec2) => Vec2(this.x - r.x, this.y - r.y);
46+
Vec2 Vec2::operator::-(r: float32) => Vec2(this.x - r, this.y - r);
47+
48+
Vec2 Vec2::operator::+(r: Vec2) => Vec2(this.x + r.x, this.y + r.y);
49+
Vec2 Vec2::operator::+(r: float32) => Vec2(this.x + r, this.y + r);
50+
51+
Vec2 Vec2::operator::*(r: Vec2) => Vec2(this.x * r.x, this.y * r.y);
52+
Vec2 Vec2::operator::*(r: float32) => Vec2(this.x * r, this.y * r);
53+
54+
Vec2 Vec2::operator::/(r: Vec2) => Vec2(this.x / r.x, this.y / r.y);
55+
Vec2 Vec2::operator::/(r: float32) => Vec2(this.x / r, this.y / r);
4656

Runtime/Math/Vec/Vec3.sp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ ref Norm<Vec3> Vec3::Normalize()
5353
}
5454

5555
Vec3 Vec3::operator::-(r: Vec3) => Vec3(this.x - r.x, this.y - r.y, this.z - r.z);
56+
Vec3 Vec3::operator::-(r: float32) => Vec3(this.x - r, this.y - r, this.z - r);
57+
5658
Vec3 Vec3::operator::+(r: Vec3) => Vec3(this.x + r.x, this.y + r.y, this.z + r.z);
59+
Vec3 Vec3::operator::+(r: float32) => Vec3(this.x + r, this.y + r, this.z + r);
5760

61+
Vec3 Vec3::operator::*(r: Vec3) => Vec3(this.x * r.x, this.y * r.y, this.z * r.z);
5862
Vec3 Vec3::operator::*(r: float32) => Vec3(this.x * r, this.y * r, this.z * r);
63+
64+
Vec3 Vec3::operator::/(r: Vec3) => Vec3(this.x / r.x, this.y / r.y, this.z / r.z);
65+
Vec3 Vec3::operator::/(r: float32) => Vec3(this.x / r, this.y / r, this.z / r);

Runtime/Math/Vec/Vec4.sp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,13 @@ ref Norm<Vec4> Vec4::Normalize()
5353
}
5454

5555
Vec4 Vec4::operator::-(r: Vec4) => Vec4(this.x - r.x, this.y - r.y, this.z - r.z, this.w - r.w);
56+
Vec4 Vec4::operator::-(r: float32) => Vec4(this.x - r, this.y - r, this.z - r, this.w - r);
57+
58+
Vec4 Vec4::operator::+(r: Vec4) => Vec4(this.x + r.x, this.y + r.y, this.z + r.z, this.w + r.w);
59+
Vec4 Vec4::operator::+(r: float32) => Vec4(this.x + r, this.y + r, this.z + r, this.w + r);
60+
61+
Vec4 Vec4::operator::*(r: Vec4) => Vec4(this.x * r.x, this.y * r.y, this.z * r.z, this.w * r.w);
62+
Vec4 Vec4::operator::*(r: float32) => Vec4(this.x * r, this.y * r, this.z * r, this.w * r);
63+
64+
Vec4 Vec4::operator::/(r: Vec4) => Vec4(this.x / r.x, this.y / r.y, this.z / r.z, this.w / r.w);
65+
Vec4 Vec4::operator::/(r: float32) => Vec4(this.x / r, this.y / r, this.z / r, this.w / r);

Src/IR/Interpreter/Interpreter.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ inline char* global = nullptr;
1616

1717
struct Interpreter
1818
{
19-
char* stack;
20-
char* stackFrameStart;
21-
char* stackFrameEnd;
19+
volatile char* stack;
20+
volatile char* stackFrameStart;
21+
volatile char* stackFrameEnd;
2222
int threadID;
2323
DCCallVM* dcCallVM;
2424

2525
Interpreter(size_t stackSize)
2626
{
27-
stack = new char[stackSize];
27+
stack = new volatile char[stackSize];
2828
stackFrameStart = stack;
2929
stackFrameEnd = stack;
3030
dcCallVM = CreateDynCallVM();
@@ -121,7 +121,7 @@ struct Interpreter
121121
threadID = CurrentThreadID();
122122
}
123123

124-
void* Interpret(SpiteIR::IR* ir)
124+
volatile void* Interpret(SpiteIR::IR* ir)
125125
{
126126
SpiteIR::Function* entry = ir->entry;
127127
Initialize(ir, entry->parent);
@@ -169,23 +169,23 @@ struct Interpreter
169169
{
170170
SpiteIR::Operand& param = params->at(i);
171171
SpiteIR::Argument* arg = args.at(i);
172-
CopyValue(param.reg, arg->value.type, stackFrameStart + offset, frame);
172+
CopyValue(param.reg, arg->value.type, (void*)(stackFrameStart + offset), frame);
173173
offset += param.type->size;
174174
}
175175
}
176176

177-
void* InterpretFunction(SpiteIR::Function* func, size_t start, eastl::vector<SpiteIR::Operand>* params = nullptr)
177+
volatile void* InterpretFunction(SpiteIR::Function* func, size_t start, eastl::vector<SpiteIR::Operand>* params = nullptr)
178178
{
179179
#ifdef _INTERPRETER_EXTS
180180
RunFunctionExtensions(func, params, this);
181181
#endif
182182

183-
char* prevStackStart = stackFrameStart;
184-
char* prevStackEnd = stackFrameEnd;
183+
volatile char* prevStackStart = stackFrameStart;
184+
volatile char* prevStackEnd = stackFrameEnd;
185185
stackFrameStart = stackFrameStart + start;
186186
InterpretAllocations(func->block->allocations);
187187

188-
if (params) MoveParams(params, func->arguments, prevStackStart);
188+
if (params) MoveParams(params, func->arguments, (char*)prevStackStart);
189189

190190
InterpretBlock(func->block);
191191
stackFrameStart = prevStackStart;
@@ -204,8 +204,8 @@ struct Interpreter
204204
RunFunctionExtensions(func, &params, this);
205205
#endif
206206

207-
char* prevStackStart = stackFrameStart;
208-
char* prevStackEnd = stackFrameEnd;
207+
volatile char* prevStackStart = stackFrameStart;
208+
volatile char* prevStackEnd = stackFrameEnd;
209209
stackFrameStart = stackFrameEnd;
210210
InterpretAllocations(func->block->allocations);
211211

@@ -221,18 +221,18 @@ struct Interpreter
221221
InterpretBlock(func->block);
222222
stackFrameStart = prevStackStart;
223223
stackFrameEnd = prevStackEnd;
224-
return stackFrameStart;
224+
return (void*)stackFrameStart;
225225
}
226226

227-
inline void CopyValue(size_t src, SpiteIR::Type* type, void* dst, char* frame)
227+
inline void CopyValue(size_t src, SpiteIR::Type* type, volatile void* dst, volatile char* frame)
228228
{
229-
memcpy(dst, frame + src, type->size);
229+
memcpy((void*)dst, (void*)(frame + src), type->size);
230230
}
231231

232-
inline void CopyRegValue(SpiteIR::Operand& src, SpiteIR::Operand& dst, char* frame)
232+
inline void CopyRegValue(SpiteIR::Operand& src, SpiteIR::Operand& dst, volatile char* frame)
233233
{
234-
void* dstPtr = stackFrameStart + dst.reg;
235-
memcpy(dstPtr, frame + src.reg, dst.type->size);
234+
void* dstPtr = (void*)(stackFrameStart + dst.reg);
235+
memcpy(dstPtr, (void*)(frame + src.reg), dst.type->size);
236236
}
237237

238238
inline void InterpretInstruction(SpiteIR::Instruction& inst, SpiteIR::Label*& label)
@@ -385,7 +385,7 @@ struct Interpreter
385385
StoreOperand(src, stackFrameStart + storeInst.store.dst.reg);
386386
}
387387

388-
inline void StoreOperand(SpiteIR::Operand& src, void* dst)
388+
inline void StoreOperand(SpiteIR::Operand& src, volatile void* dst)
389389
{
390390
switch (src.kind)
391391
{
@@ -477,7 +477,7 @@ struct Interpreter
477477
inline void InterpretStorePtr(SpiteIR::Instruction& storeInst)
478478
{
479479
char* ptr = *(char**)(void*)(stackFrameStart + storeInst.store.dst.reg);
480-
char* src = stackFrameStart + storeInst.store.src.reg;
480+
char* src = (char*)(stackFrameStart + storeInst.store.src.reg);
481481
memcpy(ptr, src, storeInst.store.src.type->size);
482482
}
483483

@@ -490,14 +490,14 @@ struct Interpreter
490490

491491
inline void InterpretReference(SpiteIR::Instruction& storeInst)
492492
{
493-
void* ref = (stackFrameStart + storeInst.store.src.reg);
493+
volatile void* ref = stackFrameStart + storeInst.store.src.reg;
494494
*(size_t*)(stackFrameStart + storeInst.store.dst.reg) = (size_t)ref;
495495
}
496496

497497
inline void InterpretDereference(SpiteIR::Instruction& storeInst)
498498
{
499499
char* ptr = *(char**)(void*)(stackFrameStart + storeInst.store.src.reg);
500-
char* dst = stackFrameStart + storeInst.store.dst.reg;
500+
char* dst = (char*)(stackFrameStart + storeInst.store.dst.reg);
501501
memcpy(dst, ptr, storeInst.store.dst.type->size);
502502
}
503503

@@ -723,7 +723,7 @@ struct Interpreter
723723
paramPtrs.push_back((void*)(stackFrameStart + param.reg));
724724
}
725725

726-
CallExternalFunction(func, paramPtrs, stackFrameStart + dst, dcCallVM, this);
726+
CallExternalFunction(func, paramPtrs, (char*)(stackFrameStart + dst), dcCallVM, this);
727727
}
728728

729729
inline void InterpretCall(SpiteIR::Instruction& callInst)

Src/Lower/LowerDefinitions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ struct LowerDefinitions
324324
SpiteIR::Function* func = comp.compileFunc;
325325
SpiteIR::Instruction* store = comp.storeInst;
326326

327-
void* ret = context.interpreter->InterpretFunction(func, 0);
327+
volatile void* ret = context.interpreter->InterpretFunction(func, 0);
328328
if (store)
329329
{
330-
SpiteIR::Operand src = CreateValueOperand(ret, func->returnType);
330+
SpiteIR::Operand src = CreateValueOperand((void*)ret, func->returnType);
331331
store->store.src = src;
332332
}
333333
deferredCompiles.pop_back();
@@ -2102,7 +2102,7 @@ struct LowerDefinitions
21022102
literal.f32Literal = 0.0f;
21032103
break;
21042104
case SpiteIR::PrimitiveKind::Float:
2105-
literal.floatLiteral = 0.0f;
2105+
literal.floatLiteral = 0.0;
21062106
break;
21072107
case SpiteIR::PrimitiveKind::String:
21082108
literal.stringLiteral = context.ir->AllocateString();

0 commit comments

Comments
 (0)