From 60d51c2fd82e9058eea12a9f11d9f29b4fc173e6 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Fri, 9 Sep 2022 23:47:47 +1200 Subject: Start of FALSE implementation --- src/false/false.cr | 39 +++++++++++++++++++++++++++++++++++++++ src/false/program.cr | 9 +++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/false/false.cr create mode 100644 src/false/program.cr (limited to 'src/false') diff --git a/src/false/false.cr b/src/false/false.cr new file mode 100644 index 0000000..e26fd89 --- /dev/null +++ b/src/false/false.cr @@ -0,0 +1,39 @@ +require "big.cr" + +module False + + enum Command + DUP # ( n -- n n ) + DROP # ( n1 n2 -- n1 ) + SWAP # ( n1 n2 -- n2 n1 ) + ROT # ( n1 n2 n3 -- n2 n3 n1 ) + PICK # push the n-th stack item (top of stack is index 0) + ADD # ( n1 n2 -- (n1+n2) ) + SUBTRACT # ( n1 n2 -- (n1-n2) ) + MULTIPLY # ( n1 n2 -- (n1-n2) ) + DIVIDE # ( n1 n2 -- (n1/n2) ) + NEGATE # ( n1 -- (-1*n1) ) + BAND # ( n1 n2 -- (n1&n2) ) + BOR # ( n1 n2 -- (n1|n2) ) + BNOT # invert each bit of top of the stack + GREATER # ( n1 n2 -- (n1>n2) ) + EQUAL # ( n1 n2 -- (n1==n2) ) + EXECUTE # lambda execution + CONDITIONAL # ( cond lambda -- ... ) execute lambda if cond is true, pops both + LOOP # ( cond lambda -- ... ) execute lambda repeatedly until cond is false, then pop both + STORE # ( value reference -- ) stores value at the given variable reference, pops both + FETCH # ( reference -- ) pops the reference and pushes the value stored at the reference + READ # read character from STDIN and push its character code + WRITE_CHAR # pop the stack and print the value's character ("65," prints "A") + WRITE_INT # pop the stack and print the value as an integer ("65." prints "65") + FLUSH # flush input and output buffers + end + + alias PushInt = BigInt # int literal pushes int + alias PushCharCode = Char # char literal ( 'c ) pushes char + alias PushVarRef = Char # variable name pushes its address + alias WriteString = String # string literal prints the string + + alias Operation = Command | PushInt | PushCharCode | PushVarRef | WriteString +end + diff --git a/src/false/program.cr b/src/false/program.cr new file mode 100644 index 0000000..18ce3ef --- /dev/null +++ b/src/false/program.cr @@ -0,0 +1,9 @@ +require "./false.cr" +require "../program.cr" + +struct False::Program < Flint::Program + def interpret : Nil + puts "TODO" + end +end + -- cgit v1.2.1