From 43cd95960cdbbe8fb531d7d9e873f2645973bf00 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Thu, 17 Oct 2024 13:04:02 +0200 Subject: [PATCH] Bytecode: Rename `Copy` to `Dup` --- src/lang/bytecode.h | 2 +- src/lang/interpreter.cc | 8 ++++---- src/lang/lang.h | 2 +- src/lang/passes/bytecode.cc | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lang/bytecode.h b/src/lang/bytecode.h index 957048b..4faa24f 100644 --- a/src/lang/bytecode.h +++ b/src/lang/bytecode.h @@ -23,7 +23,7 @@ inline const trieste::TokenDef ReturnValue{"return_value"}; /// which value should be duplicate. /// /// Stack: `[]::` -> `[]::::` -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"}; diff --git a/src/lang/interpreter.cc b/src/lang/interpreter.cc index a98257d..35d1f28 100644 --- a/src/lang/interpreter.cc +++ b/src/lang/interpreter.cc @@ -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); diff --git a/src/lang/lang.h b/src/lang/lang.h index 233136a..8d6cee6 100644 --- a/src/lang/lang.h +++ b/src/lang/lang.h @@ -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]; } diff --git a/src/lang/passes/bytecode.cc b/src/lang/passes/bytecode.cc index 3767372..0c3dbbc 100644 --- a/src/lang/passes/bytecode.cc +++ b/src/lang/passes/bytecode.cc @@ -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))