The very basics work!

This commit is contained in:
Sage Vaillancourt 2020-05-03 22:00:45 +01:00 committed by =
parent 7579d0b30c
commit 17b6bf12b4
9 changed files with 539 additions and 80 deletions

View File

@ -3,9 +3,9 @@
"capabilities": [ "capabilities": [
"" ""
], ],
"companyName": "Michael E.", "companyName": "Save V.",
"enableMultiJS": true, "enableMultiJS": false,
"longName": "Calculator", "longName": "PebbLisp",
"projectType": "native", "projectType": "native",
"resources": { "resources": {
"media": [ "media": [
@ -19,13 +19,13 @@
] ]
}, },
"sdkVersion": "3", "sdkVersion": "3",
"shortName": "Calculator", "shortName": "PebbLisp",
"targetPlatforms": [ "targetPlatforms": [
"aplite", "aplite",
"basalt" "basalt"
], ],
"uuid": "3a239ae0-adc5-4d40-b871-6fbcd8c37e7c", "uuid": "3a239ae0-adc5-4d40-b871-6fbcd8c37e7c",
"versionLabel": "1.1", "versionLabel": "0.1",
"watchapp": { "watchapp": {
"watchface": false "watchface": false
} }

518
calcers.vims Normal file
View File

@ -0,0 +1,518 @@
let SessionLoad = 1
if &cp | set nocp | endif
vnoremap  "+y
nnoremap  "+yy
nnoremap  
nnoremap  ^
let s:cpo_save=&cpo
set cpo&vim
nnoremap <NL> <NL>
nnoremap  
nnoremap  
nnoremap  m`v$hp``y$
nnoremap ! :!
nnoremap "p "0p
nnoremap // m`I//``:s-////--
nnoremap :W :w
nnoremap U ~
nnoremap \n :tabedit~/.notes
nnoremap \v :tabedit~/.vimrc
nnoremap \r :source ~/.vimrc
nnoremap \ga :!git add %
nnoremap \gu :!git add -u
nnoremap \gp :!git push
nnoremap \gl :!git log
nnoremap \gh :!git --help
nnoremap \gc :!git commit -m ""<Left>
nnoremap \gB :!git blame %
nnoremap \gD :!git diff
nnoremap \gd :!git diff %
nnoremap \p :w :!make run
nnoremap \c :!cat % | xclip -selection clipboard
vnoremap \PP :ha > ~/.vim.ps :!xdg-open ~/.vim.ps
nnoremap \PP :ha > ~/.vim.ps :!xdg-open ~/.vim.ps
nnoremap \b :ls :b
nnoremap ciw cw
nnoremap cw ciw
nnoremap dh d^
nnoremap dl d$
vmap gx <Plug>NetrwBrowseXVis
nmap gx <Plug>NetrwBrowseX
nnoremap gb dawbP
nnoremap gs "xdiwdwep"xp
nnoremap yh y^
nnoremap yl y$
nnoremap ~ U
vnoremap <silent> <Plug>NetrwBrowseXVis :call netrw#BrowseXVis()
nnoremap <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>')),netrw#CheckIfRemote())
inoremap <NL> 
inoremap jk l
inoremap jj l
inoremap kj l
cnoreabbr vimc tabedit ~/.vimrc
cabbr <expr> %% expand('%:p:h')
iabbr reutner return
iabbr reteun return
iabbr ruetn return
let &cpo=s:cpo_save
unlet s:cpo_save
set autoindent
set background=dark
set backspace=indent,eol,start
set dictionary=/usr/share/dict/words
set expandtab
set fileencodings=ucs-bom,utf-8,default,latin1
set foldlevelstart=5
set helplang=en
set ignorecase
set printoptions=paper:a4
set ruler
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim80,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
set shiftwidth=4
set smartcase
set smartindent
set smarttab
set splitbelow
set splitright
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
set tags=./tags;/
set thesaurus=~/.vim/thesaurus/thesaurus-vim-en
set window=44
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
let v:this_session=expand("<sfile>:p")
silent only
cd ~/work/PebbleCalc
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
badd +34 src/pebblisp.h
badd +3 src/pebblisp.c
badd +0 ~/work/PebbleCalc/src/calc.c
argglobal
silent! argdel *
$argadd src/pebblisp.h
edit ~/work/PebbleCalc/src/calc.c
set splitbelow splitright
wincmd _ | wincmd |
vsplit
1wincmd h
wincmd w
wincmd _ | wincmd |
split
1wincmd k
wincmd w
wincmd t
set winminheight=1 winheight=1 winminwidth=1 winwidth=1
exe 'vert 1resize ' . ((&columns * 76 + 76) / 153)
exe '2resize ' . ((&lines * 21 + 22) / 45)
exe 'vert 2resize ' . ((&columns * 76 + 76) / 153)
exe '3resize ' . ((&lines * 21 + 22) / 45)
exe 'vert 3resize ' . ((&columns * 76 + 76) / 153)
argglobal
setlocal keymap=
setlocal noarabic
setlocal autoindent
setlocal backupcopy=
setlocal balloonexpr=
setlocal nobinary
setlocal nobreakindent
setlocal breakindentopt=
setlocal bufhidden=
setlocal buflisted
setlocal buftype=
setlocal nocindent
setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
setlocal cinoptions=
setlocal cinwords=if,else,while,do,for,switch
setlocal colorcolumn=
setlocal comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
setlocal commentstring=/*%s*/
setlocal complete=.,w,b,u,t,i
setlocal concealcursor=
setlocal conceallevel=0
setlocal completefunc=
setlocal nocopyindent
setlocal cryptmethod=
setlocal nocursorbind
setlocal nocursorcolumn
setlocal nocursorline
setlocal define=
setlocal dictionary=
setlocal nodiff
setlocal equalprg=
setlocal errorformat=
setlocal expandtab
if &filetype != 'c'
setlocal filetype=c
endif
setlocal fixendofline
setlocal foldcolumn=0
setlocal foldenable
setlocal foldexpr=0
setlocal foldignore=#
setlocal foldlevel=5
setlocal foldmarker={{{,}}}
set foldmethod=syntax
setlocal foldmethod=syntax
setlocal foldminlines=1
setlocal foldnestmax=20
setlocal foldtext=foldtext()
setlocal formatexpr=
setlocal formatoptions=tcq
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
setlocal formatprg=
setlocal grepprg=
setlocal iminsert=0
setlocal imsearch=-1
setlocal include=
setlocal includeexpr=
setlocal indentexpr=
setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
setlocal noinfercase
setlocal iskeyword=@,48-57,_,192-255
setlocal keywordprg=
setlocal nolinebreak
setlocal nolisp
setlocal lispwords=
setlocal nolist
setlocal makeencoding=
setlocal makeprg=
setlocal matchpairs=(:),{:},[:]
setlocal modeline
setlocal modifiable
setlocal nrformats=bin,octal,hex
set number
setlocal number
setlocal numberwidth=4
setlocal omnifunc=
setlocal path=
setlocal nopreserveindent
setlocal nopreviewwindow
setlocal quoteescape=\\
setlocal noreadonly
set relativenumber
setlocal relativenumber
setlocal norightleft
setlocal rightleftcmd=search
setlocal noscrollbind
setlocal shiftwidth=4
setlocal noshortname
setlocal signcolumn=auto
setlocal smartindent
setlocal softtabstop=0
setlocal nospell
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
setlocal spellfile=
setlocal spelllang=en
setlocal statusline=
setlocal suffixesadd=
setlocal swapfile
setlocal synmaxcol=3000
if &syntax != 'c'
setlocal syntax=c
endif
setlocal tabstop=8
setlocal tagcase=
setlocal tags=
setlocal termkey=
setlocal termsize=
setlocal textwidth=0
setlocal thesaurus=
setlocal noundofile
setlocal undolevels=-123456
setlocal nowinfixheight
setlocal nowinfixwidth
setlocal wrap
setlocal wrapmargin=0
21
normal! zo
61
normal! zo
61
normal! zo
let s:l = 6 - ((5 * winheight(0) + 21) / 43)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
6
normal! 021|
wincmd w
argglobal
if bufexists('src/pebblisp.c') | buffer src/pebblisp.c | else | edit src/pebblisp.c | endif
setlocal keymap=
setlocal noarabic
setlocal autoindent
setlocal backupcopy=
setlocal balloonexpr=
setlocal nobinary
setlocal nobreakindent
setlocal breakindentopt=
setlocal bufhidden=
setlocal buflisted
setlocal buftype=
setlocal nocindent
setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
setlocal cinoptions=
setlocal cinwords=if,else,while,do,for,switch
setlocal colorcolumn=
setlocal comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
setlocal commentstring=/*%s*/
setlocal complete=.,w,b,u,t,i
setlocal concealcursor=
setlocal conceallevel=0
setlocal completefunc=
setlocal nocopyindent
setlocal cryptmethod=
setlocal nocursorbind
setlocal nocursorcolumn
setlocal nocursorline
setlocal define=
setlocal dictionary=
setlocal nodiff
setlocal equalprg=
setlocal errorformat=
setlocal expandtab
if &filetype != 'c'
setlocal filetype=c
endif
setlocal fixendofline
setlocal foldcolumn=0
setlocal foldenable
setlocal foldexpr=0
setlocal foldignore=#
setlocal foldlevel=5
setlocal foldmarker={{{,}}}
set foldmethod=syntax
setlocal foldmethod=syntax
setlocal foldminlines=1
setlocal foldnestmax=20
setlocal foldtext=foldtext()
setlocal formatexpr=
setlocal formatoptions=tcq
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
setlocal formatprg=
setlocal grepprg=
setlocal iminsert=0
setlocal imsearch=-1
setlocal include=
setlocal includeexpr=
setlocal indentexpr=
setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
setlocal noinfercase
setlocal iskeyword=@,48-57,_,192-255
setlocal keywordprg=
setlocal nolinebreak
setlocal nolisp
setlocal lispwords=
setlocal nolist
setlocal makeencoding=
setlocal makeprg=
setlocal matchpairs=(:),{:},[:]
setlocal modeline
setlocal modifiable
setlocal nrformats=bin,octal,hex
set number
setlocal number
setlocal numberwidth=4
setlocal omnifunc=
setlocal path=
setlocal nopreserveindent
setlocal nopreviewwindow
setlocal quoteescape=\\
setlocal noreadonly
set relativenumber
setlocal relativenumber
setlocal norightleft
setlocal rightleftcmd=search
setlocal noscrollbind
setlocal shiftwidth=8
setlocal noshortname
setlocal signcolumn=auto
setlocal smartindent
setlocal softtabstop=0
setlocal nospell
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
setlocal spellfile=
setlocal spelllang=en
setlocal statusline=
setlocal suffixesadd=
setlocal swapfile
setlocal synmaxcol=3000
if &syntax != 'c'
setlocal syntax=c
endif
setlocal tabstop=8
setlocal tagcase=
setlocal tags=
setlocal termkey=
setlocal termsize=
setlocal textwidth=0
setlocal thesaurus=
setlocal noundofile
setlocal undolevels=-123456
setlocal nowinfixheight
setlocal nowinfixwidth
setlocal wrap
setlocal wrapmargin=0
4
normal! zo
10
normal! zo
11
normal! zo
let s:l = 29 - ((20 * winheight(0) + 10) / 21)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
29
normal! 017|
wincmd w
argglobal
if bufexists('src/pebblisp.h') | buffer src/pebblisp.h | else | edit src/pebblisp.h | endif
setlocal keymap=
setlocal noarabic
setlocal autoindent
setlocal backupcopy=
setlocal balloonexpr=
setlocal nobinary
setlocal nobreakindent
setlocal breakindentopt=
setlocal bufhidden=
setlocal buflisted
setlocal buftype=
setlocal nocindent
setlocal cinkeys=0{,0},0),:,0#,!^F,o,O,e
setlocal cinoptions=
setlocal cinwords=if,else,while,do,for,switch
setlocal colorcolumn=
setlocal comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
setlocal commentstring=/*%s*/
setlocal complete=.,w,b,u,t,i
setlocal concealcursor=
setlocal conceallevel=0
setlocal completefunc=
setlocal nocopyindent
setlocal cryptmethod=
setlocal nocursorbind
setlocal nocursorcolumn
setlocal nocursorline
setlocal define=
setlocal dictionary=
setlocal nodiff
setlocal equalprg=
setlocal errorformat=
setlocal expandtab
if &filetype != 'cpp'
setlocal filetype=cpp
endif
setlocal fixendofline
setlocal foldcolumn=0
setlocal foldenable
setlocal foldexpr=0
setlocal foldignore=#
setlocal foldlevel=5
setlocal foldmarker={{{,}}}
set foldmethod=syntax
setlocal foldmethod=syntax
setlocal foldminlines=1
setlocal foldnestmax=20
setlocal foldtext=foldtext()
setlocal formatexpr=
setlocal formatoptions=tcq
setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*
setlocal formatprg=
setlocal grepprg=
setlocal iminsert=0
setlocal imsearch=-1
setlocal include=
setlocal includeexpr=
setlocal indentexpr=
setlocal indentkeys=0{,0},:,0#,!^F,o,O,e
setlocal noinfercase
setlocal iskeyword=@,48-57,_,192-255
setlocal keywordprg=
setlocal nolinebreak
setlocal nolisp
setlocal lispwords=
setlocal nolist
setlocal makeencoding=
setlocal makeprg=
setlocal matchpairs=(:),{:},[:]
setlocal modeline
setlocal modifiable
setlocal nrformats=bin,octal,hex
set number
setlocal number
setlocal numberwidth=4
setlocal omnifunc=
setlocal path=
setlocal nopreserveindent
setlocal nopreviewwindow
setlocal quoteescape=\\
setlocal noreadonly
set relativenumber
setlocal relativenumber
setlocal norightleft
setlocal rightleftcmd=search
setlocal noscrollbind
setlocal shiftwidth=8
setlocal noshortname
setlocal signcolumn=auto
setlocal smartindent
setlocal softtabstop=0
setlocal nospell
setlocal spellcapcheck=[.?!]\\_[\\])'\"\ \ ]\\+
setlocal spellfile=
setlocal spelllang=en
setlocal statusline=
setlocal suffixesadd=
setlocal swapfile
setlocal synmaxcol=3000
if &syntax != 'cpp'
setlocal syntax=cpp
endif
setlocal tabstop=8
setlocal tagcase=
setlocal tags=
setlocal termkey=
setlocal termsize=
setlocal textwidth=0
setlocal thesaurus=
setlocal noundofile
setlocal undolevels=-123456
setlocal nowinfixheight
setlocal nowinfixwidth
setlocal wrap
setlocal wrapmargin=0
15
normal! zo
18
normal! zo
let s:l = 19 - ((4 * winheight(0) + 10) / 21)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
19
normal! 014|
wincmd w
exe 'vert 1resize ' . ((&columns * 76 + 76) / 153)
exe '2resize ' . ((&lines * 21 + 22) / 45)
exe 'vert 2resize ' . ((&columns * 76 + 76) / 153)
exe '3resize ' . ((&lines * 21 + 22) / 45)
exe 'vert 3resize ' . ((&columns * 76 + 76) / 153)
tabnext 1
if exists('s:wipebuf')
silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20 shortmess=filnxtToO
set winminheight=1 winminwidth=1
let s:sx = expand("<sfile>:p:r")."x.vim"
if file_readable(s:sx)
exe "source " . fnameescape(s:sx)
endif
let &so = s:so_save | let &siso = s:siso_save
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 B

