Commit Graph

190 Commits

Author SHA1 Message Date
Thakee Nathees
aac9bb37f7 invalid definition inside expression fixed 2022-05-27 17:14:23 +05:30
Thakee Nathees
b020e249aa isVarType falsly returning VAR_NULL fix 2022-05-27 01:01:48 +05:30
Thakee Nathees
9686b1fb75 Register builtin function implementation 2022-05-26 11:13:27 +05:30
Thakee Nathees
82919a690e Garbage collection bugs fixed
- Objects that weren't pushed to PKVM's temp reference were fixed
- vm->bytes_allocated was modified after the re-calculation of garbage
  collection fixed.
2022-05-25 16:44:58 +05:30
Thakee Nathees
0cfdfa7415 New fibers are not added to temp list -- fixed 2022-05-25 00:06:44 +05:30
Thakee Nathees
6e91b66e69 else if change to elif again.
The primary purpose of this change is to disambiguate between
`else if` and `else \n if`.

Even though it's a breaking change, since it's at the very early
state we're allowed to make such breaking syntax change.

lang.write function moved to io and io.stdin, io.stdout, io.stderr
added for future streamed io operations

io.File read, write, open, close, getline, seek, tell implemented

str * int multiplication implemented
2022-05-24 15:31:36 +05:30
Thakee Nathees
8e04748f86 some builtin class methods were added
- check a string contains another with `in` keyword
- Number: isint, isbyte
- String: find, replace, split, startswith, endswith, strip
- Map: clear, has, get, pop
- list: insert, clear, find, pop
- removed str_sub builtin function as its redunent since we have
  range slice over strings.
- moved lower, upper attributes of strings as methods
2022-05-23 23:47:28 +05:30
Thakee Nathees
2fd7b1f6e4 More code enhancements (read bellow)
- ByteBuffer, and Vector classes were created. However thier methods are
  limited, and to do.
- Strings supports new line escape "\\n".
- typename will return class name of an instance (was just 'Inst' fixed)
- _repr() method added. if _str method doesn' exists on an instance,
  it'll try to call _repr() to make a string.
- number.isint(), number.isbyte() method added
- [], []= operator were added.
2022-05-23 03:48:35 +05:30
Thakee Nathees
6a22653263 Minor code enhancements (read bellow)
- Warnings were fixed
- Libraries are registered internally when PKVM created
  and cleanedup when PKVM freed (if PK_NO_LIBS not defined)
- Lang.clock() moved to time module and sleep, epoch time
  were added.
- Support both upper case and lower case hex literals
- Support hex excaped characters inside strings (ex: "\x41")
- Native api for import modules added `pkImportModule(...)`
- pkAllocString, pkDeallocString are changed to pkRealloc.
- NewInstance, DeleteInstance functions now take PKVM however
  delete function should not allocate any memory since it's
  invoked at the GC execution.
2022-05-21 04:15:30 +05:30
Thakee Nathees
e3cab82978 amalgamation added and libs moved to src/libs/ 2022-05-20 04:49:50 +05:30
Thakee Nathees
22cecf4415 native call api implemented 2022-05-17 23:51:01 +05:30
Thakee Nathees
48089b2a1a native instance interface implemented 2022-05-17 07:08:14 +05:30
Thakee Nathees
b5d98ca4c3 adding globals support in native interface
pkSetGlobal function implemented to support adding globals from the
native interface. Also the PKVM slots doesn't need a runtime anymore to
use them (see math.PI global to see how it works).
2022-05-09 22:52:25 +05:30
Thakee Nathees
b96b18a4d7 Number constructor from string 2022-05-09 15:25:44 +05:30
Thakee Nathees
f5e2f15d23 negative index, range slice and more
... string concat with .. operator
    exponent operator with ** operator
