All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Typedefs | Enumerations | Functions
uscript Namespace Reference

Classes

class  Chunk
 
class  Compiler
 
struct  Token
 
class  Scanner
 
struct  TData
 
struct  TField
 
struct  TClassInfo
 
class  TClassList
 
struct  ObjString
 
struct  ObjTInstance
 
struct  Value
 
class  VM
 

Typedefs

template<typename T >
using JustAChar = const char *
 
template<typename T >
using JustACharRef = const char *&
 

Enumerations

enum  OpCode {
  OP_RETURN, OP_CONSTANT, OP_NIL, OP_TRUE,
  OP_FALSE, OP_POP, OP_GET_LOCAL, OP_SET_LOCAL,
  OP_SET_GLOBAL, OP_GET_GLOBAL, OP_DEFINE_GLOBAL, OP_EQUAL,
  OP_GREATER, OP_LESS, OP_ADD, OP_SUBTRACT,
  OP_MULTIPLY, OP_DIVIDE, OP_NOT, OP_NEGATE,
  OP_PRINT, OP_FIELDS, OP_LENGTH, OP_JUMP_IF_FALSE,
  OP_JUMP, OP_LOOP, OP_CALL, OP_INDEX,
  OP_GET_PROPERTY
}
 
enum  TokenType {
  TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_LEFT_BRACE, TOKEN_RIGHT_BRACE,
  TOKEN_LEFT_BRACKET, TOKEN_RIGHT_BRACKET, TOKEN_COMMA, TOKEN_DOT,
  TOKEN_MINUS, TOKEN_PLUS, TOKEN_SEMICOLON, TOKEN_SLASH,
  TOKEN_STAR, TOKEN_BANG, TOKEN_BANG_EQUAL, TOKEN_EQUAL,
  TOKEN_EQUAL_EQUAL, TOKEN_GREATER, TOKEN_GREATER_EQUAL, TOKEN_LESS,
  TOKEN_LESS_EQUAL, TOKEN_IDENTIFIER, TOKEN_STRING, TOKEN_NUMBER,
  TOKEN_AND, TOKEN_CLASS, TOKEN_ELSE, TOKEN_FALSE,
  TOKEN_FOR, TOKEN_FUN, TOKEN_IF, TOKEN_NIL,
  TOKEN_OR, TOKEN_PRINT, TOKEN_RETURN, TOKEN_SUPER,
  TOKEN_THIS, TOKEN_TRUE, TOKEN_VAR, TOKEN_WHILE,
  TOKEN_LENGTH, TOKEN_FIELDS, TOKEN_ERROR, TOKEN_EOF
}
 
enum  TFieldType {
  FIELD_BOOL, FIELD_INT, FIELD_UNSIGNED, FIELD_FLOAT,
  FIELD_DOUBLE, FIELD_ENUM, FIELD_TINSTANCE
}
 
enum  ValueType {
  VAL_BOOL, VAL_NIL, VAL_NUMBER, VAL_INTEGER,
  VAL_OBJ_STRING, VAL_OBJ_TINSTANCE
}
 
enum  InterpretResult { INTERPRET_OK, INTERPRET_COMPILE_ERROR, INTERPRET_RUNTIME_ERROR }
 

Functions

void SetAll (VM &vm, std::initializer_list< const char * > names)
 
template<typename... Ts>
void _swallow (Ts &&...)
 
template<typename... TObjs>
void RegisterAll ()
 
template<typename... TObjs>
void AddAll (VM &vm)
 
template<typename T , typename... TObjs>
void AddAll (VM &vm, JustACharRef< T > name, JustACharRef< TObjs >...names, const T *&obj, const TObjs *&...objs)
 
template<typename... TObjs>
Chunk compileChunk (const char *source)
 
template<typename... TObjs>
std::function< uscript::Value(const
TObjs *...)> 
compile (JustAChar< TObjs >...names, const char *source)
 
 DECLARE_ADDGLOBAL_SPECIAL (int)
 
 DECLARE_ADDGLOBAL_SPECIAL (unsigned)
 
 DECLARE_ADDGLOBAL_SPECIAL (float)
 
 DECLARE_ADDGLOBAL_SPECIAL (double)
 
 DECLARE_ADDGLOBAL_SPECIAL (bool)
 

Typedef Documentation

template<typename T >
using uscript::JustAChar = typedef const char *

Definition at line 15 of file api.h.

template<typename T >
using uscript::JustACharRef = typedef const char *&

Definition at line 18 of file api.h.

Enumeration Type Documentation

Enumerator
INTERPRET_OK 
INTERPRET_COMPILE_ERROR 
INTERPRET_RUNTIME_ERROR 

Definition at line 14 of file vm.h.

Enumerator
OP_RETURN 
OP_CONSTANT 
OP_NIL 
OP_TRUE 
OP_FALSE 
OP_POP 
OP_GET_LOCAL 
OP_SET_LOCAL 
OP_SET_GLOBAL 
OP_GET_GLOBAL 
OP_DEFINE_GLOBAL 
OP_EQUAL 
OP_GREATER 
OP_LESS 
OP_ADD 
OP_SUBTRACT 
OP_MULTIPLY 
OP_DIVIDE 
OP_NOT 
OP_NEGATE 
OP_PRINT 
OP_FIELDS 
OP_LENGTH 
OP_JUMP_IF_FALSE 
OP_JUMP 
OP_LOOP 
OP_CALL 
OP_INDEX 
OP_GET_PROPERTY 

Definition at line 13 of file chunk.h.

