Add fib to forbble.
Add git branch to pl prompt. Fix readFileToString() for empty files.
This commit is contained in:
parent
a47e280c76
commit
d825ca3fe2
|
@ -33,7 +33,28 @@
|
|||
(stkadd bottom)
|
||||
)))
|
||||
|
||||
(def dup (fn () (
|
||||
(def top (pop))
|
||||
(stkadd top)
|
||||
(stkadd top)
|
||||
)))
|
||||
|
||||
(def over (fn () (
|
||||
(def second (at 1 stack))
|
||||
(stkadd second)
|
||||
)))
|
||||
|
||||
(def rot (fn () (
|
||||
(def a (pop))
|
||||
(def b (pop))
|
||||
(def c (pop))
|
||||
(stkadd b)
|
||||
(stkadd a)
|
||||
(stkadd c)
|
||||
)))
|
||||
|
||||
(def get-words (fn (text) (
|
||||
(def words ())
|
||||
(split text " ")
|
||||
)))
|
||||
|
||||
|
@ -67,14 +88,21 @@
|
|||
))
|
||||
|
||||
(def operations (table))
|
||||
(h-insert operations "cls" '(sys "clear"))
|
||||
(h-insert operations "swap" '(swap))
|
||||
(h-insert operations "??" '(pstack))
|
||||
(h-insert operations "+" '(twop +))
|
||||
(h-insert operations "-" '(twop -))
|
||||
(h-insert operations "/" '(twop /))
|
||||
(h-insert operations "*" '(twop *))
|
||||
(h-insert operations "." '(loud-pop))
|
||||
(def add-op (fn (name op) (
|
||||
(h-insert operations name op)
|
||||
)))
|
||||
(add-op "cls" '(sys "clear"))
|
||||
(add-op "over" '(over))
|
||||
(add-op "rot" '(rot))
|
||||
(add-op "dup" '(dup))
|
||||
(add-op "swap" '(swap))
|
||||
(add-op "??" '(pstack))
|
||||
(add-op "." '(loud-pop))
|
||||
(add-op "+" '(twop +))
|
||||
(add-op "-" '(twop -))
|
||||
(add-op "/" '(twop /))
|
||||
(add-op "*" '(twop *))
|
||||
(add-op "=" '(twop =))
|
||||
|
||||
(def noterr (fn (e) (not (iserr e))))
|
||||
|
||||
|
@ -99,11 +127,20 @@
|
|||
))
|
||||
)))
|
||||
|
||||
(def feval (fn (text) (
|
||||
(def fline-eval (fn (text) (
|
||||
(def words (get-words text))
|
||||
(fmap words)
|
||||
)))
|
||||
|
||||
(def feval (fn (text) (
|
||||
(for-each fline-eval (split text nl))
|
||||
)))
|
||||
|
||||
(for-each feval (
|
||||
": fib swap over + $"
|
||||
": peek dup . $"
|
||||
))
|
||||
|
||||
(def esc (ch 27))
|
||||
(def reset (cat esc "[0m"))
|
||||
(def fprompt (cat esc "[33;1mplf:> " reset))
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
(reloadConfig)
|
||||
)))
|
||||
|
||||
(def forthFile "/home/sagevaillancourt/projects/pebblisp/src/examples/forbble.pbl")
|
||||
(def forthFile (cat ~ "/projects/pebblisp/src/examples/forbble.pbl"))
|
||||
(struct Alias (name value))
|
||||
(def aliases (
|
||||
(Alias "ls" "ls --color")
|
||||
|
@ -85,11 +85,24 @@
|
|||
)
|
||||
)))
|
||||
|
||||
(def current-commit (fn () (
|
||||
(stdout "git rev-parse --short HEAD")
|
||||
)))
|
||||
|
||||
(def current-branch (fn () (
|
||||
(stdout "git branch --show-current")
|
||||
)))
|
||||
|
||||
(def prompt (fn (a) (
|
||||
(def d (cleanDir))
|
||||
(def branch (current-branch))
|
||||
(set branch
|
||||
(if (> (slen branch) 2)
|
||||
(cat bold yellow " [" (substr 0 (- (slen branch) 1) branch) "]")
|
||||
branch))
|
||||
|
||||
(cat nl
|
||||
esc "]0; " d (ch 7)
|
||||
bold red "[sage] " blue (clock (time)) " " reset cyan d nl
|
||||
bold red "[sage] " blue (clock (time)) " " reset cyan d branch nl
|
||||
bold green "pebblisp ~> " reset)
|
||||
)))
|
||||
|
|
|
@ -617,7 +617,7 @@ char* readFileToString(FILE* input)
|
|||
c = fgetc(input);
|
||||
} while (c != '\n' && c != EOF);
|
||||
} else {
|
||||
string[i++] = c;
|
||||
string[i++] = c == EOF ? '\0' : c;
|
||||
}
|
||||
|
||||
while ((c = fgetc(input)) != EOF) {
|
||||
|
|
|
@ -242,9 +242,9 @@ check "Map Filter" \
|
|||
"( 64 81 100 121 144 )"
|
||||
|
||||
title "Forbble"
|
||||
check "BasicForbbleOp" '(loadfile "examples/forbble.pbl") (feval "10 10 * .") ""' "100"
|
||||
check "Basic Forbble Definition" '(loadfile "examples/forbble.pbl") (feval ": ft 12 * $") (feval "10 ft .") ""' "120"
|
||||
#check "FibForbble" '(loadfile "examples/forbble.pbl") (feval (1 1 _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f _f .)) ""' "28657"
|
||||
check "BasicForbbleOp" '(loadfile "examples/forbble.pbl") (feval "10 10 * .")' "100"
|
||||
check "Basic Forbble Definition" '(loadfile "examples/forbble.pbl") (feval ": ft 12 * $") (feval "10 ft .")' "120"
|
||||
check "FibForbble" '(loadfile "examples/forbble.pbl") (feval "1 1 fib fib fib fib fib fib fib fib fib fib fib fib fib fib fib fib fib fib fib fib fib .")' "28657"
|
||||
#check "ForbbleDefine" '(loadfile "examples/forbble.pbl") (feval ( : "cubed" dup dup * * $ )) (feval (4 cubed .)) ""' "64"
|
||||
|
||||
title "Environment"
|
||||
|
|
Loading…
Reference in New Issue