mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-12 02:25:22 +03:00
0154018363
* FBT: cdefines to env, libs order * API: strtod, modf, itoa, calloc * Apps: elk js * Apps: mjs * JS: scripts as assets * mjs: composite resolver * mjs: stack trace * ELK JS example removed * MJS thread, MJS lib modified to support script interruption * JS console UI * Module system, BadUSB bindings rework * JS notifications, simple dialog, BadUSB demo * Custom dialogs, dialog demo * MJS as system library, some dirty hacks to make it compile * Plugin-based js modules * js_uart(BadUART) module * js_uart: support for byte array arguments * Script icon and various fixes * File browser: multiple extensions filter, running js scripts from app loader * Running js scripts from archive browser * JS Runner as system app * Example scripts moved to /ext/apps/Scripts * JS bytecode listing generation * MJS builtin printf cleanup * JS examples cleanup * mbedtls version fix * Unused lib cleanup * Making PVS happy & TODOs cleanup * TODOs cleanup #2 * MJS: initial typed arrays support * JS: fix mem leak in uart destructor Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
106 lines
2.9 KiB
C
106 lines
2.9 KiB
C
/*
|
|
* Copyright (c) 2017 Cesanta Software Limited
|
|
* All rights reserved
|
|
*/
|
|
|
|
#ifndef MJS_BCODE_H_
|
|
#define MJS_BCODE_H_
|
|
|
|
#include "mjs_internal.h"
|
|
|
|
#include "mjs_core.h"
|
|
|
|
#if defined(__cplusplus)
|
|
extern "C" {
|
|
#endif /* __cplusplus */
|
|
|
|
enum mjs_opcode {
|
|
OP_NOP, /* ( -- ) */
|
|
OP_DROP, /* ( a -- ) */
|
|
OP_DUP, /* ( a -- a a ) */
|
|
OP_SWAP, /* ( a b -- b a ) */
|
|
OP_JMP, /* ( -- ) */
|
|
OP_JMP_TRUE, /* ( -- ) */
|
|
OP_JMP_NEUTRAL_TRUE, /* ( -- ) */
|
|
OP_JMP_FALSE, /* ( -- ) */
|
|
OP_JMP_NEUTRAL_FALSE, /* ( -- ) */
|
|
OP_FIND_SCOPE, /* ( a -- a b ) */
|
|
OP_PUSH_SCOPE, /* ( -- a ) */
|
|
OP_PUSH_STR, /* ( -- a ) */
|
|
OP_PUSH_TRUE, /* ( -- a ) */
|
|
OP_PUSH_FALSE, /* ( -- a ) */
|
|
OP_PUSH_INT, /* ( -- a ) */
|
|
OP_PUSH_DBL, /* ( -- a ) */
|
|
OP_PUSH_NULL, /* ( -- a ) */
|
|
OP_PUSH_UNDEF, /* ( -- a ) */
|
|
OP_PUSH_OBJ, /* ( -- a ) */
|
|
OP_PUSH_ARRAY, /* ( -- a ) */
|
|
OP_PUSH_FUNC, /* ( -- a ) */
|
|
OP_PUSH_THIS, /* ( -- a ) */
|
|
OP_GET, /* ( key obj -- obj[key] ) */
|
|
OP_CREATE, /* ( key obj -- ) */
|
|
OP_EXPR, /* ( ... -- a ) */
|
|
OP_APPEND, /* ( a b -- ) */
|
|
OP_SET_ARG, /* ( a -- a ) */
|
|
OP_NEW_SCOPE, /* ( -- ) */
|
|
OP_DEL_SCOPE, /* ( -- ) */
|
|
OP_CALL, /* ( func param1 param2 ... num_params -- result ) */
|
|
OP_RETURN, /* ( -- ) */
|
|
OP_LOOP, /* ( -- ) Push break & continue addresses to loop_labels */
|
|
OP_BREAK, /* ( -- ) */
|
|
OP_CONTINUE, /* ( -- ) */
|
|
OP_SETRETVAL, /* ( a -- ) */
|
|
OP_EXIT, /* ( -- ) */
|
|
OP_BCODE_HEADER, /* ( -- ) */
|
|
OP_ARGS, /* ( -- ) Mark the beginning of function call arguments */
|
|
OP_FOR_IN_NEXT, /* ( name obj iter_ptr -- name obj iter_ptr_next ) */
|
|
OP_MAX
|
|
};
|
|
|
|
struct pstate;
|
|
struct mjs;
|
|
|
|
MJS_PRIVATE void emit_byte(struct pstate* pstate, uint8_t byte);
|
|
MJS_PRIVATE void emit_int(struct pstate* pstate, int64_t n);
|
|
MJS_PRIVATE void emit_str(struct pstate* pstate, const char* ptr, size_t len);
|
|
|
|
/*
|
|
* Inserts provided offset `v` at the offset `offset`.
|
|
*
|
|
* Returns delta at which the code was moved; the delta can be any: 0 or
|
|
* positive or negative.
|
|
*/
|
|
MJS_PRIVATE int
|
|
mjs_bcode_insert_offset(struct pstate* p, struct mjs* mjs, size_t offset, size_t v);
|
|
|
|
/*
|
|
* Adds a new bcode part; does not retain `bp`.
|
|
*/
|
|
MJS_PRIVATE void mjs_bcode_part_add(struct mjs* mjs, const struct mjs_bcode_part* bp);
|
|
|
|
/*
|
|
* Returns bcode part by the bcode number
|
|
*/
|
|
MJS_PRIVATE struct mjs_bcode_part* mjs_bcode_part_get(struct mjs* mjs, int num);
|
|
|
|
/*
|
|
* Returns bcode part by the global bcode offset
|
|
*/
|
|
MJS_PRIVATE struct mjs_bcode_part* mjs_bcode_part_get_by_offset(struct mjs* mjs, size_t offset);
|
|
|
|
/*
|
|
* Returns a number of bcode parts
|
|
*/
|
|
MJS_PRIVATE int mjs_bcode_parts_cnt(struct mjs* mjs);
|
|
|
|
/*
|
|
* Adds the bcode being generated (mjs->bcode_gen) as a next bcode part
|
|
*/
|
|
MJS_PRIVATE void mjs_bcode_commit(struct mjs* mjs);
|
|
|
|
#if defined(__cplusplus)
|
|
}
|
|
#endif /* __cplusplus */
|
|
|
|
#endif /* MJS_BCODE_H_ */
|