JavaScript "emitlib"

Admin User, erstellt 15. März 2024
         
/**
* Modern Albufeira Prolog Interpreter
*
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
import {add, check_atom, check_nonvar, Compound,
copy_term, get_ctx, launch, make_error, deref,
check_number, exec_build, exec_unify, check_clause,
narrow_float, norm_float, make_check
} from "../../dogelog.mjs";
import {
check_element
} from "./domlib.mjs";
function test_dom_cell_clear(args) {
let at = deref(exec_build(args[0]));
check_element(at);
at.innerHTML = "";
return true;
}
function test_dom_cell_goto(args) {
let id = deref(exec_build(args[0]));
check_atom(id);
return exec_unify(args[1], document.getElementById(id));
}
function test_dom_cell_listen(args) {
let buf = get_ctx();
let at = deref(exec_build(args[0]));
check_element(at);
let type = deref(exec_build(args[1]));
check_atom(type);
let clause = deref(exec_build(args[2]));
check_clause(clause);
let flag = deref(exec_build(args[3]));
at.addEventListener(type, function (event) {launch(clause, buf, [event])}, flag);
return true;
}
function test_dom_prevent_default(args) {
let event = deref(exec_build(args[0]));
check_event(event);
event.preventDefault();
return true;
}
function test_dom_stop_propagation(args) {
let event = deref(exec_build(args[0]));
check_event(event);
event.stopPropagation();
return true;
}
function check_event(beta) {
if (!(beta instanceof Event)) {
check_nonvar(beta);
beta = copy_term(beta);
throw make_error(new Compound("type_error", ["event", beta]));
}
}
function test_ir_float_current(args) {
let obj = deref(exec_build(args[0]));
let key = deref(exec_build(args[1]));
check_atom(key);
let res = obj[key];
if (res === undefined)
return false;
check_number(res);
res = norm_float(narrow_float(res));
return exec_unify(args[2], res);
}
function test_ir_float_set(args) {
let obj = deref(exec_build(args[0]));
let key = deref(exec_build(args[1]));
check_atom(key);
let value = deref(exec_build(args[2]));
check_number(value);
obj[key] = narrow_float(value);
return true;
}
export function main() {
add("dom_cell_clear", 1, make_check(test_dom_cell_clear));
add("dom_cell_goto", 2, make_check(test_dom_cell_goto));
add("dom_cell_listen", 4, make_check(test_dom_cell_listen));
add("dom_prevent_default", 1, make_check(test_dom_prevent_default));
add("dom_stop_propagation", 1, make_check(test_dom_stop_propagation));
add("ir_float_current", 3, make_check(test_ir_float_current));
add("ir_float_set", 3, make_check(test_ir_float_set));
}