Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
code_do_instruction = pysh_instruction.Pysh_Instruction('code_do',
code_do,
stack_types = ['_code', '_exec'])
ri.register_instruction(code_do_instruction)
def code_do_star(state):
if len(state.stacks['_code']) > 0:
top_code = state.stacks['_code'].stack_ref(0)
state.stacks['_exec'].push_item(top_code)
return state
code_do_star_instruction = pysh_instruction.Pysh_Instruction('code_do*',
code_do_star,
stack_types = ['_code', '_exec'])
ri.register_instruction(code_do_star_instruction)
def code_do_range(state):
if len(state.stacks['_code']) > 0 and len(state.stacks['_integer']) > 1:
to_do = state.stacks['_code'].stack_ref(0)
current_index = state.stacks['_integer'].stack_ref(1)
destination_index = state.stacks['_integer'].stack_ref(0)
state.stacks['_integer'].pop_item()
state.stacks['_integer'].pop_item()
state.stacks['_code'].pop_item()
increment = 0
if current_index < destination_index:
increment = 1
elif current_index > destination_index:
increment = -1
stack_types = ['_exec', '_boolean'],
parentheses = 1)
ri.register_instruction(exec_while_intruction)
def exec_do_while(state):
if len(state.stacks['_exec']) > 0:
block = state.stacks['_exec'].stack_ref(0)
state.stacks['_exec'].push_item(exec_while_intruction)
state.stacks['_exec'].push_item(block)
return state
exec_do_while_intruction = pysh_instruction.Pysh_Instruction('exec_do*while',
exec_do_while,
stack_types = ['_exec', '_boolean'],
parentheses = 1)
ri.register_instruction(exec_do_while_intruction)
state.stacks[pysh_type].pop_item()
state.stacks[pysh_type].push_item(second_item)
state.stacks[pysh_type].push_item(first_item)
state.stacks[pysh_type].push_item(third_item)
instruction = instr.Pysh_Instruction(pysh_type[1:] + '_rot',
rot,
stack_types = [pysh_type])
if pysh_type == '_exec':
instruction.parentheses = 3
return instruction
registered_instructions.register_instruction(rotter('_exec'))
#
#
#
#
registered_instructions.register_instruction(rotter('_integer'))
#
#
#
#
registered_instructions.register_instruction(rotter('_float'))
#
#
#
#
registered_instructions.register_instruction(rotter('_code'))
#
#
#
#
registered_instructions.register_instruction(rotter('_boolean'))
#
string_length,
stack_types = ['_string', '_integer'])
registered_instructions.register_instruction(string_length_instruction)
def string_reverse(state):
if len(state.stacks['_string']) > 0:
s = state.stacks['_string'].stack_ref(0)
s = s[::-1]
state.stacks['_string'].pop_item()
state.stacks['_string'].push_item(s)
return state
string_reverse_instruction = pysh_instruction.Pysh_Instruction('string_reverse',
string_reverse,
stack_types = ['_string'])
registered_instructions.register_instruction(string_reverse_instruction)
def string_char_at(state):
if len(state.stacks['_string']) > 0 and len(state.stacks['_integer']) > 0:
s = state.stacks['_string'].stack_ref(0)
if len(s) == 0:
c = ''
else:
i = state.stacks['_integer'].stack_ref(0) % len(s)
c = s[i]
state.stacks['_string'].pop_item()
state.stacks['_integer'].pop_item()
state.stacks['_string'].push_item(c)
return state
string_char_at_instruction = pysh_instruction.Pysh_Instruction('string_char_at',
string_char_at,
#Casts the top boolean to a string and pushes the result onto the string stack.
#
def string_concat(state):
if len(state.stacks['_string']) > 1:
s1 = state.stacks['_string'].stack_ref(0)
s2 = state.stacks['_string'].stack_ref(0)
state.stacks['_string'].pop_item()
state.stacks['_string'].pop_item()
state.stacks['_string'].push_item(s1 + s2)
return state
string_concat_instruction = pysh_instruction.Pysh_Instruction('string_concat',
string_concat,
stack_types = ['_string'])
registered_instructions.register_instruction(string_concat_instruction)
#
#string_concat
#Pops top 2 strings, and pushes result of concatenating those strings to the string stack.
#
def string_head(state):
if len(state.stacks['_string']) > 0 and len(state.stacks['_integer']) > 0:
s = state.stacks['_string'].stack_ref(0)
i = state.stacks['_integer'].stack_ref(0)
state.stacks['_string'].pop_item()
state.stacks['_integer'].pop_item()
state.stacks['_string'].push_item(s[:i])
return state
string_head_instruction = pysh_instruction.Pysh_Instruction('string_head',
string_head,
ri.register_instruction(code_maker('_float'))
ri.register_instruction(code_maker('_integer'))
ri.register_instruction(code_maker('_exec'))
def code_append(state):
if len(state.stacks['_code']) > 1:
new_item = u.ensure_list(state.stacks['_code'].stack_ref(0)) + u.ensure_list(state.stacks['_code'].stack_ref(1))
state.stacks['_code'].pop_item()
state.stacks['_code'].pop_item()
state.stacks['_code'].push_item(new_item)
return state
code_append_instruction = pysh_instruction.Pysh_Instruction('code_append',
code_append,
stack_types = ['_code'])
ri.register_instruction(code_append_instruction)
def code_atom(state):
if len(state.stacks['_code']) > 0:
top_code = state.stacks['_code'].stack_ref(0)
state.stacks['_code'].pop_item()
state.stacks['_boolean'].push_item(not (type(top_code) == list))
return state
code_atom_instruction = pysh_instruction.Pysh_Instruction('code_atom',
code_atom,
stack_types = ['_code', '_boolean'])
ri.register_instruction(code_atom_instruction)
def code_car(state):
if len(state.stacks['_code']) > 0 and len(u.ensure_list(state.stacks['_code'].stack_ref(0))) > 0:
#
#
#
def flusher(pysh_type):
'''
Returns an instruction that that empties the stack of the given state.
'''
def flush(state):
state.stacks[pysh_type].stack_flush()
instruction = instr.Pysh_Instruction(pysh_type[1:] + '_flush',
flush,
stack_types = [pysh_type])
return instruction
registered_instructions.register_instruction(flusher('_exec'))
#
#
#
#
registered_instructions.register_instruction(flusher('_integer'))
#
#
#
#
registered_instructions.register_instruction(flusher('_float'))
#
#
#
#
registered_instructions.register_instruction(flusher('_code'))
#
code_append_instruction = pysh_instruction.Pysh_Instruction('code_append',
code_append,
stack_types = ['_code'])
ri.register_instruction(code_append_instruction)
def code_atom(state):
if len(state.stacks['_code']) > 0:
top_code = state.stacks['_code'].stack_ref(0)
state.stacks['_code'].pop_item()
state.stacks['_boolean'].push_item(not (type(top_code) == list))
return state
code_atom_instruction = pysh_instruction.Pysh_Instruction('code_atom',
code_atom,
stack_types = ['_code', '_boolean'])
ri.register_instruction(code_atom_instruction)
def code_car(state):
if len(state.stacks['_code']) > 0 and len(u.ensure_list(state.stacks['_code'].stack_ref(0))) > 0:
top_code = u.ensure_list(state.stacks['_code'].stack_ref(0))[0]
state.stacks['_code'].pop_item()
state.stacks['_code'].push_item(top_code)
return state
code_car_instruction = pysh_instruction.Pysh_Instruction('code_car',
code_car,
stack_types = ['_code'])
ri.register_instruction(code_car_instruction)
def code_cdr(state):
if len(state.stacks['_code']) > 0:
from .. import pysh_instruction
from .. import pysh_utils
from . import registered_instructions
def string_from_integer(state):
if len(state.stacks['_integer']) > 0:
top_int = state.stacks['_integer'].stack_ref(0)
state.stacks['_integer'].pop_item()
state.stacks['_string'].push_item(str(top_int))
return state
string_from_integer_intruction = pysh_instruction.Pysh_Instruction('string_from_integer',
string_from_integer,
stack_types = ['_string', '_integer'])
registered_instructions.register_instruction(string_from_integer_intruction)
#
#string_from_integer
#Casts the top integer to a string and pushes the result onto the string stack.
#
def string_from_float(state):
if len(state.stacks['_float']) > 0:
top_float = state.stacks['_float'].stack_ref(0)
state.stacks['_float'].pop_item()
state.stacks['_string'].push_item(str(top_float))
return state
string_from_float_intruction = pysh_instruction.Pysh_Instruction('string_from_float',
string_from_float,
stack_types = ['_string', '_float'])
registered_instructions.register_instruction(string_from_float_intruction)