Beispiel #1
0
def intf_INCR(E):
    """An increment function. Will increment a value by adding 1. Will
    also try to add one to the value of a symbol (leaving nothing).
    Incrementing text will append an extra copy of the last letter of
    the original string. Lists increment by adding another copy of the
    last item."""
    term = E.The.StackPop()
    if term.whatami == 'SYM':
        if E.symtab[term.val].whatami == 'VAL':
            # Needs a new object to break old refs links.
            v = objectifier.StackOB_VAL(E.symtab[term.val].val + 1)
            E.symtab[term.val] = v
        elif E.symtab[term.val].whatami == 'TXT':
            # Needs a new object to break old refs links.
            t = objectifier.StackOB_TXT(E.symtab[term.val].val +
                                        E.symtab[term.val].val[-1])
            E.symtab[term.val] = t
        elif E.symtab[term.val].whatami == 'LST':
            # Needs a new object to break old refs links.
            t = objectifier.StackOB_LST(E.symtab[term.val].val +
                                        [E.symtab[term.val].val[-1]])
            E.symtab[term.val] = t
        elif E.symtab[term.val].whatami == 'SYM':
            pass  # This is not complete. Because it's hard.
    elif term.whatami == 'VAL':
        E.The.StackPush(objectifier.StackOB_VAL(term.val + 1))
    elif term.whatami == 'TXT':
        newseq = term.val + term.val[-1]
        E.The.StackPush(objectifier.StackOB_TXT(newseq))
    elif term.whatami == 'LST':
        newseq = term.val + [term.val[-1]]  # Orig. list + last item.
        E.The.StackPush(objectifier.StackOB_LST(newseq))
    E.Undo.StackPush([objectifier.StackOB_SYM('drop'), term])
Beispiel #2
0
def intf_CEIL(E):
    """Ceiling, highest whole integer."""
    X= E.The.StackPop() # Numeric input object.
    x= X.val # Value of it.
    answer= objectifier.StackOB_VAL( math.ceil(x) )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #3
0
def intf_RAND(E):
    """Returns a random value between 0 and 1."""
    import random
    x = random.random()
    answer = objectifier.StackOB_VAL(x)
    E.The.StackPush(answer)
    E.Undo.StackPush([objectifier.StackOB_SYM('drop')])
Beispiel #4
0
def SimplePushForUndo(E):
    """This function is a bit different. It is not a user function. It
    basically exists to handle any housekeeping needed when no real
    action needs to occur but a value needs to be pushed onto the
    stack. It takes care of loading the Undo list properly, for
    example."""
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop') ] )
Beispiel #5
0
def intf_EXP(E):
    """Constant e to the value of level one."""
    X= E.The.StackPop() # Numeric input object.
    x= X.val # Value of it.
    answer= objectifier.StackOB_VAL( math.exp(x) )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #6
0
def intf_ABS(E):
    """Absolute value."""
    X= E.The.StackPop() # Numeric input object.
    x= X.val # Value of it.
    answer= objectifier.StackOB_VAL( math.fabs(x) )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #7
0
def intf_FLOOR(E):
    """Floor, lowest whole integer."""
    X= E.The.StackPop() # Numeric input object.
    x= X.val # Value of it.
    answer= objectifier.StackOB_VAL( math.floor(x) )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #8
0
def intf_DECR(E):
    """A decrement function. Will decrease a value by subracting 1. Will
    also try to subtract one from the value of a symbol (leaving nothing).
    Decrementing text will remove the last letter of the original
    string. Lists decrement by removing the last item."""
    term = E.The.StackPop()
    if term.whatami == 'SYM':
        if E.symtab[term.val].whatami == 'VAL':
            # Needs a new object to break old refs links.
            v = objectifier.StackOB_VAL(E.symtab[term.val].val - 1)
            E.symtab[term.val] = v
        elif E.symtab[term.val].whatami == 'TXT':
            # Needs a new object to break old refs links.
            t = objectifier.StackOB_TXT(E.symtab[term.val].val[0:-1])
            E.symtab[term.val] = t
        elif E.symtab[term.val].whatami == 'LST':
            # Needs a new object to break old refs links.
            t = objectifier.StackOB_LST(E.symtab[term.val].val[0:-1])
            E.symtab[term.val] = t
        elif E.symtab[term.val].whatami == 'SYM':
            pass  # This is not complete. Because it's hard.
    elif term.whatami == 'VAL':
        E.The.StackPush(objectifier.StackOB_VAL(term.val - 1))
    elif term.whatami == 'TXT':
        newseq = term.val[0:-1]
        E.The.StackPush(objectifier.StackOB_TXT(newseq))
    elif term.whatami == 'LST':
        newseq = term.val[0:-1]
        E.The.StackPush(objectifier.StackOB_LST(newseq))
    E.Undo.StackPush([objectifier.StackOB_SYM('drop'), term])
Beispiel #9
0
def intf_2RAD(E):
    """Sine of level one which should be in degrees."""
    X= E.The.StackPop() # Numeric input object.
    d= X.val # Value of it.
    answer= objectifier.StackOB_VAL( math.radians(d) )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #10
