Skip to content

Commit

Permalink
latest work on app compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Sep 4, 2012
1 parent c892c94 commit d5b4eab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
25 changes: 16 additions & 9 deletions system/app_compiler.py
Expand Up @@ -12,26 +12,33 @@

import copy

def compile_impl(name, args, body, env):
methname = "invoke" + str(count(args).int())
def compile_impl(name, argsv, body, env):
methname = "invoke" + str(count(argsv).int())
self = tr.Argument("self")
args = {symbol(methname), self}
args = {symbol(methname): self}
trarg = [self]
for x in range(count(args).int()):
s = nth(args, integer(x))
for x in range(count(argsv).int()):
s = nth(argsv, integer(x))
args[s] = tr.Argument(s.repr())
trarg.append(args[s])

with merge_locals(env, args):
expr = tr.Func(trarg, compile_do(body, env)).toFunc()
return [methname, expr]
expr = tr.Func(trarg, compile_do(body, env))
return [tr.Const(methname), expr]

def compile_do(forms, env):
s = forms
out = []
while s is not None:
out.append(compile(first(s), env))
s = next(s)
return tr.Do(*out)

def compile_impls(name, impls, env):
s = impls
meths = []
while impls is not None:
meths.extend(compile_impl(name, first(impl), next(impl), env))
while s is not None:
meths.extend(compile_impl(name, first(first(s)), next(first(s)), env))

s = next(s)

Expand Down
2 changes: 2 additions & 0 deletions system/helpers.py
Expand Up @@ -19,3 +19,5 @@ def isvector(self):
def islist(self):
return rt.islist.invoke1(self)

def nth(self, idx):
return rt.nth.invoke2(self, idx)
4 changes: 2 additions & 2 deletions system/persistent_array_vector.py
Expand Up @@ -31,8 +31,8 @@ def persistent_array_vector_count(self):
def persistent_array_vector_nth(self, w_nth):
return self.lst_w[w_nth.int()]

@extend(rt.islist, _tp)
def persistent_list_islist(self):
@extend(rt.isvector, _tp)
def persistent_list_isvector(self):
from system.bool import w_true
return w_true

Expand Down

0 comments on commit d5b4eab

Please sign in to comment.