Gidsss / UwUIDE

A compiler made to be cute uwu >~<
6 stars 0 forks source link

Feat/more array builtin methods #214

Closed am-cid closed 6 months ago

am-cid commented 6 months ago

closes #207


new

  1. all of methods mentioned in #207

    no descriptions means the same as python's behavior

    • [x] prepend() prepends items to start of the array
      • uses insert(0) under the hood
    • [x] pop() removes the last element in the list ALWAYS and does not return anything
    • [x] index() works the same but instead of raising when cannot find the value, it will return -1
    • [x] extend()
    • [x] prextend() like extend but at the beginning of the list
    • [x] clear()
    • [x] count()

test log

sample text file
---------------------------------------------------------
 1 |
 2 |     fwunc mainuwu-san() [[
 3 |         a-senpai[] = {}~
 4 |         a.prepend("1")~
 5 |         a.append("2")~
 6 |         a.prepend({"0"})~
 7 |         a.append({"3"})~
 8 |         a.extend({"4"})~
 9 |         a.extend({"4", "5"})~
10 |         a.extend({})~
11 |         a.pop()~
12 |         b-chan = a.index({"4"})~
13 |         a.clear()~
14 |         a.prextend({"1", {"2"}, "3", {{"4"}, "5"}})~
15 |     ]]
16 |
---------------------------------------------------------
end of file

def main():
    _a: Array = Array([])
    _a._prepend(String("1"))
    _a._append(String("2"))
    _a._prepend(Array([String("0")]))
    _a._append(Array([String("3")]))
    _a._extend(Array([String("4")]))
    _a._extend(Array([String("4"), String("5")]))
    _a._extend(Array([]))
    _a._pop()
    _b: int = int(float(_a._index(Array([String("4")]))))
    _a._clear()
    _a._prextend(Array([String("1"), Array([String("2")]), String("3"), Array([Array([String("4")]), String("5")])]))

if __name__ == '__main__':
    # clear screen before executing
    import platform
    import os
    os.system('cls' if platform.system() == 'Windows' else 'clear')

    # declare globals
    main()