0
def intf_2DEG(E):
    """Converts a radian value to degrees."""
    X= E.The.StackPop() # Numeric input object.
    r= X.val # Value of it.
    answer= objectifier.StackOB_VAL( math.degrees(r) )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #11
0
def intf_LOG10(E):
    """Base 10 logarithm of the value of level one."""
    X= E.The.StackPop() # Numeric input object.
    x= X.val # Value of it.
    answer= objectifier.StackOB_VAL( math.log10(x) )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #12
0
def intf_ACOS(E):
    """Arccosine of level one."""
    X= E.The.StackPop() # Numeric input object.
    x= X.val # Value of it.
    x= math.radians(x)
    answer= objectifier.StackOB_VAL( math.acos(x) )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #13
0
def intf_NOT(E):
    """Logical 'not' of level 1."""
    A= E.The.StackPop() # Test object.
    if A:
        E.The.StackPush(objectifier.StackOB_VAL(0))
    else:
        E.The.StackPush(objectifier.StackOB_VAL(1))
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), A ] )
Beispiel #14
0
def intf_TAN(E):
    """Tangent of level one which should be in degrees."""
    X= E.The.StackPop() # Numeric input object.
    x= X.val # Value of it.
    x= math.radians(x)
    answer= objectifier.StackOB_VAL( math.tan(x) )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #15
0
def intf_EQ(E):
    """True if level 1 and level 2 are 'equal'."""
    B= E.The.StackPop().val # Test object 2.
    A= E.The.StackPop().val # Test object 1.
    if A == B:
        E.The.StackPush(objectifier.StackOB_VAL(1))
    else:
        E.The.StackPush(objectifier.StackOB_VAL(0))
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), A, B ] )
Beispiel #16
0
def intf_ATAN(E):
    """Arctangent of level one in degrees."""
    X= E.The.StackPop() # Numeric input object.
    x= X.val # Value of it.
    answerinrad= math.atan(x)
    answerindeg= math.degrees(answerinrad)
    answer= objectifier.StackOB_VAL( answerindeg )
    E.The.StackPush(answer)
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
Beispiel #17
0
def intf_OR(E):
    """Logical 'or' of levels 1 and 2."""
    A= E.The.StackPop() # Test object.
    B= E.The.StackPop() # Evaluation object.
    if A or B:
        E.The.StackPush(objectifier.StackOB_VAL(1))
    else:
        E.The.StackPush(objectifier.StackOB_VAL(0))
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), A, B ] )
Beispiel #18
0
def intf_GE(E):
    """True if level 2 is 'greater than or equal' to level 1."""
    B= E.The.StackPop().val # Test object 2.
    A= E.The.StackPop().val # Test object 1.
    if A >= B:
        E.The.StackPush(objectifier.StackOB_VAL(1))
    else:
        E.The.StackPush(objectifier.StackOB_VAL(0))
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), A, B ] )
Beispiel #19
0
def intf_PLACEN(E):
    """Removes a number from the stack that specifies where the next
    stack item should be placed. That item is then put at the specified
    level."""
    level = E.The.StackPop()
    object2put = E.The.StackPop()
    puthere = E.The.StackSize() - int(level.val) + 1
    E.The.Stacklist.insert(puthere, object2put)
    E.Undo.StackPush([level, objectifier.StackOB_SYM('yank')])
Beispiel #20
0
def intf_LT(E):
    """True if level 2 is 'less than' level 1."""
    B= E.The.StackPop().val # Test object 2.
    A= E.The.StackPop().val # Test object 1.
    if A < B:
        E.The.StackPush(objectifier.StackOB_VAL(1))
    else:
        E.The.StackPush(objectifier.StackOB_VAL(0))
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), A, B ] )
Beispiel #21
0
def intf_GT(E):
    """True if level 2 is 'greater than' level 1."""
    B= E.The.StackPop() # Test object 2.
    A= E.The.StackPop() # Test object 1.
    if A.val > B.val:
        E.The.StackPush(objectifier.StackOB_VAL(1))
    else:
        E.The.StackPush(objectifier.StackOB_VAL(0))
    E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), A, B ] )
Beispiel #22
0
def intf_SQRT(E):
    """Calculates the square root of level one."""
    X= E.The.StackPop() # Preserve this.
    x= X.val # Value of it.
    try:
        answer= objectifier.StackOB_VAL( math.sqrt(x) )
        E.The.StackPush(answer)
        E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), X ] )
    except ValueError:
        print('sqrt(-) - Second oldest trick in the book!')
        E.The.StackPush( X ) # Run away!
Beispiel #23
0
def intf_MOD(E):
    """Software engineer's special - modolo, i.e. remainder. Doesn't work with lists."""
    orig_den = E.The.StackPop()  # Preserve in case of badness.
    orig_num = E.The.StackPop()  # Preserve in case of badness.
    try:
        E.The.StackPush(objectifier.StackOB_VAL(orig_num.val % orig_den.val))
        E.Undo.StackPush([objectifier.StackOB_SYM('drop'), orig_num, orig_den])
    except ZeroDivisionError:
        print('n/0 - Oldest trick in the book!')
        E.The.StackPush(orig_num)  # Run away!
        E.The.StackPush(orig_den)  # Run away!
