a bit better call stack

This commit is contained in:
2021-10-07 07:19:53 +02:00
parent 6ada537e47
commit f92cefc004
6 changed files with 98 additions and 68 deletions

48
ml.h
View File

@@ -1,6 +1,5 @@
#pragma once
#include <map>
#include <string>
#include <vector>
@@ -94,6 +93,8 @@ private:
// and the environment to run the function in.
typedef MlValue (*Builtin)(std::vector<MlValue>, MlEnvironment &);
// friend class
class MlPerfMon;
class MlValue {
public:
@@ -140,29 +141,15 @@ public:
MlValue eval(MlEnvironment &env);
bool is_builtin() const;
bool is_number() const;
bool is_string() const;
bool is_list() const;
// Get the boolean value of this value.
bool as_bool() const;
// Get this item's integer value
long as_int() const;
// Get this item's floating point value
double as_float() const;
// Get this item's string value
std::string as_string() const;
// Get this item's atom value
std::string as_atom() const;
// Get this item's list value
std::vector<MlValue> as_list() const;
// Push an item to the end of this list
@@ -172,13 +159,8 @@ public:
MlValue pop();
// Cast this to an integer value
MlValue cast_to_int() const;
// Cast this to a floating point value
MlValue cast_to_float() const;
// Cast this to a string
MlValue cast_to_string() const;
@@ -207,24 +189,26 @@ public:
private:
enum {
QUOTE,
ATOM,
INT,
FLOAT,
LIST,
STRING,
LAMBDA,
BUILTIN,
NIL
QUOTE,
ATOM,
INT,
FLOAT,
LIST,
STRING,
LAMBDA,
BUILTIN,
NIL
} type;
union {
long i;
double f;
Builtin b;
long i;
double f;
Builtin b;
} stack_data;
std::string str;
std::vector<MlValue> list;
MlEnvironment lambda_scope;
friend class MlPerfMon;
};