Skip to content

Commit

Permalink
feat: rename words c! to !c and c@ to @c
Browse files Browse the repository at this point in the history
  • Loading branch information
nawetimebomb committed Oct 8, 2024
1 parent 61a482c commit 6260f63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 14 additions & 4 deletions compiler/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const (
TOKEN_STR
TOKEN_STARSTR

// Macros
TOKEN_ASM
TOKEN_AT_BODY
TOKEN_CURLY_BRACKET_CLOSE
TOKEN_CURLY_BRACKET_OPEN

// Flow Control
TOKEN_CASE
TOKEN_ELSE
Expand Down Expand Up @@ -60,7 +66,6 @@ const (
// Reserved Words
TOKEN_ARGC
TOKEN_ARGV
TOKEN_ASM
TOKEN_BANG_EQUAL
TOKEN_CONST
TOKEN_EQUAL
Expand Down Expand Up @@ -108,15 +113,19 @@ var reservedWords = []reserved{
reserved{typ: TOKEN_STR, word: "str" },
reserved{typ: TOKEN_STARSTR, word: "*str" },

// MACROS
reserved{typ: TOKEN_ASM, word: "asm" },
reserved{typ: TOKEN_AT_BODY, word: "@body" },

reserved{typ: TOKEN_DASH_DASH_DASH, word: "---" },
reserved{typ: TOKEN_LET, word: "let" },
reserved{typ: TOKEN_IN, word: "in" },
reserved{typ: TOKEN_DONE, word: "done" },

reserved{typ: TOKEN_BANG, word: "!" },
reserved{typ: TOKEN_AT, word: "@" },
reserved{typ: TOKEN_C_BANG, word: "c!" },
reserved{typ: TOKEN_C_AT, word: "c@" },
reserved{typ: TOKEN_C_BANG, word: "!c" },
reserved{typ: TOKEN_C_AT, word: "@c" },

reserved{typ: TOKEN_ELSE, word: "else" },
reserved{typ: TOKEN_FI, word: "fi" },
Expand All @@ -127,7 +136,6 @@ var reservedWords = []reserved{

reserved{typ: TOKEN_ARGC, word: "argc" },
reserved{typ: TOKEN_ARGV, word: "argv" },
reserved{typ: TOKEN_ASM, word: "asm" },
reserved{typ: TOKEN_BANG_EQUAL, word: "!=" },
reserved{typ: TOKEN_CONST, word: "const" },
reserved{typ: TOKEN_EQUAL, word: "=" },
Expand Down Expand Up @@ -330,6 +338,8 @@ func TokenizeFile(f string, s string) []Token {
}

switch {
case c == '{': makeToken(TOKEN_CURLY_BRACKET_OPEN)
case c == '}': makeToken(TOKEN_CURLY_BRACKET_CLOSE)
case c == '[': makeToken(TOKEN_BRACKET_OPEN)
case c == ']': makeToken(TOKEN_BRACKET_CLOSE)
case c == '(': makeToken(TOKEN_PAREN_OPEN)
Expand Down
8 changes: 4 additions & 4 deletions libs/strings.sk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn len (int --- int) 0 dup rot < until ++ I 10 / loop ret
; - <string> len
; Returns:
; - The number of characters in teh string. "Stanczyk" returns 8
fn len (str --- int) let s in 0 0 dup s ptr c@ != until ++ dup s ptr c@ loop done ret
fn len (str --- int) let s in 0 0 dup s ptr @c != until ++ dup s ptr @c loop done ret

; Compares two strings and returns the results of the comparison
; Calling:
Expand All @@ -53,7 +53,7 @@ fn strequal (str str --- bool)
let s1 l1 s2 l2 in
l1 l2 = dup if
0 l1 <= until
I s1 ptr c@ I s2 ptr c@ != if false nip leave fi
I s1 ptr @c I s2 ptr @c != if false nip leave fi
I -- loop
fi
done
Expand All @@ -76,11 +76,11 @@ fn itoa (int ptr)

number 0 != if
0 BUFFER_CAP <= until
0 buffer I + c!
0 buffer I + !c
I -- loop

0 number len 1 - <= until
'0' number 10 % + buffer I + c!
'0' number 10 % + buffer I + !c
number 10 / &number !
I -- loop
fi
Expand Down

0 comments on commit 6260f63

Please sign in to comment.