Giter Site home page Giter Site logo

dreamycecil / lilacdragonscript Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.44 MB

A self-made interpreter for a simple scripting language with a JavaScript-like syntax. [Work In Progress]

License: MIT License

C++ 84.88% C 9.02% JavaScript 6.09%
compiler interpreter language parser programming-language scripting-language

lilacdragonscript's People

Stargazers

 avatar

Watchers

 avatar

lilacdragonscript's Issues

Fix memory leaks related to script values.

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 all bool variables in classes with masks.

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 bools 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);
};

Add functions for reading script files and reading/writing into data streams.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.