Esempio n. 1
0
def define_func(args, env):

    if isinstance(first(args), LispSymbol):
        # we have the first form

        args = to_list(args)
        assert args[-1] is nil
        assert len(args) == 3

        var = args[0]
        value = args[1]

    elif isinstance(first(args), LispPair):
        # we have the second form

        var = first(first(args))
        param = rest(first(args))
        body = rest(args)

        assert isinstance(var, (LispSymbol, LispPair))

        value = from_list([mksym("lambda"), param, body])
    else:
        raise Exception("invalid form")

    assert isinstance(var, LispSymbol)
    result = value.scm_eval(env)

    # todo set the datatype
    env.define(var.name, None, result)
    return nil
Esempio n. 2
0
def class_chmod_func(args, env):

    class_name = first(args)
    var_name = first(rest(args))
    flags = to_list(rest(rest(args)))[:-1]

    evaled_class = class_name.scm_eval(env)
    evaled_var   = var_name.scm_eval(env).name
    evaled_flags = [flag.scm_eval(env).name for flag in flags]

    evaled_class.chmod(evaled_var, evaled_flags)
    return nil
Esempio n. 3
0
def class_set_func(args, env):
    
    class_name = first(args)
    var_name = first(rest(args))
    value = first(rest(rest(args)))

    evaled_class = class_name.scm_eval(env)
    evaled_var   = var_name.scm_eval(env).name
    evaled_value = value.scm_eval(env)

    # print "class", class_name, evaled_class
    # print "param", param_name, evaled_param
    # print "value", value, evaled_value

    evaled_class.set(evaled_var, evaled_value)
    return nil
Esempio n. 4
0
 def inner_qq(inargs):
     # print "in args", inargs
     if first(inargs) is mksym("unquote"):
         # (unquote x) -> (eval x)
         assert rest(rest(inargs)) is nil
         return first(rest(inargs)).scm_eval(env)
     elif first(inargs) is mksym("quasiquote"):
         # (quasiquote x) -> (quasiquote x)
         assert rest(rest(inargs)) is nil
         return inargs
     elif first(inargs) is mksym("unquote-splicing"):
         raise Exception("Not implemented")
     else:
         # recurse the list checking each elm
         # return the newly formed list
         newlist = []
         while isinstance(inargs, LispPair):
             if isinstance(first(inargs), LispPair):
                 newlist.append(inner_qq(first(inargs)))
             else:
                 newlist.append(first(inargs))
             inargs = rest(inargs)
         
         # deal with the final element (which is probably a nil)
         if isinstance(inargs, LispPair):
             newlist.append(inner_qq(inargs))
         else:
             newlist.append(inargs)
         # put the list back into sexp
         return from_list(newlist)
Esempio n. 5
0
def class_define_func(args, env):

    class_name = first(args)
    var_name = first(rest(args))

    # todo: deal with the datatype
    # datatype = first(rest(rest(args)))
    evaled_type = None

    evaled_class = class_name.scm_eval(env)
    evaled_var = var_name.scm_eval(env).name
    evaled_class.define(evaled_var, evaled_type)

    return nil
Esempio n. 6
0
def include_func(args, env):
    file_name = first(args)
    assert rest(args) is nil
    assert isinstance(file_name, LispString)
    read_file(open(file_name.text), env)
    return nil
Esempio n. 7
0
def import_func(args, env):
    file_name = first(args)
    assert rest(args) is nil
    assert isinstance(file_name, LispString)
    return read_file(open(file_name.text), None)
Esempio n. 8
0
def macro_func(args, env):

    param = first(args)
    body = rest(args)

    return LispLambda(param, body, True)
Esempio n. 9
0
def lambda_func(args, env):

    param = first(args)
    body = rest(args)

    return LispLambda(param, body)