From f4e82feb2492b0bf466c3921b3e9fc9d056f3ea3 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Sat, 21 Nov 2015 19:59:55 -0500 Subject: fix C transcompiler REPEAT --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index eba809a..c2e67fa 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,31 @@ Simple! IF iter < 20; GOTO loop_start LOG Done! +### Prime Counter + + #!/bin/ducky + LOG Counting... + NEWLINE + LET primes=0 + LET MAX=100000 + LET n = 2 + LBL test_number + LET iter = 2 + LET stop = sqrt n + LBL test_loop + IF !(n % iter); GOTO composite + INC iter + IF iter <= stop; GOTO test_loop + INC primes + LBL composite + INC n + IF n < MAX; GOTO test_number + LOG Number of primes below + LOGVAR MAX + LOG : + LOGVAR primes + NEWLINE + ## Building POSIX systems are supported, as are some Rockbox targets. @@ -57,10 +82,32 @@ This will create `a.out`, which contains the bytecode. ducky a.out +## Technical Details + +The program consists of four parts: the interpreter, compiler, bytecode interpreter, and C transcompiler. + +### Interpreter + +Executes ducky directly. + + +### Bytecode Compiler + +Compiles ducky to a stack-machine based bytecode. + +### Bytecode Interpreter + +Executes the bytecode generated by the bytecode compiler. + +### C Transcompiler + +Translates bytecode generated by the bytecode compiler into C. +Depends on labels as values, which is a GCC extension. + ## Future Directions - - Compile to C? - Refactor code + - Input - Add more builtins - Arrays? - Functions? -- cgit v1.1