After

Width:  |  Height:  |  Size: 7.5 KiB

BIN
src/.pebblisp.c.swp Normal file

Binary file not shown.

BIN
src/.pebblisp.h.swp Normal file

Binary file not shown.

View File

@ -10,18 +10,12 @@ static inline char* getToken(int n) {
} }
static int8_t selected_token = 1; //Currently selected button, starts on '5' static int8_t selected_token = 1; //Currently selected button, starts on '5'
// static bool operator_entered = false; //Has the operator been entered yet
// static bool num1_is_ans = false; //Is the previous result in num1? Used to allow further calculations on result.
// static char num1[MAX_LENGTH] = ""; //First operand
// static char num2[MAX_LENGTH] = ""; //Second operand
// static char result_text[MAX_LENGTH] = ""; //Results text layer buffer string
// static uint8_t operator = 0; //Operator, where 0 is +, 1 is -, 2 is *, 3 is /, 4 is ^
static struct Environment env; static struct Environment env;
static void updateText() static void updateText()
{ {
strcpy(temptext, mytext); strcpy(temptext, mytext);
if(getToken(selected_token)[0] == ' ') { if(getToken(selected_token)[0] == ' ') {
strcat(temptext, "_"); strcat(temptext, "_");
} else { } else {
@ -31,11 +25,11 @@ static void updateText()
text_layer_set_text(s_input_text_layer, temptext); text_layer_set_text(s_input_text_layer, temptext);
} }
//Up or Down button handler // Button handler
static void up_down_handler(ClickRecognizerRef recognizer, void *context){ static void up_down_handler(ClickRecognizerRef recognizer, void *context){
//Move selected button down if down is pressed, and up if up is pressed // Change current token
selected_token += (click_recognizer_get_button_id(recognizer) == BUTTON_ID_DOWN) ? 1 : -1; selected_token += (click_recognizer_get_button_id(recognizer) == BUTTON_ID_DOWN) ? 1 : -1;
//If selected button is outside button range, wrap around // If selected token is outside of range, wrap around
selected_token = selected_token < 0 ? TOKEN_END : selected_token > TOKEN_END ? 0 : selected_token; selected_token = selected_token < 0 ? TOKEN_END : selected_token > TOKEN_END ? 0 : selected_token;
updateText(); updateText();
@ -48,70 +42,13 @@ static void enter(){
updateText(); updateText();
} }
// // Backspace. Clears whole number if full is true
// static void clear(bool full){
// char *num = operator_entered ? num2 : num1; //Create a pointer to the currently edited number
// if(full)
// *num = 0;
// else
// num[strlen(num)-1] = 0;
// text_layer_set_text(s_input_text_layer, num);
// }
//Calculate result, display it and reset //Calculate result, display it and reset
static void calculate(){ static void calculate(){
// Object obj = parseEval(mytext, &env); Object obj = parseEval(mytext, &env);
// snprintf(mytext, MAX_LENGTH, "R:%d", obj.number); snprintf(mytext, MAX_LENGTH, "R:%d", obj.number);
// selected_token = 0; selected_token = 0;
strcpy(mytext, "heythere"); //strcpy(mytext, HAHA);
updateText(); updateText();
if(1)
return;
/*
bool overflow = false; //Overflow flag
// Convert operands to numbers
fixed lhs = str_to_fixed(num1, &overflow);
fixed rhs = str_to_fixed(num2, &overflow);
fixed result = 0;
//Calculate the result
switch(operator){
case 0:
result = fixed_add(lhs, rhs, &overflow);
break;
case 1:
result = fixed_subt(lhs, rhs, &overflow);
break;
case 2:
result = fixed_mult(lhs, rhs, &overflow);
break;
case 3:
result = fixed_div(lhs, rhs);
break;
case 4:
result = fixed_pow(lhs, fixed_to_int(rhs), &overflow); //Exponent must be an int
break;
default:
result = 0;
}
APP_LOG(APP_LOG_LEVEL_DEBUG, "num1: %d num2: %d result: %d", lhs, rhs, result);
//Reset operands, operator_entered and entering_decimal
*num1 = 0;
*num2 = 0;
operator_entered = false;
if(overflow){
text_layer_set_text(s_input_text_layer, "Overflow Error"); //Display message on overflow
}
else{
fixed_repr(result, result_text, MAX_LENGTH); //Convert result to string
text_layer_set_text(s_input_text_layer, result_text); //Display result
strcpy(num1, result_text); //Copy result into num1
num1_is_ans = true;
}
*/
} }
// Button press handler // Button press handler

View File

@ -9,6 +9,8 @@
Window *s_window; Window *s_window;
TextLayer *s_input_text_layer; TextLayer *s_input_text_layer;
const char *HAHA = "STONKS";
char mytext[SMAX_LENGTH] = ""; char mytext[SMAX_LENGTH] = "";
char temptext[SMAX_LENGTH] = ""; char temptext[SMAX_LENGTH] = "";

View File

@ -233,9 +233,10 @@ Object parseEval(const char *input, struct Environment *env)
{ {
struct Slice *tokens = tokenize(input); struct Slice *tokens = tokenize(input);
struct Slice *debug = tokens; struct Slice *debug = tokens;
#ifdef STANDALONE
if(debug) { if(debug) {
while(debug->text) { while(debug->text) {
char tok[10]; char tok[MAX_TOK_LEN];
copySlice(tok, debug); copySlice(tok, debug);
// printf("'%s', ", tok); // printf("'%s', ", tok);
debug++; debug++;
@ -245,6 +246,7 @@ Object parseEval(const char *input, struct Environment *env)
// printf("parse error\n"); // printf("parse error\n");
} }
// printf("parseEval() parse()\n"); // printf("parseEval() parse()\n");
#endif
Object parsed = parse(tokens).obj; Object parsed = parse(tokens).obj;
return eval(&parsed, env); return eval(&parsed, env);
} }

View File

@ -3,9 +3,9 @@
// #define STANDALONE // #define STANDALONE
#define MAX_TOK_LEN 6 #define MAX_TOK_LEN 3
#define MAX_TOK_CNT 128 #define MAX_TOK_CNT 7 // 128
#define MAX_ENV_ELM 50 #define MAX_ENV_ELM 3 // 50
// static const char* tokenFail = "Missing ')'\n"; // static const char* tokenFail = "Missing ')'\n";