- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecutor.lua
More file actions
Latest commit
113 lines (86 loc) · 2.57 KB
/
Copy pathexecutor.lua
File metadata and controls
113 lines (86 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require"import"
localtblmassapply
localLispParser=import"parser" --yay redundancy
localLispFunctions=import"functions"
localLispSexp=import"Sexp"
localfunctionpkg_init(LispExecutor)
LispExecutor.exec=function (sexp, environ)
ifsexp==nilthen
returnnil
elseifLispSexp.is_ident(sexp) then
localget, set=LispExecutor.resolve_id(sexp.ident, environ)
--print (subenv, finalstep)
returnget()
elseifLispSexp.is_sexp(sexp) then
localsuccess, func, rval
success, func=pcall(LispExecutor.exec, sexp.car, environ)
ifnotsuccessthen
error("In functional expression " ..LispFunctions.display(sexp.car) ..":: \n" ..tostring(func))
end
success, rval=pcall(LispExecutor.apply, func, sexp.cdr, environ, hist)
ifnotsuccessthen
error("In expression " ..LispFunctions.display(sexp) ..":: \n" ..tostring(rval))
end
returnrval
else
returnsexp
end
end
LispExecutor.parse_id=function(ident, environ)
localdot=ident:find("[.]")
localolddot=1
localsubenv=environ
localfinalstep
whiledotdo
subenv=subenv[ident:sub(olddot,dot-1)]
olddot=dot+1
dot=ident:find("[.]", olddot)
end
finalstep=ident:sub(olddot)
returnsubenv,finalstep
end
LispExecutor.resolve_id=function (ident, environ)
localget,set
localsubenv,finalstep=LispExecutor.parse_id(ident,environ)
localdolla=finalstep:find("[$]")
ifnotdollathen
get=function ()
returnsubenv[finalstep]
end
set=function (val)
subenv[finalstep] =val
end
else
subenv=subenv[finalstep:sub(1,dolla-1)]
finalstep=finalstep:sub(dolla+1)
get=function ()
-- BUG: This doesn't play nice with nil
returnfunction(...)
returnsubenv[finalstep](subenv, unpack(arg))
end
end
set=function(val)
error("Currently not supported :(")
end
end
returnget,set
end
-- Fair warning: This has nothing to do with real lisp's "apply" function :P
-- I can't really change the way things work because it would break
-- meta-functions
LispExecutor.apply=function (expr, rest, environ)
iftype(expr) =="function" then
returnexpr(massexec(rest, environ))
elseifLispSexp.is_metafun(expr) then
returnexpr.fun(environ, rest)
else
error("Not a function or metafunction")
end
end
massexec=function (expr, environ, hist)
ifexprthen
returnLispExecutor.exec(expr.car,environ, hist), massexec(expr.cdr, environ)
end
end
end
returnpkg_init