• 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 
100 
101 #undef __insn
102 #define __insn(_name) I_##_name,
103 
104 typedef enum {
105         __insns
106         __I_MAX
107 } uc_vm_insn_t;
108 
109 typedef enum {
110         STATUS_OK,
111         STATUS_EXIT,
112         ERROR_COMPILE,
113         ERROR_RUNTIME
114 } uc_vm_status_t;
115 
116 extern uint32_t insns[__I_MAX];
117 
118 void uc_vm_init(uc_vm_t *vm, uc_parse_config_t *config);
119 void uc_vm_free(uc_vm_t *vm);
120 
121 uc_value_t *uc_vm_scope_get(uc_vm_t *vm);
122 void uc_vm_scope_set(uc_vm_t *vm, uc_value_t *ctx);
123 
124 bool uc_vm_registry_exists(uc_vm_t *vm, const char *key);
125 uc_value_t *uc_vm_registry_get(uc_vm_t *vm, const char *key);
126 void uc_vm_registry_set(uc_vm_t *vm, const char *key, uc_value_t *value);
127 bool uc_vm_registry_delete(uc_vm_t *vm, const char *key);
128 
129 void uc_vm_stack_push(uc_vm_t *vm, uc_value_t *value);
130 uc_value_t *uc_vm_stack_pop(uc_vm_t *vm);
131 uc_value_t *uc_vm_stack_peek(uc_vm_t *vm, size_t offset);
132 
133 uc_exception_handler_t *uc_vm_exception_handler_get(uc_vm_t *vm);
134 void uc_vm_exception_handler_set(uc_vm_t *vm, uc_exception_handler_t *exhandler);
135 
136 uint32_t uc_vm_trace_get(uc_vm_t *vm);
137 void uc_vm_trace_set(uc_vm_t *vm, uint32_t level);
138 
139 uc_exception_type_t uc_vm_call(uc_vm_t *vm, bool mcall, size_t nargs);
140 
141 void __attribute__((format(printf, 3, 0)))
142 uc_vm_raise_exception(uc_vm_t *vm, uc_exception_type_t type, const char *fmt, ...);
143 
144 uc_vm_status_t uc_vm_execute(uc_vm_t *vm, uc_program_t *fn, uc_value_t **retval);
145 uc_value_t *uc_vm_invoke(uc_vm_t *vm, const char *fname, size_t nargs, ...);
146 
147 #endif /* UCODE_VM_H */
148 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt