Skip to content

Commit

Permalink
feat: moved drop from internal compiler to runtime.sk
Browse files Browse the repository at this point in the history
  • Loading branch information
nawetimebomb committed Sep 29, 2024
1 parent 04e281e commit 205837c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
3 changes: 0 additions & 3 deletions compiler/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ func generateLinuxX64() {
asm.WriteText(" div rbx")
asm.WriteText(" push rax")
asm.WriteText(" push rdx")
case OP_DROP:
asm.WriteText(";; drop (%s:%d:%d)", loc.f, loc.l, loc.c)
asm.WriteText(" pop rax")
case OP_DUP:
asm.WriteText(";; dup (%s:%d:%d)", loc.f, loc.l, loc.c)
asm.WriteText(" pop rax")
Expand Down
3 changes: 0 additions & 3 deletions compiler/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,6 @@ func parseToken(token Token) {
case TOKEN_DIV:
code.op = OP_DIVIDE
emit(code)
case TOKEN_DROP:
code.op = OP_DROP
emit(code)
case TOKEN_DUP:
code.op = OP_DUP
emit(code)
Expand Down
1 change: 0 additions & 1 deletion compiler/ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const (
OP_BIND
OP_CAST
OP_DIVIDE
OP_DROP
OP_DUP
OP_END_IF
OP_END_LOOP
Expand Down
11 changes: 5 additions & 6 deletions compiler/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const (
TOKEN_CAST_PTR
TOKEN_CONST
TOKEN_DIV
TOKEN_DROP
TOKEN_DUP
TOKEN_ELSE
TOKEN_EQUAL
Expand Down Expand Up @@ -81,6 +80,11 @@ type reserved struct {
}

var reservedWords = []reserved{
reserved{typ: TOKEN_DUP, word: "dup" },
reserved{typ: TOKEN_OVER, word: "over" },
reserved{typ: TOKEN_ROTATE, word: "rotate" },
reserved{typ: TOKEN_SWAP, word: "swap" },

reserved{typ: TOKEN_ARGC, word: "argc" },
reserved{typ: TOKEN_ARGV, word: "argv" },
reserved{typ: TOKEN_BANG_EQUAL, word: "!=" },
Expand All @@ -91,13 +95,11 @@ var reservedWords = []reserved{
reserved{typ: TOKEN_CAST_PTR, word: "(ptr)" },
reserved{typ: TOKEN_CONST, word: "const" },
reserved{typ: TOKEN_DIV, word: "div" },
reserved{typ: TOKEN_DROP, word: "drop" },
reserved{typ: TOKEN_DTYPE_ANY, word: "any" },
reserved{typ: TOKEN_DTYPE_BOOL, word: "bool" },
reserved{typ: TOKEN_DTYPE_CHAR, word: "char" },
reserved{typ: TOKEN_DTYPE_INT, word: "int" },
reserved{typ: TOKEN_DTYPE_PTR, word: "ptr" },
reserved{typ: TOKEN_DUP, word: "dup" },
reserved{typ: TOKEN_ELSE, word: "else" },
reserved{typ: TOKEN_EQUAL, word: "=" },
reserved{typ: TOKEN_EXTERN, word: "extern" },
Expand All @@ -114,19 +116,16 @@ var reservedWords = []reserved{
reserved{typ: TOKEN_LOAD64, word: "->64" },
reserved{typ: TOKEN_LOOP, word: "loop" },
reserved{typ: TOKEN_MINUS, word: "-" },
reserved{typ: TOKEN_OVER, word: "over" },
reserved{typ: TOKEN_PAREN_CLOSE, word: ")" },
reserved{typ: TOKEN_PAREN_OPEN, word: "(" },
reserved{typ: TOKEN_PLUS, word: "+" },
reserved{typ: TOKEN_RET, word: "ret" },
reserved{typ: TOKEN_RIGHT_ARROW, word: "->" },
reserved{typ: TOKEN_ROTATE, word: "rotate" },
reserved{typ: TOKEN_STAR, word: "*" },
reserved{typ: TOKEN_STORE8, word: "<-8" },
reserved{typ: TOKEN_STORE16, word: "<-16" },
reserved{typ: TOKEN_STORE32, word: "<-32" },
reserved{typ: TOKEN_STORE64, word: "<-64" },
reserved{typ: TOKEN_SWAP, word: "swap" },
reserved{typ: TOKEN_TAKE, word: "take" },
reserved{typ: TOKEN_THIS, word: "this" },
reserved{typ: TOKEN_TRUE, word: "true" },
Expand Down
4 changes: 0 additions & 4 deletions compiler/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func getOperationName(code Code) string {
case OP_BIND: name = "bind"
case OP_CAST: name = "cast to " + getDataTypeName(code.value.(DataType))
case OP_DIVIDE: name = "div"
case OP_DROP: name = "drop"
case OP_DUP: name = "dup"
case OP_EQUAL: name = "= (equal)"
case OP_EXTERN: name = "extern"
Expand Down Expand Up @@ -292,9 +291,6 @@ func ValidateRun() {
assertArgumentType(dtArray(a, b), dtArray(DATA_INT, DATA_INT), code, loc)
tc.push(DATA_INT)
tc.push(DATA_INT)
case OP_DROP:
a := tc.pop()
assertArgumentType(dtArray(a), dtArray(DATA_ANY), code, loc)
case OP_DUP:
a := tc.pop()
assertArgumentType(dtArray(a), dtArray(DATA_ANY), code, loc)
Expand Down
18 changes: 16 additions & 2 deletions libs/runtime.sk
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const MAX_UINT64 18446744073709551615
; - <int/pointer> ++
; Returns:
; - The given argument + 1
fn ++ $T -> T (
fn ++ $X -> X (
1 +
)

Expand All @@ -76,7 +76,7 @@ fn ++ $T -> T (
; - <int/pointer> --
; Returns:
; - The given argument - 1.
fn -- $T -> T (
fn -- $X -> X (
1 -
)

Expand Down Expand Up @@ -116,6 +116,20 @@ fn and bool bool -> bool (
+ 2 =
)

; Removes one value from the stack
; Calling
; - <any value> drop
fn drop any (
bind ( x )
)

; Removes two values from the stack
; Calling
; - <any> <any> 2drop
fn 2drop any any (
bind ( x y )
)

; Helper function for Logical Or operator (||).
; Calling:
; - <bool1> <bool2> or
Expand Down

0 comments on commit 205837c

Please sign in to comment.