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)
|
(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 get-words (fn (text) (
|
||||||
|
(def words ())
|
||||||
(split text " ")
|
(split text " ")
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
@ -67,14 +88,21 @@
|
||||||
))
|
))
|
||||||
|
|
||||||
(def operations (table))
|
(def operations (table))
|
||||||
(h-insert operations "cls" '(sys "clear"))
|
(def add-op (fn (name op) (
|
||||||
(h-insert operations "swap" '(swap))
|
(h-insert operations name op)
|
||||||
(h-insert operations "??" '(pstack))
|
)))
|
||||||
(h-insert operations "+" '(twop +))
|
(add-op "cls" '(sys "clear"))
|
||||||
(h-insert operations "-" '(twop -))
|
(add-op "over" '(over))
|
||||||
(h-insert operations "/" '(twop /))
|
(add-op "rot" '(rot))
|
||||||
(h-insert operations "*" '(twop *))
|
(add-op "dup" '(dup))
|
||||||
(h-insert operations "." '(loud-pop))
|
(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))))
|
(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))
|
(def words (get-words text))
|
||||||
(fmap words)
|
(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 esc (ch 27))
|
||||||
(def reset (cat esc "[0m"))
|
(def reset (cat esc "[0m"))
|
||||||
(def fprompt (cat esc "[33;1mplf:> " reset))
|
(def fprompt (cat esc "[33;1mplf:> " reset))
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
(reloadConfig)
|
(reloadConfig)
|
||||||
)))
|
)))
|
||||||
|
|
||||||
(def forthFile "/home/sagevaillancourt/projects/pebblisp/src/examples/forbble.pbl")
|
(def forthFile (cat ~ "/projects/pebblisp/src/examples/forbble.pbl"))
|
||||||
(struct Alias (name value))
|
(struct Alias (name value))
|
||||||
(def aliases (
|
(def aliases (
|
||||||
(Alias "ls" "ls --color")
|
(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 prompt (fn (a) (
|
||||||
(def d (cleanDir))
|
(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
|
(cat nl
|
||||||
esc "]0; " d (ch 7)
|
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)
|
bold green "pebblisp ~> " reset)
|
||||||
)))
|
)))
|
||||||
|
|
|
@ -422,7 +422,7 @@ int hexChar(char c)
|
||||||
if (c >= 'a' && c <= 'f') {
|
if (c >= 'a' && c <= 'f') {
|
||||||
return c - 'a' + 10;
|
return c - 'a' + 10;
|
||||||
}
|
}
|
||||||
if (c >= 'A' && c <= 'F'){
|
if (c >= 'A' && c <= 'F') {
|
||||||
return c - 'A' + 10;
|
return c - 'A' + 10;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -444,7 +444,7 @@ int decChar(char c)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object parseNum(int base, const char* text, int length, int (*func)(char))
|
Object parseNum(int base, const char* text, int length, int (* func)(char))
|
||||||
{
|
{
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
|
@ -461,7 +461,7 @@ Object parseNum(int base, const char* text, int length, int (*func)(char))
|
||||||
|
|
||||||
Object optimize(Object (* func)(Object*, int, struct Environment*), int argCount, Object args[])
|
Object optimize(Object (* func)(Object*, int, struct Environment*), int argCount, Object args[])
|
||||||
{
|
{
|
||||||
struct StaticFunction *f = malloc(sizeof(struct StaticFunction) + (sizeof(Object) * argCount));
|
struct StaticFunction* f = malloc(sizeof(struct StaticFunction) + (sizeof(Object) * argCount));
|
||||||
f->refs = 1;
|
f->refs = 1;
|
||||||
f->func = func;
|
f->func = func;
|
||||||
f->arguments = (void*) f + sizeof(struct StaticFunction);
|
f->arguments = (void*) f + sizeof(struct StaticFunction);
|
||||||
|
@ -617,7 +617,7 @@ char* readFileToString(FILE* input)
|
||||||
c = fgetc(input);
|
c = fgetc(input);
|
||||||
} while (c != '\n' && c != EOF);
|
} while (c != '\n' && c != EOF);
|
||||||
} else {
|
} else {
|
||||||
string[i++] = c;
|
string[i++] = c == EOF ? '\0' : c;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((c = fgetc(input)) != EOF) {
|
while ((c = fgetc(input)) != EOF) {
|
||||||
|
|
|
@ -242,9 +242,9 @@ check "Map Filter" \
|
||||||
"( 64 81 100 121 144 )"
|
"( 64 81 100 121 144 )"
|
||||||
|
|
||||||
title "Forbble"
|
title "Forbble"
|
||||||
check "BasicForbbleOp" '(loadfile "examples/forbble.pbl") (feval "10 10 * .") ""' "100"
|
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 "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 "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"
|
#check "ForbbleDefine" '(loadfile "examples/forbble.pbl") (feval ( : "cubed" dup dup * * $ )) (feval (4 cubed .)) ""' "64"
|
||||||
|
|
||||||
title "Environment"
|
title "Environment"
|
||||||
|
|
Loading…
Reference in New Issue