Skip to content

Commit

Permalink
19796: Adds opcode_stack opcode, MINOR (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
howsohazard authored Mar 28, 2024
1 parent af48bc3 commit 2409387
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 139 deletions.
11 changes: 9 additions & 2 deletions docs/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,18 @@ var data = [
"description" : "Like target, but evaluates to the resulting node of the previous iteration for applicable opcodes.",
"example" : "(while (< (target_index) 3) (print (previous_result)) (target_index))"
},

{
"parameter" : "opcode_stack",
"output" : "list of *",
"description" : "Evaluates to the list of opcodes that include the call stack.",
"example" : "(print (opcode_stack))"
},

{
"parameter" : "stack",
"output" : "*",
"description" : "Evaluates to the current execution context, also known as the scope stack.",
"output" : "list of assoc",
"description" : "Evaluates to the current execution context, also known as the scope stack, containing all of the variables for each layer of the stack.",
"example" : "(print (stack))"
},

Expand Down
1 change: 1 addition & 0 deletions src/Amalgam/Opcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void StringInternPool::InitializeStaticStrings()
EmplaceStaticString(GetStringIdFromNodeTypeFromString(ENT_CURRENT_INDEX), "current_index");
EmplaceStaticString(GetStringIdFromNodeTypeFromString(ENT_CURRENT_VALUE), "current_value");
EmplaceStaticString(GetStringIdFromNodeTypeFromString(ENT_PREVIOUS_RESULT), "previous_result");
EmplaceStaticString(GetStringIdFromNodeTypeFromString(ENT_OPCODE_STACK), "opcode_stack");
EmplaceStaticString(GetStringIdFromNodeTypeFromString(ENT_STACK), "stack");
EmplaceStaticString(GetStringIdFromNodeTypeFromString(ENT_ARGS), "args");

Expand Down
3 changes: 2 additions & 1 deletion src/Amalgam/Opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum EvaluableNodeType : uint8_t
ENT_CURRENT_INDEX,
ENT_CURRENT_VALUE,
ENT_PREVIOUS_RESULT,
ENT_OPCODE_STACK,
ENT_STACK,
ENT_ARGS,

Expand Down Expand Up @@ -374,7 +375,7 @@ constexpr OrderedChildNodeType GetInstructionOrderedChildNodeType(EvaluableNodeT
case ENT_RETRIEVE:
case ENT_GET:
case ENT_TARGET: case ENT_CURRENT_INDEX: case ENT_CURRENT_VALUE: case ENT_PREVIOUS_RESULT:
case ENT_STACK: case ENT_ARGS:
case ENT_OPCODE_STACK: case ENT_STACK: case ENT_ARGS:
case ENT_RAND: case ENT_WEIGHTED_RAND: case ENT_GET_RAND_SEED: case ENT_SET_RAND_SEED:
case ENT_SYSTEM_TIME:
case ENT_GET_DIGITS: case ENT_SET_DIGITS:
Expand Down
3 changes: 3 additions & 0 deletions src/Amalgam/amlg_code/full_test.amlg
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,9 @@
(current_index)
)

(print "--opcode_stack--\n")
(print (size (opcode_stack)) "\n")

(print "--stack--\n")
(print (stack))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,7 @@ CompactHashMap<EvaluableNodeType, double> EvaluableNodeTreeManipulation::evaluab
{ENT_CURRENT_INDEX, 0.1},
{ENT_CURRENT_VALUE, 0.1},
{ENT_PREVIOUS_RESULT, 0.05},
{ENT_OPCODE_STACK, 0.01},
{ENT_STACK, 0.05},
{ENT_ARGS, 0.08},

Expand Down
1 change: 1 addition & 0 deletions src/Amalgam/interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ std::array<Interpreter::OpcodeFunction, ENT_NOT_A_BUILT_IN_TYPE + 1> Interpreter
&Interpreter::InterpretNode_ENT_CURRENT_INDEX, // ENT_CURRENT_INDEX
&Interpreter::InterpretNode_ENT_CURRENT_VALUE, // ENT_CURRENT_VALUE
&Interpreter::InterpretNode_ENT_PREVIOUS_RESULT, // ENT_PREVIOUS_RESULT
&Interpreter::InterpretNode_ENT_OPCODE_STACK, // ENT_OPCODE_STACK
&Interpreter::InterpretNode_ENT_STACK, // ENT_STACK
&Interpreter::InterpretNode_ENT_ARGS, // ENT_ARGS

Expand Down
1 change: 1 addition & 0 deletions src/Amalgam/interpreter/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ class Interpreter
EvaluableNodeReference InterpretNode_ENT_CURRENT_INDEX(EvaluableNode *en, bool immediate_result);
EvaluableNodeReference InterpretNode_ENT_CURRENT_VALUE(EvaluableNode *en, bool immediate_result);
EvaluableNodeReference InterpretNode_ENT_PREVIOUS_RESULT(EvaluableNode *en, bool immediate_result);
EvaluableNodeReference InterpretNode_ENT_OPCODE_STACK(EvaluableNode *en, bool immediate_result);
EvaluableNodeReference InterpretNode_ENT_STACK(EvaluableNode *en, bool immediate_result);
EvaluableNodeReference InterpretNode_ENT_ARGS(EvaluableNode *en, bool immediate_result);

Expand Down
9 changes: 9 additions & 0 deletions src/Amalgam/interpreter/InterpreterOpcodesBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,15 @@ EvaluableNodeReference Interpreter::InterpretNode_ENT_PREVIOUS_RESULT(EvaluableN
return GetAndClearPreviousResultInConstructionStack(depth);
}

EvaluableNodeReference Interpreter::InterpretNode_ENT_OPCODE_STACK(EvaluableNode *en, bool immediate_result)
{
//can create this node on the stack because will be making a copy
EvaluableNode stack_top_holder(ENT_LIST);
stack_top_holder.SetNeedCycleCheck(true);
stack_top_holder.SetOrderedChildNodes(*interpreterNodeStackNodes);
return evaluableNodeManager->DeepAllocCopy(&stack_top_holder);
}

EvaluableNodeReference Interpreter::InterpretNode_ENT_STACK(EvaluableNode *en, bool immediate_result)
{
#ifdef MULTITHREAD_SUPPORT
Expand Down
Loading

0 comments on commit 2409387

Please sign in to comment.