? Compilation I guess... ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
💀

Compilation I guess...

SB programs are compiled from top to bottom. During Compilation: When an expression is encountered: -If it is a numeric expression containing only constants (numbers, # constants, and PI()) and constant operators (- ! NOT * / DIV MOD + - << >> AND XOR OR), it is evaluated and replaced with the result. DATA only allows constant expressions and plain strings, otherwise an error occurs. OPTION STRICT enables strict mode for the rest of the program OPTION DEFINT enables integer mode for the rest of the program (unsuffixed variables default to integer type) When a variable is encountered (when not being created in VAR): -If inside a function, and no global or local variable with that name exists yet, a local variable is created (if in strict mode, an error happens) -If outside a function, and no global variable with that name exists yet, a global variable is created (if in strict mode, an error happens) When a variable is created: -If it has no type suffix, it becomes a real type (unless integer mode is enabled, when it becomes an integer) -# type suffix creates a real -% type suffix creates an integer -$ type suffix creates a string -[...] creates an array with up to 4 dimensions -Numbers are initialized to 0 -Strings are "" -Arrays are ??? When VAR is encountered: -If inside a function definition, an error occurs if a local variable exists with the same name, otherwise a local variable is created -If outside a function, an error occurs if a global variable exists with the same name, otherwise a global variable is created -Variables are created. -Numbers are initialized to 0 -Strings are "" -Arrays are ??? During Execution: USE: -compiles the code in a slot. EXEC: -compiles and runs the code in a slot. When VAR is executed: -Values are assigned to string/number variables -Arrays are initialized
Author
12Me21
Updated
Rating
3 votes
Categories
Keywords
7 Comment(s) Plancake Plancake Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Video Games I like to play video games! Hobbies Reading I like to read books! Hobbies Time to make SmileBASIC in SmileBASIC... dfrost2 dfrost2 I just thought about this: if you create a program and load it in a different slot and use slot 0 to USE it, wouldn't it be a tad faster because it's compiling before execution instead of during it? Y_ack Y_ack Head Admin compilation happens to dirty program slots when USE, RUN, or EXEC are used how does this change anything...? if anything, you're just delaying compilation. if you mean in a larger context such as : load A and B : execute A : execute B then umm... maybe you can save some time between A and B by USEing B at the start of A, I guess. dfrost2 dfrost2 I mean this: <slot 0> use 1'compiling slot 1 <slot 1> 'a whole bunch of code gets completely compiled instead of line by line COMMON DEF RANDOM() DIM RAND[20,20] FOR I = 0 TO 19 FOR J = 0 TO 19 RAND[I,J]=RNDF() NEXT NEXT RETURN RAND END When ran, SB compiles line by line which is slower while running, but if all of it is compiled at the beginning of execution, wouldn't it trade(some of) the execution time for a function call to the beginning of execution? it's hard to explain what I mean easily Y_ack Y_ack Head Admin maybe it's hard to explain because you're wrong ww? Programs are compiled in whole at the start of execution. I don't know where you got the belief that it 'compiles' each line as it is executed. dfrost2 dfrost2 i might be an oxymoron! Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies You should work on building an interpreter outside of SmileBASIC! That's definitely on my to-do list