Bob/tests.bob
Bobby Lucero 3138f6fb92 Various changes, again. Updated extension. Added classes, super, this, polymorphism.
Runtime: add method dispatch for array/string/dict/number (.len, .push, .pop, .keys, .values, .has, .toInt)
Stdlib: delete global len/push/pop/keys/values/has
Tests/docs/examples: migrate to method style; add tests/test_builtin_methods_style.bob
All tests pass
Breaking: global len/push/pop/keys/values/has removed; use methods instead
Parser/AST: add class/extends/extension/super, field initializers
Runtime: shared methods with this injection; classParents/classTemplates; super resolution; ownerClass/currentClass; extension lookup order
Builtins: method dispatch for array/string/dict/number (.len/.push/.pop/.keys/.values/.has/.toInt); remove global forms
Tests/docs/examples: add/refresh for classes, inheritance, super, polymorphism; migrate to method style; all tests pass
VS Code extension: update grammar/readme/snippets for new features
2025-08-10 22:44:46 -04:00

80 lines
2.1 KiB
Plaintext

// var a = [];
// for(var i = 0; i < 1000000; i++){
// print(i);
// // Create nested structures with functions at different levels
// if (i % 4 == 0) {
// // Nested array with function
// push(a, [
// func(){print("Array nested func i=" + i); return i;},
// [func(){return "Deep array func " + i;}],
// i
// ]);
// } else if (i % 4 == 1) {
// // Nested dict with function
// push(a, {
// "func": func(){print("Dict func i=" + i); return i;},
// "nested": {"deepFunc": func(){return "Deep dict func " + i;}},
// "value": i
// });
// } else if (i % 4 == 2) {
// // Mixed nested array/dict with functions
// push(a, [
// {"arrayInDict": func(){return "Mixed " + i;}},
// [func(){return "Array in array " + i;}, {"more": func(){return i;}}],
// func(){print("Top level in mixed i=" + i); return i;}
// ]);
// } else {
// // Simple function (original test case)
// push(a, func(){print("Simple func i=" + i); return toString(i);});
// }
// }
// print("Before: " + len(a));
// print("Memory usage: " + memoryUsage() + " MB");
// // Test different types of nested function calls
// a[3691](); // Simple function
// if (len(a[3692]) > 0) {
// a[3692][0](); // Nested array function
// }
// if (a[3693]["func"]) {
// a[3693]["func"](); // Nested dict function
// }
// //print(a);
// //writeFile("array_contents.txt", toString(a));
// print("Array contents written to array_contents.txt");
// print("Memory before cleanup: " + memoryUsage() + " MB");
// input("Press any key to free memory");
// a = none;
// print("Memory after cleanup: " + memoryUsage() + " MB");
// input("waiting...");
class Test {
func init() {
print("Test init" + this.a);
}
var a = 10;
func test() {
//print(a);
print(this.a);
}
}
var t = Test();
t.test();
extension number{
func negate(){
return -this;
}
}
print(69.negate());