M7 Script FAQ
Version & Development Status
M7 is currently in a prototype / proof-of-concept stage. The broad strokes are implemented, but the language still requires further refinement. Features will continue to be fleshed out as development progresses.
General Questions
Is M7 object-oriented?
Not yet. OOP is a planned feature for future versions. However, users can simulate object-like behavior using closures and hashes.
Example:
function createUser(string name, int age): hash {
return {
name: name,
age: age,
greet: function(): string {
return `Hello, my name is ${name}.`;
}
};
}
var user = createUser("Alice", 30);
print(user.greet()); // Outputs: Hello, my name is Alice.
Technical Questions
How does M7 handle variable scoping?
M7 uses lexical scoping, meaning variables are only accessible within their defining block or function. Blocks create new scopes, and variables cannot be accessed outside them.
Example:
if (true) {
var x = 10;
print(x); // OK
}
print(x); // ERROR: x is not accessible outside the block
Does M7 support exceptions?
Yes, exceptions are specced out, but not yet implemented. They currently compile but are ignored. Exception handling will be fully implemented before the language exits its prototype phase.
How does M7 handle memory management?
M7 uses reference counting combined with a mark-sweep approach. It checks whether a variable is still reachable before freeing memory, ensuring automatic cleanup of unused objects.
Users may manually trigger garbage collection using:
collect_garbage();
– Runs garbage collection to clean up unreachable objects.heap_destroy(ref);
– Explicitly frees a specific object from the heap.
Example:
var obj = { key: "value" };
heap_destroy(obj); // Manually free memory
collect_garbage(); // Run full cleanup
Does M7 have debugging tools?
Yes, M7 provides built-in debugging functions:
dump_workspace()
– Prints the current execution environment.varInfo(ref)
– Displays type and memory reference information for a variable.
What are the known limitations of M7?
- Parser Performance: Until the parser is optimized, compiling complex programs is slow. However, once an AST is generated, interpretation is efficient.
- Control Statements: While most structures are implemented, some control statements are incomplete but will be finalized shortly.
- Parsing Completeness: The parser fully constructs the entire parse tree, including unfinished features. This means programs can be fully parsed, but some features are not yet executable because the AST interpreter is still incomplete.
Can I save compiled stages for later execution?
Yes! Any stage of execution can be saved and used later. For example, you can compile code into an AST, save it, and reload it later for execution.
var ast = compileToAST("print(5 + 5);");
saveToFile("program.ast", ast);
var loadedAST = loadFromFile("program.ast");
interpretAST(loadedAST);
Customization & Embedding
Can I override built-in functions?
Yes. M7 allows users to override or redefine built-in functions dynamically. This is especially useful for embedding M7 into other languages or sandboxed environments.
Example:
function print(var message) {
original_print("[LOG]: " . message);
}
print("Hello"); // Outputs: [LOG]: Hello
Can I extend M7 with native libraries?
Yes, when running in standalone mode, users can load shared libraries (.so
/ .dll
) written in C.
Example:
loadLibrary("m7_extensions.so");
callExternal("customFunction", "Hello, World!");
Can different users have different sets of built-in functions?
Yes. M7 can provide different built-in libraries based on user access levels, allowing for sandboxed environments while maintaining flexibility and security.
Embedding M7 Into Other Languages
How will M7 be integrated into other languages?
M7 will be integrated using FFI (Foreign Function Interface) for Python, Perl, and PHP.
JavaScript Integration
- The initial implementation will likely be written as a native interpreter in JavaScript.
- However, I may later transition to WebAssembly and platforms like Bun or similar tools for better performance.
- Personal Take: I generally like JavaScript, so my plan is to primarily use it for writing dynamic configuration files, rather than reinventing the wheel by implementing M7 entirely in JS.
Planned Features
Will M7 support Just-In-Time (JIT) Compilation?
JIT compilation is a planned feature that will allow frequently used code to be compiled at runtime for faster execution.
Will M7 support multithreading?
Future versions may introduce multithreading or coroutines to allow concurrent execution.
Will there be built-in networking features?
I will provide networking features as time permits, but this can be enabled by exposing network functionality via built-in functions yourself.
This FAQ provides answers to common questions about M7 Script's design, execution model, customization, and future development.