2022-05-08 23:19:33 +05:30
Thakee Nathees
a83aa9438e documentations are refactored
function keyword changed back to fn
2022-05-07 17:47:58 +05:30
Thakee Nathees
168f365cde import statements are refactored.
- all import statement (native or script file) have the same syntax
- allow relative (including parent directory) imports
- cyclic imports are handled by caching the scripts
- `import foo` can potentially import `<searchpath>/foo/_init.pk`
- * import are not supported anymore
2022-05-06 11:16:48 +05:30
Thakee Nathees
3c107d4da2 native interface refactored 2022-05-05 12:54:15 +05:30
Thakee Nathees
1c7ddf07ad memory trace for vmRealloc implemented.
a little python script have written to check for memory leaks
from the trace report. Which is at scripts/leak_detect.py
2022-05-03 16:56:59 +05:30
Thakee Nathees
6ac4e93c9a stack overflow, and realloc bug fixed
stack realloc wasn't update the next callframe's base pointer which
caused a crash which is fixed

infinit recursions are now handled properly. now it'll dump the stack
frames and exit properly
2022-05-02 14:07:01 +05:30
Thakee Nathees
e47d982883 super class method call implemented 2022-05-01 20:24:07 +05:30
Thakee Nathees
2713aaba35 operator overloading implementation.
at this point only binary operators are implemented, unary are yet
to do.

getters and setters for native classes implemented with the names
@getter, and @setter (however the names or arity aren't validated
at the moment TODO:)
2022-04-30 21:35:02 +05:30
Thakee Nathees
895f177211
Merge pull request #212 from ThakeeNathees/fiber-api-change
runFunction() abstraction to hide fiber creation
2022-04-28 15:57:22 +05:30
Thakee Nathees
821874f823 class without constructor crash fix 2022-04-27 20:26:57 +05:30
Thakee Nathees
87fe3b01d6 runFunction() abstraction to hide fiber creation
the function will create a fiber and execute the function, this is
a better abstracion for the host applicaion (createFiber, runFiber
are removed) and this will come in handy when it comes to execute
pocket functions inside a native function (it's required to
implement operator overloading).
2022-04-27 08:46:00 +05:30
Thakee Nathees
acf38a31ca inheritance and 'is' test implemented 2022-04-26 21:57:35 +05:30
Thakee Nathees
b5ec401cf4 functions and classes are runtime initialized
this is necessare to make classes inherit from unknown
identifiers which are resolved at the runtime

and if we were to write the byte code to a file and run it, the globals
should be initialized at the runtime since there isn't any compile
time for them (pre compiled).
2022-04-26 15:53:30 +05:30
Thakee Nathees
cb209eb4d4 Some tiny bugs bug fix
When parsing class and if there is an EOF it's not being marked
as an error which is a regression after the syntax error refactor
which is fixed.

Constructor of boolean class return C boolean instead of VAR_BOOL()
bug fixed
2022-04-25 21:31:51 +05:30
Thakee Nathees
bb588e9470 native interface refactored into slots.
pkVar is removed and slots (like wren) are implemented for accessing or passing pocketlang values to C and vice versa. Yet all the slot related functions are callable at runtime (a fiber is associated with the VM) which needs to be refactored to allocate slots even if it's not runtime, to let users make use of the pocketlang values before or without running a function.
2022-04-24 09:56:27 +05:30
Thakee Nathees
d431dd7975 error pretty print (print lines) implemented
also support ansi color to highlight the error token.
2022-04-22 17:51:17 +05:30
Thakee Nathees
2fe579d9cc math module moved to cli/modules 2022-04-22 07:04:09 +05:30
Thakee Nathees
179026294d class compilation implementation 2022-04-21 20:35:12 +05:30
Thakee Nathees
1951b3d5f7 self initialization and constructor calls implemented
fibers are moved to builtin class and the fiber
module has removed.

native docstring support required to move math to cli
modules (TODO)
2022-04-21 15:17:32 +05:30
Thakee Nathees
03bac026ee METHOD_CALL opcode implemented
As of this commit there is only one method in the entier pocketlang
thats List.append() have added (the reset is todo).

