dreamycecil / lilacdragonscript Goto Github PK
View Code? Open in Web Editor NEWA self-made interpreter for a simple scripting language with a JavaScript-like syntax. [Work In Progress]
License: MIT License
A self-made interpreter for a simple scripting language with a JavaScript-like syntax. [Work In Progress]
License: MIT License
CLdsValue
/ ILdsValueBase
don't get cleaned up properly somewhere, leaving many values somewhere in memory during execution, eventually overflowing it.
During debugging, it always crashes on memory overflow within the ILdsValueBase::MakeCopy
method.
It happens specifically on the line inside the loop of this kind of script, at the aArray[i]
(accessor in the BinaryOp) part:
var aArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] * 1000; // populate array with 10000 repeating elements
var ctElements = aArray.count;
var iResult = 0;
// add each array entry to the resulting number
for (var i = 0; i < ctElements; i++) {
iResult += aArray[i];
}
This script is awfully slow while debugging, so it's better to allocate ~2GB of memory on launch, so it overflows faster.
Replace separate bool
variables in classes with bit masks to save space.
It's also more efficient to write a single char
mask instead of separate bool
values as char
. There aren't many different bool
s in each class anyway.
Example in CLdsValueRef
:
// Remove these
bool vr_bConst; // reference is a constant variable (for structure variables)
bool vr_bGlobal; // referencing a global variable (from CLdsScriptEngine::_mapLdsVariables; for I/O)
// Replace with this
enum ELdsValueRefFlags {
VRF_CONST = (1 << 0), // reference is a constant variable (for structure variables)
VRF_GLOBAL = (1 << 1), // referencing a global variable (from CLdsScriptEngine::_mapLdsVariables; for I/O)
}
char vr_ubFlags;
inline bool IsConst(void) {
return (vr_ubFlags & VRF_CONST);
};
inline bool IsGlobal(void) {
return (vr_ubFlags & VRF_GLOBAL);
};
Class CLdsScriptEngine
:
bool (*_pLdsLoadScript)(const char *strFile, string &strScript)
- for reading script files. Returns false if failed to load.
void (*_pLdsWriteStream)(STREAM, void *pData, const unsigned long &iSize)
- for writing some data of a certain size into a stream.
void (*_pLdsReadStream)(STREAM, void *pData, const unsigned long &iSize)
- for reading data of a certain size into the pData
from a stream.
All functions point to LDS-implemented ones by default using standard methods.
Note: STREAM
can be some common data stream class, or void *
and converted to needed class within the function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.