LoginLogin

Nossrec, The Precompiler Made To Replace SmileBasic

Root / Talk About Programs / [.]

🔒
computableeCreated:
Nossrec is a JIT precompiler I am making in SmileBasic that is intended to completely replace the use of SB! Nossrec takes code made in the normal SB editor, reads it, outputs legal SB code, and runs the SB code.
What you describe is not 'JIT'.

If you have all this working, I'm just going to have to bow down and pledge allegiance to you right now! That is some impressive stuff. I do wonder if this will get a lot of use though. It may be more powerful, but it's a lot less noob-friendly than SmileBASIC is.

Why not get rid of def when declaring a method? "def public void main" to just "public void main"

Nossrec is a JIT precompiler I am making in SmileBasic that is intended to completely replace the use of SB! Nossrec takes code made in the normal SB editor, reads it, outputs legal SB code, and runs the SB code.
What you describe is not 'JIT'.
Yeah, after looking at the relevant Wikipedia pages I would say it's Ahead-Of-Time compilation, even if the compilation is being done at runtime, because the compilation is completely done before running any compiled code.

Nossrec is a JIT precompiler I am making in SmileBasic that is intended to completely replace the use of SB! Nossrec takes code made in the normal SB editor, reads it, outputs legal SB code, and runs the SB code.
What you describe is not 'JIT'.
Yeah, after looking at the relevant Wikipedia pages I would say it's Ahead-Of-Time compilation, even if the compilation is being done at runtime, because the compilation is completely done before running any compiled code.
Fixed. Anyway, static classes are partially implemented! There are still a lot of "make the code look nice" things I've yet to add. After that, I will release the first beta version. After that, I will implement normal classes.

If you have all this working, I'm just going to have to bow down and pledge allegiance to you right now! That is some impressive stuff. I do wonder if this will get a lot of use though. It may be more powerful, but it's a lot less noob-friendly than SmileBASIC is.
Thank you for the support. All of what I showed you is indeed working ;) Anyway, I do not expect the entire community to switch over to Nossrec. This should be ideally used by the experienced programmer who's having lots of problems with SB's limitations (or just someone who comes from an OOP background).

Why not get rid of def when declaring a method? "def public void main" to just "public void main"
I considered this, but "def" is used by the compiler to identify the start of a function block. I could remove it, but that would require lots of changes, surprisingly.

Let me show you one more program that will show you a couple more features I have working right now.
'outputs 0 through 4 on the screen by storing values from a "for" loop in an object, and reading them back out.
def public void main
  new object[] obj_array <- [5]
  for (int i=0;i<5;i++)
    object_array[i]=obj(i)
  end
  for (i=0;i<5;i++)
    writeline str(obj_array[i])
  end
end
In this example, you can see how "object" is now a data type (used like an array) and how I completely changed "for" loops to act like C-style "for."
Is "object" a built-in type, or something defined in the program? Also, I think there may be some typos there, you're kind of alternating between "object" and "obj". Or is obj() the way to generate an object?

Let me show you one more program that will show you a couple more features I have working right now.
'outputs 0 through 4 on the screen by storing values from a "for" loop in an object, and reading them back out.
def public void main
  new object[] obj_array <- [5]
  for (int i=0;i<5;i++)
    object_array[i]=obj(i)
  end
  for (i=0;i<5;i++)
    writeline str(obj_array[i])
  end
end
In this example, you can see how "object" is now a data type (used like an array) and how I completely changed "for" loops to act like C-style "for."
Is "object" a built-in type, or something defined in the program? Also, I think there may be some typos there, you're kind of alternating between "object" and "obj". Or is obj() the way to generate an object?
Object is a built-in type to Nossrec. Obj() is how to convert to an object. I didn't want to have to do something like that, but it was inevitable. So now theres str(), val(), and obj().

