Euphoria Ticket #657: Alternative Literal System

There are times that a number, is better represented by a string other than what comes from sprint(). Enumerated types give the interpreter a strong hint of how to express numbers.

Consider:

type enum season 
  spring, summer, fall, winter 
end type 
 
season birth = summer 

Now, if we do 'printf(1,"%d",{birth})' we get '2' printed to the screen and that is fine for that is what it is documented to do. But while debugging if we query 'birth', or in error reporting, or in general when we want to represent 'birth' as a season it would be nice if we could get 'summer' instead.

When declared an enumerated type is defined the interpreter is given an alternative set of literals. And when a variable is declared with that type as programmers we expect those literals to be used for assignment and comparison.

There are two ways I see to do this. You can attach the strings only to the enumerated type or it could also be put into yet another member for struct d and it would be available no matter how far nested in a sequence it is.

Consider cursor styles from the standard library. Consider interval names from date/time in the standard library. These literals make more sense to use when we know what they mean. Why not provide a way for the debuggers to get to them and for programmers to display them. The examples are numerous, so instead of duplicating the list of literals as strings in the code by the user programmer it would be convenient to see this happen in the language itself.

Details

Type: Feature Request Severity: Normal Category: Language
Assigned To: unknown Status: Fixed Reported Release: 4.0.2
Fixed in SVN #: View VCS: none Milestone: 4.1.0

1. Comment by mattlewis Apr 26, 2011

We'd probably need some sort of built-in that might work like:

type enum season  
  spring, summer, fall, winter  
end type  
  
season birth = summer  
printf(1, "%s\n", { name_of( season, birth ) } ) 

Other possibilities: to_string(), enum_name(), symbol_name().

For debuggers, I'm thinking to just give them a pointer to the symbol table, so they'll be able to look up whatever information they want (also to modify data).

2. Comment by SDPringle Jul 27, 2011

Unless we use routine_ids these are more like key words than built-ins.

3. Comment by SDPringle Sep 14, 2011

See: hg:euphoria/rev/23783000c80c

changeset: 5155:23783000c80c branch: alternative_literals tag: tip parent: 5132:9661ab6e18e5 user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Sep 14 10:43:12 2011 -0300 files: docs/builtins.txt docs/literals.txt docs/refman_2.txt include/euphoria/keywords.e source/dis.e source/global.e source/keylist.e source/literal_set.e source/parser.e tests/t_enum_type.e description: fixing ticket 657: Works with Euphoria Backend

4. Comment by SDPringle Sep 20, 2011

See: hg:euphoria/rev/4817b09dcaa2

changeset: 5159:4817b09dcaa2 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Mon Sep 19 21:11:00 2011 -0300 files: source/literal_set.e source/parser.e source/symtab.e description:

  • ticket 657
  • now works translated
  • most tests passing.

5. Comment by SDPringle Sep 20, 2011

See: hg:euphoria/rev/07b95619887f

changeset: 5160:07b95619887f branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Tue Sep 20 09:08:57 2011 -0300 files: source/parser.e description:

  • ticket 657
  • compiled interpreter works with name_of
  • works around problem with derefercing NOVALUE object before assignment.

6. Comment by SDPringle Sep 24, 2011

See: hg:euphoria/rev/7263623ec451

changeset: 5162:7263623ec451 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Sep 24 00:39:30 2011 -0300 files: source/literal_set.e source/parser.e tests/t_enum_type.e description:

  • ticket 657
  • optimized for some special cases
  • added more tests and documented unit test file t_enum_type

7. Comment by SDPringle Sep 24, 2011

See: hg:euphoria/rev/efe8238655c0

changeset: 5163:efe8238655c0 branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Sep 24 00:43:32 2011 -0300 files: source/parser.e description:

  • ticket 657
  • optimization

8. Comment by SDPringle Oct 23, 2011

See: hg:euphoria/rev/9f0570c2b759

changeset: 5178:9f0570c2b759 branch: alternative_literals parent: 5163:efe8238655c0 user: Shawn Pringle <shawn.pringle@gmail.com> date: Fri Oct 21 18:21:28 2011 -0300 files: docs/literals.txt description:

  • ticket 657
  • changed impossible example
  • corrected grammar

9. Comment by SDPringle Oct 23, 2011

See: hg:euphoria/rev/4f7a9854cc21

changeset: 5179:4f7a9854cc21 branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Sun Oct 23 21:24:53 2011 -0300 files: source/compile.e source/global.e source/literal_set.e source/parser.e description:

  • ticket 657
  • fixed tests with non-integer numbers by setting identical constants to the same double.

10. Comment by SDPringle Oct 28, 2011

See: hg:euphoria/rev/4e1a97f67bc4

changeset: 5198:4e1a97f67bc4 branch: alternative_literals parent: 5197:faa3e79de843 parent: 5177:c65c912af24b user: Shawn Pringle <shawn.pringle@gmail.com> date: Thu Oct 27 15:55:49 2011 -0300 files: include/std/math.e source/be_alloc.c source/configure source/literal_set.e source/parser.e description:

  • merge 4.0 changes into branch
  • set to use no optimizations
  • ticket 657

11. Comment by SDPringle Nov 12, 2011

See: hg:euphoria/rev/cb3ed0a9a899

changeset: 5227:cb3ed0a9a899 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Tue Nov 01 00:03:11 2011 -0300 files: source/parser.e description:

  • expression optimization
  • ticket 657

12. Comment by SDPringle Nov 12, 2011

See: hg:euphoria/rev/e4777e8e4c20

changeset: 5228:e4777e8e4c20 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Nov 12 17:55:38 2011 -0300 files: source/buildsys.e source/compile.e source/emit.e source/global.e source/literal_set.e source/msgtext.e source/parser.e source/symtab.e tests/manual/enumwarn.e tests/t_warning.e description:

  • implementing ticket 657
  • removed 'with trace' and trace(1) lines
  • removed debugging print lines
  • added a new test in tests/manual/enumwarn.e
  • added more tests to tests/t_warning.e
  • implemented warnings for ticket 657

13. Comment by SDPringle Nov 12, 2011

See: hg:euphoria/rev/e4777e8e4c20

changeset: 5228:e4777e8e4c20 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Nov 12 17:55:38 2011 -0300 files: source/buildsys.e source/compile.e source/emit.e source/global.e source/literal_set.e source/msgtext.e source/parser.e source/symtab.e tests/manual/enumwarn.e tests/t_warning.e description:

  • implementing ticket 657
  • removed 'with trace' and trace(1) lines
  • removed debugging print lines
  • added a new test in tests/manual/enumwarn.e
  • added more tests to tests/t_warning.e
  • implemented warnings for ticket 657

14. Comment by SDPringle Nov 12, 2011

See: hg:euphoria/rev/89921a54be27

changeset: 5230:89921a54be27 branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Nov 12 18:34:57 2011 -0300 files: source/global.e source/msgtext.e source/parser.e tests/manual/enumwarn.e description:

  • implementing ticket 657
  • customized warnings for mismatched in routine-calls

15. Comment by SDPringle Nov 30, 2011

See: hg:euphoria/rev/fd758a3f0045

changeset: 5295:fd758a3f0045 branch: alternative_literals tag: tip parent: 5277:4bb60a09af77 user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Nov 30 08:32:13 2011 -0300 files: source/be_rterror.c source/be_rterror.h description:

  • fixing ticket 657
  • now ex.err files generated with the backend written in C will include alternative literals.

16. Comment by SDPringle Dec 05, 2011

See: hg:euphoria/rev/17f1d82b3212

changeset: 5317:17f1d82b3212 branch: alternative_literals tag: tip parent: 5311:df94bf030c53 user: Shawn Pringle <shawn.pringle@gmail.com> date: Sun Dec 04 22:35:01 2011 -0300 files: source/global.e tests/t_c_name_of_not_enum_type.d/control.err tests/t_c_name_of_not_enum_type.e tests/t_c_name_of_not_udt.d/control.err tests/t_name_of.e description:

  • fixing ticket 657
  • completed merge with 4.0
  • fixed tests
  • removed an old out of date test

17. Comment by SDPringle Dec 13, 2011

See: hg:euphoria/rev/b5757f81ae34

changeset: 5345:b5757f81ae34 branch: alternative_literals parent: 5317:17f1d82b3212 user: Shawn Pringle <shawn.pringle@gmail.com> date: Tue Dec 13 22:38:18 2011 -0300 files: source/backend.e source/be_alloc.c source/be_alloc.h source/be_machine.c source/be_runtime.c source/be_runtime.h source/execute.h description:

  • moved sequence memory resizing to a new function ReNewS1
  • created a new machine function called M_SPRINT, which does the same as sprint
  • the new M_SPRINT function will allow us to implement name_of for non enumerated types
  • implements ticket 657

18. Comment by SDPringle Dec 22, 2011

See: hg:euphoria/rev/155cfd74b7e8

changeset: 5407:155cfd74b7e8 branch: alternative_literals tag: tip parent: 5346:bc18a94779c2 user: Shawn Pringle <shawn.pringle@gmail.com> date: Thu Dec 22 12:03:04 2011 -0300 files: docs/release/4.1.0.txt source/execute.e source/parser.e source/reswords.e source/reswords.h tests/t_c_name_of_expression.d/control.err tests/t_c_name_of_expression.e tests/t_c_name_of_fwd.d/control.err tests/t_c_name_of_fwd.e tests/t_c_name_of_not_enum_type.d/control.err tests/t_c_name_of_not_enum_type.e tests/t_c_name_of_not_udt.d/control.err tests/t_c_name_of_not_udt.e tests/t_name_of.e description:

  • changed tests to match documentation:
  • non-enumerated types should work the same as if you use sprint() on them.
  • modified code to handle non-enumerated types this way as well.
  • fixes ticket 657

19. Comment by SDPringle Jan 02, 2012

Marking as 'accepted' from 'fixed' due to a bug Matt Lewis pointed out.

20. Comment by SDPringle Jan 21, 2012

See: hg:euphoria/rev/9f04d252c763

changeset: 5470:9f04d252c763 branch: alternative_literals parent: 5424:de69dc611e16 user: Shawn Pringle <shawn.pringle@gmail.com> date: Tue Jan 03 10:17:35 2012 -0300 files: source/parser.e tests/enum_type.e tests/t_enum_type.e description:

  • removed trace code
  • added even more tests
  • handled negative type symbols as an error
  • still no fix for forward references
  • ticket 657

21. Comment by SDPringle Feb 06, 2012

See: hg:euphoria/rev/cf16e4efcc5a

changeset: 5497:cf16e4efcc5a branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Mon Feb 06 12:29:44 2012 -0300 files: source/parser.e tests/manual/enumwarn.e description:

  • fixed warnings for paramter passing into routines
  • added better, complete, and more up to date comments in tests/manual/enumwarn.e
  • ticket 657

22. Comment by SDPringle Feb 13, 2012

See: hg:euphoria/rev/fb4246c41a66

changeset: 5499:fb4246c41a66 branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Mon Feb 13 20:03:11 2012 -0300 files: source/fwdref.e source/parser.e tests/manual/enumwarn.e description:

  • attempting to add forward ref support for literal mismatch warnings
  • not yet translating
  • ticket 657

23. Comment by SDPringle Aug 29, 2012

See: hg:euphoria/rev/a418f3ba146b

changeset: 5625:a418f3ba146b branch: alternative_literals parent: 5498:8e845592c0fe user: Shawn Pringle <shawn.pringle@gmail.com> date: Sun Feb 19 01:01:08 2012 -0300 files: source/fwdref.e source/parser.e tests/manual/enum_type_fwd.e tests/manual/enumwarn.e tests/manual/t_enumwarn.e tests/manual/t_enumwarn_fwd.e description:

  • added a manual test for warnings involving forward references
  • added some support for forward referencing
  • tests passing
  • ticket 657

24. Comment by SDPringle Aug 29, 2012

See: hg:euphoria/rev/a8e3ce2af926

changeset: 5626:a8e3ce2af926 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Sun Feb 19 11:57:41 2012 -0300 files: include/std/console.e source/fwdref.e source/parser.e tests/manual/t_enumwarn_fwd.e description:

  • put boolean types for use in std/console.e
  • documented the status of builtins using forward references
  • four warnings working out of nine on t_enumwarn_fwd.e
  • all warnings working on t_enumwarn.e
  • t_enum_type.e tests working....
  • ticket 657

25. Comment by SDPringle Aug 29, 2012

See: hg:euphoria/rev/51321f5810a1

changeset: 5628:51321f5810a1 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Aug 25 19:14:46 2012 -0300 files: source/fwdref.e source/parser.e tests/manual/t_enumwarn_fwd.e description:

  • Now only one warning message isn't being printed to the screen.
  • modified the way data is stored for the 'test_literal_match_pair_key' property.
  • ticket 657

26. Comment by SDPringle Aug 29, 2012

See: hg:euphoria/rev/41393ed684b8

changeset: 5629:41393ed684b8 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Sun Aug 26 10:09:47 2012 -0300 files: source/fwdref.e source/shift.e description:

  • fixes alternative literal warnings for routine calls
  • fixes ticket 657

27. Comment by SDPringle Aug 29, 2012

See: hg:euphoria/rev/6420eeb0dcdd

changeset: 5633:6420eeb0dcdd branch: alternative_literals parent: 5631:caf6f3eba1de user: Shawn Pringle <shawn.pringle@gmail.com> date: Sun Aug 26 21:49:13 2012 -0300 files: source/Makefile.gnu source/fwdref.e description:

  • documented the property routines
  • prevented incorrect decrement of property_count
  • ticket 657

28. Comment by SDPringle Aug 29, 2012

See: hg:euphoria/rev/53e797bfb4c5

changeset: 5634:53e797bfb4c5 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Tue Aug 28 14:22:41 2012 -0300 files: docs/release/4.1.0.txt source/fwdref.e source/parser.e description:

  • added a little bit of encapsulation for storing values into the literal match pair data.
  • added comment about the warnings in the release notes.
  • fixes ticket 657

29. Comment by SDPringle Aug 31, 2012

See: hg:euphoria/rev/ef7177a7071e

changeset: 5636:ef7177a7071e branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Thu Aug 30 23:12:56 2012 -0300 files: source/backend.e source/be_machine.c source/be_runtime.c description:

  • 44 more unit test files now passing that were not passing before
  • ticket 657

30. Comment by SDPringle Aug 31, 2012

See: hg:euphoria/rev/2dab070bc00a

changeset: 5637:2dab070bc00a branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Fri Aug 31 08:47:58 2012 -0300 files: tests/t_c_749_goto.d/control.err description:

  • modified control.err file for it had extra blank lines
  • this fixes another test
  • ticket 657

31. Comment by SDPringle Jan 11, 2013

See: hg:euphoria/rev/49046500fcb9

changeset: 5914:49046500fcb9 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Nov 21 17:03:33 2012 -0300 files: docs/builtins.txt docs/manual.af description:

  • added FIXME comments for manual.af
  • fixed up builtins.txt to work with TeX
  • ticket 657

32. Comment by SDPringle Jan 11, 2013

See: hg:euphoria/rev/3b62b730124c

changeset: 5915:3b62b730124c branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Nov 21 18:11:08 2012 -0300 files: docs/manual.af include/std/console.e description:

  • changed 'type enum' to 'enum type' to keep TeX from crashing
  • removed FIXME lines in docs/manual.af
  • ticket 657

33. Comment by SDPringle Mar 12, 2013

See: hg:euphoria/rev/4709344bfea8

changeset: 6032:4709344bfea8 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Jan 23 17:07:30 2013 -0300 files: docs/builtins.txt docs/literals.txt docs/release/4.1.0.txt docs/whatsnew4_1.txt include/euphoria/keywords.e source/be_execute.c source/be_runtime.c source/compile.e source/dis.e source/emit.e source/keylist.e source/opnames.e source/redef.h source/reswords.e source/reswords.h source/shift.e description:

  • implemtnting a new builtin type_info
  • ticket 657

34. Comment by SDPringle Mar 12, 2013

See: hg:euphoria/rev/637d78adb1a4

changeset: 6035:637d78adb1a4 branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Mon Mar 11 09:27:26 2013 -0300 files: include/euphoria.h include/euphoria/keywords.e include/euphoria/symstruct.e source/backend.e source/be_execute.c source/be_symtab.c source/be_symtab.h source/compile.e source/dis.e source/emit.e source/execute.e source/execute.h source/inline.e source/keylist.e source/opnames.e source/opnames.h source/redef.h source/reswords.e source/reswords.h source/shift.e source/symtab.h description:

  • adding type_info() routine
  • type_info() works using the euphoria coded backend only
  • other implementations just fail with -1 returned.
  • t_filesys.e failing now but other tests pass.
  • ticket 657

35. Comment by SDPringle Mar 12, 2013

See: hg:euphoria/rev/331912a695df

changeset: 6036:331912a695df branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Tue Mar 12 22:59:28 2013 -0300 files: source/backend.e source/be_runtime.c source/be_symtab.c source/c_decl.e source/compile.e description:

  • set a CTypeInfo routine. Now works with translated code.
  • There is a stub now for interpreted code
  • For now returns the index to the symbol for the value in the Symtab table rather than the value itself.
  • ticket 657

36. Comment by SDPringle Mar 13, 2013

See: hg:euphoria/rev/81787a84d740

changeset: 6042:81787a84d740 branch: alternative_literals parent: 6036:331912a695df user: Shawn Pringle <shawn.pringle@gmail.com> date: Tue Mar 12 23:33:16 2013 -0300 files: docs/literals.txt docs/whatsnew4_1.txt description:

  • added documentation for type_info
  • ticket 657

37. Comment by SDPringle Mar 13, 2013

See: hg:euphoria/rev/efedb2a8fb1a

changeset: 6043:efedb2a8fb1a branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Mar 13 08:11:33 2013 -0300 files: source/be_symtab.c description:

  • comment fix
  • ticket 657

38. Comment by SDPringle Mar 16, 2013

See: hg:euphoria/rev/258c775b7471

changeset: 6054:258c775b7471 branch: alternative_literals parent: 6044:169cb40d3ce2 user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Mar 16 00:55:00 2013 -0300 files: source/backend.e source/be_symtab.c source/symtab.h description:

  • made type info work on interpreted code (in one case)
  • maybe fixes ticket 657
  • removed trace lines from the source

39. Comment by SDPringle Mar 16, 2013

See: hg:euphoria/rev/72aa8862b175

changeset: 6055:72aa8862b175 branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Mar 16 18:43:51 2013 -0300 files: source/backend.e source/be_symtab.c tests/t_enum_type.e description:

  • t_filesys.e still failing
  • now type_info tests working
  • ticket 657

40. Comment by SDPringle Aug 22, 2013

See: hg:euphoria/rev/03128935612e

changeset: 6150:03128935612e branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Aug 07 10:32:00 2013 -0300 files: source/be_rterror.c description:

  • prevent a crash when querying non initialized alternative literal variables
  • ticket 657

41. Comment by SDPringle Aug 22, 2013

See: hg:euphoria/rev/3286879ec568

changeset: 6151:3286879ec568 branch: alternative_literals tag: 4.1ALrc1 user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Aug 10 21:06:05 2013 -0300 files: source/compile.e source/parser.e tests/t_enum_type.e description:

  • moved code for type check routine generation lower down in the SubProg routine in parser.e. A short template for returning 0 is first used.
  • ticket 657

42. Comment by SDPringle Aug 22, 2013

See: hg:euphoria/rev/2de3012be819

changeset: 6153:2de3012be819 branch: alternative_literals parent: 6152:0f24c111565b parent: 6146:01eab55e774d user: Shawn Pringle <shawn.pringle@gmail.com> date: Tue Aug 20 13:41:41 2013 -0300 files: docs/manual.af docs/refman_2.txt docs/release/4.1.0.txt include/euphoria/keywords.e include/euphoria/symstruct.e include/std/dll.e include/std/machine.e packaging/slackware/euphoria-4.0.6-1.txt source/Makefile.gnu source/Makefile.wat source/backend.e source/be_alloc.c source/be_machine.c source/be_rterror.c source/be_runtime.c source/be_runtime.h source/be_socket.c source/buildsys.e source/compile.e source/configure source/execute.h source/global.e source/intinit.e source/msgtext.e source/symtab.e source/traninit.e description:

  • merged in trunk changes into alternative litearls
  • ticket 657

43. Comment by SDPringle Aug 22, 2013

See: hg:euphoria/rev/017e623bbb6c

changeset: 6154:017e623bbb6c branch: alternative_literals user: Shawn Pringle <shawn.pringle@gmail.com> date: Tue Aug 20 13:46:15 2013 -0300 files: tests/manual/README tests/manual/t_traced_enum_type.e description:

  • added a manual test for checking the trace screen
  • ticket 657

44. Comment by SDPringle Aug 22, 2013

See: hg:euphoria/rev/dea7b1c664c7

changeset: 6155:dea7b1c664c7 branch: alternative_literals tag: tip parent: 6147:2c63627c38f1 user: Shawn Pringle <shawn.pringle@gmail.com> date: Thu Aug 22 15:36:30 2013 -0300 description:

  • closing branch due to a bug we cannot squash (crashing t_filesys when translated and bound)
  • ticket 657

45. Comment by SDPringle Aug 24, 2013

See: hg:euphoria/rev/3a7020cebf5a

changeset: 6156:3a7020cebf5a branch: alternative_literals tag: tip parent: 6154:017e623bbb6c user: Shawn Pringle <shawn.pringle@gmail.com> date: Fri Aug 23 10:59:46 2013 -0300 files: source/literal_set.e description:

  • added comments to literal_set.e
  • ticket 657

46. Comment by SDPringle Aug 26, 2013

See: hg:euphoria/rev/62ae01f00a08

changeset: 6157:62ae01f00a08 branch: alternative_literals tag: tip user: Shawn Pringle <shawn.pringle@gmail.com> date: Mon Aug 26 12:05:01 2013 -0300 files: docs/literals.txt docs/manual.af docs/refman_2.txt description:

  • moved literals.txt text into refman_2.txt in order to get the TOC back in PDF build
  • ticket 657

Search



Quick Links

User menu

Not signed in.

Misc Menu