Permalink
Browse files

ready

  • Loading branch information...
1 parent 2aead05 commit 6d34618a1dc6013538ba12bbd7d081fa7815f855 @txus committed Dec 29, 2012
Showing with 234 additions and 162 deletions.
  1. +1 −1 Makefile
  2. +81 −3 README.md
  3. BIN bin/tvm
  4. +3 −3 bin/{fxvm.c → tvm.c}
  5. +0 −6 compiler/Readme.md
  6. +0 −9 src/forkix/bootstrap.h
  7. +0 −12 src/forkix/vm.h
  8. +5 −5 src/{forkix → terror}/bootstrap.c
  9. +9 −0 src/terror/bootstrap.h
  10. +1 −1 src/{forkix → terror}/bstrlib.c
  11. 0 src/{forkix → terror}/bstrlib.h
  12. +1 −1 src/{forkix → terror}/call_frame.c
  13. +5 −5 src/{forkix → terror}/call_frame.h
  14. +1 −1 src/{forkix → terror}/darray.c
  15. +1 −1 src/{forkix → terror}/darray.h
  16. +2 −2 src/{forkix → terror}/dbg.h
  17. +5 −5 src/{forkix → terror}/function.c
  18. +4 −4 src/{forkix → terror}/function.h
  19. +1 −1 src/{forkix → terror}/gc.c
  20. +3 −3 src/{forkix → terror}/gc.h
  21. +2 −2 src/{forkix → terror}/gc_header.h
  22. +3 −3 src/{forkix → terror}/hashmap.c
  23. +3 −3 src/{forkix → terror}/hashmap.h
  24. +4 −4 src/{forkix → terror}/input_reader.c
  25. +6 −6 src/{forkix → terror}/input_reader.h
  26. +2 −2 src/{forkix → terror}/list.c
  27. +3 −3 src/{forkix → terror}/list.h
  28. +2 −2 src/{forkix → terror}/opcode.h
  29. +7 −7 src/{forkix → terror}/primitives.c
  30. +4 −4 src/{forkix → terror}/primitives.h
  31. +4 −4 src/{forkix → terror}/runtime.c
  32. +3 −3 src/{forkix → terror}/runtime.h
  33. +3 −3 src/{forkix → terror}/stack.h
  34. +1 −1 src/{forkix → terror}/state.c
  35. +6 −6 src/{forkix → terror}/state.h
  36. +5 −5 src/{forkix → terror}/value.c
  37. +6 −6 src/{forkix → terror}/value.h
  38. +2 −2 src/{forkix → terror}/value_type.h
  39. +12 −12 src/{forkix → terror}/vm.c
  40. +12 −0 src/terror/vm.h
  41. +1 −1 tests/darray_tests.c
  42. +2 −2 tests/hashmap_tests.c
  43. +3 −3 tests/input_reader_tests.c
  44. +2 −2 tests/list_tests.c
  45. +2 −2 tests/minunit.h
  46. +1 −1 tests/runtime_tests.c
  47. +1 −1 tests/stack_tests.c
  48. +1 −1 tests/value_tests.c
  49. +8 −8 tests/vm_tests.c
