Aryadev Chavali
0975d92493
Introduced new instructions for comparison
...
Comparing signed and unsigned versions of numbers. Same for EQ as
well.
Notice the irregular pattern of BYTE, CHAR, INT, HWORD,LONG,WORD as
OPCODE_IS_TYPE requires the subcodes to be surrounded by BYTE and
WORD.
2023-10-31 20:50:28 +00:00
Aryadev Chavali
7ca8f2c644
asm/main logs are now indented and look prettier
2023-10-31 20:39:49 +00:00
Aryadev Chavali
75dc36cd19
Lexer now returns errors on failure
...
Currently only for invalid character literals, but still a possible
problem.
2023-10-31 20:39:26 +00:00
Aryadev Chavali
fa640f13e8
parse_word deals with characters now
...
Just takes the character literally as a number.
2023-10-31 20:38:03 +00:00
Aryadev Chavali
228f548bd9
Changed asm/parser instruction push-reg->push.reg
2023-10-31 20:37:11 +00:00
Aryadev Chavali
c534a53b6f
Make Verbose a universal flag
...
All objects target LIB anyway, so VERBOSE is a universal macro for
this code base.
2023-10-29 16:59:37 +00:00
Aryadev Chavali
157c79d53c
Added a "usage" message and colours for assembler
...
Prints useful and pretty messages when verbose being at least 1.
2023-10-29 16:59:31 +00:00
Aryadev Chavali
597a45aa73
Fixed bug where JUMP_REGISTER couldn't be in bytecode read
2023-10-29 16:58:18 +00:00
Aryadev Chavali
c4cb45f3ad
Fixed bug where reading operand bytecode may stop prematurely
...
This is due to checking for equality instead of just greater than in
darr->used against darr->available.
2023-10-29 16:56:33 +00:00
Aryadev Chavali
7c367f95c9
Added some examples to instruction-test for positive/negative literals
...
Use the push.* instructions to see this.
2023-10-29 16:56:19 +00:00
Aryadev Chavali
025b26b877
Introduced an example source file for all instructions
...
Provides calling conventions, ensures parser and lexer are working
correctly. Will be updated as more instructions are introduced and
supported in the assembler.
2023-10-29 16:56:19 +00:00
Aryadev Chavali
1177a5a45b
Auto-fill copyright notice in examples/fib.c
2023-10-29 16:56:19 +00:00
Aryadev Chavali
1c0bd20cba
Introduce error reporting in asm/main
...
Pretty simple implementation, I've stopped printing the tokens cos I
think the lexer is done.
2023-10-28 18:22:18 +01:00
Aryadev Chavali
eac8cbf1da
asm/parser supports all opcodes, introduced parse errors
...
Introduced some functions to parse differing types of opcodes. Use
the same style of a.b.c... for namespacing or type specification for
certain opcodes. Bit hacky and not tested, but does work.
Parse errors can be reported with an exact location using the token
column, line.
2023-10-28 18:21:09 +01:00
Aryadev Chavali
191fe5c6b8
Ignore comments (using semicolons) in lexer
...
Easier to do it here than at the parser.
2023-10-28 18:19:33 +01:00
Aryadev Chavali
d2429aa549
Introduced a column and line for each token
...
Accurate error reporting can be introduced using this.
2023-10-28 18:19:30 +01:00
Aryadev Chavali
32dfcc109c
Added macro to do safe subtractions on a word
...
Default C just lets overflows occur for subtraction, so this macro
will default to 0 if the subtraction causes an overflow.
2023-10-28 18:16:50 +01:00
Aryadev Chavali
fc81cda96b
Plugged in asm/parser to asm/main
...
Just prints instructions so far.
2023-10-26 11:18:07 +01:00
Aryadev Chavali
2fe2af22a9
Implemented a rudimentary parser with support for 4 instruction types
2023-10-26 11:17:55 +01:00
Aryadev Chavali
dca51106a2
Added support in lexer for negative numbers
...
Though we deal with unsigned numbers internally, it should be possible
to read and manipulate negative numbers through 2s complement. Later
on we'll add support for signed operations via 2s complement, so this
should be allowed.
2023-10-26 11:17:01 +01:00
Aryadev Chavali
e9c54e045a
Fixed bug where printing hword of an instruction prints number not hex
...
This is an easy fix.
2023-10-26 11:16:02 +01:00
Aryadev Chavali
c70a9d9879
asm/main now uses TOKEN_STREAM_AT
2023-10-26 10:23:00 +01:00
Aryadev Chavali
b152365561
Lexer forces uppercase for symbols
2023-10-26 10:22:53 +01:00
Aryadev Chavali
3200e97324
Updated README for targeting VM
2023-10-26 10:22:26 +01:00
Aryadev Chavali
d1f84a6a2c
Makefile now prints dependencies on successful compilation
2023-10-26 10:22:10 +01:00
Aryadev Chavali
74a85268c4
Moved base functions from inst.c to dedicated file
...
Doesn't make sense for them to be in the VM module when they have a
more general purpose now.
2023-10-26 10:19:10 +01:00
Aryadev Chavali
c8c5381cf2
vm/main takes a filename as input to execute bytecode
...
Also prints a usage for incorrect usage.
2023-10-26 10:18:53 +01:00
Aryadev Chavali
a07b571da2
Auto fill licenses
2023-10-26 08:01:26 +01:00
Aryadev Chavali
7bf6b53230
Unified literal for numbers, main program now tokenises
2023-10-26 07:15:52 +01:00
Aryadev Chavali
131d70a9a3
Started working on a parser
...
No implementations yet
2023-10-25 21:43:51 +01:00
Aryadev Chavali
94abb9e3d4
Separated lexer from main file in asm
2023-10-25 21:43:13 +01:00
Aryadev Chavali
dbbfac1236
Wrote lexer for assembly
...
Pretty simple tokeniser, doesn't do a lot and needs to error check better.
2023-10-24 18:20:59 +01:00
Aryadev Chavali
3aad3926d2
Removed assertion in darr_read_file
...
If an empty file is read, we want to deal with it in later user code
rather than just failing immediately.
2023-10-24 18:20:22 +01:00
Aryadev Chavali
92855ebb3e
Starting development on assembly language
2023-10-23 16:53:50 +01:00
Aryadev Chavali
42ac28d44a
Make root directory an include path, set #include's properly
...
Easier to write includes now just using < with the module name, in
comparison to using relative paths.
2023-10-23 04:46:09 +01:00
Aryadev Chavali
0ac634a9be
Reintroduced example fib.c via examples/ folder
2023-10-23 04:25:48 +01:00
Aryadev Chavali
ac57e32a02
Added lib folder for general stuff, introduced as target to Makefile
2023-10-23 04:25:48 +01:00
Aryadev Chavali
aa4a3b8614
Implemented simple example of a for loop in main
2023-10-23 03:59:34 +01:00
Aryadev Chavali
b44a61be41
src->vm, Makefile is now a bit more abstracted and pretty colours
...
Changed folder names for sake of clarity (will be introducing a new
build target soon), and Makefile can now easily support more targets.
2023-10-23 03:58:34 +01:00
Aryadev Chavali
587f31a63b
Remove unnecessary log message
2023-10-23 03:11:05 +01:00
Aryadev Chavali
9496da9d93
Added and implemented OP_JUMP_IF_*
...
Performs a jump when the (BYTE|HWORD|WORD) at the top of the stack is
non zero.
2023-10-23 01:45:54 +01:00
Aryadev Chavali
b93a4af495
Extracted code that performs a jump into its own routine
...
Checks if the operand given is a well defined program address, then
performs the jump.
2023-10-23 01:45:18 +01:00
Aryadev Chavali
2ef104f235
Fixed bug in vm_mov(byte|hword) where registers aren't set properly
...
This is because we just OR the bits into the specific byte of the
word. This means the previous state may leave artefacts as the OR
doesn't clear the bits away.
To do so, we apply a bit mask to clear the specified byte(s) of the
word, then perform the OR.
2023-10-23 01:43:24 +01:00
Aryadev Chavali
20030e364c
Moved macros to extract nth (byte|hword) from a word to base.h
2023-10-23 00:53:44 +01:00
Aryadev Chavali
00f3b3bf21
Rearrange what is printed in vm_print_all
...
First the program, then the registers then the stack.
2023-10-23 00:49:59 +01:00
Aryadev Chavali
d0ee1f3b1f
Check for and handle errors when interpreting bytecode
...
Prints an error message, returns a non zero code based on error
code (255 - err).
In main, I propagate this exit code.
2023-10-23 00:48:18 +01:00
Aryadev Chavali
919fae2df8
Added an example program fib.c
...
This is simply a program with an embedded set of instructions which
indefinitely computes and prints fibonacci numbers, computing them in
pairs.
Does it completely through the virtual machine rather than just hard C
instructions.
Also amended the Makefile to compile it. Required moving the main.c
object file into the dependencies of $(DIST)/$(OUT).
I should track the dependencies for fib.c and main.c as well.
2023-10-23 00:45:23 +01:00
Aryadev Chavali
19eb401498
Fixed bugs with ordering of bytes in some operations
...
Also fixed an overflow error in vm_dup_word, where I underflow the
index of vm->stack.data which causes a buffer overflow.
2023-10-23 00:28:39 +01:00
Aryadev Chavali
ae9bc91713
Added and implemented OP_PRINT*
...
Here is where we may have differing interpretations of what the bits
in the data pile may actually mean. This in particular refers to
printing the signed or unsigned versions of the bits given. Also,
interpreting some byte as a character or just a raw number.
2023-10-23 00:09:12 +01:00
Aryadev Chavali
45ad8f7296
Fixed bug where vm_print_program listing for program was incorrect
...
Only happens when vm_print_program(STDERR), as STDERR occurs before
STDOUT on Emacs. So while the lines would print, no instructions
would follow. This fixes that by using fp.
2023-10-23 00:08:53 +01:00