RodrigoDornelles / 3bc-lang

Low-level language, tiny virtual machine, minimal runtime, intermediate representation, embeddable, easy for beginners. (Friendly Punched cards)
https://3bc-lang.org
GNU General Public License v3.0
232 stars 25 forks source link

add CPU MODE 44 for the stack management #348

Open RodrigoDornelles opened 1 year ago

RodrigoDornelles commented 1 year ago

This can in several possibilities of resource and comfort to program.

features

do arithmetic operations in a much less messy way.

classical math

algebraic notation.

MODE NILL 0d06
PUSH NILL 1
MODE NILL 0d28
MATH NILL 2 
MODE NILL 0d13
MATH NILL 3
MODE NILL 0d6
PULL :res NILL

modern math

reverse polish notation.

MODE NILL 0d11
PUSH NILL 1
PUSH NILL 2
EVAL NILL 28
PUSH NILL 3
EVAL NILL 13
PULL :res NILL

modern math (another way)

reverse polish notation with everything on the stack.

MODE NILL 0d44
PUSH NILL 3
PUSH NILL 2
PUSH NILL 1 
EVAL NILL 28
EVAL NILL 13
PULL :res NILL

support the functional imperative

the ability to use functions (procedures with arguments) is a possible feature with the stack control.

stdcall convention

return with stack.

MODE NILL 0d9
GOTO NILL :main

# func sum(a, b)
# return a + b
MODE NILL 0d44
NILL NILL :sum
EVAL NILL 0d11
MODE NILL 0d41
BACK NILL NILL

# entry point
NILL NILL :main
# :res = sum(1, 2)
MODE NILL 0d44
PUSH NILL 1 #arg a
PUSH NILL 2 #arg b
MODE NILL 042
CALL NILL :sum
MODE NILL 0d44
PULL :res NILL
# print (:res)
MODE NILL 0d02
STRI :res NILL

??? convention

return with aux memory.

MODE NILL 0d9
GOTO NILL :main

# func sum(a, b)
# return a + b
MODE NILL 0d44
NILL NILL :sum
EVAL NILL 0d11
KEEP NILL NILL
MODE NILL 0d41
BACK NILL NILL

# entry point
NILL NILL :main
# :res = sum(1, 2)
MODE NILL 0d44
PUSH NILL 1 #arg a
PUSH NILL 2 #arg b
MODE NILL 042
CALL NILL :sum
MODE NILL 0d08
PULL :res NILL
# print (:res)
MODE NILL 0d02
STRI :res NILL