Skip to content

Commit

Permalink
Merge pull request #31 from mjp41/minor
Browse files Browse the repository at this point in the history
Just a couple of minor tidyings
  • Loading branch information
mjp41 authored Oct 24, 2024
2 parents 15980fa + e599cde commit 304a153
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SeparateDefinitionBlocks: Always
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ target_link_libraries(lang PRIVATE trieste::trieste)
add_executable(verona_dyn src/main.cc)
target_link_libraries(verona_dyn PRIVATE rt lang)

set_property(TARGET verona_dyn PROPERTY COMPILE_WARNING_AS_ERROR ON)

# Add snmallocs clang format targets
clangformat_targets()

Expand Down
7 changes: 7 additions & 0 deletions src/lang/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ namespace verona::interpreter
// ==============================================
struct ExecNext
{};

struct ExecJump
{
trieste::Location target;
};

struct ExecFunc
{
trieste::Node body;
size_t arg_ctn;
};

struct ExecReturn
{
std::optional<rt::objects::DynObject*> value;
Expand Down Expand Up @@ -76,6 +79,7 @@ namespace verona::interpreter
frame_stack.push_back(frame);
return frame;
}

InterpreterFrame* pop_stack_frame()
{
auto frame = frame_stack.back();
Expand All @@ -91,6 +95,7 @@ namespace verona::interpreter
return frame_stack.back();
}
}

