-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
900 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(ns concat-files | ||
(:require [std.fs :as fs] | ||
[clojure.java.io :as io])) | ||
|
||
(def +all-files+ | ||
(sort (keys (fs/list "src" {:recursive true | ||
:include [".clj$"]})))) | ||
|
||
(defn concat-files | ||
[& [file-filter out-file dir root]] | ||
(let [out-file (or out-file "output.clj") | ||
root (or root ".") | ||
root-path (fs/path root) | ||
dir (or dir "src") | ||
proj-file "project.clj"] | ||
(with-open [writer (io/writer out-file)] | ||
(let [all-paths (cons (str (fs/path root proj-file)) | ||
(sort (keys (fs/list (fs/path root dir) | ||
{:recursive true | ||
:include [(or file-filter ".clj$")]}))))] | ||
|
||
(doseq [p all-paths] | ||
(let [relative-path (fs/relativize root-path p)] | ||
(.write writer (str "\n\n\n;;; ------- " relative-path "------- \n\n\n")) | ||
(try (with-open [r (io/reader p)] | ||
(doseq [line (line-seq r)] | ||
(.write writer ^String line) | ||
(.write writer "\n"))) | ||
(catch Throwable t)))))))) | ||
|
||
(comment | ||
(concat-files) | ||
|
||
(fs/list (fs/path "test") | ||
{:recursive true | ||
:include [".clj$"]}) | ||
(concat-files nil | ||
"output-xtalk.clj" | ||
"src/xt") | ||
(concat-files nil | ||
"output-tests.clj" | ||
"test") | ||
|
||
|
||
(concat-files ".clj$" | ||
"output-xtalk.clj" | ||
"../statstrade-core/src/statsdb" | ||
"../statstrade-core") | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
(ns xt.demo.brainfuck | ||
(:require [std.lang :as l] | ||
[std.lib :as h])) | ||
|
||
(l/script :xtalk | ||
{:require [[xt.lang.base-lib :as k]] | ||
:export [MODULE]}) | ||
|
||
(defn.xt brainfuck-interpreter | ||
"Interprets and executes Brainfuck code" | ||
{:added "1.0"} | ||
[bfCode] | ||
;; Initialize memory, pointer, and output | ||
(var memory {}) | ||
(k/for:index [i [(x:offset 0) | ||
(x:offset 30000)]] | ||
(= (. memory [i]) 0)) | ||
(var output "") | ||
(var codeLength (k/len bfCode)) | ||
(var i 0) ;; Instruction pointer | ||
|
||
;; Execute Brainfuck commands | ||
(while (< i codeLength) | ||
(var command (k/get-idx bfCode i)) | ||
(cond | ||
;; Increment the pointer | ||
(== command ">") (:= pointer (+ pointer 1)) | ||
|
||
;; Decrement the pointer | ||
(== command "<") (:= pointer (- pointer 1)) | ||
|
||
;; Increment the value at the current cell | ||
(== command "+") | ||
(k/set-idx memory pointer (mod (+ (k/get-idx memory pointer) 1) 256)) | ||
|
||
;; Decrement the value at the current cell | ||
(== command "-") | ||
(k/set-idx memory pointer (mod (- (+ (k/get-idx memory pointer) 256) 1) 256)) | ||
|
||
;; Output the character at the current cell | ||
(== command ".") | ||
(:= output (k/cat output (k/char (k/get-idx memory pointer)))) | ||
|
||
;; Input a character into the current cell | ||
(== command ",") | ||
(do | ||
(var input (k/read "Input a character:")) | ||
(k/set-idx memory pointer (:? input (k/char-code (k/first input)) 0))) | ||
|
||
;; Jump forward if the current cell is 0 | ||
(== command "[") | ||
(if (== (k/get-idx memory pointer) 0) | ||
(do | ||
(var bracketCounter 1) | ||
(while (> bracketCounter 0) | ||
(:= i (+ i 1)) | ||
(if (== (k/get-idx bfCode i) "[") | ||
(:= bracketCounter (+ bracketCounter 1))) | ||
(if (== (k/get-idx bfCode i) "]") | ||
(:= bracketCounter (- bracketCounter 1)))))) | ||
|
||
;; Jump backward if the current cell is non-zero | ||
(== command "]") | ||
(if (not= (k/get-idx memory pointer) 0) | ||
(do | ||
(var bracketCounter 1) | ||
(while (> bracketCounter 0) | ||
(:= i (- i 1)) | ||
(if (== (k/get-idx bfCode i) "]") | ||
(:= bracketCounter (+ bracketCounter 1))) | ||
(if (== (k/get-idx bfCode i) "[") | ||
(:= bracketCounter (- bracketCounter 1)))))))) | ||
;; Move to the next instruction | ||
(:= i (+ i 1)) | ||
|
||
;; Return the output | ||
(return output)) | ||
|
||
(def.xt MODULE (!:module)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(ns xt.demo.fizzbuzz | ||
(:require [std.lang :as l] | ||
[std.lib :as h])) | ||
|
||
(l/script :xtalk | ||
{:require [[xt.lang.base-lib :as k]] | ||
:export [MODULE]}) | ||
|
||
(defn.xt fizzbuzz | ||
"Generates FizzBuzz for numbers from 1 to n" | ||
{:added "1.0"} | ||
[n] | ||
;; Initialize an empty array for results | ||
(var result []) | ||
;; Iterate through numbers 1 to n | ||
(k/for:index [i [1 (+ n 1) 1]] | ||
(var value nil) | ||
;; Check divisibility for FizzBuzz | ||
(if (and (== 0 (mod i 3)) (== 0 (mod i 5))) | ||
(:= value "FizzBuzz") | ||
(if (== 0 (mod i 3)) | ||
(:= value "Fizz") | ||
(if (== 0 (mod i 5)) | ||
(:= value "Buzz") | ||
(:= value i)))) | ||
;; Append the value to the result array | ||
(x:arr-push result value)) | ||
;; Return the result array | ||
(return result)) | ||
|
||
(def.xt MODULE (!:module)) |
Oops, something went wrong.