mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-01-22 23:29:55 +00:00
Getting PLASMA PLASM compiled
This commit is contained in:
parent
8a58ef8b5f
commit
e74257aacb
@ -38,6 +38,7 @@ import fileio
|
||||
word setpfx
|
||||
word getfileinfo
|
||||
word geteof
|
||||
word openbuf
|
||||
word open
|
||||
word close
|
||||
word read
|
||||
|
@ -27,6 +27,7 @@ struc t_fileio
|
||||
word setpfx
|
||||
word getfileinfo
|
||||
word geteof
|
||||
word openbuf
|
||||
word open
|
||||
word close
|
||||
word read
|
||||
@ -37,7 +38,7 @@ struc t_fileio
|
||||
word readblock
|
||||
word writeblock
|
||||
end
|
||||
predef a2getpfx(path), a23setpfx(path), a2getfileinfo(path, fileinfo), a23geteof(refnum), a2open(path), a23close(refnum)
|
||||
predef a2getpfx(path), a23setpfx(path), a2getfileinfo(path, fileinfo), a23geteof(refnum), a2openbuf(path, iobuf), a2open(path), a23close(refnum)
|
||||
predef a23read(refnum, buf, len), a2write(refnum, buf, len), a2create(path, type, aux), a23destroy(path)
|
||||
predef a23newline(refnum, emask, nlchar), a2readblock(unit, buf, block), a2writeblock(unit, buf, block)
|
||||
//
|
||||
@ -126,6 +127,15 @@ def a1open(path)
|
||||
*CFFA1FileName = path
|
||||
return 0
|
||||
end
|
||||
def a2openbuf(path, iobuf)
|
||||
byte params[6]
|
||||
params.0 = 3
|
||||
params:1 = path
|
||||
params:3 = iobuf
|
||||
params.5 = 0
|
||||
perr = syscall($C8, @params)
|
||||
return params.5
|
||||
end
|
||||
def a2open(path)
|
||||
byte params[6]
|
||||
params.0 = 3
|
||||
@ -135,6 +145,17 @@ def a2open(path)
|
||||
perr = syscall($C8, @params)
|
||||
return params.5
|
||||
end
|
||||
def a3openbuf(path, iobuf)
|
||||
byte params[7]
|
||||
|
||||
params.0 = 4
|
||||
params:1 = path
|
||||
params.3 = 0
|
||||
params:4 = iobuf
|
||||
params.6 = 0
|
||||
perr = syscall($C8, @params)
|
||||
return params.3
|
||||
end
|
||||
def a3open(path)
|
||||
byte params[7]
|
||||
|
||||
|
@ -71,7 +71,7 @@ TXTTYPE = .TXT
|
||||
#SYSTYPE = \#FF2000
|
||||
#TXTTYPE = \#040000
|
||||
|
||||
all: $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVM802) $(PLVM03) $(CMD) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(LONGJMP) $(ED) $(MON) $(ROD) $(SIEVE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(ROGUEIO) $(HGR1) $(TONE) $(DGR) $(DGRTEST) $(FILEIO) $(CONIO) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(SANE) $(FPSTR) $(FPU) $(SANITY) $(RPNCALC)
|
||||
all: $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVM802) $(PLVM03) $(CMD) $(PLASMAPLASM) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(LONGJMP) $(ED) $(MON) $(ROD) $(SIEVE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(ROGUEIO) $(HGR1) $(TONE) $(DGR) $(DGRTEST) $(FILEIO) $(CONIO) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(SANE) $(FPSTR) $(FPU) $(SANITY) $(RPNCALC)
|
||||
|
||||
clean:
|
||||
-rm *FE1000 *FF2000 $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVM03)
|
||||
|
@ -750,6 +750,7 @@ void emit_brnch(int tag)
|
||||
}
|
||||
void emit_breq(int tag)
|
||||
{
|
||||
emit_pending_seq();
|
||||
printf("\t%s\t$3C\t\t\t; BREQ\t_B%03d\n", DB, tag);
|
||||
printf("\t%s\t_B%03d-*\n", DW, tag);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -124,7 +124,7 @@ def scan
|
||||
constval = ^scanptr
|
||||
wend
|
||||
fin
|
||||
if ^(scanptr + 1) <> '\''; exit_err(@bad_cnst); fin
|
||||
if ^(scanptr + 1) <> '\''; exit_err(ERR_INVAL|ERR_CONST); fin
|
||||
scanptr = scanptr + 2
|
||||
break
|
||||
is '"'
|
||||
@ -155,7 +155,7 @@ def scan
|
||||
strconst++
|
||||
scanptr++
|
||||
loop
|
||||
if !^scanptr; exit_err(@bad_cnst); fin
|
||||
if !^scanptr; exit_err(ERR_INVAL|ERR_CONST); fin
|
||||
constval = @strconst
|
||||
scanptr++
|
||||
break
|
||||
@ -228,7 +228,7 @@ def scan
|
||||
scanptr++
|
||||
fin
|
||||
break
|
||||
is ':
|
||||
is ':'
|
||||
if ^(scanptr + 1) == ':'
|
||||
token = TRIELSE_TKN;
|
||||
scanptr = scanptr + 2
|
||||
@ -290,18 +290,18 @@ def nextln
|
||||
else
|
||||
if token <> EOL_TKN or token <> EOF_TKN; exit_err("Extraneous characters"); fin
|
||||
scanptr = inbuff
|
||||
instr = fileio:read(refnum, inbuff, 127)
|
||||
^instr = fileio:read(refnum, inbuff, 127)
|
||||
if instr
|
||||
^(inbuff + instr + 1) = 0 // NULL terminate string
|
||||
lineno++
|
||||
if !(lineno & $0F); putc('.'); fin
|
||||
if scan == INCLUDE_TKN
|
||||
if incref; exit_err("Nested INCLUDEs not allowed"); fin
|
||||
if scan <> STRING_TKN; exit_err("Missing INCLUDE file"); fin
|
||||
if scan <> STR_TKN; exit_err("Missing INCLUDE file"); fin
|
||||
incfile = scanptr - constval
|
||||
memcpy(@incfile + 1, constval, incfile)
|
||||
sysincbuf = heapallocalign(1024, 256)
|
||||
incref = fileio:opensys(@incfile, sysincbuf)
|
||||
sysincbuf = heapallocalign(1024, 8, @sysincfre)
|
||||
incref = fileio:openbuf(@incfile, sysincbuf)
|
||||
if not incref; exit_err("Unable to open INCLUDE file"); fin
|
||||
fileio:newline(incref, $7F, $0D)
|
||||
refnum = incref
|
||||
@ -312,8 +312,8 @@ def nextln
|
||||
fin
|
||||
else
|
||||
if refnum == incref
|
||||
fileio:close(incnum)
|
||||
heaprelease(sysincbuf)
|
||||
fileio:close(incref)
|
||||
heaprelease(sysincfre)
|
||||
incref = 0
|
||||
refnum = srcref
|
||||
parsefile = srcfile
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,165 +1,171 @@
|
||||
include "inc/cmdsys.plh"
|
||||
include "inc/args.plh"
|
||||
include "inc/fileio.plh"
|
||||
include "inc/longjmp.plh"
|
||||
//
|
||||
// Tokens
|
||||
//
|
||||
const ID_TKN = $D6 // V
|
||||
const CHR_TKN = $C3 // C
|
||||
const INT_TKN = $C9 // I
|
||||
const STR_TKN = $D3 // S
|
||||
const EOL_TKN = $02
|
||||
const EOF_TKN = $01
|
||||
const ERR_TKN = $00
|
||||
const ID_TKN = $D6 // V
|
||||
const CHR_TKN = $C3 // C
|
||||
const INT_TKN = $C9 // I
|
||||
const STR_TKN = $D3 // S
|
||||
const EOL_TKN = $02
|
||||
const EOF_TKN = $01
|
||||
const ERR_TKN = $00
|
||||
//
|
||||
//Ternary operand operators
|
||||
//
|
||||
const TERNARY_TOKEN = $BF // ?
|
||||
const TRIELSE_TOKEN = $DF // _
|
||||
const TERNARY_TKN = $BF // ?
|
||||
const TRIELSE_TKN = $DF // _
|
||||
//
|
||||
// Binary operand operators
|
||||
//
|
||||
const SET_TKN = $BD // =
|
||||
const ADD_TKN = $AB // +
|
||||
const SUB_TKN = $AD // -
|
||||
const MUL_TKN = $AA // *
|
||||
const DIV_TKN = $AF // /
|
||||
const MOD_TKN = $A5 // %
|
||||
const OR_TKN = $FC // |
|
||||
const EOR_TKN = $DE // ^
|
||||
const AND_TKN = $A6 // &
|
||||
const SHR_TKN = $D2 // R
|
||||
const SHL_TKN = $CC // L
|
||||
const GT_TKN = $BE // >
|
||||
const GE_TKN = $C8 // H
|
||||
const LT_TKN = $BC // <
|
||||
const LE_TKN = $C2 // B
|
||||
const NE_TKN = $D5 // U
|
||||
const EQ_TKN = $C5 // E
|
||||
const LOGIC_AND_TKN = $CE // N
|
||||
const LOGIC_OR_TKN = $CF // O
|
||||
const SET_TKN = $BD // =
|
||||
const ADD_TKN = $AB // +
|
||||
const SUB_TKN = $AD // -
|
||||
const MUL_TKN = $AA // *
|
||||
const DIV_TKN = $AF // /
|
||||
const MOD_TKN = $A5 // %
|
||||
const OR_TKN = $FC // |
|
||||
const EOR_TKN = $DE // ^
|
||||
const AND_TKN = $A6 // &
|
||||
const SHR_TKN = $D2 // R
|
||||
const SHL_TKN = $CC // L
|
||||
const GT_TKN = $BE // >
|
||||
const GE_TKN = $C8 // H
|
||||
const LT_TKN = $BC // <
|
||||
const LE_TKN = $C2 // B
|
||||
const NE_TKN = $D5 // U
|
||||
const EQ_TKN = $C5 // E
|
||||
const LOGIC_AND_TKN = $CE // N
|
||||
const LOGIC_OR_TKN = $CF // O
|
||||
//
|
||||
// Unary operand operators
|
||||
//
|
||||
const AT_TKN = $C0 // @
|
||||
const DOT_TKN = $AE // .
|
||||
const COLON_TKN = $BA // :
|
||||
const NEG_TKN = $AD // -
|
||||
const POUND_TKN = $A3 // #
|
||||
const COMP_TKN = $FE // ~
|
||||
const LOGIC_NOT_TKN = $A1 // !
|
||||
const BPTR_TKN = $DE // ^
|
||||
const WPTR_TKN = $AA // *
|
||||
const PTRB_TKN = $D8 // X
|
||||
const PTRW_TKN = $D7 // W
|
||||
const INC_TKN = $C1 // A
|
||||
const DEC_TKN = $C4 // D
|
||||
const AT_TKN = $C0 // @
|
||||
const DOT_TKN = $AE // .
|
||||
const COLON_TKN = $BA // :
|
||||
const NEG_TKN = $AD // -
|
||||
const POUND_TKN = $A3 // #
|
||||
const COMP_TKN = $FE // ~
|
||||
const LOGIC_NOT_TKN = $A1 // !
|
||||
const BPTR_TKN = $DE // ^
|
||||
const WPTR_TKN = $AA // *
|
||||
const PTRB_TKN = $D8 // X
|
||||
const PTRW_TKN = $D7 // W
|
||||
const INC_TKN = $C1 // A
|
||||
const DEC_TKN = $C4 // D
|
||||
const LAMBDA_TKN = $A6 // &
|
||||
//
|
||||
// Enclosure tokens
|
||||
//
|
||||
const OPEN_PAREN_TKN = $A8 // (
|
||||
const CLOSE_PAREN_TKN = $A9 // )
|
||||
const OPEN_BRACKET_TKN = $DB // [
|
||||
const CLOSE_BRACKET_TKN = $DD // ]
|
||||
const OPEN_PAREN_TKN = $A8 // (
|
||||
const CLOSE_PAREN_TKN = $A9 // )
|
||||
const OPEN_BRACKET_TKN = $DB // [
|
||||
const CLOSE_BRACKET_TKN = $DD // ]
|
||||
//
|
||||
// Misc. tokens
|
||||
//
|
||||
const COMMA_TKN = $AC // ,
|
||||
//const COMMENT_TKN = $BB // //
|
||||
const DROP_TKN = $BB
|
||||
const COMMA_TKN = $AC // ,
|
||||
//const COMMENT_TKN = $BB // //
|
||||
const DROP_TKN = $BB
|
||||
//
|
||||
// Keyword tokens
|
||||
//
|
||||
const CONST_TKN = $80
|
||||
const BYTE_TKN = $81
|
||||
const WORD_TKN = $82
|
||||
const IF_TKN = $83
|
||||
const ELSEIF_TKN = $84
|
||||
const ELSE_TKN = $85
|
||||
const FIN_TKN = $86
|
||||
const END_TKN = $87
|
||||
const WHILE_TKN = $88
|
||||
const LOOP_TKN = $89
|
||||
const CASE_TKN = $8A
|
||||
const OF_TKN = $8B
|
||||
const DEFAULT_TKN = $8C
|
||||
const ENDCASE_TKN = $8D
|
||||
const FOR_TKN = $8E
|
||||
const TO_TKN = $8F
|
||||
const DOWNTO_TKN = $90
|
||||
const STEP_TKN = $91
|
||||
const NEXT_TKN = $92
|
||||
const REPEAT_TKN = $93
|
||||
const UNTIL_TKN = $94
|
||||
const DEF_TKN = $95
|
||||
const STRUC_TKN = $96
|
||||
const SYSFLAGS_TKN = $97
|
||||
const DONE_TKN = $98
|
||||
const RETURN_TKN = $99
|
||||
const BREAK_TKN = $9A
|
||||
const CONT_TKN = $9B
|
||||
const PREDEF_TKN = $9C
|
||||
const IMPORT_TKN = $9D
|
||||
const EXPORT_TKN = $9E
|
||||
const INCLUDE_TKN = $9F
|
||||
const CONST_TKN = $80
|
||||
const BYTE_TKN = $81
|
||||
const WORD_TKN = $82
|
||||
const IF_TKN = $83
|
||||
const ELSEIF_TKN = $84
|
||||
const ELSE_TKN = $85
|
||||
const FIN_TKN = $86
|
||||
const END_TKN = $87
|
||||
const WHILE_TKN = $88
|
||||
const LOOP_TKN = $89
|
||||
const CASE_TKN = $8A
|
||||
const OF_TKN = $8B
|
||||
const DEFAULT_TKN = $8C
|
||||
const ENDCASE_TKN = $8D
|
||||
const FOR_TKN = $8E
|
||||
const TO_TKN = $8F
|
||||
const DOWNTO_TKN = $90
|
||||
const STEP_TKN = $91
|
||||
const NEXT_TKN = $92
|
||||
const REPEAT_TKN = $93
|
||||
const UNTIL_TKN = $94
|
||||
const DEF_TKN = $95
|
||||
const STRUC_TKN = $96
|
||||
const SYSFLAGS_TKN = $97
|
||||
const DONE_TKN = $98
|
||||
const RETURN_TKN = $99
|
||||
const BREAK_TKN = $9A
|
||||
const CONT_TKN = $9B
|
||||
const PREDEF_TKN = $9C
|
||||
const IMPORT_TKN = $9D
|
||||
const EXPORT_TKN = $9E
|
||||
const INCLUDE_TKN = $9F
|
||||
//
|
||||
// Types
|
||||
//
|
||||
const CONST_TYPE = $01
|
||||
const BYTE_TYPE = $02
|
||||
const WORD_TYPE = $04
|
||||
const VAR_TYPE = $06 // (WORD_TYPE | BYTE_TYPE)
|
||||
const FUNC_TYPE = $08
|
||||
const FUNC_CONST_TYPE = $09
|
||||
const ADDR_TYPE = $0E // (VAR_TYPE | FUNC_TYPE)
|
||||
const LOCAL_TYPE = $10
|
||||
const BPTR_TYPE = $20
|
||||
const WPTR_TYPE = $40
|
||||
const PTR_TYPE = $60 // (BPTR_TYPE | WPTR_TYPE)
|
||||
const XBYTE_TYPE = $22 // (BPTR_TYPE | BYTE_TYPE)
|
||||
const XWORD_TYPE = $44 // (WPTR_TYPE | WORD_TYPE)
|
||||
const CONSTADDR_TYPE = $61 // (CONST_TYPE | PTR_TYPE)
|
||||
const STR_TYPE = $80
|
||||
const GLOBAL_TYPE = $0000
|
||||
const CONST_TYPE = $0001
|
||||
const BYTE_TYPE = $0002
|
||||
const WORD_TYPE = $0004
|
||||
const VAR_TYPE = $0006 // (WORD_TYPE | BYTE_TYPE)
|
||||
const FUNC_TYPE = $0008
|
||||
const FUNC_CONST_TYPE = $0009
|
||||
const ADDR_TYPE = $000E // (VAR_TYPE | FUNC_TYPE)
|
||||
const LOCAL_TYPE = $0010
|
||||
const BPTR_TYPE = $0020
|
||||
const WPTR_TYPE = $0040
|
||||
const PTR_TYPE = $0060 // (BPTR_TYPE | WPTR_TYPE)
|
||||
const XBYTE_TYPE = $0022 // (BPTR_TYPE | BYTE_TYPE)
|
||||
const XWORD_TYPE = $0044 // (WPTR_TYPE | WORD_TYPE)
|
||||
const CONSTADDR_TYPE = $0061 // (CONST_TYPE | PTR_TYPE)
|
||||
const STR_TYPE = $0080
|
||||
const PREDEF_TYPE = $0100
|
||||
const EXTERN_TYPE = $0200
|
||||
const EXPORT_TYPE = $0400
|
||||
//
|
||||
// Keywords
|
||||
//
|
||||
byte keywrds = "IF", IF_TKN
|
||||
byte = "TO", TO_TKN
|
||||
byte = "IS", OF_TKN
|
||||
byte = "OR", LOGIC_OR_TKN
|
||||
byte = "FOR", FOR_TKN
|
||||
byte = "FIN", FIN_TKN
|
||||
byte = "DEF", DEF_TKN
|
||||
byte = "END", END_TKN
|
||||
byte = "AND", LOGIC_AND_TKN
|
||||
byte = "NOT", LOGIC_NOT_TKN
|
||||
byte = "BYTE", BYTE_TKN
|
||||
byte = "WORD", WORD_TKN
|
||||
byte = "ELSE", ELSE_TKN
|
||||
byte = "NEXT", NEXT_TKN
|
||||
byte = "WHEN", CASE_TKN
|
||||
byte = "LOOP", LOOP_TKN
|
||||
byte = "STEP", STEP_TKN
|
||||
byte = "DONE", DONE_TKN
|
||||
byte = "WEND", ENDCASE_TKN
|
||||
byte = "DROP", DROP_TKN
|
||||
byte = "CONST", CONST_TKN
|
||||
byte = "STRUC", STRUC_TKN
|
||||
byte = "ELSIF", ELSEIF_TKN
|
||||
byte = "WHILE", WHILE_TKN
|
||||
byte = "UNTIL", UNTIL_TKN
|
||||
byte = "BREAK", BREAK_TKN
|
||||
byte = "IMPORT", IMPORT_TKN
|
||||
byte = "EXPORT", EXPORT_TKN
|
||||
byte = "DOWNTO", DOWNTO_TKN
|
||||
byte = "REPEAT", REPEAT_TKN
|
||||
byte = "RETURN", RETURN_TKN
|
||||
byte = "PREDEF", PREDEF_TKN
|
||||
byte = "INCLUDE", INCLUDE_TKN
|
||||
byte = "CONTINUE", CONT_TKN
|
||||
byte = "SYSFLAGS", SYSFLAGS_TKN
|
||||
byte = "OTHERWISE",DEFAULT_TKN
|
||||
byte = $FF
|
||||
byte keywrds = "IF", IF_TKN
|
||||
byte = "TO", TO_TKN
|
||||
byte = "IS", OF_TKN
|
||||
byte = "OR", LOGIC_OR_TKN
|
||||
byte = "FOR", FOR_TKN
|
||||
byte = "FIN", FIN_TKN
|
||||
byte = "DEF", DEF_TKN
|
||||
byte = "END", END_TKN
|
||||
byte = "AND", LOGIC_AND_TKN
|
||||
byte = "NOT", LOGIC_NOT_TKN
|
||||
byte = "BYTE", BYTE_TKN
|
||||
byte = "WORD", WORD_TKN
|
||||
byte = "ELSE", ELSE_TKN
|
||||
byte = "NEXT", NEXT_TKN
|
||||
byte = "WHEN", CASE_TKN
|
||||
byte = "LOOP", LOOP_TKN
|
||||
byte = "STEP", STEP_TKN
|
||||
byte = "DONE", DONE_TKN
|
||||
byte = "WEND", ENDCASE_TKN
|
||||
byte = "DROP", DROP_TKN
|
||||
byte = "CONST", CONST_TKN
|
||||
byte = "STRUC", STRUC_TKN
|
||||
byte = "ELSIF", ELSEIF_TKN
|
||||
byte = "WHILE", WHILE_TKN
|
||||
byte = "UNTIL", UNTIL_TKN
|
||||
byte = "BREAK", BREAK_TKN
|
||||
byte = "IMPORT", IMPORT_TKN
|
||||
byte = "EXPORT", EXPORT_TKN
|
||||
byte = "DOWNTO", DOWNTO_TKN
|
||||
byte = "REPEAT", REPEAT_TKN
|
||||
byte = "RETURN", RETURN_TKN
|
||||
byte = "PREDEF", PREDEF_TKN
|
||||
byte = "INCLUDE", INCLUDE_TKN
|
||||
byte = "CONTINUE", CONT_TKN
|
||||
byte = "SYSFLAGS", SYSFLAGS_TKN
|
||||
byte = "OTHERWISE",DEFAULT_TKN
|
||||
byte = $FF
|
||||
//
|
||||
// Mathematical ops
|
||||
//
|
||||
@ -196,92 +202,132 @@ byte[16] sizestack
|
||||
byte[16] typestack
|
||||
word valsp = 0
|
||||
//
|
||||
// Generated code buffers
|
||||
// Constant code group
|
||||
//
|
||||
const databuff = $0C00
|
||||
const codebuff = $A900
|
||||
const codebuffsz = $1000
|
||||
const CONST_GROUP = $00
|
||||
const CONST_CODE = $2C
|
||||
const CONSTR_GROUP = $01
|
||||
const CONSTR_CODE = $2E
|
||||
//
|
||||
// Stack code group
|
||||
//
|
||||
const STACK_GROUP = $02
|
||||
const INDEXB_CODE = $02
|
||||
const ADD_CODE = $02
|
||||
const SUB_CODE = $04
|
||||
const MUL_CODE = $06
|
||||
const DIV_CODE = $08
|
||||
const MOD_CODE = $0A
|
||||
const INC_CODE = $0C
|
||||
const DEC_CODE = $0E
|
||||
const NEG_CODE = $10
|
||||
const COMP_CODE = $12
|
||||
const AND_CODE = $14
|
||||
const OR_CODE = $16
|
||||
const EOR_CODE = $18
|
||||
const SHL_CODE = $1A
|
||||
const SHR_CODE = $1C
|
||||
const INDEXW_CODE = $1E
|
||||
const LOGIC_NOT_CODE = $20
|
||||
const LOGIC_OR_CODE = $22
|
||||
const LOGIC_AND_CODE = $24
|
||||
const DROP_CODE = $30
|
||||
const DUP_CODE = $32
|
||||
const EQ_CODE = $40
|
||||
const NE_CODE = $42
|
||||
const GT_CODE = $44
|
||||
const LT_CODE = $46
|
||||
const GE_CODE = $48
|
||||
const LE_CODE = $4A
|
||||
const ICAL_CODE = $56
|
||||
const RET_CODE = $5C
|
||||
const LB_CODE = $60
|
||||
const BPTR_CODE = $60
|
||||
const LW_CODE = $62
|
||||
const WPTR_CODE = $62
|
||||
const SB_CODE = $70
|
||||
const SW_CODE = $72
|
||||
//
|
||||
// Local address code group
|
||||
//
|
||||
const LOCAL_GROUP = $03
|
||||
const LADDR_CODE = $28
|
||||
const LLB_CODE = $64
|
||||
const LLW_CODE = $66
|
||||
const DLB_CODE = $6C
|
||||
const DLW_CODE = $6E
|
||||
const SLB_CODE = $74
|
||||
const SLW_CODE = $76
|
||||
//
|
||||
// Global address code group
|
||||
//
|
||||
const GLOBAL_GROUP = $04
|
||||
const GADDR_CODE = $26
|
||||
const LAB_CODE = $68
|
||||
const LAW_CODE = $6A
|
||||
const SAB_CODE = $78
|
||||
const SAW_CODE = $7A
|
||||
const DAB_CODE = $7C
|
||||
const DAW_CODE = $7E
|
||||
const CALL_CODE = $54
|
||||
//
|
||||
// Relative address code group
|
||||
//
|
||||
const RELATIVE_GROUP = $05
|
||||
const BRFALSE_CODE = $4C
|
||||
const BRTRUE_CODE = $4E
|
||||
const BRNCH_CODE = $50
|
||||
//
|
||||
// Code tag address group
|
||||
//
|
||||
const CODETAG_GROUP = $06
|
||||
//
|
||||
// Symbol table variables
|
||||
//
|
||||
struc t_opseq
|
||||
byte opcode
|
||||
word opval
|
||||
byte opgroup
|
||||
word opval[]
|
||||
word optag
|
||||
word opoffsz
|
||||
byte optype
|
||||
word opoffset
|
||||
word opnext
|
||||
end
|
||||
const OPSEQNUM = 200
|
||||
struc t_id
|
||||
word idval
|
||||
byte idtype
|
||||
byte idname
|
||||
word idtype
|
||||
byte funcparms
|
||||
byte funcvals
|
||||
byte idname
|
||||
end
|
||||
const idglobal_tblsz = 2048
|
||||
const idlocal_tblsz = 512
|
||||
const idglobal_tbl = $1600
|
||||
const idlocal_tbl = $1E00
|
||||
const ctag_max = 1024
|
||||
const ctag_tbl = $800
|
||||
word globals = 0
|
||||
word datasize = 0
|
||||
word lastglobal
|
||||
byte locals = 0
|
||||
word framesize = 0
|
||||
word lastlocal
|
||||
byte lastop = $FF
|
||||
//
|
||||
// Generated code buffers
|
||||
//
|
||||
const IS_RESOLVED = $8000
|
||||
const IS_RELATIVE = $8000
|
||||
const IS_CTAG = $8000
|
||||
const MASK_CTAG = $7FFF
|
||||
const OPSEQNUM = 256
|
||||
const CTAGNUM = 1024
|
||||
const IDGLOBALSZ = 2048
|
||||
const IDLOCALSZ = 512
|
||||
word codetag = -1
|
||||
word codeptr, entrypoint
|
||||
word modsysflags = 0
|
||||
word idglobal_tbl, idlocal_tbl, ctag_tbl
|
||||
word freeop_lst, pending_seq
|
||||
word globals, lastglobal, lastlocal, savelast
|
||||
word codebufsz, datasize, framesize, savesize
|
||||
byte locals, savelocals
|
||||
word codebuff, codeptr, entrypoint
|
||||
word modsysflags
|
||||
byte[16] moddep_tbl[8]
|
||||
byte moddep_cnt
|
||||
predef emit_pending_seq#0
|
||||
//
|
||||
// Scanner variables
|
||||
// Compiler flags
|
||||
//
|
||||
const inbuff = $0200
|
||||
const instr = $01FF
|
||||
word scanptr = @nullstr
|
||||
byte scanchr, token, tknlen
|
||||
byte parserrpos, parserr = 0
|
||||
word tknptr, parserrln
|
||||
word constval
|
||||
word lineno = 0
|
||||
//
|
||||
// Compiler output messages
|
||||
//
|
||||
byte dup_id[] = "DUPLICATE IDENTIFIER"
|
||||
byte undecl_id[] = "UNDECLARED IDENTIFIER"
|
||||
byte bad_cnst[] = "BAD CONSTANT"
|
||||
byte bad_struc[] = "BAD STRUCTURE"
|
||||
byte bad_offset[] = "BAD STRUCT OFFSET"
|
||||
byte bad_decl[] = "BAD DECLARATION"
|
||||
byte bad_op[] = "BAD OPERATION"
|
||||
byte bad_stmnt[] = "BAD STATMENT"
|
||||
byte bad_expr[] = "BAD EXPRESSION"
|
||||
byte bad_syntax[] = "BAD SYNTAX"
|
||||
byte local_overflw[] = "LOCAL FRAME OVERFLOW"
|
||||
byte global_sym_overflw[] = "GLOBAL SYMBOL TABLE OVERFLOW"
|
||||
byte local_sym_overflw[] = "LOCAL SYMBOL TABLE OVERFLOW"
|
||||
byte ctag_full[] = "CODE LABEL OVERFLOW"
|
||||
byte no_ctag_offst[] = "CODE OFFSET NOT SUPPORTED"
|
||||
byte no_close_paren[] = "MISSING CLOSING PAREN"
|
||||
byte no_close_bracket[] = "MISSING CLOSING BRACKET"
|
||||
byte missing_op[] = "MISSING OPERAND"
|
||||
byte no_loop[] = "MISSING LOOP"
|
||||
byte no_until[] = "MISSING UNTIL"
|
||||
byte no_done[] = "MISSING DONE"
|
||||
byte no_local_init[] = "NO INITIALIZED LOCALS"
|
||||
//
|
||||
// Compiler optimizer flags
|
||||
//
|
||||
const OPTIMIZE = 1
|
||||
const OPTIMIZE2 = 2
|
||||
const NO_COMBINE = 4
|
||||
const OPTIMIZE = 1
|
||||
const OPTIMIZE2 = 2
|
||||
const NO_COMBINE = 4
|
||||
const WARNINGS = 8
|
||||
byte outflags
|
||||
//
|
||||
// ProDOS/SOS file references
|
||||
@ -290,25 +336,65 @@ byte refnum, srcref, incref
|
||||
byte[32] srcfile
|
||||
byte[32] incfile
|
||||
byte[32] relfile
|
||||
word parsefile // Pointer to current file
|
||||
word sysincbuf // System I/O buffer for include files
|
||||
word srcline // Saved source line number
|
||||
word parsefile // Pointer to current file
|
||||
word sysincbuf, sysincfre // System I/O buffer for include files
|
||||
word srcline // Saved source line number
|
||||
//
|
||||
// Scanner variables
|
||||
//
|
||||
const inbuff = $0200
|
||||
const instr = $01FF
|
||||
word scanptr = inbuff
|
||||
byte scanchr, token, tknlen
|
||||
word tknptr, parserrln
|
||||
word constval
|
||||
word lineno = 0
|
||||
//
|
||||
// Parser variables
|
||||
//
|
||||
const LVALUE = 0
|
||||
const RVALUE = 1
|
||||
const LAMBDANUM = 16
|
||||
byte[128] strconst
|
||||
byte infunc = 0
|
||||
byte stack_loop = 0
|
||||
byte prevstmnt = 0
|
||||
word infunvals = 0
|
||||
word retfunc_tag = 0
|
||||
word break_tag = 0
|
||||
word cont_tag = 0
|
||||
predef parse_constexpr#3, parse_expr(codeseq), parse_lambda
|
||||
byte infunc
|
||||
byte stack_loop
|
||||
byte prevstmnt
|
||||
word infuncvals
|
||||
word retfunc_tag
|
||||
word break_tag
|
||||
word cont_tag
|
||||
byte lambda_cnt, lambda_num
|
||||
byte[LAMBDANUM] lambda_id[8], lambda_cparms
|
||||
word[LAMBDANUM] lambda_seq
|
||||
word[LAMBDANUM] lambda_tag
|
||||
predef parse_constexpr#3, parse_expr(codeseq)#2, parse_lambda
|
||||
//
|
||||
// Arg pointer - overlay setjmp pointer
|
||||
//
|
||||
word[] arg
|
||||
//
|
||||
// Long jump environment
|
||||
//
|
||||
word exit
|
||||
//
|
||||
// Error string flags
|
||||
//
|
||||
const ERR_DUP = $0001
|
||||
const ERR_UNDECL = $0002
|
||||
const ERR_INVAL = $0004
|
||||
const ERR_MISS = $0008
|
||||
const ERR_OVER = $0010
|
||||
const ERR_CLOSE = $0020
|
||||
const ERR_LOCAL = $0040
|
||||
const ERR_GLOBAL = $0080
|
||||
const ERR_CODE = $0100
|
||||
const ERR_ID = $0200
|
||||
const ERR_CONST = $0400
|
||||
const ERR_INIT = $0800
|
||||
const ERR_STATE = $1000
|
||||
const ERR_FRAME = $2000
|
||||
const ERR_TABLE = $4000
|
||||
const ERR_SYNTAX = $8000
|
||||
|
||||
//=====================================
|
||||
//
|
||||
@ -327,20 +413,61 @@ def strcpy(dst, src)
|
||||
fin
|
||||
return ^dst
|
||||
end
|
||||
//
|
||||
// Error handler
|
||||
//
|
||||
def exit_err(errstr)#0
|
||||
def nametostr(namestr, len, strptr)#0
|
||||
^strptr = len
|
||||
memcpy(strptr + 1, namestr, len)
|
||||
end
|
||||
def putcurln#0
|
||||
puts(parsefile); putc('['); puti(lineno); puts("] ")
|
||||
end
|
||||
def putmrkr#0
|
||||
byte i
|
||||
|
||||
puts(parsefile); putc('['); puti(lineno); putc(']'); putc(':'); puts(errstr); putln
|
||||
putln
|
||||
puts(instr)
|
||||
for i = tknptr - inbuff - 1 downto 0
|
||||
for i = tknptr - inbuff downto 1
|
||||
putc(' ')
|
||||
next
|
||||
puts("^\n")
|
||||
end
|
||||
//
|
||||
// Error handler
|
||||
//
|
||||
def exit_err(err)#0
|
||||
byte i
|
||||
|
||||
putcurln
|
||||
puts("Error:")
|
||||
if err & ERR_DUP; puts("duplicate "); fin
|
||||
if err & ERR_UNDECL; puts("undeclared "); fin
|
||||
if err & ERR_INVAL; puts("invalid "); fin
|
||||
if err & ERR_MISS; puts("missing "); fin
|
||||
if err & ERR_OVER; puts("overflowed "); fin
|
||||
if err & ERR_CLOSE; puts("closing "); fin
|
||||
if err & ERR_LOCAL; puts("local "); fin
|
||||
if err & ERR_GLOBAL; puts("global "); fin
|
||||
if err & ERR_CODE; puts("code "); fin
|
||||
if err & ERR_ID; puts("identifier "); fin
|
||||
if err & ERR_CONST; puts("constant"); fin
|
||||
if err & ERR_INIT; puts("initializer"); fin
|
||||
if err & ERR_STATE; puts("statement"); fin
|
||||
if err * ERR_FRAME; puts("frame"); fin
|
||||
if err & ERR_TABLE; puts("table"); fin
|
||||
if err & ERR_SYNTAX; puts("syntax"); fin
|
||||
putmrkr
|
||||
fileio:close(0) // Close all open files
|
||||
longjump(exit, TRUE)
|
||||
longjmp(exit, TRUE)
|
||||
end
|
||||
//
|
||||
// Warning
|
||||
//
|
||||
def parse_warn(msg)#0
|
||||
if outflags & WARNINGS
|
||||
putcurln
|
||||
puts("Warning:")
|
||||
puts(msg)
|
||||
putmrkr
|
||||
fin
|
||||
end
|
||||
//
|
||||
// Include code to reduce size of this file
|
||||
@ -359,11 +486,13 @@ if ^arg and ^(arg + 1) == '-'
|
||||
outflags = outflags | OPTIMIZE
|
||||
arg++
|
||||
if ^arg == '2'
|
||||
outflags = outflags | OPTIMIZE
|
||||
outflags = outflags | OPTIMIZE2
|
||||
arg++
|
||||
fin
|
||||
elsif toupper(^arg) == 'N'
|
||||
outflags = outflags | NO_COMBINE
|
||||
elsif toupper(^arg) == 'W'
|
||||
outflags = outflags | WARNINGS
|
||||
else
|
||||
break
|
||||
fin
|
||||
@ -378,19 +507,36 @@ if arg
|
||||
fin
|
||||
fin
|
||||
if srcfile and relfile
|
||||
exit = heapalloc(t_longjmp)
|
||||
if not setjmp(exit)
|
||||
//
|
||||
// Parse source code module
|
||||
//
|
||||
parsemodule
|
||||
puts("Bytes compiled: "); puti(codeptr - codebuff); putln
|
||||
//
|
||||
// Write REL file
|
||||
//
|
||||
writerel
|
||||
srcref = fileio:open(@srcfile)
|
||||
if srcref
|
||||
fileio:newline(srcref, $7F, $0D)
|
||||
refnum = srcref
|
||||
parsefile = @srcfile
|
||||
exit = heapalloc(t_longjmp)
|
||||
if not setjmp(exit)
|
||||
//
|
||||
// Parse source code module
|
||||
//
|
||||
parse_module
|
||||
fileio:close(srcref)
|
||||
puts("Bytes compiled: "); puti(codeptr - codebuff); putln
|
||||
//
|
||||
// Write REL file
|
||||
//
|
||||
fileio:destroy(@relfile)
|
||||
fileio:create(@relfile, $FE, $1000) // full access, REL file
|
||||
srcref = fileio:open(@relfile)
|
||||
if srcref
|
||||
//writerel(srcref)
|
||||
fileio:close(srcref)
|
||||
else
|
||||
puts("Error opening: "); puts(@relfile); putln
|
||||
fin
|
||||
fin
|
||||
else
|
||||
puts("Error opening: "); puts(@srcfile); putln
|
||||
fin
|
||||
else
|
||||
puts("Usage: +PLASM [-O[2]] <srcfile> <relfile>\n")
|
||||
puts("Usage: +PLASM [-[W][O[2]][N]] <srcfile> <relfile>\n")
|
||||
fin
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user