InterpreterFrame* parent_stack_frame()
{
return frame_stack[frame_stack.size() - 2];
Expand All @@ -100,10 +105,12 @@ namespace verona::interpreter
{
return frame_stack.back()->stack;
}

rt::objects::DynObject* frame()
{
return frame_stack.back()->frame;
}

rt::objects::DynObject* global_frame()
{
return frame_stack.front()->frame;
Expand Down
3 changes: 3 additions & 0 deletions src/lang/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,18 @@ inline Node create_print(size_t line, std::string text)
ss << "Line " << line << ": " << text;
return NodeDef::create(Print, ss.str());
}

inline Node create_print(Node from, std::string text)
{
auto [line, col] = from->location().linecol();
return create_print(line + 1, text);
}

inline Node create_print(Node from)
{
return create_print(from, std::string(from->location().view()));
}

inline Node create_from(Token def, Node from)
{
return NodeDef::create(def, from->location());
Expand Down
2 changes: 2 additions & 0 deletions src/lang/passes/flatten.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ namespace verona::wf
} // namespace verona::wf

int g_jump_label_counter = 0;

std::string new_jump_label()
{
g_jump_label_counter += 1;
return "label_" + std::to_string(g_jump_label_counter);
}

int g_iter_name = 0;

std::string new_iter_name()
{
g_iter_name += 1;
Expand Down
18 changes: 11 additions & 7 deletions src/rt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace rt::core
: objects::DynObject(prototype), name(name_)
{}

std::string get_name()
std::string get_name() override
{
std::stringstream stream;
stream << "[" << name << "]";
Expand Down Expand Up @@ -55,12 +55,14 @@ namespace rt::core
static PrototypeObject* proto = new PrototypeObject("Function");
return proto;
}

inline PrototypeObject* bytecodeFuncPrototypeObject()
{
static PrototypeObject* proto =
new PrototypeObject("BytecodeFunction", funcPrototypeObject());
return proto;
}

inline PrototypeObject* builtinFuncPrototypeObject()
{
static PrototypeObject* proto =
Expand All @@ -84,6 +86,7 @@ namespace rt::core
BytecodeFuncObject(verona::interpreter::Bytecode* body_)
: FuncObject(bytecodeFuncPrototypeObject()), body(body_)
{}

~BytecodeFuncObject()
{
verona::interpreter::delete_bytecode(this->body);
Expand Down Expand Up @@ -126,7 +129,7 @@ namespace rt::core
: objects::DynObject(stringPrototypeObject()), value(value_)
{}

std::string get_name()
std::string get_name() override
{
std::stringstream stream;
stream << "\"" << value << "\"";
Expand All @@ -138,7 +141,7 @@ namespace rt::core
return value;
}

objects::DynObject* is_primitive()
objects::DynObject* is_primitive() override
{
return this;
}
Expand All @@ -149,6 +152,7 @@ namespace rt::core
static StringObject* val = new StringObject("True");
return val;
}

inline StringObject* falseObject()
{
static StringObject* val = new StringObject("False");
Expand Down Expand Up @@ -186,12 +190,12 @@ namespace rt::core
return obj;
}

std::string get_name()
std::string get_name() override
{
return "<iterator>";
}

objects::DynObject* is_primitive()
objects::DynObject* is_primitive() override
{
return this;
}
Expand Down Expand Up @@ -227,12 +231,12 @@ namespace rt::core
this->fields["region"] = region;
}

std::string get_name()
std::string get_name() override
{
return "<cown>";
}

objects::DynObject* is_primitive()
objects::DynObject* is_primitive() override
{
return this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rt/objects/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ namespace rt::objects
r->parent = p;
assert(r->parent_reference_count == 1);

// If the region has local references, then we need the parent to have a
// local reference to.
// If the sub-region has local references, then we need the parent to have
// a local reference to.
if (r->local_reference_count == 0)
return;

Expand Down
7 changes: 7 additions & 0 deletions src/rt/rt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace rt
core::globals()->insert(builtin);
core::global_names()->insert({name, builtin});
}

objects::DynObject* get_builtin(std::string name)
{
auto globals = core::global_names();
Expand All @@ -33,22 +34,27 @@ namespace rt
{
return new core::BytecodeFuncObject(body);
}

objects::DynObject* make_iter(objects::DynObject* iter_src)
{
return new core::KeyIterObject(iter_src->fields);
}

objects::DynObject* make_str(std::string value)
{
return new core::StringObject(value);
}

objects::DynObject* make_object()
{
return new objects::DynObject();
}

objects::DynObject* make_frame(objects::DynObject* parent)
{
return new core::FrameObject(parent);
}

objects::DynObject* make_cown(objects::DynObject* region)
{
return new core::CownObject(region);
Expand Down Expand Up @@ -137,6 +143,7 @@ namespace rt
{
return core::trueObject();
}

objects::DynObject* get_false()
{
return core::falseObject();
Expand Down
3 changes: 3 additions & 0 deletions src/rt/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace rt::core
namespace rt::ui
{
class MermaidDiagram;

class MermaidUI : public UI
{
friend class MermaidDiagram;
Expand Down Expand Up @@ -57,6 +58,7 @@ namespace rt::ui
{
unreachable_hide.insert(obj);
}

void remove_unreachable_hide(objects::DynObject* obj)
{
unreachable_hide.erase(obj);
Expand All @@ -66,6 +68,7 @@ namespace rt::ui
{
always_hide.insert(obj);
}

void remove_always_hide(objects::DynObject* obj)
{
always_hide.erase(obj);
Expand Down
2 changes: 2 additions & 0 deletions src/rt/ui/mermaid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ namespace rt::ui
objects::visit({nullptr, "", root}, explore);
}
}

void draw_regions()
{
// Output any region parent edges.
Expand Down Expand Up @@ -162,6 +163,7 @@ namespace rt::ui
out << "end" << std::endl;
}
}

void draw_immutable_region()
{
// Output the immutable region.
Expand Down
2 changes: 2 additions & 0 deletions src/utils/tagged_pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace utils

public:
TaggedPointer(T* ptr) : ptr(reinterpret_cast<uintptr_t>(ptr)) {}

constexpr TaggedPointer(std::nullptr_t) : ptr(0) {}

TaggedPointer(T* ptr, uintptr_t tag)
Expand All @@ -32,6 +33,7 @@ namespace utils
{
return ptr == other.ptr;
}

bool operator!=(TaggedPointer other) const
{
return ptr != other.ptr;
Expand Down

0 comments on commit 304a153

Please sign in to comment.