A "for" loop in C is essentially a fancy "while" loop. For instance, in C (and any other language with this syntax), you can do silly stuff like: for(printf("loop start\n"); shouldrun(); printf("loop iteration\n")) { //Something silly here } This is because all 3 "for" loop sections are just expressions. The first expression is what is run at the beginning (and doesn't even have to be an assignment), the second is the loop check expression and allows the loop to continue if the expression is true, and the third is what you do at the end of every loop iteration. Will your language support this? If not, you'll need to specify very clearly that it doesn't, as this is the expected behavior.

Oh, and if you are indeed implementing your for loops using SmileBASIC's WHILE, keep in mind that every continue will need to execute the increment statement before continuing the loop.

This looks like quite the undertaking if you start adding features. And I wish you the best of luck. But still, very cool.
I do wonder if this will get a lot of use though. It may be more powerful, but it's a lot less noob-friendly than SmileBASIC is.
I'm wondering if this is usable at all from a 3DS. So far, the examples seem to be longer ways to achieve shorter SmileBasic code. Are there any plans to make this compilable from a PC? I can see a type system being useful when you can actually type a lot of types.
new object objectname <- classname
What is the arrow doing in this syntax? Are types and classes separate? Why are there two ways to declare an object variable?
new object[] obj_array <- [5]
Is this an array literal?
switch (op)
    case "+"
      ans=num1+num2
      end
...
I'm curious how this is implemented in SB. This also has a very specific behavior in C. Is the "end" required after every case? EDIT:
C#, F#, and Python
Which OOP flavour is this going to be? Those are pretty much the most polar languages in terms of the object model.

A "for" loop in C is essentially a fancy "while" loop. For instance, in C (and any other language with this syntax), you can do silly stuff like: for(printf("loop start\n"); shouldrun(); printf("loop iteration\n")) { //Something silly here } This is because all 3 "for" loop sections are just expressions. The first expression is what is run at the beginning (and doesn't even have to be an assignment), the second is the loop check expression and allows the loop to continue if the expression is true, and the third is what you do at the end of every loop iteration. Will your language support this? If not, you'll need to specify very clearly that it doesn't, as this is the expected behavior.
For loops compile to WHILE loops, so
for (int i=0; i<5; i++)
  'code goes here
end
compiles to
VAR i%=0
WHILE i%<5
  'code goes here
  INC i%
WEND

For loops compile to WHILE loops, so
for (int i=0; i<5; i++)
  'code goes here
end
compiles to
VAR i%=0
WHILE i%<5
  'code goes here
  INC i%
WEND
What about continues then? as calc said:
Oh, and if you are indeed implementing your for loops using SmileBASIC's WHILE, keep in mind that every continue will need to execute the increment statement before continuing the loop.

Continue has not been implemented and I have no plans to do so. If there is strong enough demand,I suppose I could add it.

So what's the point of having this?

Are there any plans to make this compilable from a PC? I can see a type system being useful when you can actually type a lot of types.
I considered making this compilable to C#. I am still pondering doing this, but the main purpose of Nossrec was to be an optional complete replacement of SmileBasic
new object objectname <- classname
What is the arrow doing in this syntax? Are types and classes separate? Why are there two ways to declare an object variable?
<- corresponds with the "new" keyword. "New" is used for two main purposes: creating arrays, and assigning class references to objects. You can create an object variable type that does not correspond with a class (basically a variable that can hold any value) by not using the "new" keyword and using "=" instead of "<-"
new object[] obj_array <- [5]
Is this an array literal?
This is just how you declare an array. Like I said, "new" and "<-" are also used for arrays, not just assigning a class reference to an object. This might be changed later depending on your feedback.
switch (op)
    case "+"
      ans=num1+num2
      end
...
I'm curious how this is implemented in SB. This also has a very specific behavior in C. Is the "end" required after every case?
This compiles to legal code for my "switch/case" library, which has a few COMMON DEFs that deal with this. The "end" is required after every case, just as "break" would be required in C#. I replaced it with "end" because "end" is pretty much the universal keyword for something completing, like for/while/dowhile loops, ifs, switch/case, etc.
C#, F#, and Python
Which OOP flavour is this going to be? Those are pretty much the most polar languages in terms of the object model.
Objects will have the functionality of C#, with syntax similar to what you might see in F# or Python.

So what's the point of having this?
As was in the original post:
Its main goal was to do better what SB does, and add things that were not possible in SB. Nossrec completely revamps normal SB code and makes it look cleaner. It also removes requirements like variable suffixes; the compiler takes care of that automatically.

So what's the point of having this?
As was in the original post:
Its main goal was to do better what SB does, and add things that were not possible in SB. Nossrec completely revamps normal SB code and makes it look cleaner. It also removes requirements like variable suffixes; the compiler takes care of that automatically.
k

http://smilebasicsource.com/page?pid=146 Nossrec Beta v1 is out! The programs shown on this page need to be put inside a static class named "entry" (example on the program page).