Compare commits
7 Commits
js-rm-coer
...
js-op
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dafcbaa4d4 | ||
|
|
1bc34bb99c | ||
|
|
8ac78e0be6 | ||
|
|
dca3ede464 | ||
|
|
42087910ab | ||
|
|
c581935fd8 | ||
|
|
632b038561 |
@@ -67,11 +67,11 @@ function Sun() {
|
|||||||
var bodies = Array(Sun(), Jupiter(), Saturn(), Uranus(), Neptune());
|
var bodies = Array(Sun(), Jupiter(), Saturn(), Uranus(), Neptune());
|
||||||
|
|
||||||
function offsetMomentum() {
|
function offsetMomentum() {
|
||||||
let px = 0;
|
var px = 0;
|
||||||
let py = 0;
|
var py = 0;
|
||||||
let pz = 0;
|
var pz = 0;
|
||||||
var size = bodies.length;
|
var size = bodies.length;
|
||||||
for (let i = 0; i < size; i++) {
|
for (var i = 0; i < size; i++) {
|
||||||
var body = bodies[i];
|
var body = bodies[i];
|
||||||
var mass = body.mass;
|
var mass = body.mass;
|
||||||
px += body.vx * mass;
|
px += body.vx * mass;
|
||||||
@@ -86,14 +86,14 @@ function offsetMomentum() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function advance(dt) {
|
function advance(dt) {
|
||||||
var size = bodies.length;
|
def size = bodies.length;
|
||||||
|
|
||||||
for (let i = 0; i < size; i++) {
|
for (var i = 0; i < size; i++) {
|
||||||
var bodyi = bodies[i];
|
var bodyi = bodies[i];
|
||||||
let vxi = bodyi.vx;
|
var vxi = bodyi.vx;
|
||||||
let vyi = bodyi.vy;
|
var vyi = bodyi.vy;
|
||||||
let vzi = bodyi.vz;
|
var vzi = bodyi.vz;
|
||||||
for (let j = i + 1; j < size; j++) {
|
for (var j = i + 1; j < size; j++) {
|
||||||
var bodyj = bodies[j];
|
var bodyj = bodies[j];
|
||||||
var dx = bodyi.x - bodyj.x;
|
var dx = bodyi.x - bodyj.x;
|
||||||
var dy = bodyi.y - bodyj.y;
|
var dy = bodyi.y - bodyj.y;
|
||||||
@@ -117,7 +117,7 @@ function advance(dt) {
|
|||||||
bodyi.vz = vzi;
|
bodyi.vz = vzi;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < size; i++) {
|
for (var i = 0; i < size; i++) {
|
||||||
var body = bodies[i];
|
var body = bodies[i];
|
||||||
body.x += dt * body.vx;
|
body.x += dt * body.vx;
|
||||||
body.y += dt * body.vy;
|
body.y += dt * body.vy;
|
||||||
@@ -126,16 +126,16 @@ function advance(dt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function energy() {
|
function energy() {
|
||||||
let e = 0;
|
var e = 0;
|
||||||
var size = bodies.length;
|
var size = bodies.length;
|
||||||
|
|
||||||
for (let i = 0; i < size; i++) {
|
for (var i = 0; i < size; i++) {
|
||||||
var bodyi = bodies[i];
|
var bodyi = bodies[i];
|
||||||
|
|
||||||
e += 0.5 * bodyi.mass * ( bodyi.vx * bodyi.vx +
|
e += 0.5 * bodyi.mass * ( bodyi.vx * bodyi.vx +
|
||||||
bodyi.vy * bodyi.vy + bodyi.vz * bodyi.vz );
|
bodyi.vy * bodyi.vy + bodyi.vz * bodyi.vz );
|
||||||
|
|
||||||
for (let j = i + 1; j < size; j++) {
|
for (var j = i + 1; j < size; j++) {
|
||||||
var bodyj = bodies[j];
|
var bodyj = bodies[j];
|
||||||
var dx = bodyi.x - bodyj.x;
|
var dx = bodyi.x - bodyj.x;
|
||||||
var dy = bodyi.y - bodyj.y;
|
var dy = bodyi.y - bodyj.y;
|
||||||
@@ -154,8 +154,39 @@ offsetMomentum();
|
|||||||
|
|
||||||
log.console(`n = ${n}`)
|
log.console(`n = ${n}`)
|
||||||
log.console(energy().toFixed(9))
|
log.console(energy().toFixed(9))
|
||||||
for (let i = 0; i < n; i++)
|
for (var i = 0; i < n; i++)
|
||||||
advance(0.01);
|
advance(0.01);
|
||||||
log.console(energy().toFixed(9))
|
log.console(energy().toFixed(9))
|
||||||
|
|
||||||
|
//var js = use('js')
|
||||||
|
//log.console(js.disassemble(advance))
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
// Get function metadata
|
||||||
|
var fn_info = js.fn_info(advance)
|
||||||
|
log.console(`${fn_info.filename}:${fn_info.line}:${fn_info.column}: function: ${fn_info.name}`)
|
||||||
|
|
||||||
|
// Display arguments
|
||||||
|
if (fn_info.args && fn_info.args.length > 0) {
|
||||||
|
log.console(` args: ${fn_info.args.join(' ')}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display local variables
|
||||||
|
if (fn_info.locals && fn_info.locals.length > 0) {
|
||||||
|
log.console(' locals:')
|
||||||
|
for (var i = 0; i < fn_info.locals.length; i++) {
|
||||||
|
var local = fn_info.locals[i]
|
||||||
|
log.console(` ${local.index}: ${local.type} ${local.name}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display stack size
|
||||||
|
//log.console(` stack_size: ${fn_info.stack_size}`)
|
||||||
|
|
||||||
|
// Display disassembly
|
||||||
|
//log.console(json.encode(js.disassemble(advance)))
|
||||||
|
//log.console(js.disassemble(advance).length)
|
||||||
|
*/
|
||||||
|
|
||||||
$_.stop()
|
$_.stop()
|
||||||
40
cell.md
40
cell.md
@@ -6,6 +6,46 @@ CELLSCRIPT
|
|||||||
|
|
||||||
Javascript to its core. Objects. What does the language need? It can be quite small, I think. The key is, ANYTHING that we want to be fast and JIT'd, must be present. So, record lookups. These are actually quicker in a jit'd language that have them as a feature. Most things should be libraries. Blobs need to be in the runtime.
|
Javascript to its core. Objects. What does the language need? It can be quite small, I think. The key is, ANYTHING that we want to be fast and JIT'd, must be present. So, record lookups. These are actually quicker in a jit'd language that have them as a feature. Most things should be libraries. Blobs need to be in the runtime.
|
||||||
|
|
||||||
|
## Actors and Objects
|
||||||
|
Actors have a unique memory space and are made up of many objects. Objects are created in the Self style, but with a limitation: only one parent.
|
||||||
|
|
||||||
|
Actors only communicate with messages. Messages are a record of data consisting of a few base types: text, numbers, arrays, records, boolean values. There is no RPC, and it is not recommended to build it into your message passing protocol. Messages are very high level things: "do X", which the actor can then go and carry out.
|
||||||
|
|
||||||
|
Cell provides a fast way to condense an object for sending.
|
||||||
|
|
||||||
|
## How is it different from Javascript?
|
||||||
|
Cell condenses Javascript down into a few core ideas. There are three pillars which cell relies on:
|
||||||
|
|
||||||
|
1. The idea of actors as a method of communication between parts of a program.
|
||||||
|
2. The idea of objects as a way to organize and encapsulate data.
|
||||||
|
3. The idea of the capability model as security.
|
||||||
|
|
||||||
|
Javascript already supplied some of these things; Cell takes the core of Javascript and makes these ideas more explicit, and layers on the actor communication. It removes some goofy suckiness with javascript.
|
||||||
|
|
||||||
|
It acts as something like an operating system at the application level. It allows random code to be ran on your machine without worrying it will break something. This is built into the language.
|
||||||
|
|
||||||
|
It is completly dynamically typed. In comparison with C, in C, you can treat everything as everything: it is almost not typed at all. If you try to use a type as another type, no error is thrown; it might work, but it mightly silently not work. In Cell, data has a hard type, but if you use it "incorrectly", it will throw, and you can correct it. It's a live system.
|
||||||
|
|
||||||
|
Cell is linked very closely with C. It's best to think of cell as a layer for message passing on top of C. It is a way to describe how to translate C tasks from one section of the program to another - or to totally different computers (actors).
|
||||||
|
|
||||||
|
As such, cell's primary duty is marshalling data; so it has been designed for that to be as fast as possible. It has a syntax similar to C to make it easy to translate formulae from cell to C (or the other way, if desired).
|
||||||
|
|
||||||
|
Unlike many actor languages, Cell does not eschew assignment. You must have some assignment. However, when it comes to actor->actor communication, you do not assign. RPC is too direct: one actor should not care all that much what specific functions another actor has available. It should request it to do something, and get a result, or possibly not get a result. It doesn't care what the actor does as long as that gets done.
|
||||||
|
|
||||||
|
But within itself, it will assign; it must. Actors, or cells, are best thought of as computers or nodes within the internet. You request data from a URL by typing it into your browser; that computer you're attempting to reach may not even be on. It very likely has written some other data to disk whenever you contact it. But you're not doing the specific assigning. You just request data with HTTP commands.
|
||||||
|
|
||||||
|
## Objects and actors
|
||||||
|
Objects and actors are both similar ideas: they can hold data and respond to messages. Objects, local to an actor, can be thought of more like an RPC idea: they're invoked and return immediately. However, a failed RPC can crash an object; and in that case, the actor halts. It can be corrected.
|
||||||
|
|
||||||
|
## What does Cell bring you over C?
|
||||||
|
Programs which are built with C; they're built statically; they're built to not crash; they're built doing extremely low level things, like assignment.
|
||||||
|
|
||||||
|
The goal of cell is to thrust your C code into the parallel, actor realm. It lets your code crash and resume it; even rewriting the C code which is butressing your cell code and reloading it live.
|
||||||
|
|
||||||
|
There are two primary sorts of Cell modules you create from C code: data and IO. C code like
|
||||||
|
|
||||||
|
Where there were two similar things in javscript, one has been deleted and one kept. For example, there is only null now, no undefined. There are not four ways to test for equality; there is one.
|
||||||
|
|
||||||
The purpose of this is to be a great language for passing messages. So it should be fast at creating records first and foremost, and finding items on them. So it needs first class, jitt'd records.
|
The purpose of this is to be a great language for passing messages. So it should be fast at creating records first and foremost, and finding items on them. So it needs first class, jitt'd records.
|
||||||
|
|
||||||
Finally, it needs to use less memory. Deleting a bunch of this stuff should make that simpler.
|
Finally, it needs to use less memory. Deleting a bunch of this stuff should make that simpler.
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ src += [
|
|||||||
'anim.c', 'config.c', 'datastream.c','font.c','HandmadeMath.c','jsffi.c','model.c',
|
'anim.c', 'config.c', 'datastream.c','font.c','HandmadeMath.c','jsffi.c','model.c',
|
||||||
'render.c','simplex.c','spline.c', 'transform.c','cell.c', 'wildmatch.c',
|
'render.c','simplex.c','spline.c', 'transform.c','cell.c', 'wildmatch.c',
|
||||||
'sprite.c', 'rtree.c', 'qjs_nota.c', 'qjs_soloud.c', 'qjs_sdl.c', 'qjs_sdl_input.c', 'qjs_sdl_video.c', 'qjs_sdl_surface.c', 'qjs_math.c', 'qjs_geometry.c', 'qjs_transform.c', 'qjs_sprite.c', 'qjs_io.c', 'qjs_fd.c', 'qjs_os.c', 'qjs_actor.c',
|
'sprite.c', 'rtree.c', 'qjs_nota.c', 'qjs_soloud.c', 'qjs_sdl.c', 'qjs_sdl_input.c', 'qjs_sdl_video.c', 'qjs_sdl_surface.c', 'qjs_math.c', 'qjs_geometry.c', 'qjs_transform.c', 'qjs_sprite.c', 'qjs_io.c', 'qjs_fd.c', 'qjs_os.c', 'qjs_actor.c',
|
||||||
'qjs_qr.c', 'qjs_wota.c', 'monocypher.c', 'qjs_blob.c', 'qjs_crypto.c', 'qjs_time.c', 'qjs_http.c', 'qjs_rtree.c', 'qjs_spline.c', 'qjs_js.c', 'qjs_debug.c', 'picohttpparser.c', 'qjs_miniz.c', 'qjs_num.c', 'timer.c', 'qjs_socket.c', 'qjs_kim.c', 'qjs_utf8.c', 'qjs_fit.c', 'qjs_text.c'
|
'qjs_qr.c', 'qjs_wota.c', 'monocypher.c', 'qjs_blob.c', 'qjs_crypto.c', 'qjs_time.c', 'qjs_http.c', 'qjs_rtree.c', 'qjs_spline.c', 'qjs_js.c', 'qjs_debug.c', 'picohttpparser.c', 'qjs_miniz.c', 'qjs_num.c', 'timer.c', 'qjs_socket.c', 'qjs_kim.c', 'qjs_utf8.c', 'qjs_fit.c', 'qjs_text.c', 'qjs_layout.c'
|
||||||
]
|
]
|
||||||
# quirc src
|
# quirc src
|
||||||
src += [
|
src += [
|
||||||
|
|||||||
@@ -8,6 +8,22 @@ var graphics = use('graphics')
|
|||||||
var util = use('util')
|
var util = use('util')
|
||||||
var input = use('input')
|
var input = use('input')
|
||||||
|
|
||||||
|
function normalizeSpacing(spacing) {
|
||||||
|
if (typeof spacing == 'number') {
|
||||||
|
return {l: spacing, r: spacing, t: spacing, b: spacing}
|
||||||
|
} else if (Array.isArray(spacing)) {
|
||||||
|
if (spacing.length == 2) {
|
||||||
|
return {l: spacing[0], r: spacing[0], t: spacing[1], b: spacing[1]}
|
||||||
|
} else if (spacing.length == 4) {
|
||||||
|
return {l: spacing[0], r: spacing[1], t: spacing[2], b: spacing[3]}
|
||||||
|
}
|
||||||
|
} else if (typeof spacing == 'object') {
|
||||||
|
return {l: spacing.l || 0, r: spacing.r || 0, t: spacing.t || 0, b: spacing.b || 0}
|
||||||
|
} else {
|
||||||
|
return {l:0, r:0, t:0, b:0}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var lay_ctx = layout.make_context();
|
var lay_ctx = layout.make_context();
|
||||||
|
|
||||||
var clay_base = {
|
var clay_base = {
|
||||||
@@ -55,7 +71,7 @@ clay.draw = function draw(size, fn, config = {})
|
|||||||
box.content = lay_ctx.get_rect(box.id);
|
box.content = lay_ctx.get_rect(box.id);
|
||||||
box.boundingbox = Object.assign({}, box.content);
|
box.boundingbox = Object.assign({}, box.content);
|
||||||
|
|
||||||
var padding = util.normalizeSpacing(box.config.padding || 0);
|
var padding = normalizeSpacing(box.config.padding || 0);
|
||||||
if (padding.l || padding.r || padding.t || padding.b) {
|
if (padding.l || padding.r || padding.t || padding.b) {
|
||||||
// Adjust the boundingbox to include the padding
|
// Adjust the boundingbox to include the padding
|
||||||
box.boundingbox.x -= padding.l;
|
box.boundingbox.x -= padding.l;
|
||||||
@@ -64,7 +80,7 @@ clay.draw = function draw(size, fn, config = {})
|
|||||||
box.boundingbox.height += padding.t + padding.b;
|
box.boundingbox.height += padding.t + padding.b;
|
||||||
}
|
}
|
||||||
box.marginbox = Object.assign({}, box.content);
|
box.marginbox = Object.assign({}, box.content);
|
||||||
var margin = util.normalizeSpacing(box.config.margin || 0);
|
var margin = normalizeSpacing(box.config.margin || 0);
|
||||||
box.marginbox.x -= margin.l;
|
box.marginbox.x -= margin.l;
|
||||||
box.marginbox.y -= margin.t;
|
box.marginbox.y -= margin.t;
|
||||||
box.marginbox.width += margin.l+margin.r;
|
box.marginbox.width += margin.l+margin.r;
|
||||||
@@ -118,11 +134,12 @@ function image_size(img)
|
|||||||
function add_item(config)
|
function add_item(config)
|
||||||
{
|
{
|
||||||
// Normalize the child's margin
|
// Normalize the child's margin
|
||||||
var margin = util.normalizeSpacing(config.margin || 0);
|
var margin = normalizeSpacing(config.margin || 0);
|
||||||
var padding = util.normalizeSpacing(config.padding || 0);
|
var padding = normalizeSpacing(config.padding || 0);
|
||||||
var childGap = root_config.child_gap || 0;
|
var childGap = root_config.child_gap || 0;
|
||||||
|
|
||||||
// Adjust for child_gap
|
// Adjust for child_gap
|
||||||
|
root_config._childIndex ??= 0
|
||||||
if (root_config._childIndex > 0) {
|
if (root_config._childIndex > 0) {
|
||||||
var parentContain = root_config.contain || 0;
|
var parentContain = root_config.contain || 0;
|
||||||
var isVStack = (parentContain & layout.contain.column) != 0;
|
var isVStack = (parentContain & layout.contain.column) != 0;
|
||||||
@@ -187,8 +204,8 @@ clay.text = function text(str, ...configs)
|
|||||||
{
|
{
|
||||||
var config = rectify_configs(configs);
|
var config = rectify_configs(configs);
|
||||||
config.size ??= [0,0];
|
config.size ??= [0,0];
|
||||||
config.font = graphics.get_font(config.font)
|
// config.font = graphics.get_font(config.font)
|
||||||
var tsize = config.font.text_size(str, 0, 0, config.size.x);
|
var tsize = 12; //config.font.text_size(str, 0, 0, config.size.x);
|
||||||
config.size = config.size.map((x,i) => Math.max(x, tsize[i]));
|
config.size = config.size.map((x,i) => Math.max(x, tsize[i]));
|
||||||
config.text = str;
|
config.text = str;
|
||||||
add_item(config);
|
add_item(config);
|
||||||
@@ -209,8 +226,8 @@ var button_base = Object.assign(Object.create(clay_base), {
|
|||||||
clay.button = function button(str, action, config = {})
|
clay.button = function button(str, action, config = {})
|
||||||
{
|
{
|
||||||
config.__proto__ = button_base;
|
config.__proto__ = button_base;
|
||||||
config.font = graphics.get_font(config.font)
|
// config.font = graphics.get_font(config.font)
|
||||||
config.size = config.font.text_size(str)
|
config.size = 12;//config.font.text_size(str)
|
||||||
add_item(config);
|
add_item(config);
|
||||||
config.text = str;
|
config.text = str;
|
||||||
config.action = action;
|
config.action = action;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ var game = args[0]
|
|||||||
|
|
||||||
var video
|
var video
|
||||||
|
|
||||||
var cnf = use('accio/config')
|
//var cnf = use('accio/config')
|
||||||
|
|
||||||
$_.start(e => {
|
$_.start(e => {
|
||||||
if (e.type != 'greet') return
|
if (e.type != 'greet') return
|
||||||
@@ -30,7 +30,7 @@ $_.start(e => {
|
|||||||
start_pipeline()
|
start_pipeline()
|
||||||
}, args[0], $_)
|
}, args[0], $_)
|
||||||
})
|
})
|
||||||
}, 'prosperon/sdl_video', cnf)
|
}, 'prosperon/sdl_video', {})
|
||||||
|
|
||||||
var geometry = use('geometry')
|
var geometry = use('geometry')
|
||||||
|
|
||||||
@@ -237,6 +237,8 @@ function translate_draw_commands(commands) {
|
|||||||
src: img.rect
|
src: img.rect
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
log.console(json.encode(renderer_commands[renderer_commands.length-1]))
|
||||||
break
|
break
|
||||||
|
|
||||||
case "draw_text":
|
case "draw_text":
|
||||||
@@ -397,8 +399,6 @@ function render_step() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$_.receiver(e => {
|
$_.receiver(e => {
|
||||||
switch(e.op) {
|
switch(e.op) {
|
||||||
case 'resolution':
|
case 'resolution':
|
||||||
|
|||||||
@@ -40,14 +40,14 @@ function console_rec(line, file, msg) {
|
|||||||
|
|
||||||
var console_mod = cell.hidden.console
|
var console_mod = cell.hidden.console
|
||||||
|
|
||||||
var logs = {}
|
globalThis.log = {}
|
||||||
logs.console = function(msg)
|
log.console = function(msg)
|
||||||
{
|
{
|
||||||
var caller = caller_data(2)
|
var caller = caller_data(2)
|
||||||
console_mod.print(console_rec(caller.line, caller.file, msg))
|
console_mod.print(console_rec(caller.line, caller.file, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
logs.error = function(msg = new Error())
|
log.error = function(msg = new Error())
|
||||||
{
|
{
|
||||||
var caller = caller_data(4)
|
var caller = caller_data(4)
|
||||||
|
|
||||||
@@ -57,21 +57,11 @@ logs.error = function(msg = new Error())
|
|||||||
console_mod.print(console_rec(caller.line,caller.file,msg))
|
console_mod.print(console_rec(caller.line,caller.file,msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
logs.system = function(msg) {
|
log.system = function(msg) {
|
||||||
msg = "[SYSTEM] " + msg
|
msg = "[SYSTEM] " + msg
|
||||||
log.console(msg)
|
log.console(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
function noop() {}
|
|
||||||
globalThis.log = new Proxy(logs, {
|
|
||||||
get(target,prop,receiver) {
|
|
||||||
if (target[prop])
|
|
||||||
return (...args) => target[prop](args.join(' '))
|
|
||||||
|
|
||||||
return noop
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Get hidden modules from cell.hidden before stripping it
|
// Get hidden modules from cell.hidden before stripping it
|
||||||
var hidden = cell.hidden
|
var hidden = cell.hidden
|
||||||
var actor_mod = hidden.actor
|
var actor_mod = hidden.actor
|
||||||
|
|||||||
@@ -751,7 +751,6 @@ void script_startup(cell_rt *prt)
|
|||||||
JS_AddIntrinsicRegExp(js);
|
JS_AddIntrinsicRegExp(js);
|
||||||
JS_AddIntrinsicJSON(js);
|
JS_AddIntrinsicJSON(js);
|
||||||
JS_AddIntrinsicMapSet(js);
|
JS_AddIntrinsicMapSet(js);
|
||||||
JS_AddIntrinsicProxy(js);
|
|
||||||
|
|
||||||
JS_SetContextOpaque(js, prt);
|
JS_SetContextOpaque(js, prt);
|
||||||
prt->context = js;
|
prt->context = js;
|
||||||
@@ -870,79 +869,6 @@ int main(int argc, char **argv)
|
|||||||
int profile_enabled = 0;
|
int profile_enabled = 0;
|
||||||
int script_start = 1;
|
int script_start = 1;
|
||||||
|
|
||||||
/* 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], 0);
|
|
||||||
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 */
|
/* Check for --profile flag */
|
||||||
if (argc > 1 && strcmp(argv[1], "--profile") == 0) {
|
if (argc > 1 && strcmp(argv[1], "--profile") == 0) {
|
||||||
profile_enabled = 1; script_start = 2;
|
profile_enabled = 1; script_start = 2;
|
||||||
|
|||||||
@@ -1546,6 +1546,7 @@ JSC_CCALL(os_value_id,
|
|||||||
#include "qjs_wota.h"
|
#include "qjs_wota.h"
|
||||||
#include "qjs_socket.h"
|
#include "qjs_socket.h"
|
||||||
#include "qjs_nota.h"
|
#include "qjs_nota.h"
|
||||||
|
#include "qjs_layout.h"
|
||||||
|
|
||||||
//JSValue js_imgui_use(JSContext *js);
|
//JSValue js_imgui_use(JSContext *js);
|
||||||
#define MISTLINE(NAME) (ModuleEntry){#NAME, js_##NAME##_use}
|
#define MISTLINE(NAME) (ModuleEntry){#NAME, js_##NAME##_use}
|
||||||
@@ -1581,7 +1582,7 @@ void ffi_load(JSContext *js)
|
|||||||
arrput(rt->module_registry, MISTLINE(text));
|
arrput(rt->module_registry, MISTLINE(text));
|
||||||
arrput(rt->module_registry, MISTLINE(wota));
|
arrput(rt->module_registry, MISTLINE(wota));
|
||||||
arrput(rt->module_registry, MISTLINE(nota));
|
arrput(rt->module_registry, MISTLINE(nota));
|
||||||
|
|
||||||
// power user
|
// power user
|
||||||
arrput(rt->module_registry, MISTLINE(js));
|
arrput(rt->module_registry, MISTLINE(js));
|
||||||
arrput(rt->module_registry, MISTLINE(debug));
|
arrput(rt->module_registry, MISTLINE(debug));
|
||||||
@@ -1598,6 +1599,7 @@ void ffi_load(JSContext *js)
|
|||||||
arrput(rt->module_registry, MISTLINE(graphics));
|
arrput(rt->module_registry, MISTLINE(graphics));
|
||||||
arrput(rt->module_registry, MISTLINE(video));
|
arrput(rt->module_registry, MISTLINE(video));
|
||||||
arrput(rt->module_registry, MISTLINE(soloud));
|
arrput(rt->module_registry, MISTLINE(soloud));
|
||||||
|
arrput(rt->module_registry, MISTLINE(layout));
|
||||||
|
|
||||||
// arrput(rt->module_registry, MISTLINE(imgui));
|
// arrput(rt->module_registry, MISTLINE(imgui));
|
||||||
arrput(rt->module_registry, ((ModuleEntry){"camera", js_camera_use}));
|
arrput(rt->module_registry, ((ModuleEntry){"camera", js_camera_use}));
|
||||||
|
|||||||
1196
source/layout.h
Normal file
1196
source/layout.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -74,6 +74,14 @@ JSC_CCALL(js_compile_unblob,
|
|||||||
return JS_ReadObject(js, data, size, JS_READ_OBJ_BYTECODE);
|
return JS_ReadObject(js, data, size, JS_READ_OBJ_BYTECODE);
|
||||||
)
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(js_disassemble,
|
||||||
|
return js_debugger_fn_bytecode(js, argv[0]);
|
||||||
|
)
|
||||||
|
|
||||||
|
JSC_CCALL(js_fn_info,
|
||||||
|
return js_debugger_fn_info(js, argv[0]);
|
||||||
|
)
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_js_funcs[] = {
|
static const JSCFunctionListEntry js_js_funcs[] = {
|
||||||
MIST_FUNC_DEF(os, calc_mem, 0),
|
MIST_FUNC_DEF(os, calc_mem, 0),
|
||||||
MIST_FUNC_DEF(os, mem_limit, 1),
|
MIST_FUNC_DEF(os, mem_limit, 1),
|
||||||
@@ -85,6 +93,8 @@ static const JSCFunctionListEntry js_js_funcs[] = {
|
|||||||
MIST_FUNC_DEF(js, eval_compile, 1),
|
MIST_FUNC_DEF(js, eval_compile, 1),
|
||||||
MIST_FUNC_DEF(js, compile_blob, 1),
|
MIST_FUNC_DEF(js, compile_blob, 1),
|
||||||
MIST_FUNC_DEF(js, compile_unblob, 1),
|
MIST_FUNC_DEF(js, compile_unblob, 1),
|
||||||
|
MIST_FUNC_DEF(js, disassemble, 1),
|
||||||
|
MIST_FUNC_DEF(js, fn_info, 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
JSValue js_js_use(JSContext *js) {
|
JSValue js_js_use(JSContext *js) {
|
||||||
|
|||||||
213
source/qjs_layout.c
Normal file
213
source/qjs_layout.c
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
#include "quickjs.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define LAY_FLOAT 1
|
||||||
|
#define LAY_IMPLEMENTATION
|
||||||
|
#include "layout.h"
|
||||||
|
|
||||||
|
static JSClassID js_layout_class_id;
|
||||||
|
|
||||||
|
#define GETLAY \
|
||||||
|
lay_context *lay = JS_GetOpaque2(js, self, js_layout_class_id); \
|
||||||
|
if (!lay) return JS_EXCEPTION;
|
||||||
|
|
||||||
|
#define GETITEM(VAR, ARG) \
|
||||||
|
lay_id VAR; \
|
||||||
|
if (JS_ToUint32(js, &VAR, ARG)) return JS_EXCEPTION; \
|
||||||
|
|
||||||
|
static JSValue js_layout_context_new(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) {
|
||||||
|
lay_context *lay = js_malloc(js, sizeof(*lay));
|
||||||
|
lay_init_context(lay);
|
||||||
|
JSValue obj = JS_NewObjectClass(js, js_layout_class_id);
|
||||||
|
JS_SetOpaque(obj, lay);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_item(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) {
|
||||||
|
GETLAY
|
||||||
|
lay_id item_id = lay_item(lay);
|
||||||
|
return JS_NewUint32(js,item_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_set_size(JSContext *js, JSValueConst self, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
if (argc < 2) return JS_EXCEPTION;
|
||||||
|
|
||||||
|
GETLAY
|
||||||
|
GETITEM(id, argv[0])
|
||||||
|
double size[2];
|
||||||
|
JSValue width_val = JS_GetPropertyUint32(js, argv[1], 0);
|
||||||
|
JSValue height_val = JS_GetPropertyUint32(js, argv[1], 1);
|
||||||
|
JS_ToFloat64(js, &size[0], width_val);
|
||||||
|
JS_ToFloat64(js, &size[1], height_val);
|
||||||
|
JS_FreeValue(js, width_val);
|
||||||
|
JS_FreeValue(js, height_val);
|
||||||
|
if (isnan(size[0])) size[0] = 0;
|
||||||
|
if (isnan(size[1])) size[1] = 0;
|
||||||
|
lay_set_size_xy(lay, id, size[0], size[1]);
|
||||||
|
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_set_behave(JSContext *js, JSValueConst self, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
GETLAY
|
||||||
|
GETITEM(id, argv[0])
|
||||||
|
uint32_t behave_flags;
|
||||||
|
JS_ToUint32(js, &behave_flags, argv[1]);
|
||||||
|
lay_set_behave(lay, id, behave_flags);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_set_contain(JSContext *js, JSValueConst self, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
GETLAY
|
||||||
|
GETITEM(id, argv[0])
|
||||||
|
uint32_t contain_flags;
|
||||||
|
JS_ToUint32(js, &contain_flags, argv[1]);
|
||||||
|
lay_set_contain(lay, id, contain_flags);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PULLMARGIN(DIR,MARGIN) \
|
||||||
|
JSValue js_##DIR = JS_GetPropertyStr(js, argv[1], #DIR); \
|
||||||
|
if (!JS_IsNull(js_##DIR)) { \
|
||||||
|
JS_ToFloat64(js, &margins[MARGIN], js_##DIR); \
|
||||||
|
if (isnan(margins[MARGIN])) margins[MARGIN] = 0; \
|
||||||
|
JS_FreeValue(js, js_##DIR); \
|
||||||
|
}\
|
||||||
|
|
||||||
|
static JSValue js_layout_set_margins(JSContext *js, JSValueConst self, int argc, JSValueConst *argv)
|
||||||
|
{
|
||||||
|
GETLAY
|
||||||
|
GETITEM(id, argv[0])
|
||||||
|
double margins[4] = {0};
|
||||||
|
PULLMARGIN(l,0)
|
||||||
|
PULLMARGIN(r,2)
|
||||||
|
PULLMARGIN(t,1)
|
||||||
|
PULLMARGIN(b,3)
|
||||||
|
lay_set_margins_ltrb(lay, id, margins[0], margins[1], margins[2], margins[3]);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_insert(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) {
|
||||||
|
GETLAY
|
||||||
|
GETITEM(parent, argv[0])
|
||||||
|
GETITEM(child, argv[1])
|
||||||
|
lay_insert(lay, parent, child);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_append(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) {
|
||||||
|
GETLAY
|
||||||
|
GETITEM(earlier, argv[0])
|
||||||
|
GETITEM(later, argv[1])
|
||||||
|
lay_append(lay, earlier, later);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_push(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) {
|
||||||
|
GETLAY
|
||||||
|
GETITEM(parent, argv[0])
|
||||||
|
GETITEM(child, argv[1])
|
||||||
|
lay_push(lay, parent, child);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_run(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) {
|
||||||
|
GETLAY
|
||||||
|
lay_run_context(lay);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_get_rect(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) {
|
||||||
|
GETLAY
|
||||||
|
GETITEM(id, argv[0])
|
||||||
|
lay_vec4 rect = lay_get_rect(lay, id);
|
||||||
|
JSValue ret = JS_NewObject(js);
|
||||||
|
JS_SetPropertyStr(js, ret, "x", JS_NewFloat64(js, rect[0]));
|
||||||
|
JS_SetPropertyStr(js, ret, "y", JS_NewFloat64(js, rect[1]));
|
||||||
|
JS_SetPropertyStr(js, ret, "width", JS_NewFloat64(js, rect[2]));
|
||||||
|
JS_SetPropertyStr(js, ret, "height", JS_NewFloat64(js, rect[3]));
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_layout_reset(JSContext *js, JSValueConst self, int argc, JSValueConst *argv) {
|
||||||
|
GETLAY
|
||||||
|
lay_reset_context(lay);
|
||||||
|
return JS_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void js_layout_finalizer(JSRuntime *rt, JSValue val) {
|
||||||
|
lay_context *ctx = JS_GetOpaque(val, js_layout_class_id);
|
||||||
|
lay_destroy_context(ctx);
|
||||||
|
js_free_rt(rt, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSClassDef js_layout_class = {
|
||||||
|
"layout_context",
|
||||||
|
.finalizer = js_layout_finalizer,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const JSCFunctionListEntry js_layout_proto_funcs[] = {
|
||||||
|
JS_CFUNC_DEF("item", 1, js_layout_item),
|
||||||
|
JS_CFUNC_DEF("insert", 2, js_layout_insert),
|
||||||
|
JS_CFUNC_DEF("append", 2, js_layout_append),
|
||||||
|
JS_CFUNC_DEF("push", 2, js_layout_push),
|
||||||
|
JS_CFUNC_DEF("run", 0, js_layout_run),
|
||||||
|
JS_CFUNC_DEF("get_rect", 1, js_layout_get_rect),
|
||||||
|
JS_CFUNC_DEF("reset", 0, js_layout_reset),
|
||||||
|
JS_CFUNC_DEF("set_margins", 2, js_layout_set_margins),
|
||||||
|
JS_CFUNC_DEF("set_size", 2, js_layout_set_size),
|
||||||
|
JS_CFUNC_DEF("set_contain", 2, js_layout_set_contain),
|
||||||
|
JS_CFUNC_DEF("set_behave", 2, js_layout_set_behave),
|
||||||
|
};
|
||||||
|
|
||||||
|
static const JSCFunctionListEntry js_layout_funcs[] = {
|
||||||
|
JS_CFUNC_DEF("make_context", 0, js_layout_context_new)
|
||||||
|
};
|
||||||
|
|
||||||
|
JSValue js_layout_use(JSContext *js)
|
||||||
|
{
|
||||||
|
JS_NewClassID(&js_layout_class_id);
|
||||||
|
JS_NewClass(JS_GetRuntime(js), js_layout_class_id, &js_layout_class);
|
||||||
|
|
||||||
|
JSValue proto = JS_NewObject(js);
|
||||||
|
JS_SetPropertyFunctionList(js, proto, js_layout_proto_funcs, sizeof(js_layout_proto_funcs) / sizeof(JSCFunctionListEntry));
|
||||||
|
JS_SetClassProto(js, js_layout_class_id, proto);
|
||||||
|
|
||||||
|
JSValue contain = JS_NewObject(js);
|
||||||
|
JSValue behave = JS_NewObject(js);
|
||||||
|
JS_SetPropertyStr(js, contain, "row", JS_NewUint32(js, LAY_ROW));
|
||||||
|
JS_SetPropertyStr(js, contain, "column", JS_NewUint32(js, LAY_COLUMN));
|
||||||
|
JS_SetPropertyStr(js, contain, "layout", JS_NewUint32(js, LAY_LAYOUT));
|
||||||
|
JS_SetPropertyStr(js, contain, "flex", JS_NewUint32(js, LAY_FLEX));
|
||||||
|
JS_SetPropertyStr(js, contain, "wrap", JS_NewUint32(js, LAY_WRAP));
|
||||||
|
JS_SetPropertyStr(js, contain, "nowrap", JS_NewUint32(js, LAY_NOWRAP));
|
||||||
|
|
||||||
|
JS_SetPropertyStr(js, contain, "start", JS_NewUint32(js, LAY_START));
|
||||||
|
JS_SetPropertyStr(js, contain, "middle", JS_NewUint32(js, LAY_MIDDLE));
|
||||||
|
JS_SetPropertyStr(js, contain, "end", JS_NewUint32(js, LAY_END));
|
||||||
|
JS_SetPropertyStr(js, contain, "justify", JS_NewUint32(js, LAY_JUSTIFY));
|
||||||
|
|
||||||
|
JS_SetPropertyStr(js, behave, "left", JS_NewUint32(js, LAY_LEFT));
|
||||||
|
JS_SetPropertyStr(js, behave, "top", JS_NewUint32(js, LAY_TOP));
|
||||||
|
JS_SetPropertyStr(js, behave, "right", JS_NewUint32(js, LAY_RIGHT));
|
||||||
|
JS_SetPropertyStr(js, behave, "bottom", JS_NewUint32(js, LAY_BOTTOM));
|
||||||
|
JS_SetPropertyStr(js, behave, "hfill", JS_NewUint32(js, LAY_HFILL));
|
||||||
|
JS_SetPropertyStr(js, behave, "vfill", JS_NewUint32(js, LAY_VFILL));
|
||||||
|
JS_SetPropertyStr(js, behave, "hcenter", JS_NewUint32(js, LAY_HCENTER));
|
||||||
|
JS_SetPropertyStr(js, behave, "vcenter", JS_NewUint32(js, LAY_VCENTER));
|
||||||
|
JS_SetPropertyStr(js, behave, "center", JS_NewUint32(js, LAY_CENTER));
|
||||||
|
JS_SetPropertyStr(js, behave, "fill", JS_NewUint32(js, LAY_FILL));
|
||||||
|
JS_SetPropertyStr(js, behave, "break", JS_NewUint32(js, LAY_BREAK));
|
||||||
|
|
||||||
|
JSValue export = JS_NewObject(js);
|
||||||
|
JS_SetPropertyFunctionList(js, export, js_layout_funcs, sizeof(js_layout_funcs)/sizeof(JSCFunctionListEntry));
|
||||||
|
JS_SetPropertyStr(js, export, "behave", behave);
|
||||||
|
JS_SetPropertyStr(js, export, "contain", contain);
|
||||||
|
|
||||||
|
return export;
|
||||||
|
}
|
||||||
8
source/qjs_layout.h
Normal file
8
source/qjs_layout.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef QJS_LAYOUT_H
|
||||||
|
#define QJS_LAYOUT_H
|
||||||
|
|
||||||
|
#include "cell.h"
|
||||||
|
|
||||||
|
JSValue js_layout_use(JSContext *js);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -246,7 +246,7 @@ static JSValue js_window_constructor(JSContext *js, JSValueConst new_target, int
|
|||||||
// Handle text input
|
// Handle text input
|
||||||
JSValue text_input = JS_GetPropertyStr(js, opts, "textInput");
|
JSValue text_input = JS_GetPropertyStr(js, opts, "textInput");
|
||||||
if (JS_ToBool(js, text_input)) {
|
if (JS_ToBool(js, text_input)) {
|
||||||
SDL_StartTextInput(window);
|
// SDL_StartTextInput(window);
|
||||||
}
|
}
|
||||||
JS_FreeValue(js, text_input);
|
JS_FreeValue(js, text_input);
|
||||||
|
|
||||||
@@ -1781,8 +1781,6 @@ JSC_CCALL(sdl_createWindowAndRenderer,
|
|||||||
#include "qjs_wota.h"
|
#include "qjs_wota.h"
|
||||||
|
|
||||||
JSValue js_sdl_video_use(JSContext *js) {
|
JSValue js_sdl_video_use(JSContext *js) {
|
||||||
printf("initing on thread %d\n", SDL_GetThreadID(NULL));
|
|
||||||
|
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO))
|
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||||
return JS_ThrowInternalError(js, "Unable to initialize video subsystem: %s", SDL_GetError());
|
return JS_ThrowInternalError(js, "Unable to initialize video subsystem: %s", SDL_GetError());
|
||||||
|
|
||||||
|
|||||||
@@ -207,10 +207,14 @@ DEF( delete, 1, 2, 1, none)
|
|||||||
DEF( delete_var, 5, 0, 1, atom)
|
DEF( delete_var, 5, 0, 1, atom)
|
||||||
|
|
||||||
DEF( mul, 1, 2, 1, none)
|
DEF( mul, 1, 2, 1, none)
|
||||||
|
DEF( mul_float, 1, 2, 1, none)
|
||||||
DEF( div, 1, 2, 1, none)
|
DEF( div, 1, 2, 1, none)
|
||||||
|
DEF( div_float, 1, 2, 1, none)
|
||||||
DEF( mod, 1, 2, 1, none)
|
DEF( mod, 1, 2, 1, none)
|
||||||
DEF( add, 1, 2, 1, none)
|
DEF( add, 1, 2, 1, none)
|
||||||
|
DEF( add_float, 1, 2, 1, none)
|
||||||
DEF( sub, 1, 2, 1, none)
|
DEF( sub, 1, 2, 1, none)
|
||||||
|
DEF( sub_float, 1, 2, 1, none)
|
||||||
DEF( pow, 1, 2, 1, none)
|
DEF( pow, 1, 2, 1, none)
|
||||||
DEF( shl, 1, 2, 1, none)
|
DEF( shl, 1, 2, 1, none)
|
||||||
DEF( sar, 1, 2, 1, none)
|
DEF( sar, 1, 2, 1, none)
|
||||||
|
|||||||
1717
source/quickjs.c
1717
source/quickjs.c
File diff suppressed because it is too large
Load Diff
@@ -263,6 +263,10 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
|
|||||||
#define JS_VALUE_IS_BOTH_INT(v1, v2) ((JS_VALUE_GET_TAG(v1) | JS_VALUE_GET_TAG(v2)) == 0)
|
#define JS_VALUE_IS_BOTH_INT(v1, v2) ((JS_VALUE_GET_TAG(v1) | JS_VALUE_GET_TAG(v2)) == 0)
|
||||||
#define JS_VALUE_IS_BOTH_FLOAT(v1, v2) (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v1)) && JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v2)))
|
#define JS_VALUE_IS_BOTH_FLOAT(v1, v2) (JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v1)) && JS_TAG_IS_FLOAT64(JS_VALUE_GET_TAG(v2)))
|
||||||
|
|
||||||
|
#define JS_TAG_IS_STRING(v1) (v1 == JS_TAG_STRING || v1 == JS_TAG_STRING_ROPE)
|
||||||
|
|
||||||
|
#define JS_TAG_IS_NUMBER(v1) (JS_TAG_IS_FLOAT64(v1) || v1 == JS_TAG_INT)
|
||||||
|
|
||||||
#define JS_VALUE_HAS_REF_COUNT(v) ((unsigned)JS_VALUE_GET_TAG(v) >= (unsigned)JS_TAG_FIRST)
|
#define JS_VALUE_HAS_REF_COUNT(v) ((unsigned)JS_VALUE_GET_TAG(v) >= (unsigned)JS_TAG_FIRST)
|
||||||
|
|
||||||
/* special values */
|
/* special values */
|
||||||
@@ -455,12 +459,7 @@ typedef struct JSClassExoticMethods {
|
|||||||
returned, the property descriptor 'desc' is filled if != NULL. */
|
returned, the property descriptor 'desc' is filled if != NULL. */
|
||||||
int (*get_own_property)(JSContext *ctx, JSPropertyDescriptor *desc,
|
int (*get_own_property)(JSContext *ctx, JSPropertyDescriptor *desc,
|
||||||
JSValueConst obj, JSAtom prop);
|
JSValueConst obj, JSAtom prop);
|
||||||
/* '*ptab' should hold the '*plen' property keys. Return 0 if OK,
|
|
||||||
-1 if exception. The 'is_enumerable' field is ignored.
|
|
||||||
*/
|
|
||||||
int (*get_own_property_names)(JSContext *ctx, JSPropertyEnum **ptab,
|
|
||||||
uint32_t *plen,
|
|
||||||
JSValueConst obj);
|
|
||||||
/* return < 0 if exception, or TRUE/FALSE */
|
/* return < 0 if exception, or TRUE/FALSE */
|
||||||
int (*delete_property)(JSContext *ctx, JSValueConst obj, JSAtom prop);
|
int (*delete_property)(JSContext *ctx, JSValueConst obj, JSAtom prop);
|
||||||
/* return < 0 if exception or TRUE/FALSE */
|
/* return < 0 if exception or TRUE/FALSE */
|
||||||
@@ -468,26 +467,6 @@ typedef struct JSClassExoticMethods {
|
|||||||
JSAtom prop, JSValueConst val,
|
JSAtom prop, JSValueConst val,
|
||||||
JSValueConst getter, JSValueConst setter,
|
JSValueConst getter, JSValueConst setter,
|
||||||
int flags);
|
int flags);
|
||||||
/* The following methods can be emulated with the previous ones,
|
|
||||||
so they are usually not needed */
|
|
||||||
/* return < 0 if exception or TRUE/FALSE */
|
|
||||||
int (*has_property)(JSContext *ctx, JSValueConst obj, JSAtom atom);
|
|
||||||
JSValue (*get_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,
|
|
||||||
JSValueConst receiver);
|
|
||||||
/* return < 0 if exception or TRUE/FALSE */
|
|
||||||
int (*set_property)(JSContext *ctx, JSValueConst obj, JSAtom atom,
|
|
||||||
JSValueConst value, JSValueConst receiver, int flags);
|
|
||||||
|
|
||||||
/* To get a consistent object behavior when get_prototype != NULL,
|
|
||||||
get_property, set_property and set_prototype must be != NULL
|
|
||||||
and the object must be created with a JS_NULL prototype. */
|
|
||||||
JSValue (*get_prototype)(JSContext *ctx, JSValueConst obj);
|
|
||||||
/* return < 0 if exception or TRUE/FALSE */
|
|
||||||
int (*set_prototype)(JSContext *ctx, JSValueConst obj, JSValueConst proto_val);
|
|
||||||
/* return < 0 if exception or TRUE/FALSE */
|
|
||||||
int (*is_extensible)(JSContext *ctx, JSValueConst obj);
|
|
||||||
/* return < 0 if exception or TRUE/FALSE */
|
|
||||||
int (*prevent_extensions)(JSContext *ctx, JSValueConst obj);
|
|
||||||
} JSClassExoticMethods;
|
} JSClassExoticMethods;
|
||||||
|
|
||||||
typedef void JSClassFinalizer(JSRuntime *rt, JSValue val);
|
typedef void JSClassFinalizer(JSRuntime *rt, JSValue val);
|
||||||
@@ -1030,6 +1009,7 @@ JSValue js_debugger_closure_variables(JSContext *ctx, JSValue fn);
|
|||||||
JSValue js_debugger_local_variables(JSContext *ctx, int stack_index);
|
JSValue js_debugger_local_variables(JSContext *ctx, int stack_index);
|
||||||
JSValue js_debugger_build_backtrace(JSContext *ctx, const uint8_t *cur_pc);
|
JSValue js_debugger_build_backtrace(JSContext *ctx, const uint8_t *cur_pc);
|
||||||
JSValue js_debugger_fn_info(JSContext *ctx, JSValue fn);
|
JSValue js_debugger_fn_info(JSContext *ctx, JSValue fn);
|
||||||
|
JSValue js_debugger_fn_bytecode(JSContext *js, JSValue fn);
|
||||||
|
|
||||||
#undef js_unlikely
|
#undef js_unlikely
|
||||||
#undef js_force_inline
|
#undef js_force_inline
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#define SPRITE_H
|
#define SPRITE_H
|
||||||
|
|
||||||
#include "HandmadeMath.h"
|
#include "HandmadeMath.h"
|
||||||
#include "render.h"
|
|
||||||
#include "cell.h"
|
#include "cell.h"
|
||||||
|
|
||||||
struct sprite{
|
struct sprite{
|
||||||
|
|||||||
Reference in New Issue
Block a user