port over the entire computer into computer.desmos

This commit is contained in:
randomuser 2023-11-15 20:01:35 -06:00
parent d0ea507968
commit badb755812
2 changed files with 130 additions and 6 deletions

View File

@ -1,8 +1,104 @@
ticker 1 : loopaction, loop
# Main memory structure
: B=\left[0for i=\left[1...4000\right]\right]
: B = [1...100] * 0
# Operations on memory
: set(l, i, v) = \left[ifval(l, i, c, v) for c = \left[1...length(l)\right]\right]
: setlistval(i, v) = B -> set(B, i, v)
: incx(i,v) = setlistval(i, B[i]+v)
: q(l, v, i)=ifval(l, i, [1...length(l)], v)
: setlistval(index, v) = B -> q(B, v, index)
: incx(index, v) = setlistval(index, B[index] + v)
: ifval(l, index, c, v) = {c = index : v, l[c]}
# Operations
: oadd(x, y) = x + y
: osub(x, y) = x - y
: odiv(x, y) = x / y
: omul(x, y) = x * y
# Instruction implementation
: ijmp(a, b, c) = ip -> a, jumped -> 1
: iadd(a, b, t_o) = setlistval(t_o, oadd(B[a], B[b]))
: isub(a, b, t_o) = setlistval(t_o, osub(B[a], B[b]))
: idiv(a, b, t_o) = setlistval(t_o, odiv(B[a], B[b]))
: imul(a, b, t_o) = setlistval(t_o, omul(B[a], B[b]))
: icmp(a, b, z) = { a = b : equals -> 1 , a > b : greater -> 1 , a < b : less -> 1}
: irst(a, b, c) = equals -> 0, greater -> 0, less -> 0
: ield(addr, b) = setlistval(addr, equals)
: igld(addr, b) = setlistval(addr, greater)
: illd(addr, b) = setlistval(addr, less)
: ibe(addr, b, c) = {equals = 1 : ijmp(addr, 0, 0), jumped -> 1}
: ibne(addr, b, c) = {equals = 0 : ijmp(addr, 0, 0), jumped -> 1}
: ibg(addr, b, c) = {greater = 1 : ijmp(addr, 0, 0), jumped -> 1}
: ibl(addr, b, c) = {less = 1 : ijmp(addr, 0, 0), jumped -> 1}
: isto(v, addr) = setlistval(addr, v)
# registers
# instruction pointer
: ip = 1
# is the result of icmp equal?
: equals = 0
# ditto for greater than
: greater = 0
# ditto for less than
: less = 0
# instruction loading areas
: inst = 0
# next three values after the instruction
: paramone = 0
: paramtwo = 0
: paramthree = 0
# main execution flows
: load(addr) = jumped -> 0, inst -> B[addr], \
paramone -> B[addr + 1], \
paramtwo -> B[addr + 2], \
paramthree -> B[addr + 3]
: exec = { \
inst = sto : isto(paramone, paramtwo), \
inst = add : iadd(paramone, paramtwo, paramthree), \
inst = cmp : icmp(paramone, paramtwo, paramthree), \
inst = eld : ield(paramone, paramtwo), \
inst = gld : igld(paramone, paramtwo), \
inst = lld : illd(paramone, paramtwo), \
inst = jmp : ijmp(paramone, paramtwo, paramthree), \
inst = be : ibe(paramone, paramtwo, paramthree), \
inst = bne : ibne(paramone, paramtwo, paramthree), \
inst = bg : ibg(paramone, paramtwo, paramthree), \
inst = bl : ibl(paramone, paramtwo, paramthree), \
inst = sub : isub(paramone, paramtwo, paramthree), \
inst = mul : imul(paramone, paramtwo, paramthree), \
inst = div : idiv(paramone, paramtwo, paramthree) \
}
: incip = {jumped = 0 : ip -> ip + instwidth[inst] + 1}
# execution occurs here
: execution = 0
: jumped = 0
: loop = {execution = 0 : execution -> 1, execution = 1 : execution -> 2, execution = 2 : execution -> 0}
: loopaction = {execution = 0 : load(ip), execution = 1 : exec, execution = 2 : incip}
: sto = 1
: add = 2
: cmp = 3
: eld = 4
: gld = 5
: lld = 6
: jmp = 7
: be = 8
: bne = 9
: bg = 10
: bl = 11
: sub = 12
: mul = 13
: div = 14
: rst = 15
: instwidth = [2,3,1,1,1,1,1,1,1,1,3,3,3,3,0]

View File

@ -1,6 +1,6 @@
# desmos reserved keywords. think function names, and other verbs
# like with, etc.
reserved_keywords = "sin cos tan csc sec cot mean median min max quertile quantile stdev stdevp var mad cov covp corr spearman stats count total join sort shuffle unique for histogram dotplot boxplot normaldist tdist poissondist binomialdist uniformdist pdf cdf inversecdf random ttest tscore ittest frac sinh cosh tanh csch sech coth polygon distance midpoint rgb hsv lcm gcd mod ceil floor round sign nPr nCr log with cdot to in length left right"
reserved_keywords = "sin cos tan csc sec cot mean median min max quertile quantile stdev stdevp var mad cov covp corr spearman stats count total join sort shuffle unique for histogram dotplot boxplot normaldist tdist poissondist binomialdist uniformdist pdf cdf inversecdf random ttest tscore ittest frac sinh cosh tanh csch sech coth polygon distance midpoint rgb hsv lcm gcd mod ceil floor round sign nPr nCr log with cdot to in length left right operatorname"
reserved_keywords = reserved_keywords.split(' ')
def continue_lines(string):
@ -22,8 +22,24 @@ def split_linewise(string):
def merge_multiple_spaces(string):
return ' '.join(string.split())
def curly_brackets(string):
return string.replace('{', '\\left\\{').replace('}', '\\right\\}')
def parens(string):
return string.replace('(', '\\left(').replace(')', '\\right)')
def for_fix(string):
return string \
.replace('for\\ ', "\\operatorname{for}") \
.replace('for', "\\operatorname{for}") \
.replace('length\\ ', "\\operatorname{length}") \
.replace('length', "\\operatorname{length}")
def make_spaces_permanant(string):
return string.replace(' ', '\\ ')
return string.replace(' ', '\ ')
def change_square_brackets(string):
return string.replace('[', '\\left[').replace(']', '\\right]')
def subscriptize(string):
output = ""
@ -139,9 +155,21 @@ class Parser:
# now, remove multiple spaces in lines, replacing them with one.
lines[index].latex = merge_multiple_spaces(line.latex)
# replace curly brackets and parens
lines[index].latex = curly_brackets(line.latex)
lines[index].latex = parens(line.latex)
# convert things like testing to t_{esting}
lines[index].latex = subscriptize(line.latex)
# change square brackets to \\left[ and \\right]
lines[index].latex = change_square_brackets(line.latex)
print(lines[index].latex)
# replace for with \\operatorname{for}
lines[index].latex = for_fix(line.latex)
print(lines[index].latex)
# make the spaces escaped and 'permanant'
lines[index].latex = make_spaces_permanant(line.latex)