View
@@ -13,7 +13,7 @@ TESTS=$(patsubst %.c,%,$(TEST_SRC))
PROGRAMS_SRC=$(wildcard bin/*.c)
PROGRAMS=$(patsubst %.c,%,$(PROGRAMS_SRC))
-TARGET=build/libforkix.a
+TARGET=build/libterror.a
SO_TARGET=$(patsubst %.a,%.so,$(TARGET))
View
@@ -1,10 +1,88 @@
-# C project
+# TerrorVM
+
+![TerrorVM](https://github.com/txus/terrorvm/raw/master/assets/tvm_large.png)
+
+A lightweight Virtual Machine for dynamic, object-oriented languages.
TODO: Write a project description
-## Usage
+## Building the VM
+
+ $ git clone git://github.com/txus/terrorvm.git
+ $ cd terrorvm
+ $ make
+
+To run the tests:
+
+ $ make dev
+
+And to clean the mess:
+
+ $ make clean
+
+## Running programs
+
+TerrorVM runs `.tvm` bytecode files such as the `hello_world.tvm` under the
+`examples` directory.
+
+ $ ./bin/vm examples/hello_world.tvm
+
+It ships with a simple compiler written in Ruby (Rubinius) that compiles a
+tiny subset of Ruby to `.tvm` files. Check out the `compiler` directory, which
+has its own Readme, and the `compiler/examples` where we have the
+`hello_world.rb` file used to produce the `hello_world.tvm`.
+
+TerrorVM doesn't need Ruby to run; even the example compiler is a proof of
+concept and could be written in any language (even in C obviously).
+
+## Prelude
+
+TerrorVM tries to implement as much as possible in its own code. You can find a
+prelude under `compiler/examples/prelude.rb`, or in native format under
+`examples/prelude.tvm`.
+
+This prelude wires up the VM primitives to the real objects at runtime, so that your code can use them conveniently.
+
+To recompile all examples and kernel files from Ruby to Tvm, do this:
+
+ $ make kernel
+ $ make examples
+
+## Implementing your own dynamic language running on TerrorVM
+
+TerrorVM is designed to run dynamic languages. You can easily implement a
+compiler of your own that compiles your favorite dynamic language down to TVM
+bytecode.
+
+I've written a demo compiler in Ruby under the `compiler/` folder, just to
+show how easy it is to write your own. This demo compiler compiles a subset of
+Ruby down to TerrorVM bytecode, so you can easily peek at the source code or
+just copy and modify it.
+
+You can write your compiler in whatever language you prefer, of course.
+
+## Bytecode format
+
+(I rewrote it entirely so I have to write the new format here soon.)
+
+### Examples
+
+* Hello world ([Ruby code](https://github.com/txus/terrorvm/blob/master/compiler/examples/hello_world.rb), [TVM bytecode](https://github.com/txus/terrorvm/blob/master/examples/hello_world.tvm))
+* Maps ([Ruby code](https://github.com/txus/terrorvm/blob/master/compiler/examples/maps.rb), [TVM code](https://github.com/txus/terrorvm/blob/master/examples/maps.tvm))
+* Vectors ([Ruby code](https://github.com/txus/terrorvm/blob/master/compiler/examples/vectors.rb), [TVM code](https://github.com/txus/terrorvm/blob/master/examples/vectors.tvm))
+* Numbers ([Ruby code](https://github.com/txus/terrorvm/blob/master/compiler/examples/numbers.rb), [TVM code](https://github.com/txus/terrorvm/blob/master/examples/numbers.tvm))
+* Objects with prototypal inheritance ([Ruby code](https://github.com/txus/terrorvm/blob/master/compiler/examples/objects.rb), [TVM bytecode](https://github.com/txus/terrorvm/blob/master/examples/objects.tvm))
+* Functions and closures ([Ruby code](https://github.com/txus/terrorvm/blob/master/compiler/examples/functions.rb), [TVM bytecode](https://github.com/txus/terrorvm/blob/master/examples/functions.tvm))
+
+### Instruction set
+
+(I have to write the new one here as well.)
+
+## Who's this
-TODO: Write usage instructions here
+This was made by [Josep M. Bach (Txus)](http://txustice.me) under the MIT
+license. I'm [@txustice](http://twitter.com/txustice) on twitter (where you
+should probably follow me!).
## Contributing
View
BIN bin/tvm
Binary file not shown.
View
@@ -1,7 +1,7 @@
#include <stdio.h>
-#include <forkix/dbg.h>
-#include <forkix/bstrlib.h>
-#include <forkix/vm.h>
+#include <terror/dbg.h>
+#include <terror/bstrlib.h>
+#include <terror/vm.h>
int
main(int argc, char *argv[])
View
@@ -3,12 +3,6 @@
This is a proof-of-concept compiler written in Ruby (although it runs only on
Rubinius) that compiles a subset of Ruby to Terror bytecode.
-Since writing a compiler targeting a register-based VM is not trivial to me,
-register allocation is rather naive and non-efficient. Basically, reusability
-of registers is close to zero. If you have a suggestion about this (some book
-or article regarding this topic) I'd be really happy if you pointed it out for
-me to read about this.
-
## Usage
$ rvm use rbx-head
View
@@ -1,9 +0,0 @@
-#ifndef _fx_bootstrap_h_
-#define _fx_bootstrap_h_
-
-#include <forkix/state.h>
-
-void State_bootstrap(STATE);
-
-#endif
-
View
@@ -1,12 +0,0 @@
-#ifndef _fx_vm_h_
-#define _fx_vm_h_
-
-#include <forkix/stack.h>
-#include <forkix/state.h>
-#include <forkix/value.h>
-#include <forkix/input_reader.h>
-
-VALUE VM_run(STATE);
-void VM_start(bstring filename);
-
-#endif
@@ -1,8 +1,8 @@
-#include <forkix/bootstrap.h>
-#include <forkix/darray.h>
-#include <forkix/bstrlib.h>
-#include <forkix/runtime.h>
-#include <forkix/primitives.h>
+#include <terror/bootstrap.h>
+#include <terror/darray.h>
+#include <terror/bstrlib.h>
+#include <terror/runtime.h>
+#include <terror/primitives.h>
#include <dirent.h>
VALUE Integer_bp;
View
@@ -0,0 +1,9 @@
+#ifndef _tvm_bootstrap_h_
+#define _tvm_bootstrap_h_
+
+#include <terror/state.h>
+
+void State_bootstrap(STATE);
+
+#endif
+
@@ -22,7 +22,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#include <forkix/bstrlib.h>
+#include <terror/bstrlib.h>
/* Optionally include a mechanism for debugging memory */
File renamed without changes.
@@ -1,5 +1,5 @@
#include <stdlib.h>
-#include <forkix/call_frame.h>
+#include <terror/call_frame.h>
CallFrame*
CallFrame_new(VALUE self, Function *fn, int *ret)
@@ -1,9 +1,9 @@
-#ifndef _fx_call_frame_h_
-#define _fx_call_frame_h_
+#ifndef _tvm_call_frame_h_
+#define _tvm_call_frame_h_
-#include <forkix/value.h>
-#include <forkix/darray.h>
-#include <forkix/function.h>
+#include <terror/value.h>
+#include <terror/darray.h>
+#include <terror/function.h>
struct call_frame_s {
VALUE self;
@@ -1,4 +1,4 @@
-#include <forkix/darray.h>
+#include <terror/darray.h>
#include <assert.h>
DArray *DArray_create(size_t element_size, size_t initial_max)
@@ -2,7 +2,7 @@
#define _DArray_h
#include <stdlib.h>
#include <assert.h>
-#include <forkix/dbg.h>
+#include <terror/dbg.h>
typedef struct DArray {
int end;
@@ -1,5 +1,5 @@
-#ifndef __fx_dbg_h__
-#define __fx_dbg_h__
+#ifndef __tvm_dbg_h__
+#define __tvm_dbg_h__
#include <stdio.h>
#include <errno.h>
@@ -1,8 +1,8 @@
-#include <forkix/function.h>
-#include <forkix/value.h>
-#include <forkix/stack.h>
-#include <forkix/state.h>
-#include <forkix/call_frame.h>
+#include <terror/function.h>
+#include <terror/value.h>
+#include <terror/stack.h>
+#include <terror/state.h>
+#include <terror/call_frame.h>
Function*
Function_new(int *code, DArray *literals)
@@ -1,8 +1,8 @@
-#ifndef _fx_function_h_
-#define _fx_function_h_
+#ifndef _tvm_function_h_
+#define _tvm_function_h_
-#include <forkix/darray.h>
-#include <forkix/stack.h>
+#include <terror/darray.h>
+#include <terror/stack.h>
struct state_s;
struct val_s;
@@ -1,4 +1,4 @@
-#include <forkix/gc.h>
+#include <terror/gc.h>
#include <stdlib.h>
VALUE
@@ -1,8 +1,8 @@
-#ifndef _fx_gc_h_
-#define _fx_gc_h_
+#ifndef _tvm_gc_h_
+#define _tvm_gc_h_
#include <stdlib.h>
-#include <forkix/value.h>
+#include <terror/value.h>
VALUE gc_alloc(size_t size);
void gc_dealloc(VALUE obj);
@@ -1,5 +1,5 @@
-#ifndef _fx_gc_header_h_
-#define _fx_gc_header_h_
+#ifndef _tvm_gc_header_h_
+#define _tvm_gc_header_h_
struct gc_header_s {
short int marked;
@@ -1,7 +1,7 @@
#include <stdint.h>
-#include <forkix/hashmap.h>
-#include <forkix/dbg.h>
-#include <forkix/bstrlib.h>
+#include <terror/hashmap.h>
+#include <terror/dbg.h>
+#include <terror/bstrlib.h>
int reverse_compare(void *a, void *b)
{
@@ -1,8 +1,8 @@
-#ifndef _fx_Hashmap_h
-#define _fx_Hashmap_h
+#ifndef _tvm_Hashmap_h
+#define _tvm_Hashmap_h
#include <stdint.h>
-#include <forkix/darray.h>
+#include <terror/darray.h>
#define DEFAULT_NUMBER_OF_BUCKETS 100
@@ -3,10 +3,10 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
-#include <forkix/dbg.h>
-#include <forkix/bstrlib.h>
-#include <forkix/input_reader.h>
-#include <forkix/value.h>
+#include <terror/dbg.h>
+#include <terror/bstrlib.h>
+#include <terror/input_reader.h>
+#include <terror/value.h>
/*
* Return the filesize of `filename` or -1.
@@ -1,10 +1,10 @@
-#ifndef _fx_input_reader_h_
-#define _fx_input_reader_h_
+#ifndef _tvm_input_reader_h_
+#define _tvm_input_reader_h_
-#include <forkix/bstrlib.h>
-#include <forkix/function.h>
-#include <forkix/darray.h>
-#include <forkix/hashmap.h>
+#include <terror/bstrlib.h>
+#include <terror/function.h>
+#include <terror/darray.h>
+#include <terror/hashmap.h>
typedef struct {
bstring filename;
@@ -1,5 +1,5 @@
-#include <forkix/list.h>
-#include <forkix/dbg.h>
+#include <terror/list.h>
+#include <terror/dbg.h>
List *List_create()
{
@@ -1,5 +1,5 @@
-#ifndef _fx_list_h
-#define _fx_list_h
+#ifndef _tvm_list_h
+#define _tvm_list_h
#include <stdlib.h>
@@ -38,4 +38,4 @@ void *List_remove(List *list, ListNode *node);
ListNode *V = NULL;\
for(V = _node = L->S; _node != NULL; V = _node = _node->M)
-#endif
+#endif
@@ -1,5 +1,5 @@
-#ifndef _fx_opcode_h_
-#define _fx_opcode_h_
+#ifndef _tvm_opcode_h_
+#define _tvm_opcode_h_
typedef enum {
NOOP = 0,
@@ -1,10 +1,10 @@
-#include <forkix/primitives.h>
-#include <forkix/runtime.h>
-#include <forkix/bstrlib.h>
-#include <forkix/state.h>
-#include <forkix/call_frame.h>
-#include <forkix/input_reader.h>
-#include <forkix/vm.h>
+#include <terror/primitives.h>
+#include <terror/runtime.h>
+#include <terror/bstrlib.h>
+#include <terror/state.h>
+#include <terror/call_frame.h>
+#include <terror/input_reader.h>
+#include <terror/vm.h>
#include <assert.h>
/*
@@ -1,8 +1,8 @@
-#ifndef _fx_primitives_h_
-#define _fx_primitives_h_
+#ifndef _tvm_primitives_h_
+#define _tvm_primitives_h_
-#include <forkix/value.h>
-#include <forkix/state.h>
+#include <terror/value.h>
+#include <terror/state.h>
#include <assert.h>
#define CHECK_TYPE(O, T) assert((O)->type == (T) && "Type mismatch in primitive operation")
Oops, something went wrong.

0 comments on commit 6d34618

Please sign in to comment.