Java "domlib"

Admin User, created Mar 04. 2024
         
package liblet.misc;
import liblet.util.auxlib;
import nova.Machine;
import nova.Runtime;
import nova.Special;
import nova.Store;
import java.io.IOException;
import java.util.HashMap;
public final class domlib {
private static boolean test_ir_is_sink(Object[] args) {
Object obj = Machine.deref(Machine.exec_build(args[0]));
return (obj instanceof Runtime.Sink);
}
private static boolean test_ir_data_current(Object[] args) {
Object obj = Machine.deref(Machine.exec_build(args[0]));
Runtime.check_sink(obj);
return Machine.exec_unify(args[1], ((Runtime.Sink) obj).data);
}
private static boolean test_ir_flush_buffer(Object[] args) {
Object obj = Machine.deref(Machine.exec_build(args[0]));
Runtime.check_sink(obj);
Runtime.flush_buffer((Runtime.Sink) obj);
return true;
}
private static boolean test_ir_indent_current(Object[] args) {
Object obj = Machine.deref(Machine.exec_build(args[0]));
Runtime.check_sink(obj);
return Machine.exec_unify(args[1], Integer.valueOf(((Runtime.Sink) obj).indent));
}
private static boolean test_ir_indent_set(Object[] args) {
Object obj = Machine.deref(Machine.exec_build(args[0]));
Runtime.check_sink(obj);
Object alpha = Machine.deref(Machine.exec_build(args[1]));
Special.check_integer(alpha);
if (Special.is_bigint(alpha))
throw Machine.make_error(new Store.Compound("representation_error",
new Object[]{"int"}));
((Runtime.Sink) obj).indent = ((Integer) alpha).intValue();
return true;
}
private static boolean test_dom_output_new(Object[] args) {
Object obj = Machine.deref(Machine.exec_build(args[0]));
Runtime.check_sink(obj);
Runtime.Sink dst = new Runtime.Sink();
dst.data = obj;
dst.send = domlib::dom_send;
dst.release = domlib::dom_release;
dst.notify = domlib::dom_notify;
return Machine.exec_unify(args[1], dst);
}
private static void dom_send(Object data, StringBuilder buf) {
String text = auxlib.xml_escape(buf.toString());
Runtime.put_atom((Runtime.Sink) data, text);
}
private static void dom_notify(Object data) {
Runtime.flush((Runtime.Sink) data);
}
private static void dom_release(Object data) {
Runtime.close(data);
}
private static boolean test_dom_error_new(Object[] args) {
Object obj = Machine.deref(Machine.exec_build(args[0]));
Runtime.check_sink(obj);
Runtime.Sink dst = new Runtime.Sink();
dst.data = obj;
dst.send = domlib::dom_alert;
dst.release = domlib::dom_release;
dst.notify = domlib::dom_notify;
return Machine.exec_unify(args[1], dst);
}
private static void dom_alert(Object data, StringBuilder buf) {
String text = "<span style='color: #A52A2A'>" + auxlib.xml_escape(buf.toString()) + "</span>";
Runtime.put_atom((Runtime.Sink) data, text);
}
public static void main() {
Store.add("ir_is_sink", 1, Special.make_check(domlib::test_ir_is_sink));
Store.add("ir_data_current", 2, Special.make_check(domlib::test_ir_data_current));
Store.add("ir_flush_buffer", 1, Special.make_check(domlib::test_ir_flush_buffer));
Store.add("ir_indent_current", 2, Special.make_check(domlib::test_ir_indent_current));
Store.add("ir_indent_set", 2, Special.make_check(domlib::test_ir_indent_set));
Store.add("dom_output_new", 2, Special.make_check(domlib::test_dom_output_new));
Store.add("dom_error_new", 2, Special.make_check(domlib::test_dom_error_new));
}
}