Beispiel #24
0
def intf_FACT(E):
    """Factorial (not a complete Gamma function) of the value of level one.
    Any value greater than 170 will return 0 because any argument larger
    than this will create an answer too big to safely handle.
      6 fact -> 720.0
    """
    X = E.The.StackPop()  # Numeric input object.
    x = int(X.val)  # Value of it.
    answer = objectifier.StackOB_VAL(fact(x))
    E.The.StackPush(answer)
    E.Undo.StackPush([objectifier.StackOB_SYM('drop'), X])
Beispiel #25
0
def intf_YANK(E):
    """Takes a number off the stack and then finds that levels object
    (if there  is one) and pulls it down to be the first item on the
    stack. The original is removed."""
    level = E.The.StackPop()
    # This comically allows getting from stack level 3.2, etc.
    grabhere = E.The.StackSize() - int(level.val)
    object2yank = E.The.Stacklist[grabhere]
    del E.The.Stacklist[grabhere]
    E.The.StackPush(object2yank)
    E.Undo.StackPush([level, objectifier.StackOB_SYM('placen')])
Beispiel #26
0
def intf_PICKN(E):
    """Picks an object off the stack replacing the level specified
    level number with that level's object. Original is preserved."""
    level = E.The.StackPop()  # For future undo use too.
    n = int(E.The.StackSize() - level.val)
    #n -= 1 # Subtract one to account for specifier n itself.
    d = E.The.Stacklist[n]
    if d.whatami == "LST":
        dupedpart_new = d.deep_copy()
    else:
        dupedpart_new = d
    E.The.StackPush(dupedpart_new)
    E.Undo.StackPush([objectifier.StackOB_SYM('drop'), level])
Beispiel #27
0
def intf_POW(E):
    """Raises the value at level 2 to the value at level 1."""
    orig_num_1= E.The.StackPop() # Preserve this.
    orig_num_2= E.The.StackPop() # Preserve this.
    p= orig_num_1.val # Power part.
    b= orig_num_2.val # Base part.
    try:
        answer= objectifier.StackOB_VAL( math.pow(b,p) )
        E.The.StackPush(answer)
        E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'),
                                      orig_num_2, orig_num_1 ] )
    except ValueError:
        print('sqrt(-) - Second oldest trick in the book!')
        E.The.StackPush( orig_num_2 ) # Run away!
        E.The.StackPush( orig_num_1 ) # Run away!
Beispiel #28
0
def intf_LOGBASE(E):
    """Logarithm of the value of level 2 with a base of the value of
    level 1."""
    orig_base=  E.The.StackPop() # Preserve in case of badness.
    orig_x=  E.The.StackPop() # Preserve in case of badness.
    b= orig_base.val
    x= orig_x.val
    try:
        E.The.StackPush(
             objectifier.StackOB_VAL( math.log(x,b) ) )
        E.Undo.StackPush( [ objectifier.StackOB_SYM('drop'), 
              orig_x, orig_base ] )
    except ZeroDivisionError:
        print('n/0 - Oldest trick in the book!')
        E.The.StackPush( orig_x ) # Run away!
        E.The.StackPush( orig_base ) # Run away!
Beispiel #29
0
def intf_MMTEST(E):
    """Simple test of the creation of a mm function. Get rid of this when
    everything is working fine."""
    macro= "10 10 0 p dup 100 10 0 p dup rot l drop 50 100 0 p dup rot l drop l drop"
    oblistcontent= list()
    for s in macro.split(' '):
        try:
            s= float(s)
        except ValueError:
            pass
        if type(s) == type('str'):
            oblistcontent.append(objectifier.StackOB_SYM(s))
        else:
            oblistcontent.append(objectifier.StackOB_VAL(s))
    testmacro= objectifier.StackOB_LST(oblistcontent) 
    testmacro.dead= False
    E.The.StackPush(testmacro)
Beispiel #30
0
def intf_DUPN(E):
    """Duplicate n items of the stack."""
    level = E.The.StackPop()
    n = level.val
    start_at = int(E.The.StackSize() - n)
    # Notice here that this slicing causes a copy of the Python object
    # and not just a copy of the reference. This is lucky here.
    # Update- Actually, this is fine except for lists which are
    # still copied by  reference. This means that wake of one will
    # wake all. This might not be so bad though. PickN has the same issue.
    dupedpart_orig = E.The.Stacklist[start_at:]

    dupedpart_new = list()
    for d in dupedpart_orig:
        if d.whatami == "LST":
            dupedpart_new.append(d.deep_copy())
        else:
            dupedpart_new.append(d)

    E.The.Stacklist.extend(dupedpart_new)
    E.Undo.StackPush([level, objectifier.StackOB_SYM('dropn')])