make maps oop

This commit is contained in:
2023-04-08 15:34:15 +02:00
parent d1cd747e86
commit 644a78154e
33 changed files with 709 additions and 276 deletions

34
tests/brainfuck.ar Normal file
View File

@@ -0,0 +1,34 @@
let interpret(code) = do
memory = map()
pointer = 0
code_ptr = 0
loops = []
while (code_ptr < code.length) do
command = code[code_ptr]
if (command == '>') pointer = pointer + 1
else if (command == '<') pointer = pointer - 1
else if (command == '+') do
if (pointer not in memory) memory[pointer] = 0
memory[pointer] = memory[pointer] + 1
else if (command == '-') do
if (pointer not in memory) memory[pointer] = 0
memory[pointer] = memory[pointer] - 1
else if (command == '.') term.plain.oneLine(chr(memory.get(pointer, 0)), end='')
else if (command == ',') memory[pointer] = ord(input())
else if (command == '[') do
if (memory.get(pointer, 0) == 0) do
loop_depth = 1
while (loop_depth > 0) do
code_ptr = code_ptr + 1
if (code[code_ptr] == '[') loop_depth = loop_depth + 1
else if (code[code_ptr] == ']') loop_depth = loop_depth - 1
else loops.append(code_ptr)
else if (command == ']') do
if (memory.get(pointer, 0) != 0) code_ptr = loops[-1]
else loops.pop()
code_ptr = code_ptr + 1
interpret('>++++++++[<+++++++++>-]<.>++++[<+++++++>-]<+.+++++++..+++.>>++++++[<+++++++>-]<++.------------.>++++++[<+++++++++>-]<+.<.+++.------.--------.>>>++++[<++++++++>-]<+.')

View File

@@ -11,8 +11,7 @@ name = "william bell"
term.log(getInitials(name))
term.log(name)
let addLastName(name) = do
name.append(" Bell")
let addLastName(name) = name.append(" Bell")
name = "William"
addLastName(name)

View File

@@ -1,8 +1,7 @@
f() = do
a = []
for (i from 0 to 10000000) a.append(i)
for (i from 0 to 10000) a.append(i)
term.log("start")
f()
term.log("end")
time.snooze(100000000)
term.log("end")

7
tests/stack test.ar Normal file
View File

@@ -0,0 +1,7 @@
x = 10
do
let x = 20
term.log(x)
term.log(x)

View File

@@ -1,4 +1,3 @@
term.log(" ____ ")
term.log(" /\\ |___ \\ ")
term.log(" / \\ _ __ __ _ ___ _ __ __ ____) |")
term.log(" / /\\ \\ | '__/ _` |/ _ \\| '_ \\ \\ \\ / /__ < ")
@@ -7,5 +6,4 @@ term.log(" /_/ \\_\\_| \\__, |\\___/|_| |_| \\_/|____/ ")
term.log(" __/ | ")
term.log(" |___/ ")
term.log("----------------------------------------------")
term.log("Welcome to ARGON for WASM!")
term.log("write code above and click run to see it work like magic!")
term.log("Welcome to ARGON!")