finish remove?

This commit is contained in:
2025-06-15 05:15:51 -05:00
parent 108c39d22d
commit 0702e3495d
9 changed files with 136 additions and 986 deletions

View File

@@ -1,4 +1,4 @@
var N = 10000000;
var N = 1000000;
var num = 0;
for (var i = 0; i < N; i ++) {
var x = 2 * $_.random();

View File

@@ -162,14 +162,6 @@ else
endif
# Try to find system-installed qjs-layout first
qjs_layout_dep = dependency('qjs-layout', static: true, required: false)
if not qjs_layout_dep.found()
message('⚙ System qjs-layout not found, building subproject...')
deps += dependency('qjs-layout', static:true)
else
deps += qjs_layout_dep
endif
miniz_dep = dependency('miniz', static: true, required: false)
if not miniz_dep.found()
message('⚙ System miniz not found, building subproject...')
@@ -178,14 +170,6 @@ else
deps += miniz_dep
endif
libuv_dep = dependency('libuv', static: true, required: false)
if not libuv_dep.found()
message('⚙ System libuv not found, building subproject...')
deps += dependency('libuv', static:true, fallback: ['libuv', 'libuv_dep'])
else
deps += libuv_dep
endif
# Try to find system-installed physfs first
physfs_dep = dependency('physfs', static: true, required: false)
if not physfs_dep.found()

View File

@@ -4,13 +4,6 @@ Object.mixin = function (target, source) {
return target;
};
Object.mixin[cell.DOC] = `Copy all property descriptors from 'source' into 'target'.
:param target: The object that will receive properties.
:param source: The object whose properties are to be copied.
:return: The updated 'target' object.
`;
Object.defineProperty(Object.prototype, "mixin", {
value: function mixin(obj) {
if (typeof obj === "string") obj = use(obj);
@@ -18,13 +11,6 @@ Object.defineProperty(Object.prototype, "mixin", {
},
});
(Object.prototype.mixin)[cell.DOC] = `Mix properties from 'obj' into the current object. If 'obj' is a string,
it first calls 'use(obj)' to retrieve the object.
:param obj: The object (or string reference to an object) to mix in.
:return: None
`;
/* STRING DEFS */
Object.defineProperty(String.prototype, "rm", {
value: function (index, endidx = index + 1) {
@@ -32,14 +18,6 @@ Object.defineProperty(String.prototype, "rm", {
},
});
(String.prototype.rm)[cell.DOC] = `Remove characters from this string between 'index' (inclusive)
and 'endidx' (exclusive). If 'endidx' is omitted, it defaults to 'index + 1'.
:param index: The starting index to remove.
:param endidx: The ending index (exclusive).
:return: A new string with the specified characters removed.
`;
Object.defineProperty(String.prototype, "tolast", {
value: function (val) {
var idx = this.lastIndexOf(val);
@@ -48,12 +26,6 @@ Object.defineProperty(String.prototype, "tolast", {
},
});
(String.prototype.tolast)[cell.DOC] = `Return the substring of this string up to the last occurrence of 'val'.
If 'val' is not found, the entire string is returned.
:param val: The substring to locate from the end.
:return: A substring up to the last occurrence of 'val'.
`;
Object.defineProperty(String.prototype, "dir", {
value: function () {
@@ -62,11 +34,6 @@ Object.defineProperty(String.prototype, "dir", {
},
});
(String.prototype.dir)[cell.DOC] = `Return everything before the last slash ('/') in the string.
If no slash is found, return an empty string.
:return: The directory portion of the path.
`;
Object.defineProperty(String.prototype, "next", {
value: function (char, from) {
@@ -89,14 +56,6 @@ Object.defineProperty(String.prototype, "next", {
},
});
(String.prototype.next)[cell.DOC] = `Search for the next occurrence of 'char' in this string, starting at 'from'.
If 'char' is an array, any of those characters qualifies. Return the matching index,
or -1 if none is found.
:param char: A character (or array of characters) to locate.
:param from: The index to start from.
:return: The index of the next occurrence, or -1 if not found.
`;
Object.defineProperty(String.prototype, "prev", {
value: function (char, from, count = 0) {
@@ -115,15 +74,6 @@ Object.defineProperty(String.prototype, "prev", {
},
});
(String.prototype.prev)[cell.DOC] = `Search for the previous occurrence of 'char' before index 'from'.
If 'count' is greater than 1, skip multiple occurrences going backward.
Return the found index or 0 if not found.
:param char: The character to locate.
:param from: The index to start from (defaults to the end of the string).
:param count: How many occurrences to skip backward (default 0).
:return: The index of the previous occurrence, or 0 if not found.
`;
Object.defineProperty(String.prototype, "strip_ext", {
value: function () {
@@ -131,11 +81,6 @@ Object.defineProperty(String.prototype, "strip_ext", {
},
});
(String.prototype.strip_ext)[cell.DOC] = `Return the string up to (but not including) the last '.' character.
If '.' is not found, the entire string is returned.
:return: The string without its last extension.
`;
Object.defineProperty(String.prototype, "ext", {
value: function () {
@@ -143,11 +88,6 @@ Object.defineProperty(String.prototype, "ext", {
},
});
(String.prototype.ext)[cell.DOC] = `Return the substring after the last '.' in this string.
If '.' is not found, return an empty string.
:return: The file extension or an empty string.
`;
Object.defineProperty(String.prototype, "up_path", {
value: function () {
@@ -158,10 +98,6 @@ Object.defineProperty(String.prototype, "up_path", {
},
});
(String.prototype.up_path)[cell.DOC] = `Go up one directory level from the current path, preserving the file name at the end.
:return: A new path string one directory up, with the base filename preserved.
`;
Object.defineProperty(String.prototype, "fromlast", {
value: function (val) {
@@ -171,12 +107,6 @@ Object.defineProperty(String.prototype, "fromlast", {
},
});
(String.prototype.fromlast)[cell.DOC] = `Return the substring that appears after the last occurrence of 'val'.
If 'val' is not found, an empty string is returned.
:param val: The substring to locate.
:return: The substring after the last occurrence of 'val'.
`;
Object.defineProperty(String.prototype, "tofirst", {
value: function (val) {
@@ -186,12 +116,6 @@ Object.defineProperty(String.prototype, "tofirst", {
},
});
(String.prototype.tofirst)[cell.DOC] = `Return the substring from the start of this string up to the first occurrence
of 'val' (excluded). If 'val' is not found, the entire string is returned.
:param val: The substring to locate.
:return: A substring up to the first occurrence of 'val'.
`;
Object.defineProperty(String.prototype, "fromfirst", {
value: function (val) {
@@ -201,12 +125,6 @@ Object.defineProperty(String.prototype, "fromfirst", {
},
});
(String.prototype.fromfirst)[cell.DOC] = `Return the substring after the first occurrence of 'val'.
If 'val' is not found, the entire string is returned.
:param val: The substring to locate.
:return: The substring after 'val', or the entire string if 'val' not found.
`;
Object.defineProperty(String.prototype, "name", {
value: function () {
@@ -216,12 +134,6 @@ Object.defineProperty(String.prototype, "name", {
},
});
(String.prototype.name)[cell.DOC] = `Return the "name" portion of the path without extension.
If no slash is found, it's up to the last '.' in the entire string.
If there is a slash, it's from the last slash up to (but not including) the last '.'.
:return: The name portion of the path without extension.
`;
Object.defineProperty(String.prototype, "set_name", {
value: function (name) {
@@ -230,12 +142,6 @@ Object.defineProperty(String.prototype, "set_name", {
},
});
(String.prototype.set_name)[cell.DOC] = `Set the base name (excluding extension) of the path to 'name', preserving
the original directory and extension.
:param name: The new name to use.
:return: A new path string with the updated name.
`;
Object.defineProperty(String.prototype, "base", {
value: function () {
@@ -243,11 +149,6 @@ Object.defineProperty(String.prototype, "base", {
},
});
(String.prototype.base)[cell.DOC] = `Return the portion of this string after the last '/' character.
If no '/' is present, the entire string is returned.
:return: The base name of the path.
`;
Object.defineProperty(String.prototype, "updir", {
value: function () {
@@ -257,11 +158,6 @@ Object.defineProperty(String.prototype, "updir", {
},
});
(String.prototype.updir)[cell.DOC] = `Go up one directory from the current path, removing the last directory name.
If the path ends with a slash, remove it first. Then remove the final directory.
:return: A new string representing one directory level up.
`;
/* ARRAY DEFS */
Object.defineProperty(Array.prototype, "filter!", {
@@ -276,13 +172,6 @@ Object.defineProperty(Array.prototype, "filter!", {
},
});
(Array.prototype["filter!"])[cell.DOC] = `Perform an in-place filter of this array using the provided callback 'fn'.
Any element for which 'fn' returns a falsy value is removed. The array is modified
and then returned.
:param fn: A callback function(element, index, array) => boolean.
:return: The filtered (modified) array.
`;
Object.defineProperty(Array.prototype, "delete", {
value: function(item) {
@@ -292,12 +181,6 @@ Object.defineProperty(Array.prototype, "delete", {
}
});
(Array.prototype.delete)[cell.DOC] = `Remove the first occurrence of 'item' from the array, if it exists.
Returns undefined.
:param item: The item to remove.
:return: undefined
`;
Object.defineProperty(Array.prototype, "copy", {
value: function () {
@@ -309,11 +192,6 @@ Object.defineProperty(Array.prototype, "copy", {
},
});
(Array.prototype.copy)[cell.DOC] = `Return a deep copy of this array by applying 'deep_copy' to each element.
The resulting array is entirely new.
:return: A new array that is a deep copy of the original.
`;
Object.defineProperty(Array.prototype, "equal", {
value: function equal(b) {
@@ -329,12 +207,6 @@ Object.defineProperty(Array.prototype, "equal", {
},
});
(Array.prototype.equal)[cell.DOC] = `Check if this array and array 'b' have the same elements in the same order.
If they are of different lengths, return false. Otherwise compare them via JSON.
:param b: Another array to compare against.
:return: True if they match, false otherwise.
`;
Object.defineProperty(Array.prototype, "last", {
value: function () {
@@ -342,10 +214,6 @@ Object.defineProperty(Array.prototype, "last", {
},
});
(Array.prototype.last)[cell.DOC] = `Return the last element of this array. If the array is empty, returns undefined.
:return: The last element of the array, or undefined if empty.
`;
Object.defineProperty(Array.prototype, "wrapped", {
value: function (x) {
@@ -355,12 +223,6 @@ Object.defineProperty(Array.prototype, "wrapped", {
},
});
(Array.prototype.wrapped)[cell.DOC] = `Return a copy of the array with the first 'x' elements appended to the end.
Does not modify the original array.
:param x: The number of leading elements to re-append.
:return: A new array with the leading elements wrapped to the end.
`;
Object.defineProperty(Array.prototype, "wrap_idx", {
value: function (x) {
@@ -371,12 +233,6 @@ Object.defineProperty(Array.prototype, "wrap_idx", {
},
});
(Array.prototype.wrap_idx)[cell.DOC] = `Wrap the integer 'x' around this array's length, ensuring the resulting index
lies within [0, this.length - 1].
:param x: The index to wrap.
:return: A wrapped index within this array's bounds.
`;
Object.defineProperty(Array.prototype, "mirrored", {
value: function (x) {
@@ -387,9 +243,3 @@ Object.defineProperty(Array.prototype, "mirrored", {
},
});
(Array.prototype.mirrored)[cell.DOC] = `Return a new array that appends a reversed copy (excluding the last element)
of itself to the end. For example, [1,2,3] -> [1,2,3,2,1]. If the array has length
<= 1, a copy of it is returned directly.
:return: A new "mirrored" array.
`;

View File

@@ -248,6 +248,7 @@ globalThis.use = function use(file, ...args) {
return ret
}
globalThis.json = use('json')
var time = use('time')
var st_now = time.number()
@@ -424,7 +425,7 @@ $_.connection[cell.DOC] = "The connection function takes a callback function, an
var peers = {}
var id_address = {}
var peer_queue = new WeakMap()
var peer_queue = new Map()
var portal = undefined
var portal_fn = undefined

View File

@@ -870,7 +870,80 @@ int main(int argc, char **argv)
int profile_enabled = 0;
int script_start = 1;
/* Check for --profile flag first */
/* Check for --script flag - execute script directly without engine */
if (argc > 2 && strcmp(argv[1], "--script") == 0) {
/* Read and execute the script file */
FILE *f = fopen(argv[2], "rb");
if (!f) {
perror("fopen");
return 1;
}
fseek(f, 0, SEEK_END);
long size = ftell(f);
if (size < 0) {
perror("ftell");
fclose(f);
return 1;
}
char *script = malloc(size + 1);
if (!script) {
perror("malloc");
fclose(f);
return 1;
}
rewind(f);
if (fread(script, 1, size, f) != size) {
perror("fread");
free(script);
fclose(f);
return 1;
}
fclose(f);
script[size] = '\0';
/* Create minimal JS runtime */
JSRuntime *rt = JS_NewRuntime();
JSContext *js = JS_NewContextRaw(rt);
/* Add basic intrinsics */
JS_AddIntrinsicBaseObjects(js);
JS_AddIntrinsicEval(js);
JS_AddIntrinsicRegExp(js);
JS_AddIntrinsicJSON(js);
JS_AddIntrinsicMapSet(js);
JS_AddIntrinsicProxy(js);
cell_rt *prt = malloc(sizeof(*prt));
JS_SetContextOpaque(js, prt);
/* Load FFI functions */
ffi_load(js);
/* Execute the script */
JSValue result = JS_Eval(js, script, size, argv[2], JS_EVAL_FLAG_STRICT);
free(script);
/* Check for exceptions */
if (JS_IsException(result)) {
JSValue exp = JS_GetException(js);
const char *str = JS_ToCString(js, exp);
if (str) {
fprintf(stderr, "Exception: %s\n", str);
JS_FreeCString(js, str);
}
JS_FreeValue(js, exp);
}
JS_FreeValue(js, result);
JS_FreeContext(js);
JS_FreeRuntime(rt);
return 0;
}
/* Check for --profile flag */
if (argc > 1 && strcmp(argv[1], "--profile") == 0) {
profile_enabled = 1; script_start = 2;
}

View File

@@ -1530,7 +1530,6 @@ js_##NAME = JS_NewObject(js); \
JS_SetPropertyFunctionList(js, js_##NAME, js_##NAME##_funcs, countof(js_##NAME##_funcs)); \
JS_SetPrototype(js, js_##NAME, PARENT); \
JSValue js_layout_use(JSContext *js);
JSValue js_miniz_use(JSContext *js);
JSValue js_num_use(JSContext *js);
@@ -1621,7 +1620,6 @@ void ffi_load(JSContext *js)
arrput(rt->module_registry, MISTLINE(graphics));
arrput(rt->module_registry, MISTLINE(video));
arrput(rt->module_registry, MISTLINE(soloud));
arrput(rt->module_registry, MISTLINE(layout));
// arrput(rt->module_registry, MISTLINE(imgui));
arrput(rt->module_registry, ((ModuleEntry){"camera", js_camera_use}));

View File

@@ -69,7 +69,6 @@ DEF( push_i32, 5, 0, 1, i32)
DEF( push_const, 5, 0, 1, const)
DEF( fclosure, 5, 0, 1, const) /* must follow push_const */
DEF(push_atom_value, 5, 0, 1, atom)
DEF( private_symbol, 5, 0, 1, atom)
DEF( undefined, 1, 0, 1, none)
DEF( null, 1, 0, 1, none)
DEF( push_this, 1, 0, 1, none) /* only used at the start of a function */
@@ -113,7 +112,6 @@ DEF( check_ctor, 1, 0, 0, none)
DEF( init_ctor, 1, 0, 1, none)
DEF( check_brand, 1, 2, 2, none) /* this_obj func -> this_obj func */
DEF( add_brand, 1, 2, 0, none) /* this_obj home_obj -> */
DEF( return_async, 1, 1, 0, none)
DEF( throw, 1, 1, 0, none)
DEF( throw_error, 6, 0, 0, atom_u8)
DEF( eval, 5, 1, 1, npop_u16) /* func args... -> ret_val */
@@ -121,7 +119,6 @@ DEF( apply_eval, 3, 2, 1, u16) /* func array -> ret_eval */
DEF( regexp, 1, 2, 1, none) /* create a RegExp object from the pattern and a
bytecode string */
DEF( get_super, 1, 1, 1, none)
DEF( import, 1, 2, 1, none) /* dynamic module import */
DEF( check_var, 5, 0, 1, atom) /* check if a variable exists */
DEF( get_var_undef, 5, 0, 1, atom) /* push undefined if the variable does not exist */
@@ -204,20 +201,13 @@ DEF( make_var_ref, 5, 0, 2, atom)
DEF( for_in_start, 1, 1, 1, none)
DEF( for_of_start, 1, 1, 3, none)
DEF(for_await_of_start, 1, 1, 3, none)
DEF( for_in_next, 1, 1, 3, none)
DEF( for_of_next, 2, 3, 5, u8)
DEF(for_await_of_next, 1, 3, 4, none) /* iter next catch_offset -> iter next catch_offset obj */
DEF(iterator_check_object, 1, 1, 1, none)
DEF(iterator_get_value_done, 1, 2, 3, none) /* catch_offset obj -> catch_offset value done */
DEF( iterator_close, 1, 3, 0, none)
DEF( iterator_next, 1, 4, 4, none)
DEF( iterator_call, 2, 4, 5, u8)
DEF( initial_yield, 1, 0, 0, none)
DEF( yield, 1, 1, 2, none)
DEF( yield_star, 1, 1, 2, none)
DEF(async_yield_star, 1, 1, 2, none)
DEF( await, 1, 1, 1, none)
/* arithmetic/logic operations */
DEF( neg, 1, 1, 1, none)

File diff suppressed because it is too large Load Diff

View File

@@ -340,9 +340,6 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int64_t d)
#define JS_EVAL_FLAG_COMPILE_ONLY (1 << 5)
/* don't include the stack frames before this eval in the Error() backtraces */
#define JS_EVAL_FLAG_BACKTRACE_BARRIER (1 << 6)
/* allow top-level await in normal script. JS_Eval() returns a
promise. Only allowed with JS_EVAL_TYPE_GLOBAL */
#define JS_EVAL_FLAG_ASYNC (1 << 7)
typedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);
@@ -404,7 +401,6 @@ void JS_AddIntrinsicJSON(JSContext *ctx);
void JS_AddIntrinsicProxy(JSContext *ctx);
void JS_AddIntrinsicMapSet(JSContext *ctx);
void JS_AddIntrinsicTypedArrays(JSContext *ctx);
void JS_AddIntrinsicWeakRef(JSContext *ctx);
JSValue js_string_codePointRange(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv);
@@ -1103,8 +1099,6 @@ typedef struct js_debug {
void js_debug_info(JSContext *js, JSValue fn, js_debug *dbg);
void free_js_debug_info(JSContext *js, js_debug *dbg);
JSValue js_newsymbol(JSContext *js, const char *desc, int global);
typedef void (*js_hook)(JSContext*, JSValue);
#define JS_HOOK_CALL 0
#define JS_HOOK_RET 1