Commit Graph

39 Commits

Author SHA1 Message Date
Aryadev Chavali
6dfc4ceaeb Better logs for assembler 2023-11-02 23:29:43 +00:00
Aryadev Chavali
6c4469958e Implemented CALL(_STACK) and RET on the assembler 2023-11-02 23:29:23 +00:00
Aryadev Chavali
bd39c2b283 Made lexer more error prone so parser is less
Lexer now will straight away attempt to eat up any type or later
portions of an opcode rather than leaving everything but the root.
This means checking for type in the parser is a direct check against
the name rather than prefixed with a dot.

Checks are a bit more strong to cause more tokens to go straight to
symbol rather than getting checked after one routine in at on the
parser side.
2023-11-02 23:29:07 +00:00
Aryadev Chavali
9afeed6d61 Made separate tokens for JUMP_ABS and JUMP_STACK
Makes more sense, don't need to fiddle around with strings as much in
the parser due to this!
2023-11-02 20:54:26 +00:00
Aryadev Chavali
114fb82990 Removed instruction OP_JUMP_REGISTER
Not necessary when you can just push the relevant word onto the stack
then just do OP_JUMP_STACK.
2023-11-02 20:41:36 +00:00
Aryadev Chavali
4990d93a1c Created a preprocessing unit presult_t and a function to process them
Essentially a presult_t contains one of these:

1) A label construction, which stores the label symbol into
`label` (PRES_LABEL)

2) An instruction that calls upon a label, storing the instruction
in `instruction` and the label name in `label` (PRES_LABEL_ADDRESS)

3) An instruction that uses a relative address offset, storing the
instruction in `instruction` and the offset wanted into
`relative_address` (PRES_RELATIVE_ADDRESS)

4) An instruction that requires no further processing, storing the
instruction into `instruction` (PRES_COMPLETE_INSTRUCTION)

In the processing stage, we resolve all calls by iterating one by one
and maintaining an absolute instruction address.  Pretty nice, lots
more machinery involved in parsing now.
2023-11-02 20:31:55 +00:00
Aryadev Chavali
d5e311c9d4 Started work on preprocessing jump addresses 2023-11-02 20:31:22 +00:00
Aryadev Chavali
740627b12d Implemented MALLOC_STACK and SUB in the assembler 2023-11-01 22:56:40 +00:00
Aryadev Chavali
90e04542a2 Implemented stack versions of MGET and MSET in assembler 2023-11-01 22:09:39 +00:00
Aryadev Chavali
44125d7ad9 Implemented OP_MSIZE into lexer/parser of ASM 2023-11-01 21:47:19 +00:00
Aryadev Chavali
7564938113 Implemented lexer and parser for new memory management instructions 2023-11-01 21:40:25 +00:00
Aryadev Chavali
83678ad29a Add MULT to lexer and parser for assembler 2023-11-01 18:09:00 +00:00
Aryadev Chavali
57e6923279 Fixed bug where comparators wouldn't be parsed correctly
This is because comparators may apply to signed types, so I need to
use the right parsing function.
2023-11-01 17:55:54 +00:00
Aryadev Chavali
6d35283ef0 Clearer VERBOSE messages 2023-11-01 15:22:47 +00:00
Aryadev Chavali
6a270eda1e Parser now uses updated lexer
Much simpler, uses a switch case which is a much faster method of
doing the parsing.  Though roughly equivalent in terms of LOC, I feel
that this is more extensible
2023-11-01 15:09:56 +00:00
Aryadev Chavali
93d234cd48 Lexer now returns more descriptive tokens
More useful tokens, in particular for each opcode possible.  This
makes parsing a simpler task to reason as now we're just checking
against an enum rather than doing a string check in linear time.

It makes more sense to do this at the tokeniser as the local data from
the buffer will be in the cache most likely as the buffer is
contiguously allocated.  While it will always be slow to do linear
time checks on strings, when doing it at the parser we're having to
check strings that may be allocated in a variety of different places.
This means caching becomes a harder task, but with this approach we're
less likely to have cache misses as long as the buffer stays there.
2023-11-01 15:09:47 +00:00
Aryadev Chavali
0f0a1c7699 Allow hex literals for numbers
As strto(ul|ll) allow the parsing of hex literals of the form `0x`, we
allow lexing of hex literals which start with `x`.

They're lexed into C hex literals which work for strtol.
2023-10-31 22:27:53 +00:00
Aryadev Chavali
7817b5acc9 Use standardised signed version of word type from base.h 2023-10-31 21:24:50 +00:00
Aryadev Chavali
5d800d4366 Moved inst module to lib
As it has no dependencies on vm specifically, and it's more necessary
for any vendors who wish to target the virtual machine, it makes more
sense for inst to be a lib module rather than a vm module.
2023-10-31 21:14:14 +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
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
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
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
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
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
92855ebb3e Starting development on assembly language 2023-10-23 16:53:50 +01:00