Jump to content




CCBASIC - C64 type BASIC in ComputerCraft!


17 replies to this topic

#1 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 04 December 2017 - 09:09 PM

ComputerCraft BASIC

What is BASIC?

BASIC( Beginner's All-purpose Symbolic Instruction Code ) is an interpreted programming language created in 1964 and was widely used in mid-1970s. For more information click on BASIC link above.

What kind of BASIC I am emulating?

Well I am emulating Commodore 64's BASIC

From where did I get the Idea to create one?

Well check this post then!


Okay Let's get started!

Typical BASIC Functions and Keywords

BASIC programs
How to get and run BASIC
Some pictures of BASIC

If you found a BUG or you have any suggestions or I left out something, post it here :)


Thanks in advance,
LeDark Lua

Edited by LeDark Lua, 07 January 2018 - 12:23 PM.


#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 04 December 2017 - 09:44 PM

I'm stuck between "why would anyone want to recreate BASIC?" and "this is pretty impressive". Seriously though, good job!

#3 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 04 December 2017 - 10:50 PM

View PostSquidDev, on 04 December 2017 - 09:44 PM, said:

I'm stuck between "why would anyone want to recreate BASIC?" and "this is pretty impressive". Seriously though, good job!
Much Thanks! Well I got the idea from that post where a guy asked for BASIC to be implemented in ComputerCraft, and in my opinion, it gives more of a retro feel, Dan wants to emulate that retro(ness) but Lua is a bit modern, so I used what suited the best, to give that full RETRO feeling.

OffTopic:
If you think that making an interpreted language in an interpreted language is bad, then think of this way, Lua is machine code and BASIC is just a program for the machine, like 6502 processor has the machine code and BASIC is a program for that CPU.

Edited by LeDark Lua, 04 December 2017 - 11:31 PM.


#4 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 05 December 2017 - 09:18 PM

View PostLeDark Lua, on 04 December 2017 - 10:50 PM, said:

If you think that making an interpreted language in an interpreted language is bad

*cough* Lua in Java *cough* (not quite the same but vm in a vm thing)

Edited by Lupus590, 05 December 2017 - 09:19 PM.


#5 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 05 December 2017 - 09:25 PM

View PostLupus590, on 05 December 2017 - 09:18 PM, said:

View PostLeDark Lua, on 04 December 2017 - 10:50 PM, said:

If you think that making an interpreted language in an interpreted language is bad

*cough* Lua in Java *cough* (not quite the same but vm in a vm thing)
True :lol:

#6 Exerro

  • Members
  • 801 posts

Posted 05 December 2017 - 09:30 PM

I got excited and made a 'decompiler' that shows the bytecode of a compiled program. It's quite interesting to see how things compile (and how they can be optimised!)

Download
pastebin get sqsPm71U decompiler

Example
Spoiler


#7 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 05 December 2017 - 09:39 PM

View PostLupus590, on 05 December 2017 - 09:18 PM, said:

*cough* Lua in Java *cough* (not quite the same but vm in a vm thing)
Depending on your JVM, it's quite likely that the Lua VM will be interpreted before JITing occurs.

That being said, I wonder how hard it'd be to compile BASIC/the bytecode to Lua instead - this way you shave one level of this interpreter stack and so make things much faster.

Edited by SquidDev, 05 December 2017 - 09:39 PM.


#8 Exerro

  • Members
  • 801 posts

Posted 05 December 2017 - 09:49 PM

View PostSquidDev, on 05 December 2017 - 09:39 PM, said:

That being said, I wonder how hard it'd be to compile BASIC/the bytecode to Lua instead - this way you shave one level of this interpreter stack and so make things much faster.

Heh, this is what I was going for with the decompiler. I was just gonna use that to analyse the bytecode then make an actual compiler to Lua source.

#9 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 05 December 2017 - 10:11 PM

View PostExerro, on 05 December 2017 - 09:30 PM, said:

I got excited and made a 'decompiler' that shows the bytecode of a compiled program. It's quite interesting to see how things compile (and how they can be optimised!)

Download
pastebin get sqsPm71U decompiler

Example
Spoiler
Yeah I know, I need to work now on optimizing the compiled bytecode, working on some solutions, but for now I just wanted to push out a stable version :P
And I got excited when I saw that you are excited, glad to see that people are interested in this :D

#10 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 05 December 2017 - 10:16 PM

View PostSquidDev, on 05 December 2017 - 09:39 PM, said:

That being said, I wonder how hard it'd be to compile BASIC/the bytecode to Lua instead - this way you shave one level of this interpreter stack and so make things much faster.
Not that hard really, simple and easy, but you would need to work around jumps ( wrap the compiled line in a function maybe? )

#11 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 08 December 2017 - 07:31 PM

***UPDATE***

Added:

  • Basic optimization
  • Fixed some bugs
How optimization works:
Spoiler

NOTE: This is just basic Pre-Processed binary operations, more optimization will be added soon!

To download the new version, use the old link!

Edited by LeDark Lua, 08 December 2017 - 07:33 PM.


#12 Exerro

  • Members
  • 801 posts

Posted 08 December 2017 - 11:32 PM

Looks like I broke the optimiser:
print 1 + 2 - 3 + 4 - 5 + 6 - 7 + 8 - 9
Turns out this also breaks it:
print 2 - 1
By break I mean an infinite loop somewhere - it just freezes until the computer shuts off. Note I'm using ccemux but I doubt that would affect anything.

Tested with the older version too and it didn't break then.

Edit: quick fix:
Spoiler

Edited by Exerro, 08 December 2017 - 11:36 PM.


#13 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 08 December 2017 - 11:54 PM

Oh thanks! Fixed it, and fixed some other bugs that may cause an infinite loop, now should be fine and dandy!

#14 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 10 December 2017 - 12:57 PM

***UPDATE***

Added:

  • New function: SPRITE, COLOR, STOREN
  • Improved LIST command in terminal, now you can display blocks of code
  • Added a new program to tinker around
  • Fixed some minor bugs
To download the new version, use the old link!

Edited by LeDark Lua, 22 December 2017 - 06:35 PM.


#15 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 22 December 2017 - 06:24 PM

***UPDATE***

Added:

  • Interpreters speed is increased!
  • Variables: cycles, timer
  • Variables are case sensitive but Keywords and Functions are not
  • Another program to check out: Moving Pixel ( uses new features )
  • Fixed some bugs!
To download the new version, use the old link!

Edited by LeDark Lua, 22 December 2017 - 07:22 PM.


#16 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 26 December 2017 - 01:19 PM

***UPDATE***

Added:

  • New functions: FLOAD, EXIT, DISPOSE
  • Added a new program: BASIC Loader ( uses new features )
  • A bit of bug fixes

OPCODE CHANGE:

  • GOSUB opcode no longer accepts an argument, instead it pops a value from the stack!

Compiler CHANGE:

  • Labels define as variables, so your programs may be larger if you have a lot of labels! But that will not impact the performance of your program!
  • Fixed binary operations a bit, added precedence over other operations.

NOTE:

Older COMPILED programs that use GoSub command are not compatible with the new version, text based programs are fine! Just recompile your code!

To download the new version, use the old link!

Edited by LeDark Lua, 26 December 2017 - 06:25 PM.


#17 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 31 December 2017 - 09:00 AM

***UPDATE***

Added:

  • Added lambda function as DEF ( check OP )
  • Added more optimization!
  • New opcode: EXPECT
  • Fixed a lot of bugs!

NOTE:


Older COMPILED programs that use EXPECT opcode are not compatible with the new version, text based programs are fine! Just recompile your code!


To download the new version, use the old link!

Edited by LeDark Lua, 31 December 2017 - 09:01 AM.


#18 LeDark Lua

  • Members
  • 369 posts
  • LocationLeLua

Posted 07 January 2018 - 09:20 AM

***BIG UPDATE***

Added:

  • Added NETWORKING! And some new functions. Check the OP.
  • Changed timer functionality a bit, check the OP.
  • Fixed and/or bugs, always evaluating 1, now they're working properly
  • Fixed optimize bugs and errors
  • Fixed parsing a bit
  • And fixed some minor bugs.
To download the new version, use the old link!

Edited by LeDark Lua, 07 January 2018 - 09:21 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users