Skip to content

Commit

Permalink
Bytecode: Rename Copy to Dup
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Oct 17, 2024
1 parent 867fbfe commit 43cd959
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/lang/bytecode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ inline const trieste::TokenDef ReturnValue{"return_value"};
/// which value should be duplicate.
///
/// Stack: `[]::<arg_0>` -> `[]::<arg_0>::<arg_0>`
inline const trieste::TokenDef Copy{"copy", trieste::flag::print};
inline const trieste::TokenDef Dup{"dup", trieste::flag::print};

inline const trieste::TokenDef CreateRegion{"create_region"};
inline const trieste::TokenDef FreezeObject{"freeze_object"};
Expand Down
8 changes: 4 additions & 4 deletions src/lang/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,15 @@ namespace verona::interpreter
return action;
}

if (node == Copy)
if (node == Dup)
{
// This breaks the normal idea of a stack machine, but every other
// solution would require more effort and would be messier
auto copy_idx = std::stoul(std::string(node->location().view()));
auto dup_idx = std::stoul(std::string(node->location().view()));
auto stack_size = stack().size();
assert(copy_idx < stack_size && "the stack is too small for this copy");
assert(dup_idx < stack_size && "the stack is too small for this duplication");

auto var = stack()[stack_size - copy_idx - 1];
auto var = stack()[stack_size - dup_idx - 1];
stack().push_back(var);
std::cout << "push " << var << std::endl;
rt::add_reference(frame(), var);
Expand Down
2 changes: 1 addition & 1 deletion src/lang/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace verona::wf
(LoadFrame | StoreFrame | LoadField | StoreField | Drop | Null |
CreateObject | CreateRegion | FreezeObject | IterNext | Print | Eq | Neq |
Jump | JumpFalse | Label | Call | Return | ReturnValue | ClearStack |
Copy)++) |
Dup)++) |
(CreateObject <<= (Dictionary | String | KeyIter | Proto | Func)) |
(Func <<= Body) | (Label <<= Ident)[Ident];
}
Expand Down
4 changes: 2 additions & 2 deletions src/lang/passes/bytecode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ PassDef bytecode()
// `self` lookup and first argument
<< (Compile << _(Op))
<< (Compile << _[List])
// Copy self
<< (Copy ^ std::to_string(arg_ctn))
// Duplicate self
<< (Dup ^ std::to_string(arg_ctn))
// Fetch the function
<< (Compile << _(Key))
<< create_from(LoadField, _(Lookup))
Expand Down

0 comments on commit 43cd959

Please sign in to comment.