Merge pull request 'Integrate further spudulons into hyperpotatospace' (#4) from heavpoot/potatOS:master into master

Reviewed-on: #4
This commit is contained in:
osmarks 2021-01-29 22:13:52 +00:00
commit 457ffd6745
1 changed files with 9 additions and 5 deletions

View File

@ -1,3 +1,4 @@
if not unpack then unpack = table.unpack end
function deepclone(t) function deepclone(t)
local res={} local res={}
for i,v in ipairs(t) do for i,v in ipairs(t) do
@ -173,7 +174,8 @@ function into_ast(tokens)
local tmp=p() local tmp=p()
if (tmp==nil) or tmp==false or tokens[bk][1]=="EOF" then if (tmp==nil) or tmp==false or tokens[bk][1]=="EOF" then
if tokens[bk][1]~="EOF" then if tokens[bk][1]~="EOF" then
error("[HL] line "..tokens[bk].line..": some syntax error occured.") print("line "..tokens[bk].line..": some syntax error occured.")
os.exit(1)
end end
ptr=bk ptr=bk
break break
@ -265,7 +267,8 @@ function interpret(ast,imports)
end end
end end
local function throwerror(reason) local function throwerror(reason)
error("[HL] line "..cline..": "..reason) print("line "..cline..": "..reason)
os.exit(1)
end end
local function get(k) local function get(k)
local t=top() local t=top()
@ -298,6 +301,7 @@ function interpret(ast,imports)
["number"]="number", ["number"]="number",
["boolean"]="bool", ["boolean"]="bool",
["table"]="list", ["table"]="list",
["function"]="function",
})[type(v)],value=v}) })[type(v)],value=v})
end end
end end
@ -363,7 +367,7 @@ function interpret(ast,imports)
if x and x.type=="list" then if x and x.type=="list" then
local res={type="list",value={}} local res={type="list",value={}}
for i,v in pairs(x.value) do for i,v in pairs(x.value) do
table.insert(res.value,i) table.insert(res.value,to(i))
end end
return res return res
end end
@ -419,7 +423,7 @@ function interpret(ast,imports)
tmp[#tmp+1]="(function)" tmp[#tmp+1]="(function)"
end end
end end
print(#args>0 and unpack(tmp) or "nil") print(unpack(tmp))
return {type="bool",value=true} return {type="bool",value=true}
end, end,
["type"]=function(x) ["type"]=function(x)
@ -574,4 +578,4 @@ end
local function run(x,lua) local function run(x,lua)
return interpret(into_ast(tokenize(x)),lua) return interpret(into_ast(tokenize(x)),lua)
end end
return {run=run, interpret=interpret, into_ast=into_ast, tokenize=tokenize} return {run=run}