2020-09-13 21:32:55 -04:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-22 22:30:12 -04:00
|
|
|
/*!
|
|
|
|
* @file Interpreter.h
|
2020-11-21 12:52:38 -05:00
|
|
|
* The GOOS Interpreter and implementation of special and "built-in forms"
|
2020-08-22 22:30:12 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <memory>
|
2020-11-20 20:17:37 -05:00
|
|
|
#include <optional>
|
2022-06-22 23:37:46 -04:00
|
|
|
|
2020-08-22 22:30:12 -04:00
|
|
|
#include "Object.h"
|
|
|
|
#include "Reader.h"
|
|
|
|
|
|
|
|
namespace goos {
|
|
|
|
class Interpreter {
|
|
|
|
public:
|
2021-11-24 00:44:04 -05:00
|
|
|
Interpreter(const std::string& user_profile = "#f");
|
2020-08-29 19:13:29 -04:00
|
|
|
~Interpreter();
|
2023-01-07 11:24:02 -05:00
|
|
|
void execute_repl(REPL::Wrapper& repl);
|
2020-08-22 22:30:12 -04:00
|
|
|
void throw_eval_error(const Object& o, const std::string& err);
|
|
|
|
Object eval_with_rewind(const Object& obj, const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
bool get_global_variable_by_name(const std::string& name, Object* dest);
|
2021-07-15 21:37:15 -04:00
|
|
|
void set_global_variable_by_name(const std::string& name, const Object& value);
|
|
|
|
void set_global_variable_to_symbol(const std::string& name, const std::string& value);
|
2023-08-30 13:36:10 -04:00
|
|
|
void set_global_variable_to_int(const std::string& name, int value);
|
2020-08-22 22:30:12 -04:00
|
|
|
Object eval(Object obj, const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object intern(const std::string& name);
|
[goalc] Cleaned up speedups (#3066)
Started at 349,880,038 allocations and 42s
- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
2023-10-07 10:48:17 -04:00
|
|
|
InternedSymbolPtr intern_ptr(const std::string& name);
|
2020-08-22 22:30:12 -04:00
|
|
|
void disable_printfs();
|
2020-09-06 17:42:20 -04:00
|
|
|
Object eval_symbol(const Object& sym, const std::shared_ptr<EnvironmentObject>& env);
|
2021-02-21 11:02:28 -05:00
|
|
|
bool eval_symbol(const Object& sym,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env,
|
|
|
|
Object* result);
|
2020-09-06 17:42:20 -04:00
|
|
|
Arguments get_args(const Object& form, const Object& rest, const ArgumentSpec& spec);
|
2023-04-29 21:46:14 -04:00
|
|
|
Arguments get_args_no_named(const Object& form, const Object& rest, const ArgumentSpec& spec);
|
2020-09-06 17:42:20 -04:00
|
|
|
void set_args_in_env(const Object& form,
|
|
|
|
const Arguments& args,
|
|
|
|
const ArgumentSpec& arg_spec,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_list_return_last(const Object& form,
|
|
|
|
Object rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2020-09-07 13:28:16 -04:00
|
|
|
bool truthy(const Object& o);
|
2020-08-22 22:30:12 -04:00
|
|
|
|
2021-07-15 21:37:15 -04:00
|
|
|
void register_form(
|
|
|
|
const std::string& name,
|
|
|
|
const std::function<
|
|
|
|
Object(const Object&, Arguments&, const std::shared_ptr<EnvironmentObject>&)>& form);
|
|
|
|
void eval_args(Arguments* args, const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
|
2020-08-22 22:30:12 -04:00
|
|
|
Reader reader;
|
|
|
|
Object global_environment;
|
|
|
|
Object goal_env;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class Goal;
|
|
|
|
void load_goos_library();
|
[goalc] Cleaned up speedups (#3066)
Started at 349,880,038 allocations and 42s
- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
2023-10-07 10:48:17 -04:00
|
|
|
void define_var_in_env(Object& env, const Object& var, const std::string& name);
|
2020-08-22 22:30:12 -04:00
|
|
|
void expect_env(const Object& form, const Object& o);
|
|
|
|
void vararg_check(
|
|
|
|
const Object& form,
|
|
|
|
const Arguments& args,
|
2020-11-20 20:17:37 -05:00
|
|
|
const std::vector<std::optional<ObjectType>>& unnamed,
|
|
|
|
const std::unordered_map<std::string, std::pair<bool, std::optional<ObjectType>>>& named);
|
2020-08-22 22:30:12 -04:00
|
|
|
|
|
|
|
Object eval_pair(const Object& o, const std::shared_ptr<EnvironmentObject>& env);
|
2023-02-20 19:49:37 -05:00
|
|
|
|
|
|
|
public:
|
2020-08-22 22:30:12 -04:00
|
|
|
ArgumentSpec parse_arg_spec(const Object& form, Object& rest);
|
|
|
|
|
2023-02-20 19:49:37 -05:00
|
|
|
private:
|
2020-08-22 22:30:12 -04:00
|
|
|
Object quasiquote_helper(const Object& form, const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
|
|
|
|
IntType number_to_integer(const Object& obj);
|
|
|
|
FloatType number_to_float(const Object& obj);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T number(const Object& obj);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
Object num_lt(const Object& form, Arguments& args, const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
template <typename T>
|
|
|
|
Object num_gt(const Object& form, Arguments& args, const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
template <typename T>
|
|
|
|
Object num_leq(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
template <typename T>
|
|
|
|
Object num_geq(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
template <typename T>
|
|
|
|
Object num_plus(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
template <typename T>
|
|
|
|
Object num_minus(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
template <typename T>
|
|
|
|
Object num_divide(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
template <typename T>
|
|
|
|
Object num_times(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
|
|
|
|
Object eval_eval(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_equals(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_exit(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_begin(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_read(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2023-01-28 20:15:58 -05:00
|
|
|
Object eval_read_data_file(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2020-08-22 22:30:12 -04:00
|
|
|
Object eval_read_file(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_load_file(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2021-11-24 00:44:04 -05:00
|
|
|
Object eval_try_load_file(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2020-08-22 22:30:12 -04:00
|
|
|
Object eval_print(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_inspect(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_plus(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_minus(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_times(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_divide(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_numequals(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_lt(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_gt(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_leq(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_geq(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_car(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_cdr(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_set_car(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_set_cdr(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_gensym(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_cons(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_null(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_type(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2020-09-25 21:11:27 -04:00
|
|
|
Object eval_format(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_error(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2021-06-12 12:55:38 -04:00
|
|
|
Object eval_string_ref(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_string_length(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2021-06-30 19:20:31 -04:00
|
|
|
Object eval_string_append(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2023-01-28 20:15:58 -05:00
|
|
|
Object eval_string_starts_with(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_string_ends_with(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_string_split(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2023-04-29 11:01:47 -04:00
|
|
|
Object eval_string_substr(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2021-06-12 12:55:38 -04:00
|
|
|
Object eval_ash(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2021-07-15 21:37:15 -04:00
|
|
|
Object eval_symbol_to_string(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2021-08-01 17:11:32 -04:00
|
|
|
Object eval_string_to_symbol(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2023-10-06 10:42:16 -04:00
|
|
|
Object eval_int_to_string(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2021-11-13 22:41:15 -05:00
|
|
|
Object eval_get_env(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
2020-08-22 22:30:12 -04:00
|
|
|
|
|
|
|
// specials
|
|
|
|
Object eval_define(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_quote(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_set(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_lambda(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_cond(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_or(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_and(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_quasiquote(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_macro(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_while(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
[goalc] Cleaned up speedups (#3066)
Started at 349,880,038 allocations and 42s
- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
2023-10-07 10:48:17 -04:00
|
|
|
Object eval_let(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_let_star(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_let_common(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env,
|
|
|
|
bool star);
|
2020-08-22 22:30:12 -04:00
|
|
|
|
2022-05-21 19:36:14 -04:00
|
|
|
Object eval_make_string_hash_table(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_hash_table_try_ref(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
Object eval_hash_table_set(const Object& form,
|
|
|
|
Arguments& args,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env);
|
|
|
|
|
[goalc] Cleaned up speedups (#3066)
Started at 349,880,038 allocations and 42s
- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
2023-10-07 10:48:17 -04:00
|
|
|
const Object& true_or_false(bool val);
|
|
|
|
|
|
|
|
void init_special_forms(
|
|
|
|
const std::unordered_map<std::string,
|
|
|
|
Object (Interpreter::*)(const Object&,
|
|
|
|
const Object&,
|
|
|
|
const std::shared_ptr<EnvironmentObject>&)>&
|
|
|
|
forms);
|
|
|
|
|
|
|
|
void init_builtin_forms(
|
|
|
|
const std::unordered_map<std::string,
|
|
|
|
Object (Interpreter::*)(const Object&,
|
|
|
|
Arguments&,
|
|
|
|
const std::shared_ptr<EnvironmentObject>&)>&
|
|
|
|
forms);
|
|
|
|
|
2020-08-22 22:30:12 -04:00
|
|
|
bool want_exit = false;
|
|
|
|
bool disable_printing = false;
|
|
|
|
|
[goalc] Cleaned up speedups (#3066)
Started at 349,880,038 allocations and 42s
- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
2023-10-07 10:48:17 -04:00
|
|
|
std::unordered_map<
|
|
|
|
void*,
|
|
|
|
Object (Interpreter::*)(const Object&, Arguments&, const std::shared_ptr<EnvironmentObject>&)>
|
2020-08-22 22:30:12 -04:00
|
|
|
builtin_forms;
|
2021-07-15 21:37:15 -04:00
|
|
|
|
[goalc] Cleaned up speedups (#3066)
Started at 349,880,038 allocations and 42s
- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
2023-10-07 10:48:17 -04:00
|
|
|
std::vector<std::pair<
|
|
|
|
void*,
|
|
|
|
std::function<Object(const Object&, Arguments&, const std::shared_ptr<EnvironmentObject>&)>>>
|
2021-07-15 21:37:15 -04:00
|
|
|
m_custom_forms;
|
[goalc] Cleaned up speedups (#3066)
Started at 349,880,038 allocations and 42s
- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
2023-10-07 10:48:17 -04:00
|
|
|
|
|
|
|
std::vector<std::pair<void*,
|
|
|
|
Object (Interpreter::*)(const Object& form,
|
|
|
|
const Object& rest,
|
|
|
|
const std::shared_ptr<EnvironmentObject>& env)>>
|
2020-08-22 22:30:12 -04:00
|
|
|
special_forms;
|
|
|
|
int64_t gensym_id = 0;
|
|
|
|
|
|
|
|
std::unordered_map<std::string, ObjectType> string_to_type;
|
[goalc] Cleaned up speedups (#3066)
Started at 349,880,038 allocations and 42s
- Switched to making `Symbol` in GOOS be a "fixed type", just a wrapper
around a `const char*` pointing to the string in the symbol table. This
is a step toward making a lot of things better, but by itself not a huge
improvement. Some things may be worse due to more temp `std::string`
allocations, but one day all these can be removed. On linux it saved
allocations (347,685,429), and saved a second or two (41 s).
- cache `#t` and `#f` in interpreter, better lookup for special
forms/builtins (hashtable of pointers instead of strings, vector for the
small special form list). Dropped time to 38s.
- special-case in quasiquote when splicing is the last thing in a list.
Allocation dropped to 340,603,082
- custom hash table for environment lookups (lexical vars). Dropped to
36s and 314,637,194
- less allocation in `read_list` 311,613,616. Time about the same.
- `let` and `let*` in Interpreter.cpp 191,988,083, time down to 28s.
2023-10-07 10:48:17 -04:00
|
|
|
|
|
|
|
const char* m_false_sym = nullptr;
|
|
|
|
const char* m_true_sym = nullptr;
|
|
|
|
Object m_false_object, m_true_object;
|
2020-08-22 22:30:12 -04:00
|
|
|
};
|
|
|
|
} // namespace goos
|