• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/include/ucode/vm.h

  1 /*
  2  * Copyright (C) 2020-2021 Jo-Philipp Wich <jo@mein.io>
  3  *
  4  * Permission to use, copy, modify, and/or distribute this software for any
  5  * purpose with or without fee is hereby granted, provided that the above
  6  * copyright notice and this permission notice appear in all copies.
  7  *
  8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15  */
 16 
 17 #ifndef UCODE_VM_H
 18 #define UCODE_VM_H
 19 
 20 #include <stdbool.h>
 21 #include <stdarg.h>
 22 
 23 #include "chunk.h"
 24 #include "util.h"
 25 #include "lexer.h"
 26 #include "types.h"
 27 #include "program.h"
 28 
 29 #define __insns \
 30 __insn(NOOP) \
 31 __insn(LOAD) \
 32 __insn(LOAD8) \
 33 __insn(LOAD16) \
 34 __insn(LOAD32) \
 35 __insn(LTHIS) \
 36 __insn(LREXP) \
 37 __insn(LNULL) \
 38 __insn(LTRUE) \
 39 __insn(LFALSE) \
 40 __insn(LLOC) \
 41 __insn(LUPV) \
 42 __insn(LVAR) \
 43 __insn(LVAL) \
 44 __insn(QLVAL) \
 45 __insn(CLFN) \
 46 __insn(ARFN) \
 47 __insn(SLOC) \
 48 __insn(SUPV) \
 49 __insn(SVAR) \
 50 __insn(SVAL) \
 51 __insn(ULOC) \
 52 __insn(UUPV) \
 53 __insn(UVAR) \
 54 __insn(UVAL) \
 55 __insn(NARR) \
 56 __insn(PARR) \
 57 __insn(MARR) \
 58 __insn(NOBJ) \
 59 __insn(SOBJ) \
 60 __insn(MOBJ) \
 61 __insn(BOR) \
 62 __insn(BXOR) \
 63 __insn(BAND) \
 64 __insn(EQS) \
 65 __insn(NES) \
 66 __insn(EQ) \
 67 __insn(NE) \
 68 __insn(LT) \
 69 __insn(LE) \
 70 __insn(GT) \
 71 __insn(GE) \
 72 __insn(IN) \
 73 __insn(LSHIFT) \
 74 __insn(RSHIFT) \
 75 __insn(ADD) \
 76 __insn(SUB) \
 77 __insn(MUL) \
 78 __insn(DIV) \
 79 __insn(MOD) \
 80 __insn(EXP) \
 81 __insn(NOT) \
 82 __insn(COMPL) \
 83 __insn(PLUS) \
 84 __insn(MINUS) \
 85 __insn(JMP) \
 86 __insn(JMPZ) \
 87 __insn(COPY) \
 88 __insn(POP) \
 89 __insn(CUPV) \
 90 __insn(RETURN) \
 91 __insn(CALL) \
 92 __insn(MCALL) \
 93 __insn(QCALL) \
 94 __insn(QMCALL) \
 95 __insn(PRINT) \
 96 __insn(NEXTK) \
 97 __insn(NEXTKV) \
 98 __insn(DELETE) \
 99 __insn(IMPORT) \
100 __insn(EXPORT) \
101 __insn(DYNLOAD)
102 
103 
104 #undef __insn
105 #define __insn(_name) I_##_name,
106 
107 typedef enum {
108         __insns
109         __I_MAX
110 } uc_vm_insn_t;
111 
112 typedef enum {
113         STATUS_OK,
114         STATUS_EXIT,
115         ERROR_COMPILE,
116         ERROR_RUNTIME
117 } uc_vm_status_t;
118 
119 typedef enum {
120         GC_ENABLED = (1 << 0)
121 } uc_vm_gc_flags_t;
122 
123 #define GC_DEFAULT_INTERVAL 1000
124 
125 extern uint32_t insns[__I_MAX];
126 
127 void uc_vm_init(uc_vm_t *vm, uc_parse_config_t *config);
128 void uc_vm_free(uc_vm_t *vm);
129 
130 uc_value_t *uc_vm_scope_get(uc_vm_t *vm);
131 void uc_vm_scope_set(uc_vm_t *vm, uc_value_t *ctx);
132 
133 bool uc_vm_registry_exists(uc_vm_t *vm, const char *key);
134 uc_value_t *uc_vm_registry_get(uc_vm_t *vm, const char *key);
135 void uc_vm_registry_set(uc_vm_t *vm, const char *key, uc_value_t *value);
136 bool uc_vm_registry_delete(uc_vm_t *vm, const char *key);
137 
138 void uc_vm_stack_push(uc_vm_t *vm, uc_value_t *value);
139 uc_value_t *uc_vm_stack_pop(uc_vm_t *vm);
140 uc_value_t *uc_vm_stack_peek(uc_vm_t *vm, size_t offset);
141 
142 uc_exception_handler_t *uc_vm_exception_handler_get(uc_vm_t *vm);
143 void uc_vm_exception_handler_set(uc_vm_t *vm, uc_exception_handler_t *exhandler);
144 
145 uint32_t uc_vm_trace_get(uc_vm_t *vm);
146 void uc_vm_trace_set(uc_vm_t *vm, uint32_t level);
147 
148 bool uc_vm_gc_start(uc_vm_t *vm, uint16_t interval);
149 bool uc_vm_gc_stop(uc_vm_t *vm);
150 
151 uc_exception_type_t uc_vm_call(uc_vm_t *vm, bool mcall, size_t nargs);
152 
153 void __attribute__((format(printf, 3, 0)))
154 uc_vm_raise_exception(uc_vm_t *vm, uc_exception_type_t type, const char *fmt, ...);
155 
156 uc_vm_status_t uc_vm_execute(uc_vm_t *vm, uc_program_t *fn, uc_value_t **retval);
157 uc_value_t *uc_vm_invoke(uc_vm_t *vm, const char *fname, size_t nargs, ...);
158 
159 uc_exception_type_t uc_vm_signal_dispatch(uc_vm_t *vm);
160 void uc_vm_signal_raise(uc_vm_t *vm, int signo);
161 int uc_vm_signal_notifyfd(uc_vm_t *vm);
162 
163 #endif /* UCODE_VM_H */
164 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt