All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
vm.cc File Reference
#include <iostream>
#include <cassert>
#include "vm.h"
#include "common.h"
#include "compile.h"

Go to the source code of this file.

Macros

#define BINARY_OP(op)
 
#define COMP_OP(op)
 
#define READ_STRING()   AS_CSTRING(ReadConstant())
 
#define READ_SHORT()   (ip += 2, (uint16_t)((chunk->code[ip-2] << 8) | chunk->code[ip-1]))
 

Functions

static bool valuesEqual (uscript::Value a, uscript::Value b)
 

Macro Definition Documentation

#define BINARY_OP (   op)
Value:
do { \
if (IS_NUMBER(Peek(0)) && IS_NUMBER(Peek(1))) { \
double b = AS_NUMBER(Pop()); \
double a = AS_NUMBER(Pop()); \
Push(NUMBER_VAL(a op b)); \
} \
else if (IS_INTEGER(Peek(0)) && IS_INTEGER(Peek(1))) { \
int b = AS_INTEGER(Pop()); \
int a = AS_INTEGER(Pop()); \
Push(INTEGER_VAL(a op b)); \
} \
else { \
RuntimeError("Operands must be both integers or both numbers."); \
} \
} while (false)
#define IS_INTEGER(value)
Definition: value.h:62
then if[["$THISISATEST"==1]]
Definition: neoSmazza.sh:95
process_name gaushit a
#define AS_NUMBER(value)
Definition: value.h:53
#define IS_NUMBER(value)
Definition: value.h:61
#define NUMBER_VAL(value)
Definition: value.h:47
#define INTEGER_VAL(value)
Definition: value.h:48
#define AS_INTEGER(value)
Definition: value.h:54
#define COMP_OP (   op)
Value:
do { \
if (IS_NUMBER(Peek(0)) && IS_NUMBER(Peek(1))) { \
double b = AS_NUMBER(Pop()); \
double a = AS_NUMBER(Pop()); \
Push(BOOL_VAL(a op b)); \
} \
else if (IS_INTEGER(Peek(0)) && IS_INTEGER(Peek(1))) { \
int b = AS_INTEGER(Pop()); \
int a = AS_INTEGER(Pop()); \
Push(BOOL_VAL(a op b)); \
} \
else { \
RuntimeError("Operands must be both integers or both numbers."); \
} \
} while (false)
#define IS_INTEGER(value)
Definition: value.h:62
then if[["$THISISATEST"==1]]
Definition: neoSmazza.sh:95
#define BOOL_VAL(value)
Definition: value.h:45
process_name gaushit a
#define AS_NUMBER(value)
Definition: value.h:53
#define IS_NUMBER(value)
Definition: value.h:61
#define AS_INTEGER(value)
Definition: value.h:54
#define READ_SHORT ( )    (ip += 2, (uint16_t)((chunk->code[ip-2] << 8) | chunk->code[ip-1]))
#define READ_STRING ( )    AS_CSTRING(ReadConstant())

Function Documentation

static bool valuesEqual ( uscript::Value  a,
uscript::Value  b 
)
static

Definition at line 48 of file vm.cc.

48  {
49  if (a.val != b.val) return false;
50 
51  switch (a.val) {
52  case uscript::VAL_BOOL: return AS_BOOL(a) == AS_BOOL(b);
53  case uscript::VAL_NIL: return true;
54  case uscript::VAL_NUMBER: return AS_NUMBER(a) == AS_NUMBER(b);
55  case uscript::VAL_INTEGER: return AS_INTEGER(a) == AS_INTEGER(b);
57  return AS_CSTRING(a) == AS_CSTRING(b);
58  }
59  default:
60  return false;
61  }
62 
63 }
#define AS_BOOL(value)
Definition: value.h:52
#define AS_NUMBER(value)
Definition: value.h:53
#define AS_CSTRING(value)
Definition: value.h:56
ValueType val
Definition: value.h:30
#define AS_INTEGER(value)
Definition: value.h:54