Example #1
0
 object CatchError(object fun, object handlerFun)
 {
     try {
         return(_vm.Apply(fun));
     } catch (Exception e) {
         return(_vm.Apply(handlerFun, new Cons(e.Message, null)));
     }
 }
Example #2
0
 public Builtins(LunulaVM vm)
 {
     _vm = vm;
     vm.DefineFunction("@make-vector", MakeVector);
     vm.DefineFunction("@vector-ref", VectorRef);
     vm.DefineFunction("@vector-set", VectorSet);
     vm.DefineFunction("@vector?", IsVector);
     vm.DefineFunction("@vector-length", VectorLength);
     vm.DefineFunction("@make-hash-table", MakeHashTable);
     vm.DefineFunction("@hash-ref", HashRef);
     vm.DefineFunction("@hash-set!", HashSet);
     vm.DefineFunction("@hash-remove!", HashRemove);
     vm.DefineFunction("@hash-keys", HashKeys);
     vm.DefineFunction("@hash-values", HashValues);
     vm.DefineFunction("@boolean?", IsBoolean);
     vm.DefineFunction("@boolean=?", BooleanEquals);
     vm.DefineFunction("@char?", IsChar);
     vm.DefineFunction("@char=?", CharEquals);
     vm.DefineFunction("@char-alphabetic?", IsCharAlphabetic);
     vm.DefineFunction("@char-numeric?", IsCharNumeric);
     vm.DefineFunction("@char-code", CharCode);
     vm.DefineFunction("@symbol?", IsSymbol);
     vm.DefineFunction("@symbol=?", SymbolEquals);
     vm.DefineFunction("@void?", IsVoid);
     vm.DefineFunction("@void", MakeVoid);
     vm.DefineFunction("@procedure?", IsProcedure);
     vm.DefineFunction("@toplevel-defined?", ToplevelIsDefined);
     vm.DefineFunction("@toplevel-define", ToplevelDefine);
     vm.DefineFunction("@toplevel-lookup", ToplevelLookup);
     vm.DefineFunction("cons?", IsCons);
     vm.DefineFunction("null?", IsNull);
     vm.DefineFunction("car", Car);
     vm.DefineFunction("cdr", Cdr);
     vm.DefineFunction("@string?", IsString);
     vm.DefineFunction("@string=?", StringEquals);
     vm.DefineFunction("@string-length", StringLength);
     vm.DefineFunction("@string-append", StringAppend);
     vm.DefineFunction("@number->string", NumberToString);
     vm.DefineFunction("@symbol->string", SymbolToString);
     vm.DefineFunction("@open-output-string", OpenOutputString);
     vm.DefineFunction("@open-input-string", OpenInputString);
     vm.DefineFunction("@get-output-string", GetOutputString);
     vm.DefineFunction("@open-output-byte-array", OpenOutputByteArray);
     vm.DefineFunction("@get-output-byte-array", GetOutputByteArray);
     vm.DefineFunction("@write-byte", WriteByte);
     vm.DefineFunction("@write-word", WriteWord);
     vm.DefineFunction("@write-dword", WriteDWord);
     vm.DefineFunction("@current-output-port", GetStdOut);
     vm.DefineFunction("@current-error-port", GetStdError);
     vm.DefineFunction("@current-input-port", GetStdIn);
     vm.DefineFunction("@cons", MakeCons);
     vm.DefineFunction("@set-car!", SetCar);
     vm.DefineFunction("@set-cdr!", SetCdr);
     vm.DefineFunction("@number?", IsNumber);
     vm.DefineFunction("@=", NumberEqual);
     vm.DefineFunction("@>", NumberGreaterThan);
     vm.DefineFunction("@>=", NumberGreaterThanAndEqual);
     vm.DefineFunction("@<", NumberLessThan);
     vm.DefineFunction("@<=", NumberLessThanAndEqual);
     vm.DefineFunction("@+", TwoArgPlus);
     vm.DefineFunction("@-", TwoArgMinus);
     vm.DefineFunction("@*", TwoArgMultiply);
     vm.DefineFunction("@/", TwoArgDivide);
     vm.DefineFunction("@bor", BinaryOr);
     vm.DefineFunction("@left-shift", LeftShift);
     vm.DefineFunction("@write-char", WriteChar);
     vm.DefineFunction("@write-string", WriteString);
     vm.DefineFunction("@flush-output", FlushOutput);
     vm.DefineFunction("@to-string", StaticToString);
     vm.DefineFunction("@open-file-output-port", OpenFileOutputPort);
     vm.DefineFunction("@open-binary-file-output-port", OpenBinaryFileOutputPort);
     vm.DefineFunction("@close-output-port", CloseOutputPort);
     vm.DefineFunction("@open-file-input-port", OpenFileInputPort);
     vm.DefineFunction("@close-input-port", CloseInputPort);
     vm.DefineFunction("@get-time", GetTime);
     vm.DefineFunction("@time-difference", TimeDifference);
     vm.DefineFunction("@string->list", StringToList);
     vm.DefineFunction("@list->string", ListToString);
     vm.DefineFunction("@string->number", StringToNumber);
     vm.DefineFunction("@string->symbol", StringToSymbol);
     vm.DefineFunction("@fail", Fail);
     vm.DefineFunction("@read-char", ReadChar);
     vm.DefineFunction("@peek-char", PeekChar);
     vm.DefineFunction("@peek-char-skip", PeekCharSkip);
     vm.DefineFunction("@eof-object?", IsEOFObject);
     vm.DefineFunction("@cons?", thing => thing is Cons);
     vm.DefineFunction("@null?", thing => thing == null);
     vm.DefineFunctionN("@apply", parms => {
         var fun  = parms.First();
         var args = Cons.Car(Cons.ConsFromArray(parms.Skip(1).ToArray()));
         return(vm.Apply(fun, Cons.ToObjectArray(args)));
     });
     vm.DefineFunction("eq?", ObjectEquals);
     vm.DefineFunction("@catch-error", CatchError);
     vm.DefineFunction("@run-template", RunTemplate);
     vm.DefineFunction("@load-lvm-file", LoadLVMFile);
     vm.DefineFunction("@print-profile-data", () => {
         throw new LunulaException("Profiler not enabled");
     });
     vm.DefineFunction("@make-type", (tag, data) => new TaggedType((Symbol)tag, data));
     vm.DefineFunction("@type-symbol", type => ((TaggedType)type).Tag);
     vm.DefineFunction("@type-data", type => ((TaggedType)type).Data);
     vm.DefineFunction("@type-data-set!", (type, data) => { ((TaggedType)type).Data = data; return(Void.TheVoidValue); });
     vm.DefineFunction("call/cc", _vm.CallWithCurrentContinuation);
     vm.DefineFunction("@exit", x => Void.TheVoidValue);
 }