⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 overview.text

📁 idel虚拟机源码
💻 TEXT
字号:
Here's a quick summary of what I'm doing -- a virtual machine for safeportable code that leaves most of the work of optimization towhoever's producing the VM code, rather than to the VM implementationlike the JVM does.  Further, it's low-level and relativelylanguage-neutral and doesn't try to define a raft of standardlibraries.  Buggy programs for this VM can run wild and scribble theirown data space, like C programs, but can't affect anything outsideexcept through explicitly granted capabilities.  (This includes CPUhogging -- you can give a program a limited amount of `fuel' to run onbefore it's terminated.)What's working right now is a straightforward interpreter in C and acompiler from a very limited subset of Forth.  To access externalfunctions, you currently have to add new instructions to the VM --that's a stopgap until I add capabilities.You might ask why this is worth building -- isn't proof-carrying codethe right answer for this sort of safety?  PCC is indeed nifty, butit's still kind of researchy.  I want to do something now thatrequires only engineering.  Also, PCC and portable binaries areorthogonal.  Consider the case where you want to suspend an arbitraryrunning program and resume execution on another node of the network --that would be really painful if it's in x86 machine code and the othernode is a Sparc.  Therefore while the design should avoid any featuresthat would make a type system or other proof stuff harder to add, itdoesn't try to do PCC in the base system.  We should leave a path opento adding unsafe instructions that are allowed only when accompaniedby a proof, for handling anything that's less efficient when goingthrough an always-safe interface.  (Indirect calls are an example.)Okay, so what's it like?  It's a 32-bit Harvard-architecture stackmachine where each procedure is required to have a deterministic stackeffect.  The only way to write loops is with tail recursion.  Thestack is not part of the main data space, so wild pointers can't muckit up.  This means we can follow a conventional procedure-callingmodel where most parameters are in hardware registers.Here's a sample function in the Idel assembly language:   : 2 1 umod   u/mod { quotient remainder -- remainder } ;This says ``define umod as a function, with 2 arguments and 1 result,that calls u/mod, names its return values `quotient' and `remainder',and returns the remainder.''  The arguments to the function are thesame as the arguments to u/mod, namely a divisor and dividend.  (The uis for unsigned.)A more interesting function, Euclid's algorithm:   : 2 1 gcd      { a b --  b 0 = if                 a               else                 b  a b umod  gcd               then } ;Obviously this is nice & convenient if you like Forth, but don't stackmachines map poorly onto register-based hardware?  Well, that's whyour stack effects are static.  This is more like the staticsingle-assignment form that compilers use, and we know how to generateefficient code from that and how to convert imperative code like Cinto it.  There's still a question whether an efficient VM will need aserious register allocator in its guts, or the compiler can do most ofthe work.  Maybe that counts as research, actually...  But thequestion doesn't go away for a register VM, since the compiler won'tknow what hardware registers there are.That was the excuse for why a stack machine is acceptable, now what'sthe actual reason?  I just want to do whatever is dead-simple yetstill works -- that's the philosophy throughout this project.That raises the question, wouldn't a safe higher-level language besimpler than software fault isolation?  Yes, it would, and you mightprefer to go that way for your problem.  It's just not quite theproblem I'm trying to solve -- I want something you could reasonablytarget C onto.  (On the other hand C is not the whole story -- Iinsist on supporting tail recursion, for example.)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -