Re: Homogeneous sequence
Pete Lomax wrote:
> Juergen Luethje wrote:
> > the program will crash instead of returning FALSE, in case 'foo' is
> > not an integer. In order to avoid that, currently we have to define the
> > type somehow like this:
> >
> > type char(object x)
> > return integer(x) and x >= 0 and x <= 255
> > end type
> >
> > What would that problem mean regarding the proposed extension of the type
> > system? Or maybe this behaviour can be changed, when the type system is
> > revised? I'd appreciate that.
> Good point. My proposal is useless without that change, I forgot that.
>
> I suspect this is a relatively easy change to try: Instead of emitting a
> TYPE_CHECK
> opcode at the top of a type definition, emit new opcodes which effect a return
> 0:
> Somewhere in parser.e you should find:
>
> if SymTab[p][S_TOKEN] = TYPE and param_num != 1 then
> CompileErr("types must have exactly one parameter")
> end if
>
> which seems the point to set a flag (change "and" to "then flag=1 if"), then
> after
>
> -- code to perform type checks on all the parameters
> sym = SymTab[p][S_NEXT]
> for i = 1 to SymTab[p][S_NUM_ARGS] do
> TypeCheck(sym)
> sym = SymTab[sym][S_NEXT]
> end for
>
> clear that flag. Within TypeCheck(), instead of
>
> emit_op(INTEGER_CHECK)
> emit_op(SEQUENCE_CHECK)
> emit_op(ATOM_CHECK)
> emit_op(TYPE_CHECK)
>
> when this flag is set emit some new opcodes which instead of (in execute.e):
>
> procedure opINTEGER_CHECK()
> a = Code[pc+1]
> if not integer(val[a]) then
> RTFatalType(pc+1)
> end if
> pc += 2
> end procedure
>
> do a hacked version of opRETURNP/F() (instead of RTFatal) to return 0.
>
> At that point, it got a bit too messy for a quick hack to carry on with right
> now, but if you get the gist
> give it a twirl.
>
> Obviously I am only suggesting an experiment on eu.ex/hll back-end, in pure
> Eu code, also obviously you cannot test the flag in opINTEGER_CHECK(), but
> need
> the new opcodes and new routines.
All this is a bit over my head.
> An interesting point would be whether you can find *ANY* working program that
> this change breaks, obviously I somewhat doubt it.
>
> > And what do you think about Pete's proposal:
> And what do you think about Pete's proposal?
My feeling says that it's really a good idea in order to avoid the
clutter demonstrated by Salix. By I think I don't have sufficient
knowledge to make a reasonable judgement.
Regards,
Juergen
|
Not Categorized, Please Help
|
|