From 23781266cd42bf1637efbad7265e1866a17a562d Mon Sep 17 00:00:00 2001 From: razetime Date: Wed, 17 Aug 2022 19:21:12 +0530 Subject: [PATCH] add melanjan --- melanjan.factor | 47 +++++++++++++++++++++++++++++++++++++++++++++++ mtest.mel | 2 ++ 2 files changed, 49 insertions(+) create mode 100755 melanjan.factor create mode 100644 mtest.mel diff --git a/melanjan.factor b/melanjan.factor new file mode 100755 index 0000000..8f680ae --- /dev/null +++ b/melanjan.factor @@ -0,0 +1,47 @@ +! Copyright (C) 2022 Raghu Ranganathan. +! See http://factorcode.org/license.txt for BSD license. + +USING: kernel math sequences locals arrays formatting strings combinators + io io.files io.encodings.ascii system command-line ; +IN: melanjan + +: end ( str -- ) [ print flush ] with-output>error 0 exit ; +: dump ( a b c i seq -- ) "a=%d | b=%d | c=%d | i=%d\nProgram:\n%[%d, %]\n" printf flush ; +:: run-m ( dbg prg -- ) + 0 0 0 0 :> ( a! b! c! i! ) + prg length :> l + [ l i = not ] [ + i l >= i 0 < and [ "Instruction pointer 'i' out of program bounds, exiting" sprintf end ] when + i 1 + prg nth { + { CHAR: a [ a ] } + { CHAR: b [ b ] } + { CHAR: c [ c ] } + { CHAR: i [ i ] } + { CHAR: A [ prg a nth ] } + { CHAR: B [ prg b nth ] } + { CHAR: C [ prg c nth ] } + { CHAR: 1 [ 1 ] } + { CHAR: o [ read1 ] } + [ drop f ] + } case + i prg nth { + { CHAR: a [ [ a - a! ] ] } + { CHAR: b [ [ b - b! ] ] } + { CHAR: c [ [ c - c! ] ] } + { CHAR: i [ [ i - i! ] ] } + { CHAR: A [ [ a prg nth - a prg set-nth ] ] } + { CHAR: B [ [ b prg nth - b prg set-nth ] ] } + { CHAR: C [ [ c prg nth - c prg set-nth ] ] } + { CHAR: o [ [ write1 ] ] } + [ drop f ] + } case + call( x -- ) + i 2 + i! + dbg [ a b c i prg dump ] when + ] while +; + +! (command-line) dup length 3 < +! [ "USAGE: melanjan [-debug]" end ] [ [ 3 ?nth ] [ 2 ?nth ] bi ] if + +! ascii file-contents >array run diff --git a/mtest.mel b/mtest.mel new file mode 100644 index 0000000..286c59a --- /dev/null +++ b/mtest.mel @@ -0,0 +1,2 @@ + +oo