13  {
14  OP_RETURN,
16  OP_NIL,
17  OP_TRUE,
18  OP_FALSE,
19  OP_POP,
25  OP_EQUAL,
26  OP_GREATER,
27  OP_LESS,
28  OP_ADD,
31  OP_DIVIDE,
32  OP_NOT,
33  OP_NEGATE,
34  OP_PRINT,
35  OP_FIELDS,
36  OP_LENGTH,
38  OP_JUMP,
39  OP_LOOP,
40  OP_CALL,
41  OP_INDEX,
43 };
Enumerator
FIELD_BOOL 
FIELD_INT 
FIELD_UNSIGNED 
FIELD_FLOAT 
FIELD_DOUBLE 
FIELD_ENUM 
FIELD_TINSTANCE 

Definition at line 11 of file tclass.h.

Enumerator
TOKEN_LEFT_PAREN 
TOKEN_RIGHT_PAREN 
TOKEN_LEFT_BRACE 
TOKEN_RIGHT_BRACE 
TOKEN_LEFT_BRACKET 
TOKEN_RIGHT_BRACKET 
TOKEN_COMMA 
TOKEN_DOT 
TOKEN_MINUS 
TOKEN_PLUS 
TOKEN_SEMICOLON 
TOKEN_SLASH 
TOKEN_STAR 
TOKEN_BANG 
TOKEN_BANG_EQUAL 
TOKEN_EQUAL 
TOKEN_EQUAL_EQUAL 
TOKEN_GREATER 
TOKEN_GREATER_EQUAL 
TOKEN_LESS 
TOKEN_LESS_EQUAL 
TOKEN_IDENTIFIER 
TOKEN_STRING 
TOKEN_NUMBER 
TOKEN_AND 
TOKEN_CLASS 
TOKEN_ELSE 
TOKEN_FALSE 
TOKEN_FOR 
TOKEN_FUN 
TOKEN_IF 
TOKEN_NIL 
TOKEN_OR 
TOKEN_PRINT 
TOKEN_RETURN 
TOKEN_SUPER 
TOKEN_THIS 
TOKEN_TRUE 
TOKEN_VAR 
TOKEN_WHILE 
TOKEN_LENGTH 
TOKEN_FIELDS 
TOKEN_ERROR 
TOKEN_EOF 

Definition at line 8 of file scanner.h.

8  {
9  // Single-character tokens.
15 
16  // One or two character tokens.
21 
22  // Literals.
24 
25  // Keywords.
30 
31  // more keywords
33 
35  TOKEN_EOF
36 };
Enumerator
VAL_BOOL 
VAL_NIL 
VAL_NUMBER 
VAL_INTEGER 
VAL_OBJ_STRING 
VAL_OBJ_TINSTANCE 

Definition at line 9 of file value.h.

Function Documentation

template<typename... Ts>
void uscript::_swallow ( Ts &&  ...)

Definition at line 27 of file api.h.

27 {}
template<typename... TObjs>
void uscript::AddAll ( VM &  vm)

Definition at line 35 of file api.h.

35 {}
template<typename T , typename... TObjs>
void uscript::AddAll ( VM &  vm,
JustACharRef< T >  name,
JustACharRef< TObjs >...  names,
const T *&  obj,
const TObjs *&...  objs 
)

Definition at line 38 of file api.h.

38  {
39  vm.AddGlobal(name, obj);
40  AddAll<TObjs...>(vm, names..., objs...);
41 }
void AddAll(VM &vm)
Definition: api.h:35
static const std::vector< std::string > names
then echo fcl name
template<typename... TObjs>
std::function<uscript::Value (const TObjs*...)> uscript::compile ( JustAChar< TObjs >...  names,
const char *  source 
)

Definition at line 55 of file api.h.

55  {
56  Chunk chunk = compileChunk<TObjs...>(source);
57 
58  VM vm;
59  SetAll(vm, {names...});
60  return [chunk, vm, names...](const TObjs *... data) mutable {
61  vm.SetChunk(&chunk);
62  AddAll<TObjs...>(vm, names..., data...);
63  Value value;
64  vm.Run(&value);
65  return value;
66  };
67 }
Chunk compileChunk(const char *source)
Definition: api.h:45
do source
void AddAll(VM &vm)
Definition: api.h:35
void SetAll(VM &vm, std::initializer_list< const char * > names)
Definition: api.h:20
static const std::vector< std::string > names
temporary value
template<typename... TObjs>
Chunk uscript::compileChunk ( const char *  source)

Definition at line 45 of file api.h.

45  {
46  Chunk chunk;
47  RegisterAll<TObjs...>();
48 
50 
51  return std::move(chunk);
52 }
do source
void RegisterAll()
Definition: api.h:30
static bool Compile(const char *source, Chunk *chunk)
Definition: compile.h:140
uscript::DECLARE_ADDGLOBAL_SPECIAL ( int  )
uscript::DECLARE_ADDGLOBAL_SPECIAL ( unsigned  )
uscript::DECLARE_ADDGLOBAL_SPECIAL ( float  )
uscript::DECLARE_ADDGLOBAL_SPECIAL ( double  )
uscript::DECLARE_ADDGLOBAL_SPECIAL ( bool  )
template<typename... TObjs>
void uscript::RegisterAll ( )

Definition at line 30 of file api.h.

30  {
31  _swallow(uscript::Compiler::Register<TObjs>...);
32 }
void _swallow(Ts &&...)
Definition: api.h:27
void uscript::SetAll ( VM &  vm,
std::initializer_list< const char * >  names 
)
inline

Definition at line 20 of file api.h.

20  {
21  for (const char *name: names) {
22  vm.AddGlobal(name);
23  }
24 }
static const std::vector< std::string > names
then echo fcl name