method searching algorithm should be optimized in the future by
sorting the methods according to their names and do a binary search
2022-04-21 07:11:21 +05:30
Thakee Nathees
167355be59 getMethod and preConstructSelf functions impl 2022-04-20 20:38:23 +05:30
Thakee Nathees
67ab2057c0 method buffer added to classes
and also allocation/de-allocation callbacks were added to newClass
function and yet registering attribute getters and setters is to do.
2022-04-20 16:41:57 +05:30
Thakee Nathees
776ea0ab87 builtin types added.
This commit adds the builtin types to the VM's builtin classes
buffer (however no methods were added to those classes) and a super
class parameter introduced while creating a new class.
2022-04-20 15:35:33 +05:30
Thakee Nathees
4d46930d1b instance and class type cleaned
this is a part of the class implementation. In this commit classes
and instances type were completely cleaned and prepared for a new
implementation. Native class registering mechanism were fully refactored
and made it much simpler.
2022-04-20 14:40:08 +05:30
Thakee Nathees
29be68fc86 classes were removed temproarly
to implement classes properly and support methods I had to remove
the older class syntax temproarly.
2022-04-20 13:54:45 +05:30
Thakee Nathees
1f8a71fe0a dlfcn removed and minor code cleanups 2022-04-20 13:08:14 +05:30
Thakee Nathees
88c45cccac function and else if keywords are changed.
- `func` keyword has change to `function`.
- `elsif` changed to `else if`
2022-04-17 07:33:40 +05:30
Thakee Nathees
c67572d552
names buffer merged with constant pool (#202)
a buffer of classes for primitive types added to PKVM, but they'll
not be initialized in this commit.

names buffer and constant pool of a module are now merged (just like
java's constant pool).

VM's core libraries and scirpt modules are merged into a single
map name modules.

creating a new module doesn't register it automatically anymore,
you need to call pkRegisterModule(...) each time.

newModule() function refactored with a simpler interface, we're not
setting path or registering globals anymore, the caller is
responsible for that.
2022-04-17 06:47:27 +05:30
Thakee Nathees
d8d229b0fb tcc build supported.
inorder to support tcc, I need to remove some math functions that
tcc on windows doesn't support (v language is using openlibm).
This is temproarly and the math functions should be moved to it's
own math script module once the import system is refactored.

TCC build tested with the binary downloaded from --
https://download.savannah.gnu.org/releases/tinycc/tcc-0.9.27-win64-bin.zip
(download link from the https://bellard.org/tcc/ website), and this
should be added to the CI workflow.
2022-04-16 09:37:38 +05:30
Thakee Nathees
5aee9616c1 modules were moved to cli/modules
now it's easier to re-use cli modules into another hosting
application and a little python script have added to generate
native api to support native extension library.
2022-04-15 19:30:26 +05:30
Thakee Nathees
ddc8bd8197 yet another refactor.
This commit doesn't change any behavior, just moving the code
around cleaning things.
2022-04-15 09:58:02 +05:30
Thakee Nathees
b285336895 fiber stored as register variable
and the benchmark script refactored, and now it will generate an
html report
2022-04-14 08:01:16 +05:30
Thakee Nathees
8d062e38b8 closures were completely added. 2022-04-13 14:31:57 +05:30
Thakee Nathees
2e1d8d89dd lexical scoping support using upvalues 2022-04-13 09:20:56 +05:30
Thakee Nathees
e0852139b9 exprName re-defined
The exprName function re-defined into a cleanner way, and now it's
possible to override builtin functions, this will come in handy
to introduce upvalues.
2022-04-13 08:40:37 +05:30
Thakee Nathees
227be9aab5 local variable miss-calculation bug fix
for nested functions the count of locals and the required stack size
are miss-calculated, ie. No new count wasn't started for inner functions
it makes the required stack size greater than or equal to it's enclosing
functions stack size.
2022-04-12 16:29:20 +05:30