00001
00013 #ifndef NEWTVM_H
00014 #define NEWTVM_H
00015
00016
00017
00018 #include <stdio.h>
00019 #include "NewtType.h"
00020 #include "NewtMem.h"
00021
00022
00023
00024
00026 enum {
00027 kIterIndex = 0,
00028 kIterValue,
00029 kIterObj,
00030 kIterDeeply,
00031 kIterPos,
00032 kIterMax,
00033 kIterMap,
00034
00035
00036 kIterALength
00037 };
00038
00039
00041 typedef struct {
00042 newtRefVar func;
00043 uint32_t pc;
00044 uint32_t sp;
00045 newtRefVar locals;
00046 newtRefVar rcvr;
00047 newtRefVar impl;
00048 } vm_reg_t;
00049
00050
00052 typedef struct {
00053 uint32_t callsp;
00054 uint32_t excppc;
00055
00056 newtRefVar sym;
00057 uint32_t pc;
00058 } vm_excp_t;
00059
00060
00062 typedef struct {
00063
00064 uint8_t * bc;
00065 uint32_t bclen;
00066
00067
00068 vm_reg_t reg;
00069
00070
00071 newtStack stack;
00072 newtStack callstack;
00073 newtStack excpstack;
00074
00075
00076 newtRefVar currexcp;
00077
00078
00079 uint16_t level;
00080 } vm_env_t;
00081
00082
00083 extern vm_env_t vm_env;
00084
00085
00086
00087
00088 #ifdef __cplusplus
00089 extern "C" {
00090 #endif
00091
00092
00093 newtRef NVMSelf(void);
00094 newtRef NVMCurrentFunction(void);
00095 newtRef NVMCurrentImplementor(void);
00096 bool NVMHasVar(newtRefArg name);
00097 void NVMThrowData(newtRefArg name, newtRefArg data);
00098 void NVMThrow(newtRefArg name, newtRefArg data);
00099 void NVMRethrow(void);
00100 newtRef NVMCurrentException(void);
00101 void NVMClearException(void);
00102
00103 bool NVMFuncCheckNumArgs(newtRefArg fn, int16_t numArgs);
00104
00105 void NVMDumpInstName(FILE * f, uint8_t a, int16_t b);
00106 void NVMDumpCode(FILE * f, uint8_t * bc, uint32_t len);
00107 void NVMDumpBC(FILE * f, newtRefArg instructions);
00108 void NVMDumpFn(FILE * f, newtRefArg fn);
00109 void NVMDumpStackTop(FILE * f, char * s);
00110 void NVMDumpStacks(FILE * f);
00111
00112 void NVMFnCall(newtRefArg fn, int16_t numArgs);
00113 newtRef NVMInterpret(newtRefArg fn, newtErr * errP);
00114 newtErr NVMInfo(const char * name);
00115
00116 newtRef NVMCall(newtRefArg fn, int16_t numArgs, newtErr * errP);
00117 newtRef NVMInterpretFile(const char * path, newtErr * errP);
00118 newtRef NVMInterpretStr(const char * s, newtErr * errP);
00119
00120 newtRef NVMMessageSendWithArgArray(newtRefArg inImpl, newtRefArg inRcvr,
00121 newtRefArg inFunction, newtRefArg inArgs);
00122
00123 #ifdef __cplusplus
00124 }
00125 #endif
00126
00127
00128 #endif
00129